@@ -130,9 +130,7 @@ func (h *packetHandler) SetTargetIPValidator(targetIPValidator onet.TargetIPVali
130
130
// Listen on addr for encrypted packets and basically do UDP NAT.
131
131
// We take the ciphers as a pointer because it gets replaced on config updates.
132
132
func (h * packetHandler ) Handle (clientConn net.PacketConn ) {
133
- var running sync.WaitGroup
134
-
135
- nm := newNATmap (h .natTimeout , h .m , & running , h .logger )
133
+ nm := newNATmap (h .natTimeout , h .m , h .logger )
136
134
defer nm .Close ()
137
135
cipherBuf := make ([]byte , serverUDPBufferSize )
138
136
textBuf := make ([]byte , serverUDPBufferSize )
@@ -143,7 +141,6 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
143
141
break
144
142
}
145
143
146
- keyID := ""
147
144
var proxyTargetBytes int
148
145
var targetConn * natconn
149
146
@@ -171,7 +168,7 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
171
168
var textData []byte
172
169
var cryptoKey * shadowsocks.EncryptionKey
173
170
unpackStart := time .Now ()
174
- textData , keyID , cryptoKey , err = findAccessKeyUDP (ip , textBuf , cipherData , h .ciphers , h .logger )
171
+ textData , keyID , cryptoKey , err : = findAccessKeyUDP (ip , textBuf , cipherData , h .ciphers , h .logger )
175
172
timeToCipher := time .Since (unpackStart )
176
173
h .ssm .AddCipherSearch (err == nil , timeToCipher )
177
174
@@ -199,9 +196,6 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
199
196
return onet .NewConnectionError ("ERR_CIPHER" , "Failed to unpack data from client" , err )
200
197
}
201
198
202
- // The key ID is known with confidence once decryption succeeds.
203
- keyID = targetConn .keyID
204
-
205
199
var onetErr * onet.ConnectionError
206
200
if payload , tgtUDPAddr , onetErr = h .validatePacket (textData ); onetErr != nil {
207
201
return onetErr
@@ -256,7 +250,6 @@ func isDNS(addr net.Addr) bool {
256
250
type natconn struct {
257
251
net.PacketConn
258
252
cryptoKey * shadowsocks.EncryptionKey
259
- keyID string
260
253
metrics UDPConnMetrics
261
254
// NAT timeout to apply for non-DNS packets.
262
255
defaultTimeout time.Duration
@@ -320,11 +313,10 @@ type natmap struct {
320
313
logger * slog.Logger
321
314
timeout time.Duration
322
315
metrics UDPMetrics
323
- running * sync.WaitGroup
324
316
}
325
317
326
- func newNATmap (timeout time.Duration , sm UDPMetrics , running * sync. WaitGroup , l * slog.Logger ) * natmap {
327
- m := & natmap {logger : l , metrics : sm , running : running }
318
+ func newNATmap (timeout time.Duration , sm UDPMetrics , l * slog.Logger ) * natmap {
319
+ m := & natmap {logger : l , metrics : sm }
328
320
m .keyConn = make (map [string ]* natconn )
329
321
m .timeout = timeout
330
322
return m
@@ -336,11 +328,10 @@ func (m *natmap) Get(key string) *natconn {
336
328
return m .keyConn [key ]
337
329
}
338
330
339
- func (m * natmap ) set (key string , pc net.PacketConn , cryptoKey * shadowsocks.EncryptionKey , keyID string , connMetrics UDPConnMetrics ) * natconn {
331
+ func (m * natmap ) set (key string , pc net.PacketConn , cryptoKey * shadowsocks.EncryptionKey , connMetrics UDPConnMetrics ) * natconn {
340
332
entry := & natconn {
341
333
PacketConn : pc ,
342
334
cryptoKey : cryptoKey ,
343
- keyID : keyID ,
344
335
metrics : connMetrics ,
345
336
defaultTimeout : m .timeout ,
346
337
}
@@ -366,16 +357,14 @@ func (m *natmap) del(key string) net.PacketConn {
366
357
367
358
func (m * natmap ) Add (clientAddr net.Addr , clientConn net.PacketConn , cryptoKey * shadowsocks.EncryptionKey , targetConn net.PacketConn , keyID string ) * natconn {
368
359
connMetrics := m .metrics .AddUDPNatEntry (clientAddr , keyID )
369
- entry := m .set (clientAddr .String (), targetConn , cryptoKey , keyID , connMetrics )
360
+ entry := m .set (clientAddr .String (), targetConn , cryptoKey , connMetrics )
370
361
371
- m .running .Add (1 )
372
362
go func () {
373
- timedCopy (clientAddr , clientConn , entry , keyID , m .logger )
363
+ timedCopy (clientAddr , clientConn , entry , m .logger )
374
364
connMetrics .RemoveNatEntry ()
375
365
if pc := m .del (clientAddr .String ()); pc != nil {
376
366
pc .Close ()
377
367
}
378
- m .running .Done ()
379
368
}()
380
369
return entry
381
370
}
@@ -399,7 +388,7 @@ func (m *natmap) Close() error {
399
388
var maxAddrLen int = len (socks .ParseAddr ("[2001:db8::1]:12345" ))
400
389
401
390
// copy from target to client until read timeout
402
- func timedCopy (clientAddr net.Addr , clientConn net.PacketConn , targetConn * natconn , keyID string , l * slog.Logger ) {
391
+ func timedCopy (clientAddr net.Addr , clientConn net.PacketConn , targetConn * natconn , l * slog.Logger ) {
403
392
// pkt is used for in-place encryption of downstream UDP packets, with the layout
404
393
// [padding?][salt][address][body][tag][extra]
405
394
// Padding is only used if the address is IPv4.
0 commit comments