net

package
v0.0.0-...-acf744c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: GPL-3.0 Imports: 8 Imported by: 7

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

func NewCanNotConnectError

func NewCanNotConnectError(err string) error

func NewCanNotParseResponseError

func NewCanNotParseResponseError(err string) error

func NewCanNotSendError

func NewCanNotSendError(err string) error

func NewNoResponseError

func NewNoResponseError(err string) error

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 NewNodeAddr(host string, port int) NodeAddr

func (NodeAddr) CompareToAddress

func (n NodeAddr) CompareToAddress(addr NodeAddr) bool

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

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

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

func (NodeAddr) String

func (n NodeAddr) String() string

Convert to string in format host:port

type NodeAddrShort

type NodeAddrShort struct {
	Host []byte
	Port int
}

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

func (n *NodeNetwork) Init()

Init nodes network object

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

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