Skip to content

Commit

Permalink
Change network id to name
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Jul 7, 2019
1 parent d1fc3c3 commit eafc930
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions network/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +65,7 @@ func (n *network) lease(muid string) *pb.Lease {
Muid: muid,
Id: id,
Address: address,
Network: n.id,
Network: n.name,
},
}
}
Expand All @@ -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
}
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions network/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,7 +156,7 @@ func newNode(n *network) (*node, error) {
// a registrar or tld or whatever
if err := node.registry.Register(&registry.Service{
// register with the network id
Name: "network:" + n.Id(),
Name: n.Name(),
Nodes: []*registry.Node{
{Id: node.id, Address: addr, Port: port},
},
Expand Down Expand Up @@ -473,7 +473,7 @@ func (n *node) Close() error {

// deregister self
n.registry.Deregister(&registry.Service{
Name: "network:" + n.network.Id(),
Name: n.network.Name(),
Nodes: []*registry.Node{
{Id: n.id, Address: n.address},
},
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit eafc930

Please sign in to comment.