kbucketfix

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-libp2p-kad-dht-patcher

ci codecov loc

Utility to patch peer protection logic in go-libp2p-kad-dht

N-Bucket problem

Details to be added

Run tests

go mod vendor
go test -v

Options

// Max number of peers to protect
// non-positive means unlimited
// default is 0
MaxProtected int
// Target percentage of protected peers, (0.0,1.0]
// default is 0.5
ProtectionRate float32

Public APIs

// Creates a new patcher instance
func NewPatcher() DHTPeerProtectionPatcher

// Notify the patcher with a validated / known trusted peer id
// so that it will be prefered in the protected peer selection algorithm
func (p *DHTPeerProtectionPatcher) Heartbeat(peerId peer.ID) bool

// Patches the peer protection algorithm of the given dht instance
func (p *DHTPeerProtectionPatcher) Patch(dht *kaddht.IpfsDHT)

Usage

patcher := NewPatcher()

if hostDHT, err := kaddht.New(ctx, host, dhtOpts...); err != nil {
    patcher.ProtectionRate = targetProtectionRate
	patcher.MaxProtected = maxProtected
	patcher.Patch(hostDHT)
}

Refer to kbucket_fix_test.go for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DHTPeerProtectionPatcher

type DHTPeerProtectionPatcher struct {
	// Max number of peers to protect
	// non-positive means unlimited
	// default is 0
	MaxProtected int
	// Target percentage of protected peers, (0.0,1.0]
	// default is 0.5
	ProtectionRate float32
	// contains filtered or unexported fields
}

func NewPatcher

func NewPatcher() DHTPeerProtectionPatcher

Creates a new patcher instance

func (*DHTPeerProtectionPatcher) Heartbeat

func (p *DHTPeerProtectionPatcher) Heartbeat(peerId peer.ID) bool

Notify the patcher with a validated / known trusted peer id so that it will be prefered in the protected peer selection algorithm

func (*DHTPeerProtectionPatcher) Patch

func (p *DHTPeerProtectionPatcher) Patch(dht *kaddht.IpfsDHT)

Patches the peer protection algorithm of the given dht instance

Jump to

Keyboard shortcuts

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