network

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrToPeerInfo

func AddrToPeerInfo(multiAddr string) (*peer.AddrInfo, error)

AddrToPeerInfo transfer addr to PeerInfo addr example: "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64"

func Message

func Message(data []byte) *network_pb.Message

Types

type Config

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

type ConnectCallback

type ConnectCallback func(*peer.AddrInfo) error

type MessageHandler

type MessageHandler func(network.Stream, []byte)

type Network

type Network interface {
	// Start start the network service.
	Start() error

	// Stop stop the network service.
	Stop() error

	// Connect connects peer by ID.
	Connect(*peer.AddrInfo) error

	// Disconnect peer with id
	Disconnect(*peer.AddrInfo) error

	// SetConnectionCallback sets the callback after connecting
	SetConnectCallback(ConnectCallback)

	// SetMessageHandler sets message handler
	SetMessageHandler(MessageHandler)

	// AsyncSend sends message to peer with peer info.
	AsyncSend(*peer.AddrInfo, *network_pb.Message) error

	// Send message using existed stream
	SendWithStream(network.Stream, *network_pb.Message) error

	// Send sends message waiting response
	Send(*peer.AddrInfo, *network_pb.Message) (*network_pb.Message, error)

	// Broadcast message to all node
	Broadcast([]*peer.AddrInfo, *network_pb.Message) error

	// GetRemotePubKey gets remote public key
	GetRemotePubKey(id peer.ID) (crypto.PubKey, error)
}

type Option

type Option func(*Config)

func WithLocalAddr

func WithLocalAddr(addr string) Option

func WithLogger

func WithLogger(logger logrus.FieldLogger) Option

func WithPrivateKey

func WithPrivateKey(privKey crypto.PrivKey) Option

func WithProtocolID

func WithProtocolID(id protocol.ID) Option

type P2P

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

func New

func New(opts ...Option) (*P2P, error)

func (*P2P) AsyncSend

func (p2p *P2P) AsyncSend(addr *peer.AddrInfo, msg *network_pb.Message) error

AsyncSend message to peer with specific id.

func (*P2P) Broadcast

func (p2p *P2P) Broadcast(ids []*peer.AddrInfo, msg *network_pb.Message) error

func (*P2P) Connect

func (p2p *P2P) Connect(addr *peer.AddrInfo) error

Connect peer.

func (*P2P) Disconnect

func (p2p *P2P) Disconnect(addr *peer.AddrInfo) error

func (*P2P) GetRemotePubKey added in v1.0.1

func (p2p *P2P) GetRemotePubKey(id peer.ID) (crypto.PubKey, error)

func (*P2P) Send

func (p2p *P2P) Send(addr *peer.AddrInfo, msg *network_pb.Message) (*network_pb.Message, error)

func (*P2P) SendWithStream

func (p2p *P2P) SendWithStream(s network.Stream, msg *network_pb.Message) error

func (*P2P) SetConnectCallback

func (p2p *P2P) SetConnectCallback(callback ConnectCallback)

func (*P2P) SetMessageHandler

func (p2p *P2P) SetMessageHandler(handler MessageHandler)

func (*P2P) Start

func (p2p *P2P) Start() error

Start start the network service.

func (*P2P) Stop

func (p2p *P2P) Stop() error

Stop stop the network service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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