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-dms3
Commits
e658ade6
Commit
e658ade6
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sigmoid strat placeholder
parent
668a90f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
bitswap/strategy.go
bitswap/strategy.go
+20
-0
bitswap/strategy_test.go
bitswap/strategy_test.go
+17
-0
No files found.
bitswap/strategy.go
0 → 100644
View file @
e658ade6
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
)
}
This diff is collapsed.
Click to expand it.
bitswap/strategy_test.go
0 → 100644
View file @
e658ade6
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
()
}
}
This diff is collapsed.
Click to expand it.
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