<feed xmlns='http://www.w3.org/2005/Atom'>
<title>wireguard-go/device/send.go, branch js/sample-api</title>
<subtitle>Go implementation of WireGuard</subtitle>
<id>https://git.zx2c4.com/wireguard-go/atom/device/send.go?h=js%2Fsample-api</id>
<link rel='self' href='https://git.zx2c4.com/wireguard-go/atom/device/send.go?h=js%2Fsample-api'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/'/>
<updated>2020-12-18T19:18:47Z</updated>
<entry>
<title>device: add missing colon to error line</title>
<updated>2020-12-18T19:18:47Z</updated>
<author>
<name>Jason A. Donenfeld</name>
<email>Jason@zx2c4.com</email>
</author>
<published>2020-12-18T10:52:13Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=85cb3597d05db8f7ac82460ef336563cc9d07d2d'/>
<id>urn:sha1:85cb3597d05db8f7ac82460ef336563cc9d07d2d</id>
<content type='text'>
People are actually hitting this condition, so make it uniform. Also,
change a printf into a println, to match the other conventions.

Signed-off-by: Jason A. Donenfeld &lt;Jason@zx2c4.com&gt;
</content>
</entry>
<entry>
<title>device: fix races from changing private_key</title>
<updated>2020-12-17T00:16:26Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-15T23:02:13Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=4bced36d327754ad9567eba450413c07ff80da72'/>
<id>urn:sha1:4bced36d327754ad9567eba450413c07ff80da72</id>
<content type='text'>
Access keypair.sendNonce atomically.
Eliminate one unnecessary initialization to zero.

Mutate handshake.lastSentHandshake with the mutex held.

Co-authored-by: David Anderson &lt;danderson@tailscale.com&gt;
Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: always name *Queue*Element variables elem</title>
<updated>2020-12-17T00:16:26Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-16T00:00:52Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=7d88fbd2177caccef40ab60c927f9539e723903e'/>
<id>urn:sha1:7d88fbd2177caccef40ab60c927f9539e723903e</id>
<content type='text'>
They're called elem in most places.
Rename a few local variables to make it consistent.
This makes it easier to grep the code for things like elem.Drop.

Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: use channel close to shut down and drain outbound channel</title>
<updated>2020-12-17T00:16:26Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-15T23:54:48Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=15af3e58ce918d4f68f3a85710e7252f5260d741'/>
<id>urn:sha1:15af3e58ce918d4f68f3a85710e7252f5260d741</id>
<content type='text'>
This is a similar treatment to the handling of the encryption
channel found a few commits ago: Use the closing of the channel
to manage goroutine lifetime and shutdown.
It is considerably simpler because there is only a single writer.

Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: use channel close to shut down and drain encryption channel</title>
<updated>2020-12-16T00:57:09Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-14T23:07:23Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=71ef21087e9f3d7154f003289ea297641d71e723'/>
<id>urn:sha1:71ef21087e9f3d7154f003289ea297641d71e723</id>
<content type='text'>
The new test introduced in this commit used to deadlock about 1% of the time.

I believe that the deadlock occurs as follows:

* The test completes, calling device.Close.
* device.Close closes device.signals.stop.
* RoutineEncryption stops.
* The deferred function in RoutineEncryption drains device.queue.encryption.
* RoutineEncryption exits.
* A peer's RoutineNonce processes an element queued in peer.queue.nonce.
* RoutineNonce puts that element into the outbound and encryption queues.
* RoutineSequentialSender reads that elements from the outbound queue.
* It waits for that element to get Unlocked by RoutineEncryption.
* RoutineEncryption has already exited, so RoutineSequentialSender blocks forever.
* device.RemoveAllPeers calls peer.Stop on all peers.
* peer.Stop waits for peer.routines.stopping, which blocks forever.

Rather than attempt to add even more ordering to the already complex
centralized shutdown orchestration, this commit moves towards a
data-flow-oriented shutdown.

The device.queue.encryption gets closed when there will be no more writes to it.
All device.queue.encryption readers always read until the channel is closed and then exit.
We thus guarantee that any element that enters the encryption queue also exits it.
This removes the need for central control of the lifetime of RoutineEncryption,
removes the need to drain the encryption queue on shutdown, and simplifies RoutineEncryption.

This commit also fixes a data race. When RoutineSequentialSender
drains its queue on shutdown, it needs to lock the elem before operating on it,
just as the main body does.

The new test in this commit passed 50k iterations with the race detector enabled
and 150k iterations with the race detector disabled, with no failures.

Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: remove starting waitgroups</title>
<updated>2020-12-10T21:37:10Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-10T19:25:08Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=5e92865404f56c6f7f2aaa784d2588f310d2d8a7'/>
<id>urn:sha1:5e92865404f56c6f7f2aaa784d2588f310d2d8a7</id>
<content type='text'>
In each case, the starting waitgroup did nothing but ensure
that the goroutine has launched.

Nothing downstream depends on the order in which goroutines launch,
and if the Go runtime scheduler is so broken that goroutines
don't get launched reasonably promptly, we have much deeper problems.

Given all that, simplify the code.

Passed a race-enabled stress test 25,000 times without failure.

Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: clear pointers when returning elems to pools</title>
<updated>2020-12-08T22:25:02Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-04T23:36:21Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=d3ff2d6b62b095f37582affe84e267d7e5be88c6'/>
<id>urn:sha1:d3ff2d6b62b095f37582affe84e267d7e5be88c6</id>
<content type='text'>
Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: use labeled for loop instead of goto</title>
<updated>2020-12-08T22:24:20Z</updated>
<author>
<name>Josh Bleecher Snyder</name>
<email>josh@tailscale.com</email>
</author>
<published>2020-12-04T22:26:51Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=01d3aaa7f418dd0ca86643ddcc8c82544cb8398b'/>
<id>urn:sha1:01d3aaa7f418dd0ca86643ddcc8c82544cb8398b</id>
<content type='text'>
Minor code cleanup; no functional changes.

Signed-off-by: Josh Bleecher Snyder &lt;josh@tailscale.com&gt;
</content>
</entry>
<entry>
<title>device: add write queue mutex for peer</title>
<updated>2020-11-18T13:22:15Z</updated>
<author>
<name>Haichao Liu</name>
<email>liuhaichao@bytedance.com</email>
</author>
<published>2020-11-18T12:53:22Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=913f68ce3820801e045632cb05c6f11e0df50b47'/>
<id>urn:sha1:913f68ce3820801e045632cb05c6f11e0df50b47</id>
<content type='text'>
fix panic: send on closed channel when remove peer

Signed-off-by: Haichao Liu &lt;liuhaichao@bytedance.com&gt;
Signed-off-by: Jason A. Donenfeld &lt;Jason@zx2c4.com&gt;
</content>
</entry>
<entry>
<title>device: rework padding calculation and don't shadow paddedSize</title>
<updated>2020-05-18T21:43:22Z</updated>
<author>
<name>Jason A. Donenfeld</name>
<email>Jason@zx2c4.com</email>
</author>
<published>2020-05-18T20:32:31Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-go/commit/?id=99eb7896be17cc688f001886469fb109b0575cad'/>
<id>urn:sha1:99eb7896be17cc688f001886469fb109b0575cad</id>
<content type='text'>
Reported-by: Jayakumar S &lt;jayakumar82.s@gmail.com&gt;
Signed-off-by: Jason A. Donenfeld &lt;Jason@zx2c4.com&gt;
</content>
</entry>
</feed>
