Commit 29ef238f authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

remove dead code

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 86c438b6
......@@ -46,6 +46,15 @@ type ledger struct {
sentToPeer map[u.Key]time.Time
}
type debtRatio struct {
BytesSent uint64
BytesRecv uint64
}
func (dr *debtRatio) Value() float64 {
return float64(dr.BytesSent) / float64(dr.BytesRecv+1)
}
func (l *ledger) SentBytes(n int) {
l.exchangeCount++
l.lastExchange = time.Now()
......
package strategy
import (
"math"
"math/rand"
)
type strategyFunc func(*ledger) bool
// TODO avoid using rand.Float64 method. it uses a singleton lock and may cause
// performance issues. Instead, instantiate a rand struct and use that to call
// Float64()
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)
}
package strategy
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()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment