mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-04 15:58:13 +08:00
sigmoid strat placeholder
This commit is contained in:
parent
668a90f6b6
commit
e658ade600
20
bitswap/strategy.go
Normal file
20
bitswap/strategy.go
Normal file
@ -0,0 +1,20 @@
|
||||
package bitswap
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
17
bitswap/strategy_test.go
Normal file
17
bitswap/strategy_test.go
Normal file
@ -0,0 +1,17 @@
|
||||
package bitswap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProbabilitySendDecreasesAsRatioIncreases(t *testing.T) {
|
||||
grateful := debtRatio{BytesSent: 0, BytesRecv: 10000}
|
||||
pWhenGrateful := probabilitySend(grateful.Value())
|
||||
|
||||
abused := debtRatio{BytesSent: 10000, BytesRecv: 0}
|
||||
pWhenAbused := probabilitySend(abused.Value())
|
||||
|
||||
if pWhenGrateful < pWhenAbused {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user