Added Nodes method to Network interface
This commit is contained in:
parent
bf53c16e4b
commit
4f5a849211
@ -33,12 +33,31 @@ type node struct {
|
|||||||
id string
|
id string
|
||||||
// address is node address
|
// address is node address
|
||||||
address string
|
address string
|
||||||
// neighbours are node neightbours
|
// neighbours maps the node neighbourhood
|
||||||
neighbours map[string]*node
|
neighbours map[string]*node
|
||||||
|
// network returns network node is in
|
||||||
|
network Network
|
||||||
|
}
|
||||||
|
|
||||||
|
// Id is node ide
|
||||||
|
func (n *node) Id() string {
|
||||||
|
return n.id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Address returns node address
|
||||||
|
func (n *node) Address() string {
|
||||||
|
return n.address
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network returns node network
|
||||||
|
func (n *node) Network() Network {
|
||||||
|
return n.network
|
||||||
}
|
}
|
||||||
|
|
||||||
// network implements Network interface
|
// network implements Network interface
|
||||||
type network struct {
|
type network struct {
|
||||||
|
// node is network node
|
||||||
|
*node
|
||||||
// options configure the network
|
// options configure the network
|
||||||
options Options
|
options Options
|
||||||
// rtr is network router
|
// rtr is network router
|
||||||
@ -60,8 +79,6 @@ type network struct {
|
|||||||
connected bool
|
connected bool
|
||||||
// closed closes the network
|
// closed closes the network
|
||||||
closed chan bool
|
closed chan bool
|
||||||
// neighbours maps the node neighbourhood
|
|
||||||
neighbours map[string]*node
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newNetwork returns a new network node
|
// newNetwork returns a new network node
|
||||||
@ -106,7 +123,12 @@ func newNetwork(opts ...Option) Network {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return &network{
|
network := &network{
|
||||||
|
node: &node{
|
||||||
|
id: options.Id,
|
||||||
|
address: options.Address,
|
||||||
|
neighbours: make(map[string]*node),
|
||||||
|
},
|
||||||
options: options,
|
options: options,
|
||||||
Router: options.Router,
|
Router: options.Router,
|
||||||
Proxy: options.Proxy,
|
Proxy: options.Proxy,
|
||||||
@ -114,8 +136,11 @@ func newNetwork(opts ...Option) Network {
|
|||||||
server: server,
|
server: server,
|
||||||
client: client,
|
client: client,
|
||||||
tunClient: make(map[string]transport.Client),
|
tunClient: make(map[string]transport.Client),
|
||||||
neighbours: make(map[string]*node),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network.node.network = network
|
||||||
|
|
||||||
|
return network
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options returns network options
|
// Options returns network options
|
||||||
@ -695,6 +720,11 @@ func (n *network) Connect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nodes returns a list of all network nodes
|
||||||
|
func (n *network) Nodes() []Node {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (n *network) close() error {
|
func (n *network) close() error {
|
||||||
// stop the server
|
// stop the server
|
||||||
if err := n.server.Stop(); err != nil {
|
if err := n.server.Stop(); err != nil {
|
||||||
|
@ -21,14 +21,16 @@ var (
|
|||||||
|
|
||||||
// Network is micro network
|
// Network is micro network
|
||||||
type Network interface {
|
type Network interface {
|
||||||
|
// Node is network node
|
||||||
|
Node
|
||||||
// Options returns the network options
|
// Options returns the network options
|
||||||
Options() Options
|
Options() Options
|
||||||
// Name of the network
|
// Name of the network
|
||||||
Name() string
|
Name() string
|
||||||
// Address returns network bind address
|
|
||||||
Address() string
|
|
||||||
// Connect starts the resolver and tunnel server
|
// Connect starts the resolver and tunnel server
|
||||||
Connect() error
|
Connect() error
|
||||||
|
// Nodes returns list of network nodes
|
||||||
|
Nodes() []Node
|
||||||
// Close stops the tunnel and resolving
|
// Close stops the tunnel and resolving
|
||||||
Close() error
|
Close() error
|
||||||
// Client is micro client
|
// Client is micro client
|
||||||
@ -37,6 +39,16 @@ type Network interface {
|
|||||||
Server() server.Server
|
Server() server.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node is network node
|
||||||
|
type Node interface {
|
||||||
|
// Id is node id
|
||||||
|
Id() string
|
||||||
|
// Address is node bind address
|
||||||
|
Address() string
|
||||||
|
// Network is the network node is in
|
||||||
|
Network() Network
|
||||||
|
}
|
||||||
|
|
||||||
// NewNetwork returns a new network interface
|
// NewNetwork returns a new network interface
|
||||||
func NewNetwork(opts ...Option) Network {
|
func NewNetwork(opts ...Option) Network {
|
||||||
return newNetwork(opts...)
|
return newNetwork(opts...)
|
||||||
|
Loading…
Reference in New Issue
Block a user