diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-13 14:32:40 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-13 14:32:40 +0200 |
commit | 93e3848ea76e755477bec8d9540a3c4c31ea7320 (patch) | |
tree | 31c27266ebf12fa9cef06ab531ee4b9fa7b69c56 /src/peer.go | |
parent | 8393cbff521560caef5b1b468cbb2ad030e8eda4 (diff) |
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)
Diffstat (limited to 'src/peer.go')
-rw-r--r-- | src/peer.go | 19 |
1 files changed, 15 insertions, 4 deletions
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) } |