]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: only allocate peer queues once
authorJosh Bleecher Snyder <josh@tailscale.com>
Tue, 9 Feb 2021 17:08:17 +0000 (09:08 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 17:33:48 +0000 (18:33 +0100)
This serves two purposes.

First, it makes repeatedly stopping then starting a peer cheaper.
Second, it prevents a data race observed accessing the queues.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
device/peer.go

index 96481ee44c63de416014b5e68298f0ab6e0b9504..222c74f9a0702f1e41f9fd83d0c9c35aa4a221ac 100644 (file)
@@ -179,10 +179,10 @@ func (peer *Peer) Start() {
        peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
        peer.handshake.mutex.Unlock()
 
-       // prepare queues
-       peer.queue.outbound = newAutodrainingOutboundQueue(device)
-       peer.queue.inbound = newAutodrainingInboundQueue(device)
-       if peer.queue.staged == nil {
+       // prepare queues (once)
+       if peer.queue.outbound == nil {
+               peer.queue.outbound = newAutodrainingOutboundQueue(device)
+               peer.queue.inbound = newAutodrainingInboundQueue(device)
                peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize)
        }
        peer.device.queue.encryption.wg.Add(1) // keep encryption queue open for our writes