Documentation ¶
Index ¶
- Constants
- Variables
- func GetCommitteeIDOfTopic(topic string) int
- func ParseListenner(s, defaultIP string, defaultPort int) (string, int)
- type AddrKeeper
- type BlockProvider
- func (bp *BlockProvider) GetBlockBeaconByHash(ctx context.Context, req *proto.GetBlockBeaconByHashRequest) (*proto.GetBlockBeaconByHashResponse, error)
- 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) 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) 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)
- type ConnManager
- func (cm *ConnManager) BroadcastCommittee(epoch uint64, newBeaconCommittee []incognitokey.CommitteePublicKey, ...)
- func (cm *ConnManager) PublishMessage(msg wire.Message) error
- func (cm *ConnManager) PublishMessageToShard(msg wire.Message, shardID byte) error
- func (cm *ConnManager) PutData(data []byte)
- func (cm *ConnManager) PutMessage(msg *pubsub.Message)
- func (cm *ConnManager) Start(ns NetSync)
- type ConsensusData
- type Dispatcher
- type ForcedSubscriber
- type GRPCDialer
- type HighwayDiscoverer
- type Host
- type HostConfig
- type MessageListeners
- type NetSync
- type Peer
- type PeerConn
- type Peerv2Logger
- 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 )
block type
Variables ¶
var ( RegisterTimestep = 1 * time.Second // Re-register to highway ReconnectHighwayTimestep = 10 * time.Second // Check libp2p connection UpdateHighwayListTimestep = 10 * 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 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) IgnoreAddress ¶
func (keeper *AddrKeeper) IgnoreAddress(addr rpcclient.HighwayAddr)
type BlockProvider ¶
type BlockProvider struct { proto.UnimplementedHighwayServiceServer NetSync NetSync }
func NewBlockProvider ¶
func NewBlockProvider(p *p2pgrpc.GRPCProtocol, ns NetSync) *BlockProvider
func (*BlockProvider) GetBlockBeaconByHash ¶
func (bp *BlockProvider) GetBlockBeaconByHash(ctx context.Context, req *proto.GetBlockBeaconByHashRequest) (*proto.GetBlockBeaconByHashResponse, error)
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) 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 ¶
type BlockRequester struct { sync.RWMutex HandleResponseBlock func([]byte) // contains filtered or unexported fields }
func NewRequester ¶
func NewRequester(prtc GRPCDialer) *BlockRequester
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)
type ConnManager ¶
type ConnManager struct { LocalHost *Host 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, nodeMode 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) PublishMessage ¶
func (cm *ConnManager) PublishMessage(msg wire.Message) error
func (*ConnManager) PublishMessageToShard ¶
func (cm *ConnManager) PublishMessageToShard(msg wire.Message, shardID byte) error
func (*ConnManager) PutData ¶
func (cm *ConnManager) PutData(data []byte)
func (*ConnManager) PutMessage ¶
func (cm *ConnManager) PutMessage(msg *pubsub.Message)
func (*ConnManager) Start ¶
func (cm *ConnManager) Start(ns NetSync)
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) OnShardToBeacon func(p *peer.PeerConn, msg *wire.MessageShardToBeacon) OnGetBlockBeacon func(p *peer.PeerConn, msg *wire.MessageGetBlockBeacon) OnGetBlockShard func(p *peer.PeerConn, msg *wire.MessageGetBlockShard) OnGetCrossShard func(p *peer.PeerConn, msg *wire.MessageGetCrossShard) OnGetShardToBeacon func(p *peer.PeerConn, msg *wire.MessageGetShardToBeacon) 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) }
type NetSync ¶
type NetSync interface { GetBlockShardByHash(blkHashes []common.Hash) []wire.Message GetBlockBeaconByHash(blkHashes []common.Hash) []wire.Message StreamBlockByHeight(fromPool bool, req *proto.BlockByHeightRequest) chan interface{} StreamBlockByHash(fromPool bool, req *proto.BlockByHashRequest) chan interface{} }
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, ) *SubManager
func (*SubManager) GetMsgToTopics ¶
func (sub *SubManager) GetMsgToTopics() msgToTopics
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 }