remove dead code
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Dec 15, 2014 at 22:42 UTC
29ef238fa36f1997da7e8c56ae348b0c0c19015e
3 files changed
+9
-51
exchange/bitswap/strategy/ledger.go
+9
@@ -46,6 +46,15 @@ type ledger struct {
46
sentToPeer map[u.Key]time.Time
47
}
48
49
+type debtRatio struct {
50
+ BytesSent uint64
51
+ BytesRecv uint64
52
+}
53
+
54
+func (dr *debtRatio) Value() float64 {
55
+ return float64(dr.BytesSent) / float64(dr.BytesRecv+1)
56
+}
57
+
58
func (l *ledger) SentBytes(n int) {
59
l.exchangeCount++
60
l.lastExchange = time.Now()
exchange/bitswap/strategy/math.go
deleted
-34
@@ -1,34 +0,0 @@
1
-package strategy
2
-
3
-import (
4
- "math"
5
- "math/rand"
6
-)
7
-
8
-type strategyFunc func(*ledger) bool
9
-
10
-// TODO avoid using rand.Float64 method. it uses a singleton lock and may cause
11
-// performance issues. Instead, instantiate a rand struct and use that to call
12
-// Float64()
13
-func standardStrategy(l *ledger) bool {
14
- return rand.Float64() <= probabilitySend(l.Accounting.Value())
15
-}
16
-
17
-func yesManStrategy(l *ledger) bool {
18
- return true
19
-}
20
-
21
-func probabilitySend(ratio float64) float64 {
22
- x := 1 + math.Exp(6-3*ratio)
23
- y := 1 / x
24
- return 1 - y
25
-}
26
-
27
-type debtRatio struct {
28
- BytesSent uint64
29
- BytesRecv uint64
30
-}
31
-
32
-func (dr *debtRatio) Value() float64 {
33
- return float64(dr.BytesSent) / float64(dr.BytesRecv+1)
34
-}
exchange/bitswap/strategy/math_test.go
deleted
-17
@@ -1,17 +0,0 @@
1
-package strategy
2
-
3
-import (
4
- "testing"
5
-)
6
-
7
-func TestProbabilitySendDecreasesAsRatioIncreases(t *testing.T) {
8
- grateful := debtRatio{BytesSent: 0, BytesRecv: 10000}
9
- pWhenGrateful := probabilitySend(grateful.Value())
10
-
11
- abused := debtRatio{BytesSent: 10000, BytesRecv: 0}
12
- pWhenAbused := probabilitySend(abused.Value())
13
-
14
- if pWhenGrateful < pWhenAbused {
15
- t.Fail()
16
- }
17
-}