Documentation ¶
Index ¶
- Variables
- func LenSyncMap(m *sync.Map) uint
- type ConfigBasedPeerMaintainer
- type Gossip
- type HealthChecker
- type IotxOverlay
- func (o *IotxOverlay) AttachDispatcher(dispatcher dispatcher.Dispatcher)
- func (o *IotxOverlay) Broadcast(chainID uint32, msg proto.Message) error
- func (o *IotxOverlay) GetPeers() []net.Addr
- func (o *IotxOverlay) Self() net.Addr
- func (o *IotxOverlay) Start(ctx context.Context) error
- func (o *IotxOverlay) Stop(ctx context.Context) error
- func (o *IotxOverlay) Tell(chainID uint32, node net.Addr, msg proto.Message) error
- type MsgLogsCleaner
- type Overlay
- type Peer
- func (p *Peer) BroadcastMsg(req *pb.BroadcastReq) (*pb.BroadcastRes, error)
- func (p *Peer) Close() error
- func (p *Peer) Connect(config *config.Network) error
- func (p *Peer) GetPeers(req *pb.GetPeersReq) (*pb.GetPeersRes, error)
- func (p *Peer) Ping(ping *pb.Ping) (*pb.Pong, error)
- func (p *Peer) Tell(req *pb.TellReq) (*pb.TellRes, error)
- type PeerMaintainer
- type PeerManager
- type Pinger
- type RPCServer
- func (s *RPCServer) Broadcast(ctx context.Context, req *pb.BroadcastReq) (*pb.BroadcastRes, error)
- func (s *RPCServer) GetPeers(ctx context.Context, req *pb.GetPeersReq) (*pb.GetPeersRes, error)
- func (s *RPCServer) LastReqTime() time.Time
- func (s *RPCServer) Ping(ctx context.Context, ping *pb.Ping) (*pb.Pong, error)
- func (s *RPCServer) Start(_ context.Context) error
- func (s *RPCServer) Stop(_ context.Context) error
- func (s *RPCServer) Tell(ctx context.Context, req *pb.TellReq) (*pb.TellRes, error)
- type Topology
Constants ¶
This section is empty.
Variables ¶
var ErrPeerNotFound = errors.New("Peer not found")
ErrPeerNotFound means the peer is not found
Functions ¶
func LenSyncMap ¶ added in v0.2.0
LenSyncMap counts the length of a sync.map
Types ¶
type ConfigBasedPeerMaintainer ¶
type ConfigBasedPeerMaintainer struct { Overlay *IotxOverlay Addrs []net.Addr }
ConfigBasedPeerMaintainer maintain the neighbors by reading the topology file
func NewConfigBasedPeerMaintainer ¶
func NewConfigBasedPeerMaintainer(o *IotxOverlay, t *Topology) *ConfigBasedPeerMaintainer
NewConfigBasedPeerMaintainer creates an instance of ConfigBasedPeerMaintainer
func (*ConfigBasedPeerMaintainer) Update ¶ added in v0.3.0
func (cbpm *ConfigBasedPeerMaintainer) Update()
Update adds the configured addresses into the peer list
type Gossip ¶
type Gossip struct { Overlay *IotxOverlay Dispatcher dispatcher.Dispatcher MsgLogs *sync.Map CleanerTask *routine.RecurringTask // contains filtered or unexported fields }
Gossip relays messages in the IotxOverlay (at least once semantics)
func (*Gossip) AttachDispatcher ¶
func (g *Gossip) AttachDispatcher(dispatcher dispatcher.Dispatcher)
AttachDispatcher attaches to a Dispatcher instance
func (*Gossip) OnReceivingMsg ¶
OnReceivingMsg listens to and handles the incoming broadcast message
type HealthChecker ¶
type HealthChecker struct { Overlay *IotxOverlay SilentInterval time.Duration }
HealthChecker will check its peers at constant interval. If a peer is found not reachable for given period, it would be removed from the peer list
func NewHealthChecker ¶
func NewHealthChecker(o *IotxOverlay) *HealthChecker
NewHealthChecker creates an instance of HealthChecker
func (*HealthChecker) Check ¶ added in v0.3.0
func (hc *HealthChecker) Check()
Check checks peer health
type IotxOverlay ¶ added in v0.3.0
type IotxOverlay struct { PM *PeerManager RPC *RPCServer Gossip *Gossip Tasks []*routine.RecurringTask Config *config.Network Dispatcher dispatcher.Dispatcher // contains filtered or unexported fields }
IotxOverlay is the implementation
func NewOverlay ¶
func NewOverlay(config *config.Network) *IotxOverlay
NewOverlay creates an instance of IotxOverlay
func (*IotxOverlay) AttachDispatcher ¶ added in v0.3.0
func (o *IotxOverlay) AttachDispatcher(dispatcher dispatcher.Dispatcher)
AttachDispatcher attaches to a Dispatcher instance
func (*IotxOverlay) Broadcast ¶ added in v0.3.0
func (o *IotxOverlay) Broadcast(chainID uint32, msg proto.Message) error
Broadcast lets the caller to broadcast the message to all nodes in the P2P network
func (*IotxOverlay) GetPeers ¶ added in v0.3.0
func (o *IotxOverlay) GetPeers() []net.Addr
GetPeers returns the current neighbors' network identifiers
func (*IotxOverlay) Self ¶ added in v0.3.0
func (o *IotxOverlay) Self() net.Addr
Self returns the RPC server address to receive messages
func (*IotxOverlay) Start ¶ added in v0.3.0
func (o *IotxOverlay) Start(ctx context.Context) error
Start starts IotxOverlay and it's sub-models.
type MsgLogsCleaner ¶
type MsgLogsCleaner struct {
G *Gossip
}
MsgLogsCleaner periodically refreshes the recent received message log
func NewMsgLogsCleaner ¶
func NewMsgLogsCleaner(g *Gossip) *MsgLogsCleaner
NewMsgLogsCleaner generates a MsgLogsCleaner instance
type Overlay ¶
type Overlay interface { lifecycle.StartStopper Broadcast(uint32, proto.Message) error Tell(uint32, net.Addr, proto.Message) error Self() net.Addr GetPeers() []net.Addr }
Overlay represents the peer-to-peer network
type Peer ¶
type Peer struct { node.Node Client pb.PeerClient Conn *grpc.ClientConn Ctx context.Context LastResTime time.Time }
Peer represents a node in the peer-to-peer networks
func NewTCPPeer ¶
NewTCPPeer creates an instance of Peer with tcp transportation
func (*Peer) BroadcastMsg ¶
func (p *Peer) BroadcastMsg(req *pb.BroadcastReq) (*pb.BroadcastRes, error)
BroadcastMsg implements the client side RPC
func (*Peer) GetPeers ¶
func (p *Peer) GetPeers(req *pb.GetPeersReq) (*pb.GetPeersRes, error)
GetPeers implements the client side RPC
type PeerMaintainer ¶
type PeerMaintainer struct { Overlay *IotxOverlay // contains filtered or unexported fields }
PeerMaintainer helps maintain enough connections to other peers in the P2P networks
func NewPeerMaintainer ¶
func NewPeerMaintainer(o *IotxOverlay) *PeerMaintainer
NewPeerMaintainer creates an instance of PeerMaintainer
func (*PeerMaintainer) Update ¶ added in v0.3.0
func (pm *PeerMaintainer) Update()
Update maintains peer connection. Current strategy is to get the (upper_bound - count) peer addresses from one of the current peer if the count is lower than the lower bound
type PeerManager ¶
type PeerManager struct { // TODO: Need to revisit sync.Map: https://github.com/golang/go/issues/24112 Peers *sync.Map Overlay *IotxOverlay NumPeersLowerBound uint NumPeersUpperBound uint }
PeerManager represents the outgoing neighbor list TODO: We should decouple peer address and peer. Node can know more nodes than it connects to
func NewPeerManager ¶
func NewPeerManager(o *IotxOverlay, lb uint, ub uint) *PeerManager
NewPeerManager creates an instance of PeerManager
func (*PeerManager) GetOrAddPeer ¶
func (pm *PeerManager) GetOrAddPeer(addr string) *Peer
GetOrAddPeer gets a peer. If it is still not in the neighbor list, it will be added first.
func (*PeerManager) RemoveLRUPeer ¶
func (pm *PeerManager) RemoveLRUPeer()
RemoveLRUPeer removes the least recently used (contacted) peer
func (*PeerManager) RemovePeer ¶
func (pm *PeerManager) RemovePeer(addr string)
RemovePeer removes an existing peer
type Pinger ¶
type Pinger struct {
Overlay *IotxOverlay
}
Pinger is the recurring logic to constantly check if the node can talk to its peers
type RPCServer ¶
type RPCServer struct { node.Node Server *grpc.Server Overlay *IotxOverlay // contains filtered or unexported fields }
RPCServer represents the listener at the transportation layer
func NewRPCServer ¶
func NewRPCServer(o *IotxOverlay) *RPCServer
NewRPCServer creates an instance of RPCServer
func (*RPCServer) Broadcast ¶
func (s *RPCServer) Broadcast(ctx context.Context, req *pb.BroadcastReq) (*pb.BroadcastRes, error)
Broadcast implements the server side RPC logic
func (*RPCServer) GetPeers ¶
func (s *RPCServer) GetPeers(ctx context.Context, req *pb.GetPeersReq) (*pb.GetPeersRes, error)
GetPeers implements the server side RPC logic
func (*RPCServer) LastReqTime ¶ added in v0.2.0
LastReqTime returns the timestamp of the last accepted request
type Topology ¶ added in v0.3.0
Topology is the neighbor list for each node. This is used for generating the P2P network in a given topology. Note that the list contains the outgoing connections.
func NewTopology ¶ added in v0.3.0
NewTopology loads the topology struct from the given yaml file