fix vk dc upstream socks
This commit is contained in:
1 parent
2dbc6ea1eb
commit
1dad19e6b6
2 files changed
+33
-2
No files matched your search
@@ -743,6 +743,7 @@ func main() {
|
||||
ur.readBufSize = readBuf
|
||||
ur.maxDCBuf = maxDCBuf
|
||||
ur.SetObfuscator(obf)
|
||||
ur.SetUpstreamSocks(*upstreamSocks, *upstreamUser, *upstreamPass)
|
||||
ur.OnConnected = func(tun tunnel.DataTunnel) {
|
||||
rb := tunnel.NewRelayBridge(tun, "creator", common.VP8BufSize, log.Printf)
|
||||
rb.SetUpstreamSocks(*upstreamSocks, *upstreamUser, *upstreamPass)
|
||||
|
||||
@@ -42,6 +42,7 @@ type TunnelRelay struct {
|
||||
|
||||
readBufSize int
|
||||
maxDCBuf uint64
|
||||
upstream *common.Socks5Upstream
|
||||
|
||||
mode string
|
||||
modeOnce sync.Once
|
||||
@@ -49,6 +50,10 @@ type TunnelRelay struct {
|
||||
|
||||
func (u *TunnelRelay) SetObfuscator(o *tunnel.TunnelObfuscator) { u.obf = o }
|
||||
|
||||
func (u *TunnelRelay) SetUpstreamSocks(addr, user, pass string) {
|
||||
u.upstream = common.NewSocks5Upstream(addr, user, pass)
|
||||
}
|
||||
|
||||
func NewTunnelRelay() *TunnelRelay {
|
||||
return &TunnelRelay{mode: "unknown"}
|
||||
}
|
||||
@@ -322,7 +327,13 @@ func (u *TunnelRelay) sendDCFrame(connID uint32, mt byte, payload []byte) {
|
||||
|
||||
func (u *TunnelRelay) connectTCP(connID uint32, addr string) {
|
||||
log.Printf("[dc] CONNECT %d -> %s", connID, common.MaskAddr(addr))
|
||||
conn, err := net.DialTimeout("tcp", addr, 10*time.Second)
|
||||
var conn net.Conn
|
||||
var err error
|
||||
if u.upstream != nil {
|
||||
conn, err = u.upstream.DialTCP(addr, 10*time.Second)
|
||||
} else {
|
||||
conn, err = net.DialTimeout("tcp", addr, 10*time.Second)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("[dc] CONNECT %d failed: %s", connID, common.MaskError(err))
|
||||
u.sendDCFrame(connID, tunnel.MsgConnectErr, []byte(common.MaskError(err)))
|
||||
@@ -384,6 +395,26 @@ func (u *TunnelRelay) handleUDP(connID uint32, payload []byte) {
|
||||
}
|
||||
addr := string(payload[1 : 1+addrLen])
|
||||
data := payload[1+addrLen:]
|
||||
resp := make([]byte, common.UDPBufSize)
|
||||
|
||||
if u.upstream != nil {
|
||||
session, err := u.upstream.UDPAssociate(10 * time.Second)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer session.Close()
|
||||
if err := session.WriteTo(data, addr); err != nil {
|
||||
return
|
||||
}
|
||||
session.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||
n, err := session.Read(resp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
u.sendDCFrame(connID, tunnel.MsgUDPReply, resp[:n])
|
||||
return
|
||||
}
|
||||
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -395,7 +426,6 @@ func (u *TunnelRelay) handleUDP(connID uint32, payload []byte) {
|
||||
defer conn.Close()
|
||||
conn.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
conn.Write(data)
|
||||
resp := make([]byte, common.UDPBufSize)
|
||||
n, err := conn.Read(resp)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user