From 93e3848ea76e755477bec8d9540a3c4c31ea7320 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Thu, 13 Jul 2017 14:32:40 +0200 Subject: Terminate on interface deletion Program now terminates when the interface is removed Increases the number of os threads (relevant for Go <1.5, not tested) More consistent commenting Improved logging (additional peer information) --- src/peer.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/peer.go') diff --git a/src/peer.go b/src/peer.go index c8dc5c0..408c605 100644 --- a/src/peer.go +++ b/src/peer.go @@ -1,7 +1,9 @@ package main import ( + "encoding/base64" "errors" + "fmt" "net" "sync" "time" @@ -38,9 +40,9 @@ type Peer struct { /* Both keep-alive timers acts as one (see timers.go) * They are kept seperate to simplify the implementation. */ - keepalivePersistent *time.Timer // set for persistent keepalives - keepaliveAcknowledgement *time.Timer // set upon recieving messages - zeroAllKeys *time.Timer // zero all key material after RejectAfterTime*3 + keepalivePersistent *time.Timer // set for persistent keepalives + keepalivePassive *time.Timer // set upon recieving messages + zeroAllKeys *time.Timer // zero all key material after RejectAfterTime*3 } queue struct { nonce chan *QueueOutboundElement // nonce / pre-handshake queue @@ -63,8 +65,8 @@ func (device *Device) NewPeer(pk NoisePublicKey) *Peer { peer.mac.Init(pk) peer.device = device + peer.timer.keepalivePassive = NewStoppedTimer() peer.timer.keepalivePersistent = NewStoppedTimer() - peer.timer.keepaliveAcknowledgement = NewStoppedTimer() peer.timer.zeroAllKeys = NewStoppedTimer() peer.flags.keepaliveWaiting = AtomicFalse @@ -115,6 +117,15 @@ func (device *Device) NewPeer(pk NoisePublicKey) *Peer { return peer } +func (peer *Peer) String() string { + return fmt.Sprintf( + "peer(%d %s %s)", + peer.id, + peer.endpoint.String(), + base64.StdEncoding.EncodeToString(peer.handshake.remoteStatic[:]), + ) +} + func (peer *Peer) Close() { close(peer.signal.stop) } -- cgit v1.2.3