Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CplDiversityStats ¶
type CplDiversityStats struct { Cpl int Peers map[peer.ID][]PeerIPGroupKey }
CplDiversityStats contains the peer diversity stats for a Cpl.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is a peer diversity filter that accepts or rejects peers based on the blacklisting/whitelisting rules configured AND the diversity policies defined by the implementation of the PeerIPGroupFilter interface passed to it.
func (*Filter) BlacklistIPNetwork ¶
BlacklistIPv4Network will blacklist the IPv4/6 network with the given IP CIDR.
func (*Filter) GetDiversityStats ¶
func (f *Filter) GetDiversityStats() []CplDiversityStats
GetDiversityStats returns the diversity stats for each CPL and is sorted by the CPL.
func (*Filter) TryAdd ¶
TryAdd attempts to add the peer to the Filter state and returns true if it's successful, false otherwise.
func (*Filter) WhitelistIPNetwork ¶
WhitelistIPNetwork will always allow IP addresses from networks with the given CIDR. This will always override the blacklist.
func (*Filter) WhitelistPeers ¶
WhiteListPeerIds will always allow the peers given here. This will always override the blacklist.
type PeerGroupInfo ¶
type PeerGroupInfo struct { Id peer.ID Cpl int IPGroupKey PeerIPGroupKey // contains filtered or unexported fields }
PeerGroupInfo represents the grouping info for a Peer.
type PeerIPGroupFilter ¶
type PeerIPGroupFilter interface { // Allow is called by the Filter to test if a peer with the given // grouping info should be allowed/rejected by the Filter. This will be called ONLY // AFTER the peer has successfully passed all of the Filter's internal checks. // Note: If the peer is deemed accepted because of a whitelisting criteria configured on the Filter, // the peer will be allowed by the Filter without calling this function. // Similarly, if the peer is deemed rejected because of a blacklisting criteria // configured on the Filter, the peer will be rejected without calling this function. Allow(PeerGroupInfo) (allow bool) // Increment is called by the Filter when a peer with the given Grouping Info. // is added to the Filter state. This will happen after the peer has passed // all of the Filter's internal checks and the Allow function defined above for all of it's Groups. Increment(PeerGroupInfo) // Decrement is called by the Filter when a peer with the given // Grouping Info is removed from the Filter. This will happen when the caller/user of the Filter // no longer wants the peer and the IP groups it belongs to to count towards the Filter state. Decrement(PeerGroupInfo) // PeerAddresses is called by the Filter to determine the addresses of the given peer // it should use to determine the IP groups it belongs to. PeerAddresses(peer.ID) []ma.Multiaddr }
PeerIPGroupFilter is the interface that must be implemented by callers who want to instantiate a `peerdiversity.Filter`. This interface provides the function hooks that are used/called by the `peerdiversity.Filter`.
type PeerIPGroupKey ¶
type PeerIPGroupKey string
PeerIPGroupKey is a unique key that represents ONE of the IP Groups the peer belongs to. A peer has one PeerIPGroupKey per address. Thus, a peer can belong to MULTIPLE Groups if it has multiple addresses. For now, given a peer address, our grouping mechanism is as follows:
- For IPv6 addresses, we group by the ASN of the IP address.
- For IPv4 addresses, all addresses that belong to same legacy (Class A)/8 allocations OR share the same /16 prefix are in the same group.