Documentation ¶
Index ¶
- Constants
- Variables
- type ActionReceiver
- type ConfigSet
- type DropReason
- type Handler
- func (h *Handler) AddPeer(setID int, peers ...peer.ID)
- func (h *Handler) AddReservedPeer(setID int, peers ...peer.ID)
- func (h *Handler) DisconnectPeer(setID int, peers ...peer.ID)
- func (h *Handler) Incoming(setID int, peers ...peer.ID)
- func (h *Handler) Messages() chan Message
- func (h *Handler) PeerReputation(peerID peer.ID) (Reputation, error)
- func (h *Handler) RemovePeer(setID int, peers ...peer.ID)
- func (h *Handler) RemoveReservedPeer(setID int, peers ...peer.ID)
- func (h *Handler) ReportPeer(rep ReputationChange, peers ...peer.ID)
- func (h *Handler) SetReservedPeer(setID int, peers ...peer.ID)
- func (h *Handler) SortedPeers(setIdx int) chan peer.IDSlice
- func (h *Handler) Start(ctx context.Context)
- func (h *Handler) Stop()
- type Info
- type MembershipState
- type Message
- type MessageProcessor
- type PeerSet
- type PeersState
- type Reputation
- type ReputationChange
- type Status
Constants ¶
const ( // BadMessageValue used when fail to decode message. BadMessageValue Reputation = -(1 << 12) // BadMessageReason used when fail to decode message. BadMessageReason = "Bad message" // BadProtocolValue used when a peer is on unsupported protocol version. BadProtocolValue Reputation = math.MinInt32 // BadProtocolReason used when a peer is on unsupported protocol version. BadProtocolReason = "Unsupported protocol" // TimeOutValue used when a peer doesn't respond in time to our messages. TimeOutValue Reputation = -(1 << 10) // TimeOutReason used when a peer doesn't respond in time to our messages. TimeOutReason = "Request timeout" // GossipSuccessValue used when a peer successfully sends a gossip messages. GossipSuccessValue Reputation = 1 << 4 // GossipSuccessReason used when a peer successfully sends a gossip messages. GossipSuccessReason = "Successful gossip" // DuplicateGossipValue used when a peer sends us a gossip message that we already knew about. DuplicateGossipValue Reputation = -(1 << 2) // DuplicateGossipReason used when a peer send duplicate gossip message. DuplicateGossipReason = "Duplicate gossip" // GoodTransactionValue is the used for good transaction. GoodTransactionValue Reputation = 1 << 7 // GoodTransactionReason is the reason for used for good transaction. GoodTransactionReason = "Good Transaction" // BadTransactionValue used when transaction import was not performed. BadTransactionValue Reputation = -(1 << 12) // BadTransactionReason when transaction import was not performed. BadTransactionReason = "Bad Transaction" // BadBlockAnnouncementValue is used when peer announces invalid block. BadBlockAnnouncementValue Reputation = -(1 << 12) // BadBlockAnnouncementReason is used when peer announces invalid block. BadBlockAnnouncementReason = "Bad block announcement" // IncompleteHeaderValue is used when peer sends block with invalid header. IncompleteHeaderValue Reputation = -(1 << 20) // IncompleteHeaderReason is used when peer sends block with invalid header. IncompleteHeaderReason = "Incomplete header" // BannedThresholdValue used when we need to ban peer. BannedThresholdValue Reputation = 82 * (math.MinInt32 / 100) // BannedReason used when we need to ban peer. BannedReason = "Banned" // BadJustificationValue is used when peer send invalid justification. BadJustificationValue Reputation = -(1 << 16) // BadJustificationReason is used when peer send invalid justification. BadJustificationReason = "Bad justification" // GenesisMismatch is used when peer has a different genesis GenesisMismatch Reputation = math.MinInt32 // GenesisMismatchReason used when a peer has a different genesis GenesisMismatchReason = "Genesis mismatch" )
ReputationChange value and reason
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ActionReceiver ¶
type ActionReceiver uint8
ActionReceiver represents the enum value for action to be performed on peerSet
func (ActionReceiver) String ¶
func (a ActionReceiver) String() string
type DropReason ¶
type DropReason int
DropReason represents reason for disconnection of the peer
const ( // UnknownDrop is used when substream or connection has been closed for an unknown reason UnknownDrop DropReason = iota // RefusedDrop is used when sub-stream or connection has been explicitly refused by the target. // In other words, the peer doesn't actually belong to this set. RefusedDrop )
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages peerSet.
func NewPeerSetHandler ¶
NewPeerSetHandler creates a new *peerset.Handler.
func (*Handler) AddReservedPeer ¶
AddReservedPeer adds reserved peer into peerSet.
func (*Handler) DisconnectPeer ¶
DisconnectPeer calls for disconnecting a connection from peer.
func (*Handler) PeerReputation ¶
func (h *Handler) PeerReputation(peerID peer.ID) (Reputation, error)
PeerReputation returns the reputation of the peer.
func (*Handler) RemovePeer ¶
RemovePeer removes peer from peerSet.
func (*Handler) RemoveReservedPeer ¶
RemoveReservedPeer remove reserved peer from peerSet.
func (*Handler) ReportPeer ¶
func (h *Handler) ReportPeer(rep ReputationChange, peers ...peer.ID)
ReportPeer reports ReputationChange according to the peer behaviour.
func (*Handler) SetReservedPeer ¶
SetReservedPeer set the reserve peer into peerSet
func (*Handler) SortedPeers ¶
SortedPeers return chan for sorted connected peer in the peerSet.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is state of a single set.
type MembershipState ¶
type MembershipState int
MembershipState represent the state of node ingoing the set.
type Message ¶
type Message struct { // Status of the peer in current set. Status Status // PeerID peer in message. PeerID peer.ID // contains filtered or unexported fields }
Message that will be sent by the peerSet.
type MessageProcessor ¶
type MessageProcessor interface {
Process(Message)
}
MessageProcessor interface allows the network layer to receive and process messages from the peerstate layer
type PeersState ¶
PeersState struct contains a list of nodes, where each node has a reputation and is either connected to us or not
func NewPeerState ¶
func NewPeerState(cfgs []*config) (*PeersState, error)
NewPeerState initiates a new PeersState
type ReputationChange ¶
type ReputationChange struct { // PeerReputation value Value Reputation // Reason for reputation change Reason string }
ReputationChange is description of a reputation adjustment for a node
func (ReputationChange) String ¶
func (r ReputationChange) String() string