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,
Metadata: map[string]string{
"network": n.Name(),
"transport": n.transport.String(),
},
}, nil
}

View File

@ -10,28 +10,32 @@ import (
// is responsible for routing messages to the correct services.
type Network interface {
options.Options
// Create starts the network
// Create starts the network and creates a new node
Create() (*Node, error)
// Name of the network
Name() string
// Connect to a node
// Connect to a node on the network
Connect(*Node) (Conn, error)
// Listen for connections
// Listen for connections for this node
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 {
Id string
Address string
Metadata map[string]string
}
// A network node listener which can be used to receive messages
type Listener interface {
Address() string
Close() error
Accept() (Conn, error)
}
// A connection from another node on the network
type Conn interface {
// Unique id of the connection
Id() string
@ -47,6 +51,7 @@ type Conn interface {
Local() string
}
// The message type sent over the network
type Message struct {
Header map[string]string
Body []byte