]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: create channels.go
authorJosh Bleecher Snyder <josh@tailscale.com>
Mon, 8 Feb 2021 20:38:19 +0000 (12:38 -0800)
committerJosh Bleecher Snyder <josh@tailscale.com>
Mon, 8 Feb 2021 20:38:19 +0000 (12:38 -0800)
We have a bunch of stupid channel tricks, and I'm about to add more.
Give them their own file. This commit is 100% code movement.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
device/channels.go [new file with mode: 0644]
device/device.go

diff --git a/device/channels.go b/device/channels.go
new file mode 100644 (file)
index 0000000..4471477
--- /dev/null
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
+ */
+
+package device
+
+import "sync"
+
+// An outboundQueue is a channel of QueueOutboundElements awaiting encryption.
+// An outboundQueue is ref-counted using its wg field.
+// An outboundQueue created with newOutboundQueue has one reference.
+// Every additional writer must call wg.Add(1).
+// Every completed writer must call wg.Done().
+// When no further writers will be added,
+// call wg.Done to remove the initial reference.
+// When the refcount hits 0, the queue's channel is closed.
+type outboundQueue struct {
+       c  chan *QueueOutboundElement
+       wg sync.WaitGroup
+}
+
+func newOutboundQueue() *outboundQueue {
+       q := &outboundQueue{
+               c: make(chan *QueueOutboundElement, QueueOutboundSize),
+       }
+       q.wg.Add(1)
+       go func() {
+               q.wg.Wait()
+               close(q.c)
+       }()
+       return q
+}
+
+// A inboundQueue is similar to an outboundQueue; see those docs.
+type inboundQueue struct {
+       c  chan *QueueInboundElement
+       wg sync.WaitGroup
+}
+
+func newInboundQueue() *inboundQueue {
+       q := &inboundQueue{
+               c: make(chan *QueueInboundElement, QueueInboundSize),
+       }
+       q.wg.Add(1)
+       go func() {
+               q.wg.Wait()
+               close(q.c)
+       }()
+       return q
+}
+
+// A handshakeQueue is similar to an outboundQueue; see those docs.
+type handshakeQueue struct {
+       c  chan QueueHandshakeElement
+       wg sync.WaitGroup
+}
+
+func newHandshakeQueue() *handshakeQueue {
+       q := &handshakeQueue{
+               c: make(chan QueueHandshakeElement, QueueHandshakeSize),
+       }
+       q.wg.Add(1)
+       go func() {
+               q.wg.Wait()
+               close(q.c)
+       }()
+       return q
+}
index 52b0143874287e3b4aef13d6ae3677239451336c..b93ad22cb66040173126095ea5c476e099182d58 100644 (file)
@@ -133,67 +133,6 @@ func (device *Device) isUp() bool {
        return device.deviceState() == deviceStateUp
 }
 
-// An outboundQueue is a channel of QueueOutboundElements awaiting encryption.
-// An outboundQueue is ref-counted using its wg field.
-// An outboundQueue created with newOutboundQueue has one reference.
-// Every additional writer must call wg.Add(1).
-// Every completed writer must call wg.Done().
-// When no further writers will be added,
-// call wg.Done to remove the initial reference.
-// When the refcount hits 0, the queue's channel is closed.
-type outboundQueue struct {
-       c  chan *QueueOutboundElement
-       wg sync.WaitGroup
-}
-
-func newOutboundQueue() *outboundQueue {
-       q := &outboundQueue{
-               c: make(chan *QueueOutboundElement, QueueOutboundSize),
-       }
-       q.wg.Add(1)
-       go func() {
-               q.wg.Wait()
-               close(q.c)
-       }()
-       return q
-}
-
-// A inboundQueue is similar to an outboundQueue; see those docs.
-type inboundQueue struct {
-       c  chan *QueueInboundElement
-       wg sync.WaitGroup
-}
-
-func newInboundQueue() *inboundQueue {
-       q := &inboundQueue{
-               c: make(chan *QueueInboundElement, QueueInboundSize),
-       }
-       q.wg.Add(1)
-       go func() {
-               q.wg.Wait()
-               close(q.c)
-       }()
-       return q
-}
-
-// A handshakeQueue is similar to an outboundQueue; see those docs.
-type handshakeQueue struct {
-       c  chan QueueHandshakeElement
-       wg sync.WaitGroup
-}
-
-func newHandshakeQueue() *handshakeQueue {
-       q := &handshakeQueue{
-               c: make(chan QueueHandshakeElement, QueueHandshakeSize),
-       }
-       q.wg.Add(1)
-       go func() {
-               q.wg.Wait()
-               close(q.c)
-       }()
-       return q
-}
-
 /* Converts the peer into a "zombie", which remains in the peer map,
  * but processes no packets and does not exists in the routing table.
  *