Skip to content

Commit 5010f3f

Browse files
apenwarrcrawshaw
authored andcommitted
device: add a HandshakeDone callback
Every time a peer handshake completes, we call this function. That lets a GUI immediately notice when the connection has been established. Signed-off-by: Avery Pennarun <[email protected]>
1 parent 574dfee commit 5010f3f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: device/device.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Device struct {
2424
isUp AtomicBool // device is (going) up
2525
isClosed AtomicBool // device is closed? (acting as guard)
2626
log *Logger
27+
handshakeDone func()
2728
skipBindUpdate bool
2829
createBind func(uport uint16) (conn.Bind, uint16, error)
2930
createEndpoint func(key [32]byte, s string) (conn.Endpoint, error)
@@ -275,6 +276,9 @@ type DeviceOptions struct {
275276

276277
// SkipBindUpdate instructs Device to only call CreateBind once.
277278
SkipBindUpdate bool
279+
280+
// HandshakeDone is called every time we complete a peer handshake.
281+
HandshakeDone func()
278282
}
279283

280284
// TODO move logger into DeviceOptions
@@ -318,6 +322,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger, varOpts ...DeviceOptions) *
318322
}
319323
}
320324
device.skipBindUpdate = opts.SkipBindUpdate
325+
device.handshakeDone = opts.HandshakeDone
321326

322327
device.tun.device = tunDevice
323328
mtu, err := device.tun.device.MTU()

Diff for: device/send.go

+3
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ func (peer *Peer) RoutineNonce() {
409409
select {
410410
case <-peer.signals.newKeypairArrived:
411411
logDebug.Println(peer, "- Obtained awaited keypair")
412+
if device.handshakeDone != nil {
413+
device.handshakeDone()
414+
}
412415

413416
case <-peer.signals.flushNonceQueue:
414417
device.PutMessageBuffer(elem.buffer)

0 commit comments

Comments
 (0)