Documentation
¶
Index ¶
- func AppendHostQualityServerBehaviour(node *Node)
- type HostQuality
- type KnownHosts
- type Node
- func (node *Node) AddKnownHost(remoteHost utils.SocketAddr)
- func (node *Node) Address() string
- func (node *Node) HandleRequest(conn net.Conn, overlay Overlay)
- func (node *Node) KnownHosts() map[utils.SocketAddr]HostQuality
- func (node *Node) RegisterClientBehaviour(handler func(Overlay))
- func (node *Node) RegisterServerBehaviour(route string, handler func(Overlay, []byte) []byte)
- func (node *Node) RemoveKnownHost(remoteHost utils.SocketAddr)
- func (node *Node) RouteHandler(packet []byte, overlay Overlay) []byte
- func (node *Node) Shutdown()
- func (node *Node) SocketAddr() utils.SocketAddr
- func (node *Node) Start(overlay Overlay)
- func (node *Node) StorageMemoryCap() uint64
- func (node *Node) UpdateIP(ip string)
- type Overlay
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendHostQualityServerBehaviour ¶
func AppendHostQualityServerBehaviour(node *Node)
Types ¶
type HostQuality ¶
HostQuality metric for a host
type KnownHosts ¶
type KnownHosts struct { // Hosts are a map of hostname to HostQuality Hosts map[utils.SocketAddr]HostQuality // contains filtered or unexported fields }
func (*KnownHosts) Add ¶
func (knownHosts *KnownHosts) Add(host utils.SocketAddr)
Add host to known hosts
func (*KnownHosts) Addrs ¶
func (knownHosts *KnownHosts) Addrs() map[utils.SocketAddr]HostQuality
func (*KnownHosts) JsonDigest ¶
func (knownHosts *KnownHosts) JsonDigest() []byte
JsonDigest of known hosts so they can be communicated with other hosts
func (*KnownHosts) Remove ¶
func (knownHosts *KnownHosts) Remove(host utils.SocketAddr)
Remove host from known hosts
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func NewNode ¶
NewNode based on the local IP address of the computer, a port number, the desired memory usage. If the port is unspecified (i.e. 0), the OS will allocate an available port. The max memory is specified in megabytes. If the memory is not specified (i.e. 0), the default is 512 MB (0.5GB). A node has to contribute at least 512 MB of memory to the network (for it to be worthwhile) and use less memory than the total system memory.
func (*Node) AddKnownHost ¶
func (node *Node) AddKnownHost(remoteHost utils.SocketAddr)
AddKnownHost to increase node's partial view of the network. If already in known hosts, does nothing. If known hosts list is full, determines intelligently if the host should be added and which should be removed. Be careful, a node is not always added despite the function call.
func (*Node) HandleRequest ¶
HandleRequest by reading the connection buffer, processing the packet and writing the response to the connection buffer
func (*Node) KnownHosts ¶
func (node *Node) KnownHosts() map[utils.SocketAddr]HostQuality
func (*Node) RegisterClientBehaviour ¶
RegisterClientBehaviour allows you to define several ways to interface with a node. The ability to append user-defined functions allows you to add functionality to the node specific to your dapp.
func (*Node) RegisterServerBehaviour ¶
RegisterServerBehaviour allows a node to register a behaviour for a route to increase its ability to respond too requests. All routes (specific server handler functions) take the overlay network and incoming payload as parameters, process the request and return a response payload.
func (*Node) RemoveKnownHost ¶
func (node *Node) RemoveKnownHost(remoteHost utils.SocketAddr)
RemoveKnownHost from node's list. If the host is not in the list, does nothing.
func (*Node) RouteHandler ¶
RouteHandler for incoming packets that applies the correct response to the packet or returns an error ("invalid-packet/" if the node is unable to pass the packet or "invalid-route" if the node does not have a registered behaviour corresponding to the route)
func (*Node) Shutdown ¶
func (node *Node) Shutdown()
Shutdown gracefully by closing the listener, telling the network the node is leaving and passing on data as required
func (*Node) SocketAddr ¶
func (node *Node) SocketAddr() utils.SocketAddr
func (*Node) Start ¶
Start node by listening out for incoming connections and starting the application specific client behaviours. A node behaves both as a server and a client simultaneously (that's how peer-to-peer systems work!).