network

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

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

Types

type Handshake

type Handshake func(genesisHash types.Hash, currentHeight uint64) error
type Header struct {
	DupFlag, Retain bool
}

func (*Header) Decode

func (hdr *Header) Decode(r io.Reader) (msgType message.MessageType, remainingLength int32, err error)

func (*Header) Encode

func (hdr *Header) Encode(w io.Writer, msgType message.MessageType, remainingLength int32) error

type KadDHT

type KadDHT struct {
	*kademliaDHT.IpfsDHT
	// contains filtered or unexported fields
}

func NewKadDht

func NewKadDht(ctx context.Context, s *Service, isServer bool, bootstrappers ...peer.AddrInfo) (*KadDHT, error)

func (*KadDHT) Start

func (k *KadDHT) Start() error

type Message

type Message struct {
	// contains filtered or unexported fields
}

type Node

type Node struct {
	host.Host

	sync.RWMutex
	// contains filtered or unexported fields
}

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 (n *Node) AcceptHandshake(h *msg_proto.ProtocolHandshakeMessage, version string, genesisHash types.Hash, currentHeight *uint256.Int) error

func (*Node) ClearHandler

func (n *Node) ClearHandler(msgType message.MessageType) error

func (*Node) Close

func (n *Node) Close() error

func (*Node) ID

func (n *Node) ID() libpeer.ID

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

func (*Node) Start

func (n *Node) Start()

func (*Node) Write

func (n *Node) Write(msg message.IMessage) error

func (*Node) WriteMsg

func (n *Node) WriteMsg(messageType message.MessageType, payload []byte) error

type NodeConfig

type NodeConfig struct {
	Stream     network.Stream
	Protocol   protocol.ID
	CacheCount int
}

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 (s *Service) Bootstrapped() bool

func (*Service) ClosePeer

func (s *Service) ClosePeer(id peer.ID) error

func (*Service) HandlePeerFound

func (s *Service) HandlePeerFound(p peer.AddrInfo)

func (*Service) Host

func (s *Service) Host() host.Host

func (*Service) ID

func (s *Service) ID() string

func (*Service) PeerCount

func (s *Service) PeerCount() int

func (*Service) SendMsgToPeer

func (s *Service) SendMsgToPeer(id string, data []byte) error

func (*Service) SetHandler

func (s *Service) SetHandler(mt message.MessageType, handler common.ConnHandler) error

func (*Service) Start

func (s *Service) Start() error

func (*Service) Wait

func (s *Service) Wait()

func (*Service) WriterMessage

func (s *Service) WriterMessage(messageType message.MessageType, payload []byte, peer peer.ID) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL