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-bitswap
Commits
fcb13fc9
Commit
fcb13fc9
authored
Sep 09, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
engine(doc): comment on why we have the score adjustment
parent
1f09ef51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
decision/engine.go
decision/engine.go
+6
-1
No files found.
decision/engine.go
View file @
fcb13fc9
...
@@ -171,7 +171,8 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger)
...
@@ -171,7 +171,8 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger)
// longTermRatio*shortTerm period.
// longTermRatio*shortTerm period.
//
//
// To calculate the final score, we sum the short-term and long-term scores then
// To calculate the final score, we sum the short-term and long-term scores then
// adjust it ±25% based on our debt ratio. Peers that have historically been more useful to us than we are to them get the highest score.
// adjust it ±25% based on our debt ratio. Peers that have historically been
// more useful to us than we are to them get the highest score.
func
(
e
*
Engine
)
scoreWorker
(
ctx
context
.
Context
)
{
func
(
e
*
Engine
)
scoreWorker
(
ctx
context
.
Context
)
{
ticker
:=
time
.
NewTicker
(
shortTerm
)
ticker
:=
time
.
NewTicker
(
shortTerm
)
defer
ticker
.
Stop
()
defer
ticker
.
Stop
()
...
@@ -218,6 +219,10 @@ func (e *Engine) scoreWorker(ctx context.Context) {
...
@@ -218,6 +219,10 @@ func (e *Engine) scoreWorker(ctx context.Context) {
}
}
// Calculate the new score.
// Calculate the new score.
//
// The accounting score adjustment prefers peers _we_
// need over peers that need us. This doesn't help with
// leeching.
score
:=
int
((
ledger
.
shortScore
+
ledger
.
longScore
)
*
((
ledger
.
Accounting
.
Score
())
*
.5
+
.75
))
score
:=
int
((
ledger
.
shortScore
+
ledger
.
longScore
)
*
((
ledger
.
Accounting
.
Score
())
*
.5
+
.75
))
// Avoid updating the connection manager unless there's a change. This can be expensive.
// Avoid updating the connection manager unless there's a change. This can be expensive.
...
...
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