Documentation ¶
Index ¶
- Constants
- func NewService(ctx context.Context, config *conf.NetWorkConfig, peers common.PeerMap, ...) (common.INetwork, error)
- type Handshake
- type Header
- type KadDHT
- type Message
- type Node
- func (n *Node) AcceptHandshake(h *msg_proto.ProtocolHandshakeMessage, version string, genesisHash types.Hash, ...) error
- func (n *Node) ClearHandler(msgType message.MessageType) error
- func (n *Node) Close() error
- func (n *Node) ID() libpeer.ID
- func (n *Node) ProcessHandshake(h *msg_proto.ProtocolHandshakeMessage) error
- func (n *Node) ProtocolHandshake(h *msg_proto.ProtocolHandshakeMessage, version string, genesisHash types.Hash, ...) error
- func (n *Node) SetHandler(msgType message.MessageType, handler common.ConnHandler) error
- func (n *Node) Start()
- func (n *Node) Write(msg message.IMessage) error
- func (n *Node) WriteMsg(messageType message.MessageType, payload []byte) error
- type NodeConfig
- type NodeOption
- type P2PMessage
- type Service
- func (s *Service) Bootstrapped() bool
- func (s *Service) ClosePeer(id peer.ID) error
- func (s *Service) HandlePeerFound(p peer.AddrInfo)
- func (s *Service) Host() host.Host
- func (s *Service) ID() string
- func (s *Service) PeerCount() int
- func (s *Service) SendMsgToPeer(id string, data []byte) error
- func (s *Service) SetHandler(mt message.MessageType, handler common.ConnHandler) error
- func (s *Service) Start() error
- func (s *Service) Wait()
- func (s *Service) WriterMessage(messageType message.MessageType, payload []byte, peer peer.ID) error
Constants ¶
View Source
const ( DefaultP2PListenAddress = "/ip4/0.0.0.0/tcp/21324" MSGProtocol = protocol.ID("/amc/msg/1.0.0") DiscoverProtocol = "/amc/discover/1.0.0" AppProtocol = "/amc/app/1.0.0" P2ProtocolVersion = "0.0.1" )
View Source
const (
// Maximum payload size in bytes (256MiB - 1B).
MaxPayloadSize = (1 << (4 * 7)) - 1
)
Variables ¶
This section is empty.
Functions ¶
func NewService ¶
func NewService(ctx context.Context, config *conf.NetWorkConfig, peers common.PeerMap, callback common.ProtocolHandshakeFn, info common.ProtocolHandshakeInfo) (common.INetwork, error)
Types ¶
type KadDHT ¶
type KadDHT struct { *kademliaDHT.IpfsDHT // contains filtered or unexported fields }
type Node ¶
func NewNode ¶
func NewNode(ctx context.Context, h host.Host, s *Service, peer libpeer.AddrInfo, callback map[message.MessageType]common.ConnHandler, opts ...NodeOption) (*Node, error)
func (*Node) AcceptHandshake ¶
func (*Node) ClearHandler ¶
func (n *Node) ClearHandler(msgType message.MessageType) error
func (*Node) ProcessHandshake ¶
func (n *Node) ProcessHandshake(h *msg_proto.ProtocolHandshakeMessage) error
ProcessHandshake read peer's genesisHash and currentHeight
func (*Node) ProtocolHandshake ¶
func (n *Node) ProtocolHandshake(h *msg_proto.ProtocolHandshakeMessage, version string, genesisHash types.Hash, currentHeight *uint256.Int, process bool) error
ProtocolHandshake send current peer's genesisHash and height
func (*Node) SetHandler ¶
func (n *Node) SetHandler(msgType message.MessageType, handler common.ConnHandler) error
type NodeConfig ¶
type NodeOption ¶
type NodeOption func(*NodeConfig)
func WithNodeCacheCount ¶
func WithNodeCacheCount(count int) NodeOption
func WithNodeProtocol ¶
func WithNodeProtocol(protocol protocol.ID) NodeOption
func WithStream ¶
func WithStream(stream network.Stream) NodeOption
type P2PMessage ¶
type P2PMessage struct { MsgType message.MessageType Payload []byte // contains filtered or unexported fields }
func (*P2PMessage) Broadcast ¶
func (m *P2PMessage) Broadcast() bool
func (*P2PMessage) Decode ¶
func (m *P2PMessage) Decode(t message.MessageType, payload []byte) error
func (*P2PMessage) Encode ¶
func (m *P2PMessage) Encode() ([]byte, error)
func (*P2PMessage) Peer ¶
func (m *P2PMessage) Peer() peer.ID
func (*P2PMessage) Type ¶
func (m *P2PMessage) Type() message.MessageType
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) Bootstrapped ¶
func (*Service) HandlePeerFound ¶
func (*Service) SetHandler ¶
func (s *Service) SetHandler(mt message.MessageType, handler common.ConnHandler) error
func (*Service) WriterMessage ¶
Click to show internal directories.
Click to hide internal directories.