Skip to content

Commit

Permalink
Fix cipher updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Aug 10, 2018
1 parent 134b8c1 commit 91eb561
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type connectionError struct {

// Listen on addr for incoming connections.
func (port *SSPort) run(m metrics.ShadowsocksMetrics) {
go udpRemote(port.packetConn, port.keys, m)
// TODO: Register initial data metrics at zero.
go udpRemote(port.packetConn, &port.keys, m)
for {
var clientConn onet.DuplexConn
clientConn, err := port.listener.AcceptTCP()
Expand Down
9 changes: 5 additions & 4 deletions udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func unpack(dst, src []byte, ciphers map[string]shadowaead.Cipher) ([]byte, stri
}

// Listen on addr for encrypted packets and basically do UDP NAT.
func udpRemote(clientConn net.PacketConn, ciphers map[string]shadowaead.Cipher, m metrics.ShadowsocksMetrics) {
// We take the ciphers as a pointer because it gets replaced on config updates.
func udpRemote(clientConn net.PacketConn, ciphers *map[string]shadowaead.Cipher, m metrics.ShadowsocksMetrics) {
defer clientConn.Close()

nm := newNATmap(config.UDPTimeout, m)
Expand Down Expand Up @@ -78,9 +79,9 @@ func udpRemote(clientConn net.PacketConn, ciphers map[string]shadowaead.Cipher,
if err != nil {
return &connectionError{"ERR_READ", "Failed to read from client", err}
}
defer log.Printf("UDP done with %v", clientAddr.String())
log.Printf("Request from %v with %v bytes", clientAddr, clientProxyBytes)
buf, keyID, cipher, err := unpack(textBuf, cipherBuf[:clientProxyBytes], ciphers)
defer log.Printf("DEBUG UDP done with %v", clientAddr.String())
log.Printf("DEBUG UDP Request from %v with %v bytes", clientAddr, clientProxyBytes)
buf, keyID, cipher, err := unpack(textBuf, cipherBuf[:clientProxyBytes], *ciphers)
if err != nil {
return &connectionError{"ERR_CIPHER", "Failed to upack data from client", err}
}
Expand Down

0 comments on commit 91eb561

Please sign in to comment.