Documentation ¶
Index ¶
- Variables
- func NewNodeAddr(address string) (interfaces.NodeAddr, error)
- func NewP2PTransport(logger *logrus.Logger, cid types.ChainIdentifier, privateKeyHex string, ...) (interfaces.P2PTransport, error)
- func NewTransportPrivateKey() (string, error)
- func RandomNodeAddr() (interfaces.NodeAddr, error)
- type ErrInvalidNetworkAddress
- type NodeAddr
- func (pad *NodeAddr) ChainID() types.ChainIdentifier
- func (pad *NodeAddr) ChainIdentifier() types.ChainIdentifier
- func (pad *NodeAddr) Host() string
- func (pad *NodeAddr) Identity() string
- func (pad *NodeAddr) Network() string
- func (pad *NodeAddr) P2PAddr() string
- func (pad *NodeAddr) Port() int
- func (pad *NodeAddr) String() string
- func (pad *NodeAddr) Unmarshal(address string) (interfaces.NodeAddr, error)
- type P2PConn
- func (pc *P2PConn) ChainID() types.ChainIdentifier
- func (pc *P2PConn) Close() error
- func (pc *P2PConn) CloseChan() <-chan struct{}
- func (pc *P2PConn) Identity() string
- func (pc *P2PConn) Initiator() types.P2PInitiator
- func (pc *P2PConn) NodeAddr() interfaces.NodeAddr
- func (pc *P2PConn) ProtoVersion() types.ProtoVersion
- func (pc *P2PConn) Protocol() types.Protocol
- func (pc *P2PConn) RemoteAddr() net.Addr
- func (pc *P2PConn) RemoteP2PAddr() interfaces.NodeAddr
- type P2PMux
- type P2PMuxConn
- func (pmc *P2PMuxConn) ClientConn() interfaces.P2PConn
- func (pmc *P2PMuxConn) Close() error
- func (pmc *P2PMuxConn) CloseChan() <-chan struct{}
- func (pmc *P2PMuxConn) Initiator() types.P2PInitiator
- func (pmc *P2PMuxConn) NodeAddr() interfaces.NodeAddr
- func (pmc *P2PMuxConn) ServerConn() interfaces.P2PConn
- type P2PTransport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUint32Overflow occurs when attempting to decode a string // representation of bytes and the number of bytes > 4, which // would overflow if one attempts to convert the string to uint32. ErrUint32Overflow = errors.New("invalid uint32 from hex conversion. Number overflows uint32") // ErrHandshakeTimeout occurs in (client|server)Mux when the handshake // takes too long. ErrHandshakeTimeout = errors.New("handshake timeout") // ErrListenerClosed occurs if any channel receives a nil value // when called by Accept or AcceptFailures. ErrListenerClosed = errors.New("listener closed") // ErrInvalidPubKeyLength occurs in NewP2PAddrPort when public key hex // string has the incorrect length. ErrInvalidPubKeyLength = errors.New("invalid public key format: Length") // ErrEmptyPrivKey occurs when private key byte slice is empty; // this is an invalid private key. ErrEmptyPrivKey = errors.New("empty private key hex string") // ErrInvalidPrivKey occurs when private key bytes is strictly less than // 16 bytes in length; this is an invalid private key. ErrInvalidPrivKey = errors.New("invalid private key hex string") )
Functions ¶
func NewNodeAddr ¶
func NewNodeAddr(address string) (interfaces.NodeAddr, error)
NewNodeAddr constructs a new NodeAddr given an address of valid format. The network should ALWAYS be `tcp` due to the use of brontide. The address MUST be formatted as follows: <8 hex characters>|<66 hex characters>@host:port <chainIdentifier>|<hex PublicKey>@host:port
func NewP2PTransport ¶
func NewP2PTransport(logger *logrus.Logger, cid types.ChainIdentifier, privateKeyHex string, port int, host string) (interfaces.P2PTransport, error)
NewP2PTransport returns a transport object. This object is both a server and a client.
func NewTransportPrivateKey ¶
NewTransportPrivateKey returns a new transport private key as a hex string. This key is used for the creation of an authenticated and encrypted stream of data between peers.
func RandomNodeAddr ¶
func RandomNodeAddr() (interfaces.NodeAddr, error)
RandomNodeAddr returns a random NodeAddr for peer discovery lookups
Types ¶
type ErrInvalidNetworkAddress ¶
type ErrInvalidNetworkAddress struct {
// contains filtered or unexported fields
}
ErrInvalidNetworkAddress allows us to handle complicated errors where additional information is required.
func (*ErrInvalidNetworkAddress) Error ¶
func (eina *ErrInvalidNetworkAddress) Error() string
type NodeAddr ¶
type NodeAddr struct {
// contains filtered or unexported fields
}
NodeAddr is the peer to peer address type definition. This definition MUST comply with the NodeAddr interface.
func (*NodeAddr) ChainID ¶
func (pad *NodeAddr) ChainID() types.ChainIdentifier
ChainID returns the chainID of the address.
func (*NodeAddr) ChainIdentifier ¶
func (pad *NodeAddr) ChainIdentifier() types.ChainIdentifier
ChainIdentifier identifies the chain this connection is expecting it's peers to also be a member of.
func (*NodeAddr) Identity ¶
Identity returns the hex string representation of the public key of the remote peer. This is a unique identifier to each node.
func (*NodeAddr) Network ¶
Network returns the network string as expected by a net.Addr interface would return it. This is part of the net.Addr interface.
func (*NodeAddr) P2PAddr ¶
P2PAddr returns the address of the connection as a properly formatted string for use in dialing a peer.
type P2PConn ¶
The P2PConn type implements the net.Conn and the P2PConn interfaces. This is a concrete instantiation of the P2PConn object that all other objects of this system should accept as the connection object for network communications.
func (*P2PConn) ChainID ¶
func (pc *P2PConn) ChainID() types.ChainIdentifier
ChainID identifies the chain this connection is expecting it's peers to also be a member of.
func (*P2PConn) Identity ¶
Identity returns the hex string representation of the public key of the remote peer. This is a unique identifier to each node.
func (*P2PConn) Initiator ¶
func (pc *P2PConn) Initiator() types.P2PInitiator
Initiator defines if this is a locally initiated or peer initiated connection
func (*P2PConn) NodeAddr ¶
func (pc *P2PConn) NodeAddr() interfaces.NodeAddr
NodeAddr returns the address of the peer.
func (*P2PConn) ProtoVersion ¶
func (pc *P2PConn) ProtoVersion() types.ProtoVersion
ProtoVersion returns the protocol version being used. This is not used at this time.
func (*P2PConn) RemoteAddr ¶
RemoteAddr See docs for net.Conn
func (*P2PConn) RemoteP2PAddr ¶
func (pc *P2PConn) RemoteP2PAddr() interfaces.NodeAddr
RemoteP2PAddr returns the connections remote net.Addr as a P2PAddr
type P2PMux ¶
P2PMux implements the multiplexing handshake protocol for P2PMuxConn construction.
func (*P2PMux) HandleConnection ¶
func (pmx *P2PMux) HandleConnection(ctx context.Context, conn interfaces.P2PConn) (interfaces.P2PMuxConn, error)
HandleConnection runs the multiplexing protocol on the provided P2PConn and returns a multipled client and server P2PConn pair.
type P2PMuxConn ¶
type P2PMuxConn struct {
// contains filtered or unexported fields
}
P2PMuxConn object implements the P2PMuxConn interface. This object allows access to the multiplexed streams that are built on top of a single P2PConn.
func (*P2PMuxConn) ClientConn ¶
func (pmc *P2PMuxConn) ClientConn() interfaces.P2PConn
ClientConn gives access to client side of multiplexed connection
func (*P2PMuxConn) Close ¶
func (pmc *P2PMuxConn) Close() error
Close closes the multiplexed connection
func (*P2PMuxConn) CloseChan ¶
func (pmc *P2PMuxConn) CloseChan() <-chan struct{}
CloseChan returns a channel that will close when the connection begins closure
func (*P2PMuxConn) Initiator ¶
func (pmc *P2PMuxConn) Initiator() types.P2PInitiator
Initiator defines if this is a locally initiated or peer initiated connection
func (*P2PMuxConn) NodeAddr ¶
func (pmc *P2PMuxConn) NodeAddr() interfaces.NodeAddr
NodeAddr returns the address of the connection as a properly formatted string for use in dialing a peer.
func (*P2PMuxConn) ServerConn ¶
func (pmc *P2PMuxConn) ServerConn() interfaces.P2PConn
ServerConn gives access to server side of multiplexed connection
type P2PTransport ¶
type P2PTransport struct {
// contains filtered or unexported fields
}
P2PTransport wraps the brontide library in native types.
func (*P2PTransport) Accept ¶
func (pt *P2PTransport) Accept() (interfaces.P2PConn, error)
Accept method MUST be called after the transport is started. This method will return connections that remote peers open to this node.
func (*P2PTransport) Close ¶
func (pt *P2PTransport) Close() error
Close will close all loops in this object and any subListeners. This method will also cause an error to be raised on both the Accept() and AcceptFailures() methods for any listening loops that are above this transport object. This method is safe to be called multiple times from different goroutines.
func (*P2PTransport) Dial ¶
func (pt *P2PTransport) Dial(addr interfaces.NodeAddr, protocol types.Protocol) (interfaces.P2PConn, error)
Dial will dial a remote peer at the specified address with the given protocol.
func (*P2PTransport) NodeAddr ¶
func (pt *P2PTransport) NodeAddr() interfaces.NodeAddr
NodeAddr returns the listener address of the transport. This will not be the public ip address of the node, but rather this will be the interface the listener is bound to.