peerdiversity

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 11 Imported by: 20

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 NewFilter

func NewFilter(pgm PeerIPGroupFilter, logKey string, cplFnc func(peer.ID) int) (*Filter, error)

NewFilter creates a Filter for Peer Diversity.

func (*Filter) GetDiversityStats

func (f *Filter) GetDiversityStats() []CplDiversityStats

GetDiversityStats returns the diversity stats for each CPL and is sorted by the CPL.

func (*Filter) Remove

func (f *Filter) Remove(p peer.ID)

func (*Filter) TryAdd

func (f *Filter) TryAdd(p peer.ID) bool

TryAdd attempts to add the peer to the Filter state and returns true if it's successful, false otherwise.

func (*Filter) WhitelistPeers

func (f *Filter) WhitelistPeers(peers ...peer.ID)

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:

  1. For IPv6 addresses, we group by the ASN of the IP address.
  2. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL