add rtcp
This commit is contained in:
@ -75,7 +75,7 @@ func (h *localForwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||
|
||||
h.logger.Infof("%s >> %s", conn.RemoteAddr(), target.Addr())
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
@ -105,9 +105,3 @@ func (h *localForwardHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||
}).
|
||||
Infof("%s >-< %s", conn.RemoteAddr(), target.Addr())
|
||||
}
|
||||
|
||||
func (h *localForwardHandler) parseMetadata(md md.Metadata) (err error) {
|
||||
h.md.readTimeout = md.GetDuration(readTimeout)
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
return
|
||||
}
|
||||
|
@ -2,14 +2,22 @@ package local
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
readTimeout = "readTimeout"
|
||||
retryCount = "retry"
|
||||
md "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
readTimeout time.Duration
|
||||
retryCount int
|
||||
}
|
||||
|
||||
func (h *localForwardHandler) parseMetadata(md md.Metadata) (err error) {
|
||||
const (
|
||||
readTimeout = "readTimeout"
|
||||
retryCount = "retry"
|
||||
)
|
||||
|
||||
h.md.readTimeout = md.GetDuration(readTimeout)
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
return
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
"github.com/go-gost/gost/pkg/bypass"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
@ -52,38 +51,6 @@ func (h *httpHandler) Init(md md.Metadata) error {
|
||||
return h.parseMetadata(md)
|
||||
}
|
||||
|
||||
func (h *httpHandler) parseMetadata(md md.Metadata) error {
|
||||
h.md.proxyAgent = md.GetString(proxyAgentKey)
|
||||
|
||||
if v, _ := md.Get(authsKey).([]interface{}); len(v) > 0 {
|
||||
authenticator := auth.NewLocalAuthenticator(nil)
|
||||
for _, auth := range v {
|
||||
if s, _ := auth.(string); s != "" {
|
||||
ss := strings.SplitN(s, ":", 2)
|
||||
if len(ss) == 1 {
|
||||
authenticator.Add(ss[0], "")
|
||||
} else {
|
||||
authenticator.Add(ss[0], ss[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.authenticator = authenticator
|
||||
}
|
||||
|
||||
if v := md.GetString(probeResistKey); v != "" {
|
||||
if ss := strings.SplitN(v, ":", 2); len(ss) == 2 {
|
||||
h.md.probeResist = &probeResist{
|
||||
Type: ss[0],
|
||||
Value: ss[1],
|
||||
Knock: md.GetString(knockKey),
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *httpHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
@ -209,7 +176,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
|
||||
req.Header.Del("Proxy-Authorization")
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
@ -1,13 +1,10 @@
|
||||
package http
|
||||
|
||||
import "github.com/go-gost/gost/pkg/auth"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
const (
|
||||
proxyAgentKey = "proxyAgent"
|
||||
authsKey = "auths"
|
||||
probeResistKey = "probeResist"
|
||||
knockKey = "knock"
|
||||
retryCount = "retry"
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
md "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
@ -17,6 +14,46 @@ type metadata struct {
|
||||
probeResist *probeResist
|
||||
}
|
||||
|
||||
func (h *httpHandler) parseMetadata(md md.Metadata) error {
|
||||
const (
|
||||
proxyAgentKey = "proxyAgent"
|
||||
authsKey = "auths"
|
||||
probeResistKey = "probeResist"
|
||||
knockKey = "knock"
|
||||
retryCount = "retry"
|
||||
)
|
||||
|
||||
h.md.proxyAgent = md.GetString(proxyAgentKey)
|
||||
|
||||
if v, _ := md.Get(authsKey).([]interface{}); len(v) > 0 {
|
||||
authenticator := auth.NewLocalAuthenticator(nil)
|
||||
for _, auth := range v {
|
||||
if s, _ := auth.(string); s != "" {
|
||||
ss := strings.SplitN(s, ":", 2)
|
||||
if len(ss) == 1 {
|
||||
authenticator.Add(ss[0], "")
|
||||
} else {
|
||||
authenticator.Add(ss[0], ss[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.authenticator = authenticator
|
||||
}
|
||||
|
||||
if v := md.GetString(probeResistKey); v != "" {
|
||||
if ss := strings.SplitN(v, ":", 2); len(ss) == 2 {
|
||||
h.md.probeResist = &probeResist{
|
||||
Type: ss[0],
|
||||
Value: ss[1],
|
||||
Knock: md.GetString(knockKey),
|
||||
}
|
||||
}
|
||||
}
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type probeResist struct {
|
||||
Type string
|
||||
Value string
|
||||
|
@ -1,88 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
chain *chain.Chain
|
||||
retries int
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
func (r *Router) WithChain(chain *chain.Chain) *Router {
|
||||
r.chain = chain
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Router) WithRetry(retries int) *Router {
|
||||
r.retries = retries
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Router) WithLogger(logger logger.Logger) *Router {
|
||||
r.logger = logger
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Router) Dial(ctx context.Context, network, address string) (conn net.Conn, err error) {
|
||||
count := r.retries + 1
|
||||
if count <= 0 {
|
||||
count = 1
|
||||
}
|
||||
r.logger.Debugf("dial: %s/%s", address, network)
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
route := r.chain.GetRouteFor(network, address)
|
||||
|
||||
if r.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
buf := bytes.Buffer{}
|
||||
for _, node := range route.Path() {
|
||||
fmt.Fprintf(&buf, "%s@%s > ", node.Name(), node.Addr())
|
||||
}
|
||||
fmt.Fprintf(&buf, "%s", address)
|
||||
r.logger.Debugf("route(retry=%d): %s", i, buf.String())
|
||||
}
|
||||
|
||||
conn, err = route.Dial(ctx, network, address)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
r.logger.Errorf("route(retry=%d): %s", i, err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Router) Connect(ctx context.Context) (conn net.Conn, err error) {
|
||||
count := r.retries + 1
|
||||
if count <= 0 {
|
||||
count = 1
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
route := r.chain.GetRoute()
|
||||
|
||||
if r.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
buf := bytes.Buffer{}
|
||||
for _, node := range route.Path() {
|
||||
fmt.Fprintf(&buf, "%s@%s > ", node.Name(), node.Addr())
|
||||
}
|
||||
r.logger.Debugf("route(retry=%d): %s", i, buf.String())
|
||||
}
|
||||
|
||||
conn, err = route.Connect(ctx)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
r.logger.Errorf("route(retry=%d): %s", i, err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks4"
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
"github.com/go-gost/gost/pkg/bypass"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
@ -108,7 +107,7 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
@ -142,19 +141,3 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
||||
func (h *socks4Handler) handleBind(ctx context.Context, conn net.Conn, req *gosocks4.Request) {
|
||||
// TODO: bind
|
||||
}
|
||||
|
||||
func (h *socks4Handler) parseMetadata(md md.Metadata) (err error) {
|
||||
if v, _ := md.Get(authsKey).([]interface{}); len(v) > 0 {
|
||||
authenticator := auth.NewLocalAuthenticator(nil)
|
||||
for _, auth := range v {
|
||||
if v, _ := auth.(string); v != "" {
|
||||
authenticator.Add(v, "")
|
||||
}
|
||||
}
|
||||
h.md.authenticator = authenticator
|
||||
}
|
||||
|
||||
h.md.readTimeout = md.GetDuration(readTimeout)
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
return
|
||||
}
|
||||
|
@ -4,12 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
)
|
||||
|
||||
const (
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
retryCount = "retry"
|
||||
md "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
@ -17,3 +12,25 @@ type metadata struct {
|
||||
readTimeout time.Duration
|
||||
retryCount int
|
||||
}
|
||||
|
||||
func (h *socks4Handler) parseMetadata(md md.Metadata) (err error) {
|
||||
const (
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
retryCount = "retry"
|
||||
)
|
||||
|
||||
if v, _ := md.Get(authsKey).([]interface{}); len(v) > 0 {
|
||||
authenticator := auth.NewLocalAuthenticator(nil)
|
||||
for _, auth := range v {
|
||||
if v, _ := auth.(string); v != "" {
|
||||
authenticator.Add(v, "")
|
||||
}
|
||||
}
|
||||
h.md.authenticator = authenticator
|
||||
}
|
||||
|
||||
h.md.readTimeout = md.GetDuration(readTimeout)
|
||||
h.md.retryCount = md.GetInt(retryCount)
|
||||
return
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks5"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
)
|
||||
|
||||
@ -19,12 +20,20 @@ func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, req *goso
|
||||
|
||||
h.logger.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
if !h.md.enableBind {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
reply.Write(conn)
|
||||
h.logger.Debug(reply)
|
||||
h.logger.Error("BIND is diabled")
|
||||
return
|
||||
}
|
||||
|
||||
if h.chain.IsEmpty() {
|
||||
h.bindLocal(ctx, conn, addr)
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
@ -83,7 +92,7 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, addr strin
|
||||
h.logger = h.logger.WithFields(map[string]interface{}{
|
||||
"bind": socksAddr.String(),
|
||||
})
|
||||
h.logger.Infof("bind on %s OK", socksAddr.String())
|
||||
h.logger.Debugf("bind on %s OK", &socksAddr)
|
||||
|
||||
h.serveBind(ctx, conn, ln)
|
||||
}
|
||||
@ -127,10 +136,19 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
||||
case err := <-accept():
|
||||
if err != nil {
|
||||
h.logger.Error(err)
|
||||
|
||||
reply := gosocks5.NewReply(gosocks5.Failure, nil)
|
||||
if err := reply.Write(pc2); err != nil {
|
||||
h.logger.Error(err)
|
||||
}
|
||||
h.logger.Debug(reply)
|
||||
|
||||
return
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
h.logger.Debugf("peer %s accepted", rc.RemoteAddr())
|
||||
|
||||
raddr := gosocks5.Addr{}
|
||||
raddr.ParseFrom(rc.RemoteAddr().String())
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &raddr)
|
||||
@ -138,7 +156,6 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
||||
h.logger.Error(err)
|
||||
}
|
||||
h.logger.Debug(reply)
|
||||
h.logger.Infof("peer accepted: %s", raddr.String())
|
||||
|
||||
start := time.Now()
|
||||
h.logger.Infof("%s <-> %s", conn.RemoteAddr(), raddr.String())
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks5"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
)
|
||||
|
||||
@ -24,7 +25,7 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, addr s
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
@ -90,29 +90,13 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn) {
|
||||
case gosocks5.CmdConnect:
|
||||
h.handleConnect(ctx, conn, req.Addr.String())
|
||||
case gosocks5.CmdBind:
|
||||
if h.md.enableBind {
|
||||
h.handleBind(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("BIND is diabled")
|
||||
}
|
||||
h.handleBind(ctx, conn, req)
|
||||
case socks.CmdMuxBind:
|
||||
if h.md.enableBind {
|
||||
h.handleMuxBind(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("BIND is diabled")
|
||||
}
|
||||
h.handleMuxBind(ctx, conn, req)
|
||||
case gosocks5.CmdUdp:
|
||||
if h.md.enableUDP {
|
||||
h.handleUDP(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
}
|
||||
h.handleUDP(ctx, conn, req)
|
||||
case socks.CmdUDPTun:
|
||||
if h.md.enableUDP {
|
||||
h.handleUDPTun(ctx, conn, req)
|
||||
} else {
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
}
|
||||
h.handleUDPTun(ctx, conn, req)
|
||||
default:
|
||||
h.logger.Errorf("unknown cmd: %d", req.Cmd)
|
||||
resp := gosocks5.NewReply(gosocks5.CmdUnsupported, nil)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks5"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
"github.com/go-gost/gost/pkg/internal/utils/mux"
|
||||
)
|
||||
@ -20,12 +21,20 @@ func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, req *g
|
||||
|
||||
h.logger.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
if !h.md.enableBind {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
reply.Write(conn)
|
||||
h.logger.Debug(reply)
|
||||
h.logger.Error("BIND is diabled")
|
||||
return
|
||||
}
|
||||
|
||||
if h.chain.IsEmpty() {
|
||||
h.muxBindLocal(ctx, conn, addr)
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
@ -90,14 +99,14 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, addr st
|
||||
h.logger = h.logger.WithFields(map[string]interface{}{
|
||||
"bind": socksAddr.String(),
|
||||
})
|
||||
h.logger.Infof("bind on: %s OK", socksAddr.String())
|
||||
h.logger.Debugf("bind on %s OK", &socksAddr)
|
||||
|
||||
h.serveMuxBind(ctx, conn, ln)
|
||||
}
|
||||
|
||||
func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.Listener) {
|
||||
// Upgrade connection to multiplex stream.
|
||||
session, err := mux.NewMuxSession(conn)
|
||||
session, err := mux.ClientSession(conn)
|
||||
if err != nil {
|
||||
h.logger.Error(err)
|
||||
return
|
||||
@ -122,7 +131,7 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
|
||||
h.logger.Error(err)
|
||||
return
|
||||
}
|
||||
h.logger.Infof("peer accepted: %s", rc.RemoteAddr().String())
|
||||
h.logger.Debugf("peer %s accepted", rc.RemoteAddr())
|
||||
|
||||
go func(c net.Conn) {
|
||||
defer c.Close()
|
||||
@ -134,6 +143,18 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
|
||||
}
|
||||
defer sc.Close()
|
||||
|
||||
// incompatible with GOST v2.x
|
||||
if !h.md.compatibilityMode {
|
||||
addr := gosocks5.Addr{}
|
||||
addr.ParseFrom(c.RemoteAddr().String())
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &addr)
|
||||
if err := reply.Write(sc); err != nil {
|
||||
h.logger.Error(err)
|
||||
return
|
||||
}
|
||||
h.logger.Debug(reply)
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
h.logger.Infof("%s <-> %s", conn.RemoteAddr(), c.RemoteAddr().String())
|
||||
handler.Transport(sc, c)
|
||||
|
@ -11,30 +11,32 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
tlsConfig *tls.Config
|
||||
authenticator auth.Authenticator
|
||||
timeout time.Duration
|
||||
readTimeout time.Duration
|
||||
retryCount int
|
||||
noTLS bool
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
tlsConfig *tls.Config
|
||||
authenticator auth.Authenticator
|
||||
timeout time.Duration
|
||||
readTimeout time.Duration
|
||||
retryCount int
|
||||
noTLS bool
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
compatibilityMode bool
|
||||
}
|
||||
|
||||
func (h *socks5Handler) parseMetadata(md md.Metadata) error {
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
timeout = "timeout"
|
||||
retryCount = "retry"
|
||||
noTLS = "notls"
|
||||
enableBind = "bind"
|
||||
enableUDP = "udp"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
authsKey = "auths"
|
||||
readTimeout = "readTimeout"
|
||||
timeout = "timeout"
|
||||
retryCount = "retry"
|
||||
noTLS = "notls"
|
||||
enableBind = "bind"
|
||||
enableUDP = "udp"
|
||||
udpBufferSize = "udpBufferSize"
|
||||
compatibilityMode = "comp"
|
||||
)
|
||||
|
||||
var err error
|
||||
@ -81,5 +83,7 @@ func (h *socks5Handler) parseMetadata(md md.Metadata) error {
|
||||
h.md.udpBufferSize = 4096 // default buffer size
|
||||
}
|
||||
|
||||
h.md.compatibilityMode = md.GetBool(compatibilityMode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks5"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/internal/bufpool"
|
||||
"github.com/go-gost/gost/pkg/internal/utils/socks"
|
||||
)
|
||||
@ -19,6 +19,14 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, req *gosoc
|
||||
"cmd": "udp",
|
||||
})
|
||||
|
||||
if !h.md.enableUDP {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
reply.Write(conn)
|
||||
h.logger.Debug(reply)
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
return
|
||||
}
|
||||
|
||||
relay, err := net.ListenUDP("udp", nil)
|
||||
if err != nil {
|
||||
h.logger.Error(err)
|
||||
@ -43,7 +51,7 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, req *gosoc
|
||||
h.logger = h.logger.WithFields(map[string]interface{}{
|
||||
"bind": saddr.String(),
|
||||
})
|
||||
h.logger.Infof("bind on %s OK", saddr.String())
|
||||
h.logger.Debugf("bind on %s OK", &saddr)
|
||||
|
||||
if h.chain.IsEmpty() {
|
||||
// serve as standard socks5 udp relay.
|
||||
@ -81,7 +89,7 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, req *gosoc
|
||||
}
|
||||
|
||||
func (h *socks5Handler) getUDPTun(ctx context.Context) (conn net.Conn, err error) {
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gosocks5"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
"github.com/go-gost/gost/pkg/internal/bufpool"
|
||||
"github.com/go-gost/gost/pkg/internal/utils/socks"
|
||||
@ -16,6 +17,14 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, req *go
|
||||
"cmd": "udp-tun",
|
||||
})
|
||||
|
||||
if !h.md.enableUDP {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
reply.Write(conn)
|
||||
h.logger.Debug(reply)
|
||||
h.logger.Error("UDP relay is diabled")
|
||||
return
|
||||
}
|
||||
|
||||
if h.chain.IsEmpty() {
|
||||
addr := req.Addr.String()
|
||||
|
||||
@ -56,7 +65,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, req *go
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
@ -123,7 +123,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/gost/pkg/handler"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/internal/bufpool"
|
||||
"github.com/go-gost/gost/pkg/internal/utils/socks"
|
||||
"github.com/go-gost/gost/pkg/internal/utils/ss"
|
||||
@ -17,7 +17,7 @@ func (h *ssHandler) handleUDP(ctx context.Context, raddr net.Addr, conn net.Pack
|
||||
}
|
||||
|
||||
// obtain a udp connection
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
@ -51,7 +51,7 @@ func (h *ssHandler) handleUDP(ctx context.Context, raddr net.Addr, conn net.Pack
|
||||
|
||||
func (h *ssHandler) handleUDPTun(ctx context.Context, conn net.Conn) {
|
||||
// obtain a udp connection
|
||||
r := (&handler.Router{}).
|
||||
r := (&chain.Router{}).
|
||||
WithChain(h.chain).
|
||||
WithRetry(h.md.retryCount).
|
||||
WithLogger(h.logger)
|
||||
|
Reference in New Issue
Block a user