summaryrefslogtreecommitdiffhomepage
path: root/src/peer.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-18 23:34:02 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-18 23:34:02 +0100
commitd10126f883ad39567248540347b5469956ab8b2e (patch)
treea83329093198bd5dd2c7770835a3851e6d23d880 /src/peer.go
parentfa399a91d5da9874cbf248e00db8dbd87b587e91 (diff)
Moved endpoint into interface and simplified peer
Diffstat (limited to 'src/peer.go')
-rw-r--r--src/peer.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/peer.go b/src/peer.go
index a98fc97..f3eb6c2 100644
--- a/src/peer.go
+++ b/src/peer.go
@@ -15,11 +15,8 @@ type Peer struct {
keyPairs KeyPairs
handshake Handshake
device *Device
- endpoint struct {
- set bool // has a known endpoint been discovered
- value Endpoint // source / destination cache
- }
- stats struct {
+ endpoint Endpoint
+ stats struct {
txBytes uint64 // bytes send to peer (endpoint)
rxBytes uint64 // bytes received from peer
lastHandshakeNano int64 // nano seconds since epoch
@@ -110,9 +107,7 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
// reset endpoint
- peer.endpoint.set = false
- peer.endpoint.value.ClearDst()
- peer.endpoint.value.ClearSrc()
+ peer.endpoint = nil
// prepare queuing
@@ -143,16 +138,16 @@ func (peer *Peer) SendBuffer(buffer []byte) error {
defer peer.device.net.mutex.RUnlock()
peer.mutex.RLock()
defer peer.mutex.RUnlock()
- if !peer.endpoint.set {
+ if peer.endpoint == nil {
return errors.New("No known endpoint for peer")
}
- return peer.device.net.bind.Send(buffer, &peer.endpoint.value)
+ return peer.device.net.bind.Send(buffer, peer.endpoint)
}
/* Returns a short string identification for logging
*/
func (peer *Peer) String() string {
- if !peer.endpoint.set {
+ if peer.endpoint == nil {
return fmt.Sprintf(
"peer(%d unknown %s)",
peer.id,
@@ -162,7 +157,7 @@ func (peer *Peer) String() string {
return fmt.Sprintf(
"peer(%d %s %s)",
peer.id,
- peer.endpoint.value.DstToString(),
+ peer.endpoint.DstToString(),
base64.StdEncoding.EncodeToString(peer.handshake.remoteStatic[:]),
)
}