https://github.com/hanabi1224/go-libp2p-kad-dht-patcher
Utility to patch the peer protection logic in go-libp2p-kad-dht
https://github.com/hanabi1224/go-libp2p-kad-dht-patcher
Last synced: 4 months ago
JSON representation
Utility to patch the peer protection logic in go-libp2p-kad-dht
- Host: GitHub
- URL: https://github.com/hanabi1224/go-libp2p-kad-dht-patcher
- Owner: hanabi1224
- License: mit
- Created: 2022-02-21T17:26:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-18T06:26:11.000Z (over 3 years ago)
- Last Synced: 2025-03-30T19:13:39.412Z (8 months ago)
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 0
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-libp2p-kad-dht-patcher
[](https://github.com/hanabi1224/go-libp2p-kad-dht-patcher/actions/workflows/main.yml)
[](https://codecov.io/gh/hanabi1224/go-libp2p-kad-dht-patcher)
[](https://github.com/hanabi1224/go-libp2p-kad-dht-patcher)
Utility to patch peer protection logic in go-libp2p-kad-dht
## N-Bucket problem
Details to be added
## Run tests
```bash
go mod vendor
go test -v
```
## Options
```go
// 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
```go
// 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
```go
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