Skip to content

Commit ff61c9f

Browse files
authored
clean: remove unused keyID parameters (#223)
1 parent e1fd23b commit ff61c9f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

service/udp.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
141141
break
142142
}
143143

144-
keyID := ""
145144
var proxyTargetBytes int
146145
var targetConn *natconn
147146

@@ -169,7 +168,7 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
169168
var textData []byte
170169
var cryptoKey *shadowsocks.EncryptionKey
171170
unpackStart := time.Now()
172-
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)
173172
timeToCipher := time.Since(unpackStart)
174173
h.ssm.AddCipherSearch(err == nil, timeToCipher)
175174

@@ -197,9 +196,6 @@ func (h *packetHandler) Handle(clientConn net.PacketConn) {
197196
return onet.NewConnectionError("ERR_CIPHER", "Failed to unpack data from client", err)
198197
}
199198

200-
// The key ID is known with confidence once decryption succeeds.
201-
keyID = targetConn.keyID
202-
203199
var onetErr *onet.ConnectionError
204200
if payload, tgtUDPAddr, onetErr = h.validatePacket(textData); onetErr != nil {
205201
return onetErr
@@ -254,7 +250,6 @@ func isDNS(addr net.Addr) bool {
254250
type natconn struct {
255251
net.PacketConn
256252
cryptoKey *shadowsocks.EncryptionKey
257-
keyID string
258253
metrics UDPConnMetrics
259254
// NAT timeout to apply for non-DNS packets.
260255
defaultTimeout time.Duration
@@ -333,11 +328,10 @@ func (m *natmap) Get(key string) *natconn {
333328
return m.keyConn[key]
334329
}
335330

336-
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 {
337332
entry := &natconn{
338333
PacketConn: pc,
339334
cryptoKey: cryptoKey,
340-
keyID: keyID,
341335
metrics: connMetrics,
342336
defaultTimeout: m.timeout,
343337
}
@@ -363,10 +357,10 @@ func (m *natmap) del(key string) net.PacketConn {
363357

364358
func (m *natmap) Add(clientAddr net.Addr, clientConn net.PacketConn, cryptoKey *shadowsocks.EncryptionKey, targetConn net.PacketConn, keyID string) *natconn {
365359
connMetrics := m.metrics.AddUDPNatEntry(clientAddr, keyID)
366-
entry := m.set(clientAddr.String(), targetConn, cryptoKey, keyID, connMetrics)
360+
entry := m.set(clientAddr.String(), targetConn, cryptoKey, connMetrics)
367361

368362
go func() {
369-
timedCopy(clientAddr, clientConn, entry, keyID, m.logger)
363+
timedCopy(clientAddr, clientConn, entry, m.logger)
370364
connMetrics.RemoveNatEntry()
371365
if pc := m.del(clientAddr.String()); pc != nil {
372366
pc.Close()
@@ -394,7 +388,7 @@ func (m *natmap) Close() error {
394388
var maxAddrLen int = len(socks.ParseAddr("[2001:db8::1]:12345"))
395389

396390
// copy from target to client until read timeout
397-
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) {
398392
// pkt is used for in-place encryption of downstream UDP packets, with the layout
399393
// [padding?][salt][address][body][tag][extra]
400394
// Padding is only used if the address is IPv4.

0 commit comments

Comments
 (0)