Skip to content

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

License

Notifications You must be signed in to change notification settings

o1-labs/go-libp2p-kad-dht-patcher

 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%