peerv2

package
v0.0.0-...-dbbd7c7 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 38 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
)

block type

Variables

View Source
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
)
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) 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 (*BlockProvider) GetBlockShardByHash

func (*BlockProvider) Register

func (*BlockProvider) StreamBlockByHash

func (*BlockProvider) StreamBlockByHeight

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

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 ConsensusData interface {
	GetUserRole() (string, string, int)
	GetCurrentMiningPublicKey() (publickey string, keyType string)
}

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
}

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)
	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 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 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,
) *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 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