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 whitelisting rules configured AND the diversity policies defined by the implementation of the PeerIPGroupFilter interface passed to it.
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) WhitelistPeers ¶
WhitelistPeers will always allow the given peers.
type PeerGroupInfo ¶
type PeerGroupInfo struct {
Id peer.ID
Cpl int
IPGroupKey PeerIPGroupKey
}
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 whitelisted on the Filter, the peer will be allowed by the Filter 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.
func IPGroupKey ¶ added in v0.7.0
func IPGroupKey(ip net.IP) PeerIPGroupKey
returns the PeerIPGroupKey to which the given IP belongs.