add bind for relay

This commit is contained in:
ginuerzh
2021-11-23 23:23:16 +08:00
parent 7beb5bf6d7
commit 98ef6c7492
18 changed files with 391 additions and 201 deletions

View File

@ -2,6 +2,7 @@ package forward
import (
"context"
"fmt"
"net"
"time"
@ -42,7 +43,7 @@ func (h *forwardHandler) Init(md md.Metadata) (err error) {
return h.parseMetadata(md)
}
// implements chain.Chainable interface
// WithChain implements chain.Chainable interface
func (h *forwardHandler) WithChain(chain *chain.Chain) {
h.chain = chain
}
@ -74,8 +75,13 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
return
}
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
h.logger = h.logger.WithFields(map[string]interface{}{
"dst": target.Addr(),
"dst": fmt.Sprintf("%s/%s", target.Addr(), network),
})
h.logger.Infof("%s >> %s", conn.RemoteAddr(), target.Addr())
@ -85,11 +91,6 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
WithRetry(h.md.retryCount).
WithLogger(h.logger)
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
cc, err := r.Dial(ctx, network, target.Addr())
if err != nil {
h.logger.Error(err)

View File

@ -2,6 +2,7 @@ package forward
import (
"context"
"fmt"
"net"
"time"
@ -68,8 +69,13 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
return
}
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
h.logger = h.logger.WithFields(map[string]interface{}{
"dst": target.Addr(),
"dst": fmt.Sprintf("%s/%s", target.Addr(), network),
})
h.logger.Infof("%s >> %s", conn.RemoteAddr(), target.Addr())
@ -79,11 +85,6 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn) {
WithRetry(h.md.retryCount).
WithLogger(h.logger)
network := "tcp"
if _, ok := conn.(net.PacketConn); ok {
network = "udp"
}
cc, err := r.Dial(ctx, network, target.Addr())
if err != nil {
h.logger.Error(err)