Documentation ¶
Index ¶
- Constants
- func BytesToCommand(bytes []byte) string
- func CommandToBytes(command string) []byte
- func ExtractCommand(request []byte) []byte
- func GobEncode(data interface{}) ([]byte, error)
- type NodeAddr
- type NodeNetwork
- func (n *NodeNetwork) AddNodeToKnown(addr NodeAddr) bool
- func (n *NodeNetwork) CheckIsKnown(addr NodeAddr) bool
- func (n *NodeNetwork) GetCountOfKnownNodes() int
- func (n *NodeNetwork) GetNodes() []NodeAddr
- func (n *NodeNetwork) Init()
- func (n *NodeNetwork) LoadInitialNodes(geenesisHash []byte) error
- func (n *NodeNetwork) LoadNodes() error
- func (n *NodeNetwork) RemoveNodeFromKnown(addr NodeAddr)
- func (n *NodeNetwork) SetExtraManager(storage NodeNetworkStorage)
- func (n *NodeNetwork) SetNodes(nodes []NodeAddr, replace bool)
- type NodeNetworkStorage
- type NodesListJSON
Constants ¶
const AuthStringLength = 20
const CommandLength = 12
const NodeVersion = 1
const Protocol = "tcp"
Variables ¶
This section is empty.
Functions ¶
func CommandToBytes ¶
Converts a command to bytes in fixed length
func ExtractCommand ¶
Get command part from request string
Types ¶
type NodeAddr ¶
Represents a node address
func (NodeAddr) CompareToAddress ¶
Compare to other node address if is same
func (*NodeAddr) LoadFromString ¶
Parse from string
func (NodeAddr) NodeAddrToString ¶
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) 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