From 3a882eb1124bbe334fa7e71aafff64fe01eecc7a Mon Sep 17 00:00:00 2001 From: kaiyou Date: Thu, 7 May 2020 14:33:10 +0200 Subject: [PATCH] Generate the local node directly in main.go Instead of using a trivial function, simply generate the local node from main.go, manually assign fields from the nodeMeta struct. --- common/node.go | 10 +--------- main.go | 4 +++- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/common/node.go b/common/node.go index 4e23487..8f86e8a 100644 --- a/common/node.go +++ b/common/node.go @@ -26,15 +26,7 @@ func (n *Node) String() string { return n.Addr.String() } -func MakeLocalNode(overlayAddr net.IPNet, pubKey string) Node { - return Node{ - nodeMeta: nodeMeta{ - OverlayAddr: overlayAddr, - PubKey: pubKey, - }, - } -} - +// Encode the node metadata to bytes, in a deterministic reversible way func (n *Node) Encode(limit int) ([]byte, error) { buf := &bytes.Buffer{} if err := gob.NewEncoder(buf).Encode(n.nodeMeta); err != nil { diff --git a/main.go b/main.go index c1c06e6..caa1670 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,9 @@ func main() { } wg.AssignOverlayAddr((*net.IPNet)(config.OverlayNet), cluster.LocalName) - localNode := common.MakeLocalNode(wg.OverlayAddr, wg.PubKey.String()) + localNode := common.Node{} + localNode.OverlayAddr = wg.OverlayAddr + localNode.PubKey = wg.PubKey.String() cluster.Update(localNode) nodec := cluster.Members() // avoid deadlocks by starting before join