From 6bdc23a3aa305e527e79ac59236bf4ae21a74e01 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 8 Jul 2019 16:32:12 +0100 Subject: [PATCH] add comments --- network/default.go | 1 + network/network.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/network/default.go b/network/default.go index bc4024f6..626f9281 100644 --- a/network/default.go +++ b/network/default.go @@ -43,6 +43,7 @@ func (n *network) Create() (*Node, error) { Address: ip, Metadata: map[string]string{ "network": n.Name(), + "transport": n.transport.String(), }, }, nil } diff --git a/network/network.go b/network/network.go index a1439948..3198bf3f 100644 --- a/network/network.go +++ b/network/network.go @@ -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