mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"github.com/v2rayA/v2rayA/db/configure"
|
|
"github.com/v2rayA/v2rayA/server/service"
|
|
)
|
|
|
|
func GetPingLatency(ctx *gin.Context) {
|
|
updatingMu.Lock()
|
|
if updating {
|
|
common.ResponseError(ctx, processingErr)
|
|
updatingMu.Unlock()
|
|
return
|
|
}
|
|
updating = true
|
|
updatingMu.Unlock()
|
|
defer func() {
|
|
updatingMu.Lock()
|
|
updating = false
|
|
updatingMu.Unlock()
|
|
}()
|
|
|
|
var wt []*configure.Which
|
|
err := jsoniter.Unmarshal([]byte(ctx.Query("whiches")), &wt)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError("bad request"))
|
|
return
|
|
}
|
|
wt, err = service.Ping(wt, 1*time.Second)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, gin.H{
|
|
"whiches": wt,
|
|
})
|
|
}
|
|
|
|
func GetHttpLatency(ctx *gin.Context) {
|
|
updatingMu.Lock()
|
|
if updating {
|
|
common.ResponseError(ctx, processingErr)
|
|
updatingMu.Unlock()
|
|
return
|
|
}
|
|
updating = true
|
|
updatingMu.Unlock()
|
|
defer func() {
|
|
updatingMu.Lock()
|
|
updating = false
|
|
updatingMu.Unlock()
|
|
}()
|
|
|
|
var wt []*configure.Which
|
|
err := jsoniter.Unmarshal([]byte(ctx.Query("whiches")), &wt)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError("bad request"))
|
|
return
|
|
}
|
|
wt, err = service.TestHttpLatency(wt, 8*time.Second, 32, false, ctx.Query("testUrl"))
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, gin.H{
|
|
"whiches": wt,
|
|
})
|
|
}
|