node

package
v0.0.0-...-79bdfdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2023 License: GPL-3.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendHostQualityServerBehaviour

func AppendHostQualityServerBehaviour(node *Node)

Types

type HostQuality

type HostQuality struct {
	Uptime           uint64
	AvailableStorage uint64
	NbHostsKnown     uint64
}

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

func NewNode(port uint16, maxMemoryMb uint64) (*Node, error)

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) Address

func (node *Node) Address() string

func (*Node) HandleRequest

func (node *Node) HandleRequest(conn net.Conn, overlay Overlay)

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

func (node *Node) RegisterClientBehaviour(handler func(Overlay))

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

func (node *Node) RegisterServerBehaviour(route string, handler func(Overlay, []byte) []byte)

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

func (node *Node) RouteHandler(packet []byte, overlay Overlay) []byte

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

func (node *Node) Start(overlay Overlay)

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!).

func (*Node) StorageMemoryCap

func (node *Node) StorageMemoryCap() uint64

func (*Node) UpdateIP

func (node *Node) UpdateIP(ip string)

UpdateIP of node to the given IP. This is important for updating an IP from local to public during NAT traversal.

type Overlay

type Overlay interface {
	Node() *Node
	AvailableStorage() uint64
}

Overlay interface describes what an implemented Overlay struct should look like

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL