From c656877311735034b7d0af1e5182f0b366b27268 Mon Sep 17 00:00:00 2001 From: darthstren Date: Tue, 28 Oct 2025 15:53:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20APISendIP=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/panel/panel.go | 26 ++++++++++++++++++-------- conf/node.go | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/api/panel/panel.go b/api/panel/panel.go index 5d46915..cd202f8 100644 --- a/api/panel/panel.go +++ b/api/panel/panel.go @@ -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 } diff --git a/conf/node.go b/conf/node.go index 1d7bd91..df1d25c 100644 --- a/conf/node.go +++ b/conf/node.go @@ -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"` From 33b7faba5343f78c0dc2a8981c3b3983a43c86b9 Mon Sep 17 00:00:00 2001 From: LinboLen <5467712+LinboLen@users.noreply.github.com> Date: Wed, 3 Dec 2025 04:23:31 +0800 Subject: [PATCH 2/2] Merge pull request #120 from LinboLen/fix_limit_problem fix: adjust rate limiting to use actual bytes transferred --- common/rate/conn.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/rate/conn.go b/common/rate/conn.go index c94b041..5b3e68a 100644 --- a/common/rate/conn.go +++ b/common/rate/conn.go @@ -19,13 +19,19 @@ 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 } /*