Change network id to name
This commit is contained in:
parent
d1fc3c361e
commit
eafc930f84
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user