add comments

This commit is contained in:
Asim Aslam 2019-07-08 16:32:12 +01:00
parent fa54db5ba5
commit 6bdc23a3aa
2 changed files with 9 additions and 3 deletions

View File

@ -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
} }

View File

@ -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