merge: listener l01-l07

This commit is contained in:
Nixevol
2026-09-30 16:01:26 +08:00
19 changed files with 1068 additions and 107 deletions
+9 -4
View File
@@ -4,7 +4,9 @@ import (
"context"
"net"
"net/http"
"time"
"git.asio.asia/nixevol/NixMsg/internal/httpx"
"git.asio.asia/nixevol/NixMsg/internal/listener"
"github.com/coder/websocket"
)
@@ -30,12 +32,15 @@ func (b *Broker) WSHandler(proxies *listener.ProxySet) http.Handler {
defer cancel()
nc := websocket.NetConn(ctx, c, websocket.MessageBinary)
var nets []*net.IPNet
if proxies != nil {
ip := proxies.ClientIP(r)
if ip != "" {
nc = listener.WithRemoteAddr(nc, &net.TCPAddr{IP: net.ParseIP(ip)})
}
nets = proxies.IPNets()
}
ip := httpx.ClientIP(r, nets)
if parsed := net.ParseIP(ip); parsed != nil {
nc = listener.WithRemoteAddr(nc, &net.TCPAddr{IP: parsed})
}
_ = nc.SetReadDeadline(time.Now().Add(10 * time.Second))
_ = b.AttachWS(nc)
})
}