From: Simon Ruderich <simon@ruderich.org>
To: wireguard@lists.zx2c4.com
Subject: [PATCH 10/12] receive, send: specialize addTo*Queue() functions
Date: Mon, 1 Jan 2018 11:53:00 +0100 [thread overview]
Message-ID: <c7aee3fff3e7b0c0845b19efb4ecd84ff94f8a6f.1514803815.git.simon@ruderich.org> (raw)
In-Reply-To: <cover.1514803815.git.simon@ruderich.org>
In-Reply-To: <cover.1514803815.git.simon@ruderich.org>
As each function is only used with a single queue, this removes an
unnecessary argument and prevents passing the wrong queue.
---
src/receive.go | 23 ++++++++---------------
src/send.go | 8 +++-----
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/src/receive.go b/src/receive.go
index 2c4f191..f5cbe74 100644
--- a/src/receive.go
+++ b/src/receive.go
@@ -37,10 +37,8 @@ func (elem *QueueInboundElement) IsDropped() bool {
return elem.dropped.Get()
}
-func (device *Device) addToInboundQueue(
- queue chan *QueueInboundElement,
- element *QueueInboundElement,
-) {
+func (peer *Peer) addToInboundQueue(element *QueueInboundElement) {
+ queue := peer.queue.inbound
for {
select {
case queue <- element:
@@ -55,10 +53,8 @@ func (device *Device) addToInboundQueue(
}
}
-func (device *Device) addToDecryptionQueue(
- queue chan *QueueInboundElement,
- element *QueueInboundElement,
-) {
+func (device *Device) addToDecryptionQueue(element *QueueInboundElement) {
+ queue := device.queue.decryption
for {
select {
case queue <- element:
@@ -75,10 +71,8 @@ func (device *Device) addToDecryptionQueue(
}
}
-func (device *Device) addToHandshakeQueue(
- queue chan QueueHandshakeElement,
- element QueueHandshakeElement,
-) {
+func (device *Device) addToHandshakeQueue(element QueueHandshakeElement) {
+ queue := device.queue.handshake
for {
select {
case queue <- element:
@@ -183,8 +177,8 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind Bind) {
// add to decryption queues
- device.addToDecryptionQueue(device.queue.decryption, elem)
- device.addToInboundQueue(peer.queue.inbound, elem)
+ device.addToDecryptionQueue(elem)
+ peer.addToInboundQueue(elem)
buffer = device.GetMessageBuffer()
continue
@@ -203,7 +197,6 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind Bind) {
if okay {
device.addToHandshakeQueue(
- device.queue.handshake,
QueueHandshakeElement{
msgType: msgType,
buffer: buffer,
diff --git a/src/send.go b/src/send.go
index 163b75f..7f1f25c 100644
--- a/src/send.go
+++ b/src/send.go
@@ -88,10 +88,8 @@ func addToOutboundQueue(
}
}
-func addToEncryptionQueue(
- queue chan *QueueOutboundElement,
- element *QueueOutboundElement,
-) {
+func (device *Device) addToEncryptionQueue(element *QueueOutboundElement) {
+ queue := device.queue.encryption
for {
select {
case queue <- element:
@@ -231,7 +229,7 @@ func (peer *Peer) RoutineNonce() {
// add to parallel and sequential queue
- addToEncryptionQueue(device.queue.encryption, elem)
+ device.addToEncryptionQueue(elem)
addToOutboundQueue(peer.queue.outbound, elem)
}
}
--
2.15.1
next prev parent reply other threads:[~2018-01-01 10:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-01 10:52 [PATCH 00/12] Misc patches Simon Ruderich
2018-01-01 10:52 ` [PATCH 01/12] Fix typos in comments Simon Ruderich
2018-01-01 10:52 ` [PATCH 02/12] tun_linux: use getDummySock() Simon Ruderich
2018-01-01 10:52 ` [PATCH 03/12] receive, send: use AtomicBool for dropped in QueueInboundElement, QueueOutboundElement Simon Ruderich
2018-01-01 10:52 ` [PATCH 04/12] device: move removePeerUnsafe() into Device Simon Ruderich
2018-01-01 10:52 ` [PATCH 05/12] index: NewIndex(): don't use separate read-lock to check if index is present Simon Ruderich
2018-01-01 10:52 ` [PATCH 06/12] device: use UnderLoadAfterTime constant Simon Ruderich
2018-01-01 10:52 ` [PATCH 07/12] peer: NewPeer(): add missing device.mutex.Unlock() in error paths Simon Ruderich
2018-01-01 10:52 ` [PATCH 08/12] conn_linux: move comment to make its meaning more obvious Simon Ruderich
2018-01-01 10:52 ` [PATCH 09/12] ratelimiter: Allow(): don't use separate read-lock to check if ip is present Simon Ruderich
2018-01-01 10:53 ` Simon Ruderich [this message]
2018-01-01 10:53 ` [PATCH 11/12] noise_protocol: mixHash(): remove unnecessary Reset() Simon Ruderich
2018-01-01 10:53 ` [PATCH 12/12] timers: log error if handshake sending fails Simon Ruderich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c7aee3fff3e7b0c0845b19efb4ecd84ff94f8a6f.1514803815.git.simon@ruderich.org \
--to=simon@ruderich.org \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).