mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 15:27:57 +08:00
Move go-ipfs/bitswap package to go-ipfs/exchange/bitswap * Delineates the difference between the generic exchange interface and implementations (eg. BitSwap protocol) Thus, the bitswap protocol can be refined without having to overthink how future exchanges will work. Aspects common to BitSwap and other exchanges can be extracted out to the exchange package in piecemeal. Future exchange implementations can be placed in sibling packages next to exchange/bitswap. (eg. exchange/multilateral)
32 lines
515 B
Go
32 lines
515 B
Go
package strategy
|
|
|
|
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)
|
|
}
|