aboutsummaryrefslogtreecommitdiffstats
path: root/src/peer.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-10-16 21:33:47 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-10-16 21:33:47 +0200
commite86d03dca23e5adcbd1c7bd30157bc7d19a932d7 (patch)
tree5792ecf8bad5a76c96033ceeef32a91df7d344b2 /src/peer.go
parentAdded new UDPBind interface (diff)
downloadwireguard-go-e86d03dca23e5adcbd1c7bd30157bc7d19a932d7.tar.xz
wireguard-go-e86d03dca23e5adcbd1c7bd30157bc7d19a932d7.zip
Initial implementation of source caching
Yet untested.
Diffstat (limited to 'src/peer.go')
-rw-r--r--src/peer.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/peer.go b/src/peer.go
index 791c091..f24dcd8 100644
--- a/src/peer.go
+++ b/src/peer.go
@@ -14,9 +14,12 @@ type Peer struct {
persistentKeepaliveInterval uint64
keyPairs KeyPairs
handshake Handshake
- endpoint Endpoint
device *Device
- stats struct {
+ endpoint struct {
+ set bool // has a known endpoint been discovered
+ value Endpoint // source / destination cache
+ }
+ stats struct {
txBytes uint64 // bytes send to peer (endpoint)
rxBytes uint64 // bytes received from peer
lastHandshakeNano int64 // nano seconds since epoch
@@ -105,6 +108,12 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
handshake.precomputedStaticStatic = device.privateKey.sharedSecret(handshake.remoteStatic)
handshake.mutex.Unlock()
+ // reset endpoint
+
+ peer.endpoint.set = false
+ peer.endpoint.value.ClearDst()
+ peer.endpoint.value.ClearSrc()
+
// prepare queuing
peer.queue.nonce = make(chan *QueueOutboundElement, QueueOutboundSize)
@@ -129,11 +138,20 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
return peer, nil
}
+/* Returns a short string identification for logging
+ */
func (peer *Peer) String() string {
+ if !peer.endpoint.set {
+ return fmt.Sprintf(
+ "peer(%d unknown %s)",
+ peer.id,
+ base64.StdEncoding.EncodeToString(peer.handshake.remoteStatic[:]),
+ )
+ }
return fmt.Sprintf(
"peer(%d %s %s)",
peer.id,
- peer.endpoint.DestinationToString(),
+ peer.endpoint.value.DstToString(),
base64.StdEncoding.EncodeToString(peer.handshake.remoteStatic[:]),
)
}