]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: create peer queues at peer creation time
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 23:21:12 +0000 (00:21 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 23:21:12 +0000 (00:21 +0100)
Rather than racing with Start(), since we're never destroying these
queues, we just set the variables at creation time.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/peer.go

index 222c74f9a0702f1e41f9fd83d0c9c35aa4a221ac..40de59b636fec2ee2b2dc1bd35936b5fb9f11a25 100644 (file)
@@ -88,6 +88,9 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
 
        peer.cookieGenerator.Init(pk)
        peer.device = device
+       peer.queue.outbound = newAutodrainingOutboundQueue(device)
+       peer.queue.inbound = newAutodrainingInboundQueue(device)
+       peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize)
 
        // map public key
        _, ok := device.peers.keyMap[pk]
@@ -179,12 +182,6 @@ func (peer *Peer) Start() {
        peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))
        peer.handshake.mutex.Unlock()
 
-       // 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
 
        peer.timersStart()