diff --git a/tunnel/freedom/client.go b/tunnel/freedom/client.go index ae00d02c6..b151ac21a 100644 --- a/tunnel/freedom/client.go +++ b/tunnel/freedom/client.go @@ -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" diff --git a/tunnel/freedom/conn.go b/tunnel/freedom/conn.go index 376984b02..ac0bd1a04 100644 --- a/tunnel/freedom/conn.go +++ b/tunnel/freedom/conn.go @@ -13,7 +13,6 @@ import ( const MaxPacketSize = 1024 * 8 type Conn struct { - socksClient *socks5.Client net.Conn } @@ -21,13 +20,6 @@ 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 } @@ -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) { @@ -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() +}