Documentation ¶
Index ¶
- Constants
- Variables
- func GetCommitteeIDOfTopic(topic string) int
- func ParseListenner(s, defaultIP string, defaultPort int) (string, int)
- type AddrKeeper
- func (keeper *AddrKeeper) Add(addr rpcclient.HighwayAddr)
- func (keeper *AddrKeeper) ChooseHighway(discoverer HighwayDiscoverer, ourPID peer.ID) (rpcclient.HighwayAddr, error)
- func (keeper *AddrKeeper) GetHighway(selfPeerID *peer.ID) (*rpcclient.HighwayAddr, error)
- func (keeper *AddrKeeper) IgnoreAddress(addr rpcclient.HighwayAddr)
- func (keeper *AddrKeeper) Start(host *Host, ps *ping.PingService, discoverer HighwayDiscoverer, dpas []string)
- func (keeper *AddrKeeper) UpdateRTTData(host *Host, ps *ping.PingService)
- type AllConnectionStatus
- type BlockGetter
- type BlockProvider
- func (bp *BlockProvider) GetBlockBeaconByHash(ctx context.Context, req *proto.GetBlockBeaconByHashRequest) (*proto.GetBlockBeaconByHashResponse, error)
- func (bp *BlockProvider) GetBlockBeaconByHeight(fromPool bool, specificHeight bool, blkHeights []uint64) []wire.Message
- func (bp *BlockProvider) GetBlockCrossShardByHash(ctx context.Context, req *proto.GetBlockCrossShardByHashRequest) (*proto.GetBlockCrossShardByHashResponse, error)
- func (bp *BlockProvider) GetBlockShardByHash(ctx context.Context, req *proto.GetBlockShardByHashRequest) (*proto.GetBlockShardByHashResponse, error)
- func (bp *BlockProvider) GetBlockShardByHeight(fromPool bool, blkType byte, specificHeight bool, shardID byte, ...) []wire.Message
- func (bp *BlockProvider) Register(ctx context.Context, req *proto.RegisterRequest) (*proto.RegisterResponse, error)
- func (bp *BlockProvider) StreamBlockByHash(req *proto.BlockByHashRequest, ...) error
- func (bp *BlockProvider) StreamBlockByHeight(req *proto.BlockByHeightRequest, ...) error
- type BlockRequester
- func (c *BlockRequester) CloseConnection(id int)
- func (c *BlockRequester) ConnectNewHW(hwAddrInfo *peer.AddrInfo, id int) (err error)
- func (c *BlockRequester) GetBlockBeaconByHash(hashes []common.Hash) ([][]byte, error)
- func (c *BlockRequester) GetBlockShardByHash(shardID int32, hashes []common.Hash) ([][]byte, error)
- func (c *BlockRequester) IsReady() bool
- func (c *BlockRequester) Register(ctx context.Context, pubkey string, messages []string, committeeIDs []byte, ...) ([]*proto.MessageTopicPair, *proto.UserRole, error)
- func (c *BlockRequester) StreamBlockByHash(ctx context.Context, req *proto.BlockByHashRequest) (proto.HighwayService_StreamBlockByHashClient, error)
- func (c *BlockRequester) StreamBlockByHeight(ctx context.Context, req *proto.BlockByHeightRequest) (proto.HighwayService_StreamBlockByHeightClient, error)
- func (c *BlockRequester) Target() string
- func (c *BlockRequester) UpdateTarget(p peer.ID)
- func (c *BlockRequester) WatchConnection(currentHW peer.ID, id int)
- type ConnManager
- func (cm *ConnManager) BroadcastCommittee(epoch uint64, newBeaconCommittee []incognitokey.CommitteePublicKey, ...)
- func (cm *ConnManager) CloseConnToCurHW(isDisconnected bool)
- func (cm *ConnManager) GetConnectionStatus() interface{}
- func (cm *ConnManager) PickHighway() error
- func (cm *ConnManager) PublishMessage(msg wire.Message) error
- func (cm *ConnManager) PublishMessageToShard(msg wire.Message, shardID byte) error
- func (cm *ConnManager) PutMessage(msg *pubsub.Message)
- func (conn *ConnManager) RequestBeaconBlocksByHashViaStream(ctx context.Context, peerID string, hashes [][]byte) (blockCh chan types.BlockInterface, err error)
- func (conn *ConnManager) RequestBeaconBlocksViaStream(ctx context.Context, peerID string, from uint64, to uint64) (blockCh chan types.BlockInterface, err error)
- func (conn *ConnManager) RequestCrossShardBlocksByHashViaStream(ctx context.Context, peerID string, fromSID int, toSID int, hashes [][]byte) (blockCh chan types.BlockInterface, err error)
- func (conn *ConnManager) RequestCrossShardBlocksViaStream(ctx context.Context, peerID string, fromSID int, toSID int, heights []uint64) (blockCh chan types.BlockInterface, err error)
- func (conn *ConnManager) RequestShardBlocksByHashViaStream(ctx context.Context, peerID string, fromSID int, hashes [][]byte) (blockCh chan types.BlockInterface, err error)
- func (conn *ConnManager) RequestShardBlocksViaStream(ctx context.Context, peerID string, fromSID int, from uint64, to uint64) (blockCh chan types.BlockInterface, err error)
- func (cm *ConnManager) SetSyncMode(syncMode string)
- func (cm *ConnManager) Start(bg BlockGetter)
- func (cm *ConnManager) StartV2(bg BlockGetter)
- type ConnectionStatus
- type ConsensusData
- type Dispatcher
- type ForcedSubscriber
- type GRPCDialer
- type HighwayDiscoverer
- type Host
- type HostConfig
- type MessageListeners
- type Peer
- type PeerConn
- type Peerv2Logger
- type RTTInfo
- type Registerer
- type SubManager
- type Subscriber
- type Topic
Constants ¶
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
const MAX_RTT_STORE = 5
Variables ¶
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 )
var HighwayBeaconID = byte(255)
var Logger = Peerv2Logger{}
Global instant to use
Functions ¶
func GetCommitteeIDOfTopic ¶
GetCommitteeIDOfTopic handle error later TODO handle error pls
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 (bp *BlockProvider) GetBlockBeaconByHash(ctx context.Context, req *proto.GetBlockBeaconByHashRequest) (*proto.GetBlockBeaconByHashResponse, error)
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) GetBlockCrossShardByHash ¶
func (bp *BlockProvider) GetBlockCrossShardByHash(ctx context.Context, req *proto.GetBlockCrossShardByHashRequest) (*proto.GetBlockCrossShardByHashResponse, error)
func (*BlockProvider) GetBlockShardByHash ¶
func (bp *BlockProvider) GetBlockShardByHash(ctx context.Context, req *proto.GetBlockShardByHashRequest) (*proto.GetBlockShardByHashResponse, error)
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 (bp *BlockProvider) Register(ctx context.Context, req *proto.RegisterRequest) (*proto.RegisterResponse, error)
func (*BlockProvider) StreamBlockByHash ¶
func (bp *BlockProvider) StreamBlockByHash( req *proto.BlockByHashRequest, stream proto.HighwayService_StreamBlockByHashServer, ) error
func (*BlockProvider) StreamBlockByHeight ¶
func (bp *BlockProvider) StreamBlockByHeight( req *proto.BlockByHeightRequest, stream proto.HighwayService_StreamBlockByHeightServer, ) error
type BlockRequester ¶
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 (*BlockRequester) IsReady ¶
func (c *BlockRequester) IsReady() bool
func (*BlockRequester) StreamBlockByHash ¶
func (c *BlockRequester) StreamBlockByHash( ctx context.Context, req *proto.BlockByHashRequest, ) (proto.HighwayService_StreamBlockByHashClient, error)
func (*BlockRequester) StreamBlockByHeight ¶
func (c *BlockRequester) StreamBlockByHeight( ctx context.Context, req *proto.BlockByHeightRequest, ) (proto.HighwayService_StreamBlockByHeightClient, error)
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 ConsensusData ¶
type Dispatcher ¶
type Dispatcher struct { MessageListeners *MessageListeners PublishableMessage []string BC *blockchain.BlockChain CurrentHWPeerID libp2p.ID }
type ForcedSubscriber ¶
type GRPCDialer ¶
type GRPCDialer interface {
Dial(ctx context.Context, peerID peer.ID, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error)
}
type HighwayDiscoverer ¶
type HostConfig ¶
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 PeerConn ¶
type PeerConn struct { RemotePeer *Peer RW *bufio.ReadWriter }
type Peerv2Logger ¶
func (*Peerv2Logger) Init ¶
func (self *Peerv2Logger) Init(inst common.Logger)
type Registerer ¶
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 Topic ¶
type Topic struct { Name string Sub *pubsub.Subscription Act proto.MessageTopicPair_Action }