mirror of
https://github.com/SagerNet/sing-shadowsocks.git
synced 2025-04-04 04:17:39 +03:00
Improve udpnat write back
This commit is contained in:
parent
ee9be8af94
commit
e4d76a44eb
7 changed files with 40 additions and 64 deletions
|
@ -225,16 +225,16 @@ func (s *Service) newPacket(ctx context.Context, conn N.PacketConn, buffer *buf.
|
|||
|
||||
metadata.Protocol = "shadowsocks"
|
||||
metadata.Destination = destination
|
||||
s.udpNat.NewPacket(ctx, metadata.Source.AddrPort(), func() N.PacketWriter {
|
||||
return &serverPacketWriter{s, conn, metadata.Source}
|
||||
}, buffer, metadata)
|
||||
s.udpNat.NewPacket(ctx, metadata.Source.AddrPort(), buffer, metadata, func(natConn N.PacketConn) N.PacketWriter {
|
||||
return &serverPacketWriter{s, conn, natConn}
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
type serverPacketWriter struct {
|
||||
*Service
|
||||
N.PacketConn
|
||||
source M.Socksaddr
|
||||
source N.PacketConn
|
||||
nat N.PacketConn
|
||||
}
|
||||
|
||||
func (w *serverPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||
|
@ -250,5 +250,9 @@ func (w *serverPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socks
|
|||
common.KeepAlive(key)
|
||||
c.Seal(buffer.From(w.keySaltLength)[:0], rw.ZeroBytes[:c.NonceSize()], buffer.From(w.keySaltLength), nil)
|
||||
buffer.Extend(Overhead)
|
||||
return w.PacketConn.WritePacket(buffer, w.source)
|
||||
return w.source.WritePacket(buffer, M.SocksaddrFromNet(w.nat.LocalAddr()))
|
||||
}
|
||||
|
||||
func (w *serverPacketWriter) Upstream() any {
|
||||
return w.source
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue