Documentation
¶
Index ¶
- Constants
- func BytesToCommand(bytes []byte) string
- func CommandToBytes(command string) []byte
- func ExtractCommand(request []byte) []byte
- func GobEncode(data interface{}) ([]byte, error)
- func NewCanNotConnectError(err string) error
- func NewCanNotParseResponseError(err string) error
- func NewCanNotSendError(err string) error
- func NewNoResponseError(err string) error
- type NetworkError
- type NodeAddr
- func (n NodeAddr) CompareToAddress(addr NodeAddr) bool
- func (n NodeAddr) GetShortFormat() NodeAddrShort
- func (n *NodeAddr) InitAfterRestore()
- func (n *NodeAddr) LoadFromString(addr string) error
- func (n NodeAddr) NodeAddrToString() string
- func (n *NodeAddr) ReportFailedConn()
- func (n *NodeAddr) ReportSuccessConn()
- func (n NodeAddr) String() string
- type NodeAddrShort
- type NodeNetwork
- func (n *NodeNetwork) AddNodeToKnown(addr NodeAddr) bool
- func (n *NodeNetwork) CheckHadInputConnects() bool
- func (n *NodeNetwork) CheckIsKnown(addr NodeAddr) bool
- func (n NodeNetwork) GetConnecttionVerifiedNodeAddr() *NodeAddr
- func (n NodeNetwork) GetConnecttionVerifiedNodeAddresses(limit int) []*NodeAddr
- func (n *NodeNetwork) GetCountOfKnownNodes() int
- func (n *NodeNetwork) GetNodes() []NodeAddr
- func (n *NodeNetwork) GetNodesToExport() (list []NodeAddrShort)
- func (n *NodeNetwork) HookNeworkOperationResult(err error, nodeindex int)
- func (n *NodeNetwork) HookNeworkOperationResultForNode(err error, nodeU *NodeAddr)
- func (n *NodeNetwork) Init()
- func (n *NodeNetwork) InputConnectFromNode(addr NodeAddr)
- 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)
- func (n *NodeNetwork) StartNewSessionForInputConnects()
- 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
func NewCanNotConnectError ¶
func NewCanNotSendError ¶
func NewNoResponseError ¶
Types ¶
type NetworkError ¶
type NetworkError struct {
// contains filtered or unexported fields
}
func (NetworkError) Error ¶
func (e NetworkError) Error() string
func (NetworkError) WasConnFailure ¶
func (e NetworkError) WasConnFailure() bool
type NodeAddr ¶
type NodeAddr struct { Host string Port int SuccessConnections uint FailedConnections uint SuccessIncomeConnections uint }
Represents a node address
func NewNodeAddr ¶
func (NodeAddr) CompareToAddress ¶
Compare to other node address if is same
func (NodeAddr) GetShortFormat ¶
func (n NodeAddr) GetShortFormat() NodeAddrShort
Get short format of the node
func (*NodeAddr) InitAfterRestore ¶
func (n *NodeAddr) InitAfterRestore()
init a record after restore from DB
func (*NodeAddr) LoadFromString ¶
Parse from string
func (NodeAddr) NodeAddrToString ¶
Convert to string in format host:port
func (*NodeAddr) ReportFailedConn ¶
func (n *NodeAddr) ReportFailedConn()
Notify this address got failed attempt to connect
func (*NodeAddr) ReportSuccessConn ¶
func (n *NodeAddr) ReportSuccessConn()
Notify this address got success attempt to connect
type NodeAddrShort ¶
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) CheckHadInputConnects ¶
func (n *NodeNetwork) CheckHadInputConnects() bool
Check if there were recent input connects
func (*NodeNetwork) CheckIsKnown ¶
func (n *NodeNetwork) CheckIsKnown(addr NodeAddr) bool
Check if node address is known
func (NodeNetwork) GetConnecttionVerifiedNodeAddr ¶
func (n NodeNetwork) GetConnecttionVerifiedNodeAddr() *NodeAddr
Checks nodes rendomly and returns first found node that is accesible It check if a node was ever connected from this place
func (NodeNetwork) GetConnecttionVerifiedNodeAddresses ¶
func (n NodeNetwork) GetConnecttionVerifiedNodeAddresses(limit int) []*NodeAddr
Same as GetConnecttionVerifiedNodeAddr but returns all verified nodes or limited list if requested
func (*NodeNetwork) GetCountOfKnownNodes ¶
func (n *NodeNetwork) GetCountOfKnownNodes() int
Returns number of known nodes
func (*NodeNetwork) GetNodes ¶
func (n *NodeNetwork) GetNodes() []NodeAddr
func (*NodeNetwork) GetNodesToExport ¶
func (n *NodeNetwork) GetNodesToExport() (list []NodeAddrShort)
Get list of nodes in short format
func (*NodeNetwork) HookNeworkOperationResult ¶
func (n *NodeNetwork) HookNeworkOperationResult(err error, nodeindex int)
Call this when network operation with some node failed. It will analise error and do some actios to remember state of this node
func (*NodeNetwork) HookNeworkOperationResultForNode ¶
func (n *NodeNetwork) HookNeworkOperationResultForNode(err error, nodeU *NodeAddr)
Same as HookNeworkOperationResult but finds a node by address, not by index
func (*NodeNetwork) InputConnectFromNode ¶
func (n *NodeNetwork) InputConnectFromNode(addr NodeAddr)
Action on input connection from a node. We need to remember this node It is needed to know there are input connects from other nodes
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
func (*NodeNetwork) StartNewSessionForInputConnects ¶
func (n *NodeNetwork) StartNewSessionForInputConnects()
Sets input connects marker to false to check if there will be new input connects
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