Skip to content

Commit e2104a9

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 41ad63a commit e2104a9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: device/device.go

+9
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)
@@ -277,6 +278,13 @@ type DeviceOptions struct {
277278
//
278279
// TODO(crawshaw): remove this, it isn't useful externally.
279280
SkipBindUpdate bool
281+
282+
// HandshakeDone is called every time we complete a peer handshake.
283+
//
284+
// TODO(crawshaw): This isn't quite right. Library users don't care
285+
// about the handshake, per se, they want link status.
286+
// Evolve this in that direction.
287+
HandshakeDone func()
280288
}
281289

282290
// TODO move logger into DeviceOptions
@@ -320,6 +328,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger, varOpts ...DeviceOptions) *
320328
}
321329
}
322330
device.skipBindUpdate = opts.SkipBindUpdate
331+
device.handshakeDone = opts.HandshakeDone
323332

324333
device.tun.device = tunDevice
325334
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)