network

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateP2PNet

func CreateP2PNet(chanName string) (nodeNetwork *libp2pnet.LibP2pNet, err error)

CreateP2PNet use channel name create p2pnet

func SendMsg

func SendMsg(chanName string, node *libp2pnet.LibP2pNet, msg *Message, receiveId string) (err error)

SendMsg send message

func SetHandler

func SetHandler(chanName string, nodeNetwork *libp2pnet.LibP2pNet, nodeName string) (err error)

SetHandler set p2p message handler

Types

type Message

type Message struct {
	MsgType MsgType
	Data    []byte
	From    string
	To      string
}

Message define message struct

type MsgType

type MsgType int32

MsgType message type

const (
	// HBPing heart beat message type
	HBPing MsgType = iota
	// NodeJoin node join message type
	NodeJoin
	// NodeJoinResp node join response message type
	NodeJoinResp
	// NodeExit node exit message type
	NodeExit
	// NodePubkeySync node pub key sync message type
	NodePubkeySync
	// TxMsg tx message message type
	TxMsg
	// TxRequest tx request message type
	TxRequest
	// TxCommit tx commit message type
	TxCommit
	// TxNotify tx notify message type
	TxNotify
	// UpdateStateRequest update state request message type
	UpdateStateRequest
	// UpdateStateReply update state reply message type
	UpdateStateReply
	// UpdateStateConfirm update state confirm message type
	UpdateStateConfirm
	// TradePhaseNotify trade phase notify message type
	TradePhaseNotify
	// ConsensusPhaseNotify consensus phase notify message type
	ConsensusPhaseNotify
)

type NetOption

type NetOption func(ln *libp2pnet.LibP2pNet) error

NetOption is a function apply options to net instance.

func WithBlackAddresses

func WithBlackAddresses(blackAddresses ...string) NetOption

WithBlackAddresses set addresses of the nodes for blacklist.

func WithBlackNodeIds

func WithBlackNodeIds(blackNodeIds ...string) NetOption

WithBlackNodeIds set ids of the nodes for blacklist.

func WithCrypto

func WithCrypto(pkMode bool, keyFile string, certFile string) NetOption

WithCrypto set private key file and tls cert file for the net to create connection.

func WithInsecurity

func WithInsecurity(isInsecurity bool) NetOption

WithInsecurity set insecurity p2p

func WithListenAddr

func WithListenAddr(addr string) NetOption

WithListenAddr set addr that the local net will listen on.

func WithMaxPeerCountAllowed

func WithMaxPeerCountAllowed(max int) NetOption

WithMaxPeerCountAllowed set max count of nodes that connected to us.

func WithMsgCompression

func WithMsgCompression(enable bool) NetOption

WithMsgCompression set whether compressing the payload when sending msg.

func WithPeerEliminationStrategy

func WithPeerEliminationStrategy(strategy int) NetOption

WithPeerEliminationStrategy set the strategy for eliminating node when the count of nodes that connected to us reach the max value.

func WithPeerStreamPoolSize

func WithPeerStreamPoolSize(size int) NetOption

WithPeerStreamPoolSize set the max stream pool size for every node that connected to us.

func WithPktEnable

func WithPktEnable(pktEnable bool) NetOption

WithPktEnable set pk enable

func WithPriorityControlEnable

func WithPriorityControlEnable(priorityCtrlEnable bool) NetOption

WithPriorityControlEnable config priority controller

func WithPubSubMaxMessageSize

func WithPubSubMaxMessageSize(size int) NetOption

WithPubSubMaxMessageSize set max message size (M) for pub/sub.

func WithReadySignalC

func WithReadySignalC(signalC chan struct{}) NetOption

WithReadySignalC set a ready flag

func WithSeeds

func WithSeeds(seeds ...string) NetOption

WithSeeds set addresses of discovery service node.

func WithTrustRoots

func WithTrustRoots(chainId string, caFiles ...string) NetOption

WithTrustRoots set up custom Trust Roots

Jump to

Keyboard shortcuts

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