peerv2

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 43 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxCallRecvMsgSize = 50 << 20 // 50 MBs per gRPC response
	MaxConnectionRetry = 6        // connect to new highway after 6 failed retries
	PingTimes          = 10
	MaxTimeIgnoreHW    = 1 * time.Minute
)

block type

View Source
const MAX_RTT_STORE = 5

Variables

View Source
var (
	RegisterTimestep          = 2 * time.Second // Re-register to highway
	CheckSubsTimestep         = 5 * time.Second // Re-register to highway
	ReconnectHighwayTimestep  = 1 * time.Second // Check libp2p connection
	ReEstimatedRTTTimestep    = 3 * time.Minute
	UpdateHighwayListTimestep = 5 * time.Minute  // RPC to update list of highways
	RequesterDialTimestep     = 10 * time.Second // Check gRPC connection
	MaxTimePerRequest         = 30 * time.Second // Time per request
	DialTimeout               = 5 * time.Second  // Timeout for dialing's context
	PingTimeout               = 4 * time.Second  // Timeout for dialing's context

	RequesterKeepaliveTime    = 10 * time.Minute
	RequesterKeepaliveTimeout = 30 * time.Second

	IgnoreRPCDuration = 60 * time.Minute  // Ignore an address after a failed RPC
	IgnoreHWDuration  = 360 * time.Minute // Ignore a highway when cannot connect
)
View Source
var HighwayBeaconID = byte(255)
View Source
var Logger = Peerv2Logger{}

Global instant to use

Functions

func GetCommitteeIDOfTopic

func GetCommitteeIDOfTopic(topic string) int

GetCommitteeIDOfTopic handle error later TODO handle error pls

func ParseListenner

func ParseListenner(s, defaultIP string, defaultPort int) (string, int)

Types

type AddrKeeper

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

AddrKeeper stores all highway addresses for ConnManager to choose from. The address can be used to: 1. Make an RPC call to get a new list of highway 2. Choose a highway (consistent hashed) and connect to it For the 1st type, if it fails, AddrKeeper will ignore the requested address for some time so that the next few calls will be more likely to succeed. For the 2nd type, caller can manually ignore the chosen address.

func NewAddrKeeper

func NewAddrKeeper() *AddrKeeper

func (*AddrKeeper) Add

func (keeper *AddrKeeper) Add(addr rpcclient.HighwayAddr)

Add saves a highway address; should only be used at the start for bootnode since there's no usage of mutex

func (*AddrKeeper) ChooseHighway

func (keeper *AddrKeeper) ChooseHighway(discoverer HighwayDiscoverer, ourPID peer.ID) (rpcclient.HighwayAddr, error)

ChooseHighway refreshes the list of highways by asking a random one and choose a (consistently) random highway to connect

func (*AddrKeeper) GetHighway

func (keeper *AddrKeeper) GetHighway(selfPeerID *peer.ID) (*rpcclient.HighwayAddr, error)

func (*AddrKeeper) IgnoreAddress

func (keeper *AddrKeeper) IgnoreAddress(addr rpcclient.HighwayAddr)

func (*AddrKeeper) Start

func (keeper *AddrKeeper) Start(
	host *Host,
	ps *ping.PingService,
	discoverer HighwayDiscoverer,
	dpas []string,
)

func (*AddrKeeper) UpdateRTTData

func (keeper *AddrKeeper) UpdateRTTData(
	host *Host,
	ps *ping.PingService,
)

type AllConnectionStatus

type AllConnectionStatus struct {
	Status map[string][]ConnectionStatus `json:"status"`
}

type BlockGetter

type BlockGetter interface {
	StreamBlockByHeight(fromPool bool, req *proto.BlockByHeightRequest) chan interface{}
	StreamBlockByHash(fromPool bool, req *proto.BlockByHashRequest) chan interface{}
	GetShardBlockByHeight(height uint64, shardID byte) (map[common.Hash]*types.ShardBlock, error)
	GetShardBlockByHash(hash common.Hash) (*types.ShardBlock, uint64, error)
	GetBeaconBlockByHeight(height uint64) ([]*types.BeaconBlock, error)
	GetBeaconBlockByHash(beaconBlockHash common.Hash) (*types.BeaconBlock, uint64, error)
}

type BlockProvider

type BlockProvider struct {
	proto.UnimplementedHighwayServiceServer
	BlockGetter BlockGetter
}

func NewBlockProvider

func NewBlockProvider(p *p2pgrpc.GRPCProtocol, bg BlockGetter) *BlockProvider

func (*BlockProvider) GetBlockBeaconByHash

func (*BlockProvider) GetBlockBeaconByHeight

func (bp *BlockProvider) GetBlockBeaconByHeight(
	fromPool bool,
	specificHeight bool,
	blkHeights []uint64,
) []wire.Message

GetBlockBeaconByHeight return list message contains all of blocks of given heights

func (*BlockProvider) GetBlockShardByHash

func (*BlockProvider) GetBlockShardByHeight

func (bp *BlockProvider) GetBlockShardByHeight(
	fromPool bool,
	blkType byte,
	specificHeight bool,
	shardID byte,
	blkHeights []uint64,
	crossShardID byte,
) []wire.Message

GetBlockShardByHeight return list message contains all of blocks of given heights

func (*BlockProvider) Register

func (*BlockProvider) StreamBlockByHash

func (*BlockProvider) StreamBlockByHeight

type BlockRequester

type BlockRequester struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRequester

func NewRequester(prtc GRPCDialer) *BlockRequester

func NewRequesterV2

func NewRequesterV2(prtc GRPCDialer) *BlockRequester

func (*BlockRequester) CloseConnection

func (c *BlockRequester) CloseConnection(id int)

func (*BlockRequester) ConnectNewHW

func (c *BlockRequester) ConnectNewHW(hwAddrInfo *peer.AddrInfo, id int) (err error)

func (*BlockRequester) GetBlockBeaconByHash

func (c *BlockRequester) GetBlockBeaconByHash(
	hashes []common.Hash,
) ([][]byte, error)

func (*BlockRequester) GetBlockShardByHash

func (c *BlockRequester) GetBlockShardByHash(
	shardID int32,
	hashes []common.Hash,
) ([][]byte, error)

func (*BlockRequester) IsReady

func (c *BlockRequester) IsReady() bool

func (*BlockRequester) Register

func (c *BlockRequester) Register(
	ctx context.Context,
	pubkey string,
	messages []string,
	committeeIDs []byte,
	selfID peer.ID,
	role string,
) ([]*proto.MessageTopicPair, *proto.UserRole, error)

func (*BlockRequester) StreamBlockByHash

func (*BlockRequester) Target

func (c *BlockRequester) Target() string

func (*BlockRequester) UpdateTarget

func (c *BlockRequester) UpdateTarget(p peer.ID)

func (*BlockRequester) WatchConnection

func (c *BlockRequester) WatchConnection(currentHW peer.ID, id int)

type ConnManager

type ConnManager struct {
	LocalHost  *Host
	Subscriber ForcedSubscriber

	DiscoverPeersAddress []string
	IsMasterNode         bool

	Requester *BlockRequester
	Provider  *BlockProvider
	// contains filtered or unexported fields
}

func NewConnManager

func NewConnManager(
	host *Host,
	dpa []string,
	ikey *incognitokey.CommitteePublicKey,
	cd ConsensusData,
	dispatcher *Dispatcher,
	syncMode string,
	relayShard []byte,
) *ConnManager

func (*ConnManager) BroadcastCommittee

func (cm *ConnManager) BroadcastCommittee(
	epoch uint64,
	newBeaconCommittee []incognitokey.CommitteePublicKey,
	newAllShardCommittee map[byte][]incognitokey.CommitteePublicKey,
	newAllShardPending map[byte][]incognitokey.CommitteePublicKey,
)

BroadcastCommittee floods message to topic `chain_committee` for highways Only masternode actually does the broadcast, other's messages will be ignored by highway

func (*ConnManager) CloseConnToCurHW

func (cm *ConnManager) CloseConnToCurHW(isDisconnected bool)

func (*ConnManager) GetConnectionStatus

func (cm *ConnManager) GetConnectionStatus() interface{}

func (*ConnManager) PickHighway

func (cm *ConnManager) PickHighway() error

func (*ConnManager) PublishMessage

func (cm *ConnManager) PublishMessage(msg wire.Message) error

func (*ConnManager) PublishMessageToShard

func (cm *ConnManager) PublishMessageToShard(msg wire.Message, shardID byte) error

func (*ConnManager) PutMessage

func (cm *ConnManager) PutMessage(msg *pubsub.Message)

func (*ConnManager) RequestBeaconBlocksByHashViaStream

func (conn *ConnManager) RequestBeaconBlocksByHashViaStream(ctx context.Context, peerID string, hashes [][]byte) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) RequestBeaconBlocksViaStream

func (conn *ConnManager) RequestBeaconBlocksViaStream(ctx context.Context, peerID string, from uint64, to uint64) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) RequestCrossShardBlocksByHashViaStream

func (conn *ConnManager) RequestCrossShardBlocksByHashViaStream(ctx context.Context, peerID string, fromSID int, toSID int, hashes [][]byte) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) RequestCrossShardBlocksViaStream

func (conn *ConnManager) RequestCrossShardBlocksViaStream(ctx context.Context, peerID string, fromSID int, toSID int, heights []uint64) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) RequestShardBlocksByHashViaStream

func (conn *ConnManager) RequestShardBlocksByHashViaStream(ctx context.Context, peerID string, fromSID int, hashes [][]byte) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) RequestShardBlocksViaStream

func (conn *ConnManager) RequestShardBlocksViaStream(ctx context.Context, peerID string, fromSID int, from uint64, to uint64) (blockCh chan types.BlockInterface, err error)

func (*ConnManager) SetSyncMode

func (cm *ConnManager) SetSyncMode(syncMode string)

func (*ConnManager) Start

func (cm *ConnManager) Start(bg BlockGetter)

func (*ConnManager) StartV2

func (cm *ConnManager) StartV2(bg BlockGetter)

type ConnectionStatus

type ConnectionStatus struct {
	URL         string `json:"url"`
	IsCurrentHW bool   `json:"iscurrenthw"`
	RTT         string `json:"rttmetric"`
}

type ConsensusData

type ConsensusData interface {
	GetValidators() []*consensus.Validator
	GetOneValidator() *consensus.Validator
	GetOneValidatorForEachConsensusProcess() map[int]*consensus.Validator
}

type Dispatcher

type Dispatcher struct {
	MessageListeners   *MessageListeners
	PublishableMessage []string
	BC                 *blockchain.BlockChain
	CurrentHWPeerID    libp2p.ID
}

type ForcedSubscriber

type ForcedSubscriber interface {
	Subscribe(forced bool) error
	GetMsgToTopics() msgToTopics
	SetSyncMode(string)
}

type GRPCDialer

type GRPCDialer interface {
	Dial(ctx context.Context, peerID peer.ID, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error)
}

type HighwayDiscoverer

type HighwayDiscoverer interface {
	DiscoverHighway(discoverPeerAddress string, shardsStr []string) (map[string][]rpcclient.HighwayAddr, error)
}

type Host

type Host struct {
	Version  string
	Host     host.Host
	SelfPeer *Peer
	GRPC     *p2pgrpc.GRPCProtocol
}

func NewHost

func NewHost(version string, pubIP string, port int, privateKey string) *Host

func (Host) GetDirectProtocolID

func (s Host) GetDirectProtocolID() protocol.ID

func (Host) GetProxyStreamProtocolID

func (s Host) GetProxyStreamProtocolID() protocol.ID

type HostConfig

type HostConfig struct {
	MaxConnection int
	PublicIP      string
	Port          int
	PrivateKey    crypto.PrivKey
}

type MessageListeners

type MessageListeners struct {
	OnTx             func(p *peer.PeerConn, msg *wire.MessageTx)
	OnTxPrivacyToken func(p *peer.PeerConn, msg *wire.MessageTxPrivacyToken)
	OnBlockShard     func(p *peer.PeerConn, msg *wire.MessageBlockShard)
	OnBlockBeacon    func(p *peer.PeerConn, msg *wire.MessageBlockBeacon)
	OnCrossShard     func(p *peer.PeerConn, msg *wire.MessageCrossShard)
	OnGetBlockBeacon func(p *peer.PeerConn, msg *wire.MessageGetBlockBeacon)
	OnGetBlockShard  func(p *peer.PeerConn, msg *wire.MessageGetBlockShard)
	OnGetCrossShard  func(p *peer.PeerConn, msg *wire.MessageGetCrossShard)
	OnVersion        func(p *peer.PeerConn, msg *wire.MessageVersion)
	OnVerAck         func(p *peer.PeerConn, msg *wire.MessageVerAck)
	OnGetAddr        func(p *peer.PeerConn, msg *wire.MessageGetAddr)
	OnAddr           func(p *peer.PeerConn, msg *wire.MessageAddr)

	//PBFT
	OnBFTMsg     func(p *peer.PeerConn, msg wire.Message)
	OnPeerState  func(p *peer.PeerConn, msg *wire.MessagePeerState)
	OnFinishSync func(p *peer.PeerConn, msg *wire.MessageFinishSync)
	OnFeatureMsg func(p *peer.PeerConn, msg *wire.MessageFeature)
}

type Peer

type Peer struct {
	IP            string
	Port          int
	TargetAddress []core.Multiaddr
	PeerID        peer.ID
	PublicKey     crypto2.PublicKey
}

type PeerConn

type PeerConn struct {
	RemotePeer *Peer
	RW         *bufio.ReadWriter
}

type Peerv2Logger

type Peerv2Logger struct {
	common.Logger
}

func (*Peerv2Logger) Init

func (self *Peerv2Logger) Init(inst common.Logger)

type RTTInfo

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

type Registerer

type Registerer interface {
	Register(context.Context, string, []string, []byte, peer.ID, string) ([]*proto.MessageTopicPair, *proto.UserRole, error)
	Target() string
	UpdateTarget(peer.ID)
}

type SubManager

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

SubManager manages pubsub subscription of highway's topics

func NewSubManager

func NewSubManager(
	info info,
	subscriber Subscriber,
	registerer Registerer,
	messages chan *pubsub.Message,
	dispatcher *Dispatcher,
) *SubManager

func (*SubManager) GetMsgToTopics

func (sub *SubManager) GetMsgToTopics() msgToTopics

func (*SubManager) SetSyncMode

func (sub *SubManager) SetSyncMode(s string)

func (*SubManager) Subscribe

func (sub *SubManager) Subscribe(forced bool) error

Subscribe registers to proxy and save the list of new topics if needed

type Subscriber

type Subscriber interface {
	Subscribe(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
}

type Topic

type Topic struct {
	Name string
	Sub  *pubsub.Subscription
	Act  proto.MessageTopicPair_Action
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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