mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 11:27:42 +08:00
32 lines
514 B
Go
32 lines
514 B
Go
package bitswap
|
|
|
|
import (
|
|
"math"
|
|
"math/rand"
|
|
)
|
|
|
|
type StrategyFunc func(*Ledger) bool
|
|
|
|
func StandardStrategy(l *Ledger) bool {
|
|
return rand.Float64() <= probabilitySend(l.Accounting.Value())
|
|
}
|
|
|
|
func YesManStrategy(l *Ledger) bool {
|
|
return true
|
|
}
|
|
|
|
func probabilitySend(ratio float64) float64 {
|
|
x := 1 + math.Exp(6-3*ratio)
|
|
y := 1 / x
|
|
return 1 - y
|
|
}
|
|
|
|
type debtRatio struct {
|
|
BytesSent uint64
|
|
BytesRecv uint64
|
|
}
|
|
|
|
func (dr *debtRatio) Value() float64 {
|
|
return float64(dr.BytesSent) / float64(dr.BytesRecv+1)
|
|
}
|