summaryrefslogtreecommitdiffstats
path: root/device/receive.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-01-11 17:21:16 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-20 19:57:00 +0100
commit2fe19ce54db258d8c47ff03d8335fd28c7c7ad0f (patch)
tree6a38900d0ada9f5f8e3b8e92a38d9eaf8b5307fe /device/receive.go
parentdevice: put handshake buffer in pool in FlushPacketQueues (diff)
downloadwireguard-go-2fe19ce54db258d8c47ff03d8335fd28c7c7ad0f.tar.xz
wireguard-go-2fe19ce54db258d8c47ff03d8335fd28c7c7ad0f.zip
device: remove selects from encrypt/decrypt/inbound/outbound enqueuing
Block instead. Backpressure here is fine, probably preferable. This reduces code complexity. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/receive.go')
-rw-r--r--device/receive.go23
1 files changed, 3 insertions, 20 deletions
diff --git a/device/receive.go b/device/receive.go
index 20e0c8f..972b342 100644
--- a/device/receive.go
+++ b/device/receive.go
@@ -58,23 +58,6 @@ func (elem *QueueInboundElement) IsDropped() bool {
return atomic.LoadInt32(&elem.dropped) == AtomicTrue
}
-func (device *Device) addToInboundAndDecryptionQueues(inboundQueue chan *QueueInboundElement, decryptionQueue chan *QueueInboundElement, elem *QueueInboundElement) bool {
- select {
- case inboundQueue <- elem:
- select {
- case decryptionQueue <- elem:
- return true
- default:
- elem.Drop()
- elem.Unlock()
- return false
- }
- default:
- device.PutInboundElement(elem)
- return false
- }
-}
-
func (device *Device) addToHandshakeQueue(queue chan QueueHandshakeElement, elem QueueHandshakeElement) bool {
select {
case queue <- elem:
@@ -207,9 +190,9 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind conn.Bind) {
peer.queue.RLock()
if peer.isRunning.Get() {
- if device.addToInboundAndDecryptionQueues(peer.queue.inbound, device.queue.decryption.c, elem) {
- buffer = device.GetMessageBuffer()
- }
+ peer.queue.inbound <- elem
+ device.queue.decryption.c <- elem
+ buffer = device.GetMessageBuffer()
} else {
device.PutInboundElement(elem)
}