From eafc930f841712622a98b5a04b9dac33fc3e582b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 7 Jul 2019 10:10:38 +0100 Subject: [PATCH] Change network id to name --- network/default.go | 24 ++++++++++++------------ network/network.go | 8 ++++---- network/node.go | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/network/default.go b/network/default.go index fd0a6fdf..29e0bbb2 100644 --- a/network/default.go +++ b/network/default.go @@ -30,8 +30,8 @@ type network struct { // proxy used to route through the network proxy proxy.Proxy - // id of this network - id string + // name of this network + name string // links maintained for this network // based on peers not nodes. maybe maintain @@ -65,7 +65,7 @@ func (n *network) lease(muid string) *pb.Lease { Muid: muid, Id: id, Address: address, - Network: n.id, + Network: n.name, }, } } @@ -76,18 +76,18 @@ func (n *network) lookup(r registry.Registry) []*resolver.Record { rr := nreg.Resolver{Registry: r} // get all the nodes for the network that are local - localRecords, err := rr.Resolve("network:" + n.Id()) + localRecords, err := rr.Resolve(n.Name()) if err != nil { // we're not in a good place here } // if its a local network we never try lookup anything else - if n.Id() == "local" { + if n.Name() == "local" { return localRecords } // now resolve incrementally based on resolvers specified - networkRecords, err := n.resolver.Resolve(n.Id()) + networkRecords, err := n.resolver.Resolve(n.Name()) if err != nil { // still not in a good place } @@ -96,8 +96,8 @@ func (n *network) lookup(r registry.Registry) []*resolver.Record { return append(localRecords, networkRecords...) } -func (n *network) Id() string { - return n.id +func (n *network) Name() string { + return n.name } // Connect connects to the network and returns a new node. @@ -135,16 +135,16 @@ func newNetwork(opts ...options.Option) *network { // new network instance with defaults net := &network{ Options: options, - id: DefaultId, + name: DefaultName, router: router.DefaultRouter, proxy: new(mucp.Proxy), resolver: new(nreg.Resolver), } - // get network id - id, ok := options.Values().Get("network.id") + // get network name + name, ok := options.Values().Get("network.name") if ok { - net.id = id.(string) + net.name = name.(string) } // get router diff --git a/network/network.go b/network/network.go index c8f998ea..f9b32090 100644 --- a/network/network.go +++ b/network/network.go @@ -10,8 +10,8 @@ import ( // is responsible for routing messages to the correct services. type Network interface { options.Options - // Id of the network - Id() string + // Name of the network + Name() string // Connect to the network Connect() (Node, error) // Peer with a neighboring network @@ -53,8 +53,8 @@ type Message struct { } var ( - // The default network ID is local - DefaultId = "local" + // The default network name is local + DefaultName = "local" // just the standard network element DefaultNetwork = NewNetwork() diff --git a/network/node.go b/network/node.go index ea05824a..90649f09 100644 --- a/network/node.go +++ b/network/node.go @@ -69,7 +69,7 @@ func newNode(n *network) (*node, error) { // create a new node node := &node{ // this nodes unique micro assigned mac address - muid: fmt.Sprintf("%s-%s", n.id, uuid.New().String()), + muid: fmt.Sprintf("%s-%s", n.name, uuid.New().String()), // map of connected records connected: make(map[string]bool), // the links @@ -156,7 +156,7 @@ func newNode(n *network) (*node, error) { // a registrar or tld or whatever if err := node.registry.Register(®istry.Service{ // register with the network id - Name: "network:" + n.Id(), + Name: n.Name(), Nodes: []*registry.Node{ {Id: node.id, Address: addr, Port: port}, }, @@ -473,7 +473,7 @@ func (n *node) Close() error { // deregister self n.registry.Deregister(®istry.Service{ - Name: "network:" + n.network.Id(), + Name: n.network.Name(), Nodes: []*registry.Node{ {Id: n.id, Address: n.address}, }, @@ -514,7 +514,7 @@ func (n *node) Id() string { } func (n *node) Network() string { - return n.network.id + return n.network.Name() } // Send propagates a message over all links. This should probably use its proxy.