net

package
v0.0.0-...-0a36b5b Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const AuthStringLength = 20
View Source
const CommandLength = 12
View Source
const NodeVersion = 1
View Source
const Protocol = "tcp"

Variables

This section is empty.

Functions

func BytesToCommand

func BytesToCommand(bytes []byte) string

Convert bytes back to command

func CommandToBytes

func CommandToBytes(command string) []byte

Converts a command to bytes in fixed length

func ExtractCommand

func ExtractCommand(request []byte) []byte

Get command part from request string

func GobEncode

func GobEncode(data interface{}) ([]byte, error)

Encode structure to bytes

Types

type NodeAddr

type NodeAddr struct {
	Host string
	Port int
}

Represents a node address

func (NodeAddr) CompareToAddress

func (n NodeAddr) CompareToAddress(addr NodeAddr) bool

Compare to other node address if is same

func (*NodeAddr) LoadFromString

func (n *NodeAddr) LoadFromString(addr string) error

Parse from string

func (NodeAddr) NodeAddrToString

func (n NodeAddr) NodeAddrToString() string

Convert to string in format host:port

type NodeNetwork

type NodeNetwork struct {
	Logger  *utils.LoggerMan
	Nodes   []NodeAddr
	Storage NodeNetworkStorage
	// contains filtered or unexported fields
}

This manages list of known nodes by a node

func (*NodeNetwork) AddNodeToKnown

func (n *NodeNetwork) AddNodeToKnown(addr NodeAddr) bool

* Checks if a node exists in list of known nodes and adds it if no * Returns true if was added

func (*NodeNetwork) CheckIsKnown

func (n *NodeNetwork) CheckIsKnown(addr NodeAddr) bool

Check if node address is known

func (*NodeNetwork) GetCountOfKnownNodes

func (n *NodeNetwork) GetCountOfKnownNodes() int

Returns number of known nodes

func (*NodeNetwork) GetNodes

func (n *NodeNetwork) GetNodes() []NodeAddr

func (*NodeNetwork) Init

func (n *NodeNetwork) Init()

Init nodes network object

func (*NodeNetwork) LoadInitialNodes

func (n *NodeNetwork) LoadInitialNodes(geenesisHash []byte) error

If n any known nodes then it will be loaded from the url on a host Accepts genesis block hash. It will be compared to the hash in JSON doc

func (*NodeNetwork) LoadNodes

func (n *NodeNetwork) LoadNodes() error

Loads list of nodes from storage

func (*NodeNetwork) RemoveNodeFromKnown

func (n *NodeNetwork) RemoveNodeFromKnown(addr NodeAddr)

Removes a node from known

func (*NodeNetwork) SetExtraManager

func (n *NodeNetwork) SetExtraManager(storage NodeNetworkStorage)

Set extra storage for a nodes

func (*NodeNetwork) SetNodes

func (n *NodeNetwork) SetNodes(nodes []NodeAddr, replace bool)

Set nodes list. This can be used to do initial nodes loading from config or so

type NodeNetworkStorage

type NodeNetworkStorage interface {
	GetNodes() ([]NodeAddr, error)
	AddNodeToKnown(addr NodeAddr)
	RemoveNodeFromKnown(addr NodeAddr)
	GetCountOfKnownNodes() (int, error)
}

INterface for extra storage for a nodes. TODO This is not used yet

type NodesListJSON

type NodesListJSON struct {
	Nodes   []NodeAddr
	Genesis string
}

Jump to

Keyboard shortcuts

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