Skip to content

Commit

Permalink
Add a constructor for packetConn so it can be re-used in `outline-s…
Browse files Browse the repository at this point in the history
…s-server`.
  • Loading branch information
sbruens committed Oct 18, 2024
1 parent 2cff9c6 commit 81a8db4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions transport/shadowsocks/packet_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (c *packetListener) ListenPacket(ctx context.Context) (net.PacketConn, erro
if err != nil {
return nil, fmt.Errorf("could not connect to endpoint: %w", err)
}
conn := packetConn{Conn: proxyConn, key: c.key}
return &conn, nil
return NewPacketConn(proxyConn, c.key), nil
}

type packetConn struct {
Expand All @@ -65,6 +64,10 @@ type packetConn struct {

var _ net.PacketConn = (*packetConn)(nil)

func NewPacketConn(conn net.Conn, key *EncryptionKey) net.PacketConn {
return &packetConn{Conn: conn, key: key}
}

// WriteTo encrypts `b` and writes to `addr` through the proxy.
func (c *packetConn) WriteTo(b []byte, addr net.Addr) (int, error) {
socksTargetAddr := socks.ParseAddr(addr.String())
Expand Down

0 comments on commit 81a8db4

Please sign in to comment.