Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
29ef238f
Commit
29ef238f
authored
Dec 15, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Dec 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove dead code
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
86c438b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
51 deletions
+9
-51
exchange/bitswap/strategy/ledger.go
exchange/bitswap/strategy/ledger.go
+9
-0
exchange/bitswap/strategy/math.go
exchange/bitswap/strategy/math.go
+0
-34
exchange/bitswap/strategy/math_test.go
exchange/bitswap/strategy/math_test.go
+0
-17
No files found.
exchange/bitswap/strategy/ledger.go
View file @
29ef238f
...
...
@@ -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
()
...
...
exchange/bitswap/strategy/math.go
deleted
100644 → 0
View file @
86c438b6
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
)
}
exchange/bitswap/strategy/math_test.go
deleted
100644 → 0
View file @
86c438b6
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
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment