add comments
This commit is contained in:
parent
fa54db5ba5
commit
6bdc23a3aa
@ -43,6 +43,7 @@ func (n *network) Create() (*Node, error) {
|
|||||||
Address: ip,
|
Address: ip,
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"network": n.Name(),
|
"network": n.Name(),
|
||||||
|
"transport": n.transport.String(),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -10,28 +10,32 @@ import (
|
|||||||
// is responsible for routing messages to the correct services.
|
// is responsible for routing messages to the correct services.
|
||||||
type Network interface {
|
type Network interface {
|
||||||
options.Options
|
options.Options
|
||||||
// Create starts the network
|
// Create starts the network and creates a new node
|
||||||
Create() (*Node, error)
|
Create() (*Node, error)
|
||||||
// Name of the network
|
// Name of the network
|
||||||
Name() string
|
Name() string
|
||||||
// Connect to a node
|
// Connect to a node on the network
|
||||||
Connect(*Node) (Conn, error)
|
Connect(*Node) (Conn, error)
|
||||||
// Listen for connections
|
// Listen for connections for this node
|
||||||
Listen(*Node) (Listener, error)
|
Listen(*Node) (Listener, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node is a network node represented with id/address and
|
||||||
|
// metadata which includes the network name, transport, etc
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Id string
|
Id string
|
||||||
Address string
|
Address string
|
||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A network node listener which can be used to receive messages
|
||||||
type Listener interface {
|
type Listener interface {
|
||||||
Address() string
|
Address() string
|
||||||
Close() error
|
Close() error
|
||||||
Accept() (Conn, error)
|
Accept() (Conn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A connection from another node on the network
|
||||||
type Conn interface {
|
type Conn interface {
|
||||||
// Unique id of the connection
|
// Unique id of the connection
|
||||||
Id() string
|
Id() string
|
||||||
@ -47,6 +51,7 @@ type Conn interface {
|
|||||||
Local() string
|
Local() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The message type sent over the network
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Header map[string]string
|
Header map[string]string
|
||||||
Body []byte
|
Body []byte
|
||||||
|
Loading…
Reference in New Issue
Block a user