network

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Message

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

Types

type ConnectCallback

type ConnectCallback func(ID) error

type ID

type ID interface{}

ID represents peer id

type IDStore

type IDStore interface {
	Add(ID, *peer.AddrInfo)
	Remove(ID)
	Addr(ID) *peer.AddrInfo
	Addrs() map[ID]*peer.AddrInfo
}

type MessageStream

type MessageStream struct {
	Message *proto.Message
	Stream  network.Stream
}

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(ID) error

	// Disconnect peer with id
	Disconnect(ID) error

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

	// Send message to peer with peer info.
	Send(ID, *proto.Message) error

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

	// Sync Send message
	SyncSend(ID, *proto.Message) (*proto.Message, error)

	// Broadcast message to all node
	Broadcast([]ID, *proto.Message) error

	// Receive message from the channel
	Receive() <-chan *MessageStream

	// IDStore
	IDStore() IDStore
}

type OnConnectCallback

type OnConnectCallback func(*peer.AddrInfo, ID)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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