aboutsummaryrefslogtreecommitdiffstats
path: root/send.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-01 16:59:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-01 17:46:28 +0200
commit168ef61a638e4875b260edbc51551bae0dc34ac3 (patch)
tree579a18ee07b9cf5427c9bab187707917215b7e5f /send.go
parentClear src cache if route changes to new ifindex (diff)
downloadwireguard-go-168ef61a638e4875b260edbc51551bae0dc34ac3.tar.xz
wireguard-go-168ef61a638e4875b260edbc51551bae0dc34ac3.zip
Add missing locks and fix debug output, and try to flush queues
Flushing queues on exit is sort of a partial solution, but this could be better. Really what we want is for no more packets to be enqueued after isUp is set to false.
Diffstat (limited to 'send.go')
-rw-r--r--send.go53
1 files changed, 39 insertions, 14 deletions
diff --git a/send.go b/send.go
index df8efdb..5c6b350 100644
--- a/send.go
+++ b/send.go
@@ -121,7 +121,11 @@ func (device *Device) RoutineReadFromTUN() {
logDebug := device.log.Debug
logError := device.log.Error
- logDebug.Println("Routine, TUN Reader started")
+ defer func() {
+ logDebug.Println("Routine: TUN reader - stopped")
+ }()
+
+ logDebug.Println("Routine: TUN reader - started")
for {
@@ -192,11 +196,11 @@ func (peer *Peer) RoutineNonce() {
defer func() {
peer.routines.stopping.Done()
- logDebug.Println(peer.String(), ": Routine, Nonce Worker, Stopped")
+ logDebug.Println(peer.String() + ": Routine: nonce worker - stopped")
}()
peer.routines.starting.Done()
- logDebug.Println(peer.String(), ": Routine, Nonce Worker, Started")
+ logDebug.Println(peer.String() + ": Routine: nonce worker - started")
for {
NextPacket:
@@ -204,7 +208,11 @@ func (peer *Peer) RoutineNonce() {
case <-peer.routines.stop.Wait():
return
- case elem := <-peer.queue.nonce:
+ case elem, ok := <-peer.queue.nonce:
+
+ if !ok {
+ return
+ }
// wait for key pair
@@ -218,13 +226,13 @@ func (peer *Peer) RoutineNonce() {
peer.signal.handshakeBegin.Send()
- logDebug.Println(peer.String(), ": Awaiting key-pair")
+ logDebug.Println(peer.String() + ": Awaiting key-pair")
select {
case <-peer.signal.newKeyPair.Wait():
- logDebug.Println(peer.String(), ": Obtained awaited key-pair")
+ logDebug.Println(peer.String() + ": Obtained awaited key-pair")
case <-peer.signal.flushNonceQueue.Wait():
- logDebug.Println(peer.String(), ": Flushing nonce queue")
+ logDebug.Println(peer.String() + ": Flushing nonce queue")
peer.FlushNonceQueue()
goto NextPacket
case <-peer.routines.stop.Wait():
@@ -258,7 +266,22 @@ func (device *Device) RoutineEncryption() {
var nonce [chacha20poly1305.NonceSize]byte
logDebug := device.log.Debug
- logDebug.Println("Routine, encryption worker, started")
+
+ defer func() {
+ for {
+ select {
+ case elem, ok := <-device.queue.encryption:
+ if ok {
+ elem.Drop()
+ }
+ default:
+ break
+ }
+ }
+ logDebug.Println("Routine: encryption worker - stopped")
+ }()
+
+ logDebug.Println("Routine: encryption worker - started")
for {
@@ -266,10 +289,13 @@ func (device *Device) RoutineEncryption() {
select {
case <-device.signal.stop.Wait():
- logDebug.Println("Routine, encryption worker, stopped")
return
- case elem := <-device.queue.encryption:
+ case elem, ok := <-device.queue.encryption:
+
+ if !ok {
+ return
+ }
// check if dropped
@@ -323,21 +349,20 @@ func (peer *Peer) RoutineSequentialSender() {
device := peer.device
logDebug := device.log.Debug
- logDebug.Println("Routine, sequential sender, started for", peer.String())
defer func() {
peer.routines.stopping.Done()
- logDebug.Println(peer.String(), ": Routine, Sequential sender, Stopped")
+ logDebug.Println(peer.String() + ": Routine: sequential sender - stopped")
}()
+ logDebug.Println(peer.String() + ": Routine: sequential sender - started")
+
peer.routines.starting.Done()
for {
select {
case <-peer.routines.stop.Wait():
- logDebug.Println(
- "Routine, sequential sender, stopped for", peer.String())
return
case elem, ok := <-peer.queue.outbound: