Skip to content

Commit

Permalink
device: add a HandshakeDone callback
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
apenwarr authored and crawshaw committed Mar 31, 2020
1 parent 574dfee commit 5010f3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Device struct {
isUp AtomicBool // device is (going) up
isClosed AtomicBool // device is closed? (acting as guard)
log *Logger
handshakeDone func()
skipBindUpdate bool
createBind func(uport uint16) (conn.Bind, uint16, error)
createEndpoint func(key [32]byte, s string) (conn.Endpoint, error)
Expand Down Expand Up @@ -275,6 +276,9 @@ type DeviceOptions struct {

// SkipBindUpdate instructs Device to only call CreateBind once.
SkipBindUpdate bool

// HandshakeDone is called every time we complete a peer handshake.
HandshakeDone func()
}

// TODO move logger into DeviceOptions
Expand Down Expand Up @@ -318,6 +322,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger, varOpts ...DeviceOptions) *
}
}
device.skipBindUpdate = opts.SkipBindUpdate
device.handshakeDone = opts.HandshakeDone

device.tun.device = tunDevice
mtu, err := device.tun.device.MTU()
Expand Down
3 changes: 3 additions & 0 deletions device/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ func (peer *Peer) RoutineNonce() {
select {
case <-peer.signals.newKeypairArrived:
logDebug.Println(peer, "- Obtained awaited keypair")
if device.handshakeDone != nil {
device.handshakeDone()
}

case <-peer.signals.flushNonceQueue:
device.PutMessageBuffer(elem.buffer)
Expand Down

0 comments on commit 5010f3f

Please sign in to comment.