Skip to content

Commit

Permalink
fix socks5 outbound udp
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Jun 30, 2020
1 parent 9866c03 commit ae8e583
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions tunnel/freedom/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func (c *Client) DialPacket(tunnel.Tunnel) (tunnel.PacketConn, error) {
return nil, common.NewError("freedom recv invalid socks bind addr").Base(err)
}
return &SocksPacketConn{
PacketConn: packetConn,
socksAddr: socksAddr,
PacketConn: packetConn,
socksAddr: socksAddr,
socksClient: socksClient,
}, nil
}
network := "udp"
Expand Down
16 changes: 7 additions & 9 deletions tunnel/freedom/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ import (
const MaxPacketSize = 1024 * 8

type Conn struct {
socksClient *socks5.Client
net.Conn
}

func (c *Conn) Metadata() *tunnel.Metadata {
return nil
}

func (c *Conn) Close() error {
if c.socksClient != nil {
c.socksClient.Close()
}
return c.Conn.Close()
}

type PacketConn struct {
*net.UDPConn
}
Expand Down Expand Up @@ -66,7 +58,8 @@ func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (int, error) {

type SocksPacketConn struct {
net.PacketConn
socksAddr *net.UDPAddr
socksAddr *net.UDPAddr
socksClient *socks5.Client
}

func (c *SocksPacketConn) WriteWithMetadata(payload []byte, metadata *tunnel.Metadata) (int, error) {
Expand Down Expand Up @@ -102,3 +95,8 @@ func (c *SocksPacketConn) ReadWithMetadata(payload []byte) (int, *tunnel.Metadat
Address: addr,
}, nil
}

func (c *SocksPacketConn) Close() error {
c.socksClient.Close()
return c.PacketConn.Close()
}

0 comments on commit ae8e583

Please sign in to comment.