summaryrefslogtreecommitdiffhomepage
path: root/device
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-02-10 00:21:12 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-10 00:21:12 +0100
commit5bf8d731273e0c03b84b6424f00e70b87afb248f (patch)
tree694d94e311359a72789e2387a9c992bc757bca12 /device
parent587a2b2a2028430893f14f9ac49e1efa5e3f8509 (diff)
device: create peer queues at peer creation time
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>
Diffstat (limited to 'device')
-rw-r--r--device/peer.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/device/peer.go b/device/peer.go
index 222c74f..40de59b 100644
--- a/device/peer.go
+++ b/device/peer.go
@@ -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()