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
131b9df7
Commit
131b9df7
authored
Apr 25, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give peers more weight when actively participating in a session
parent
401b87dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
sessionpeermanager/sessionpeermanager.go
sessionpeermanager/sessionpeermanager.go
+13
-12
No files found.
sessionpeermanager/sessionpeermanager.go
View file @
131b9df7
...
...
@@ -14,8 +14,10 @@ import (
var
log
=
logging
.
Logger
(
"bitswap"
)
const
(
maxOptimizedPeers
=
32
reservePeers
=
2
maxOptimizedPeers
=
32
reservePeers
=
2
unoptimizedTagValue
=
5
// tag value for "unoptimized" session peers.
optimizedTagValue
=
10
// tag value for "optimized" session peers.
)
// PeerTagger is an interface for tagging peers with metadata
...
...
@@ -131,7 +133,7 @@ func (spm *SessionPeerManager) run(ctx context.Context) {
}
}
func
(
spm
*
SessionPeerManager
)
tagPeer
(
p
peer
.
ID
)
{
func
(
spm
*
SessionPeerManager
)
tagPeer
(
p
peer
.
ID
,
value
int
)
{
spm
.
tagger
.
TagPeer
(
p
,
spm
.
tag
,
10
)
}
...
...
@@ -173,7 +175,7 @@ func (pfm *peerFoundMessage) handle(spm *SessionPeerManager) {
if
_
,
ok
:=
spm
.
activePeers
[
p
];
!
ok
{
spm
.
activePeers
[
p
]
=
false
spm
.
unoptimizedPeersArr
=
append
(
spm
.
unoptimizedPeersArr
,
p
)
spm
.
tagPeer
(
p
)
spm
.
tagPeer
(
p
,
unoptimizedTagValue
)
}
}
...
...
@@ -182,17 +184,16 @@ type peerResponseMessage struct {
}
func
(
prm
*
peerResponseMessage
)
handle
(
spm
*
SessionPeerManager
)
{
p
:=
prm
.
p
isOptimized
,
ok
:=
spm
.
activePeers
[
p
]
if
!
ok
{
spm
.
activePeers
[
p
]
=
true
spm
.
tagPeer
(
p
)
if
isOptimized
{
spm
.
removeOptimizedPeer
(
p
)
}
else
{
if
isOptimized
{
spm
.
removeOptimizedPeer
(
p
)
}
else
{
spm
.
activePeers
[
p
]
=
true
spm
.
activePeers
[
p
]
=
true
spm
.
tagPeer
(
p
,
optimizedTagValue
)
// transition from unoptimized.
if
ok
{
spm
.
removeUnoptimizedPeer
(
p
)
}
}
...
...
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