mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
Merge branch 'dev_new' of github.com:wyx2685/V2bX into dev_new
This commit is contained in:
@@ -3,6 +3,7 @@ package panel
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
type Client struct {
|
||||
client *resty.Client
|
||||
APIHost string
|
||||
APISendIP string
|
||||
Token string
|
||||
NodeType string
|
||||
NodeId int
|
||||
@@ -29,7 +31,14 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(c *conf.ApiConfig) (*Client, error) {
|
||||
client := resty.New()
|
||||
var client *resty.Client
|
||||
if c.APISendIP != "" {
|
||||
client = resty.NewWithLocalAddr(&net.TCPAddr{
|
||||
IP: net.ParseIP(c.APISendIP),
|
||||
})
|
||||
} else {
|
||||
client = resty.New()
|
||||
}
|
||||
client.SetRetryCount(3)
|
||||
if c.Timeout > 0 {
|
||||
client.SetTimeout(time.Duration(c.Timeout) * time.Second)
|
||||
@@ -69,12 +78,13 @@ func New(c *conf.ApiConfig) (*Client, error) {
|
||||
"token": c.Key,
|
||||
})
|
||||
return &Client{
|
||||
client: client,
|
||||
Token: c.Key,
|
||||
APIHost: c.APIHost,
|
||||
NodeType: c.NodeType,
|
||||
NodeId: c.NodeID,
|
||||
UserList: &UserListBody{},
|
||||
AliveMap: &AliveMap{},
|
||||
client: client,
|
||||
Token: c.Key,
|
||||
APIHost: c.APIHost,
|
||||
APISendIP: c.APISendIP,
|
||||
NodeType: c.NodeType,
|
||||
NodeId: c.NodeID,
|
||||
UserList: &UserListBody{},
|
||||
AliveMap: &AliveMap{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -19,11 +19,17 @@ type Conn struct {
|
||||
}
|
||||
|
||||
func (c *Conn) Read(b []byte) (n int, err error) {
|
||||
c.limiter.Wait(int64(len(b)))
|
||||
return c.Conn.Read(b)
|
||||
n, err = c.Conn.Read(b)
|
||||
if n > 0 {
|
||||
c.limiter.Wait(int64(n))
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (c *Conn) Write(b []byte) (n int, err error) {
|
||||
c.limiter.Wait(int64(len(b)))
|
||||
return c.Conn.Write(b)
|
||||
n, err = c.Conn.Write(b)
|
||||
if n > 0 {
|
||||
c.limiter.Wait(int64(n))
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
@@ -25,6 +25,7 @@ type rawNodeConfig struct {
|
||||
|
||||
type ApiConfig struct {
|
||||
APIHost string `json:"ApiHost"`
|
||||
APISendIP string `json:"ApiSendIP"`
|
||||
NodeID int `json:"NodeID"`
|
||||
Key string `json:"ApiKey"`
|
||||
NodeType string `json:"NodeType"`
|
||||
|
||||
Reference in New Issue
Block a user