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
p2p
go-p2p-kad-dht
Commits
dd0bbb2c
Commit
dd0bbb2c
authored
Feb 04, 2020
by
Adin Schmahmann
Committed by
Steven Allen
Apr 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try another peer sorting metric. fix bug in when findproviders returns
parent
e967acad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
kpeerset/metrics.go
kpeerset/metrics.go
+36
-2
routing.go
routing.go
+1
-1
No files found.
kpeerset/metrics.go
View file @
dd0bbb2c
package
kpeerset
import
(
"math/big"
"sort"
"time"
...
...
@@ -20,7 +21,12 @@ type peerLatencyMetricList []peerLatencyMetric
func
(
p
peerLatencyMetricList
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
peerLatencyMetricList
)
Less
(
i
,
j
int
)
bool
{
pm1
,
pm2
:=
p
[
i
],
p
[
j
]
return
calculationLess
(
pm1
,
pm2
)
}
func
(
p
peerLatencyMetricList
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
peerLatencyMetricList
)
GetPeerID
(
i
int
)
peer
.
ID
{
return
p
[
i
]
.
peer
}
func
less
(
pm1
,
pm2
*
peerLatencyMetric
)
bool
{
p1Connectedness
,
p2Connectedness
:=
pm1
.
connectedness
,
pm2
.
connectedness
p1Latency
,
p2Latency
:=
pm1
.
latency
,
pm2
.
latency
...
...
@@ -58,8 +64,36 @@ func (p peerLatencyMetricList) Less(i, j int) bool {
return
pm1
.
metric
.
Cmp
(
pm2
.
metric
)
==
-
1
}
func
(
p
peerLatencyMetricList
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
peerLatencyMetricList
)
GetPeerID
(
i
int
)
peer
.
ID
{
return
p
[
i
]
.
peer
}
func
calculationLess
(
pm1
,
pm2
peerLatencyMetric
)
bool
{
return
calc
(
pm1
)
.
Cmp
(
calc
(
pm2
))
==
-
1
}
func
calc
(
pm
peerLatencyMetric
)
*
big
.
Int
{
var
c
int64
switch
pm
.
connectedness
{
case
network
.
Connected
:
c
=
1
case
network
.
CanConnect
:
c
=
5
case
network
.
CannotConnect
:
c
=
10000
default
:
c
=
20
}
l
:=
int64
(
pm
.
latency
)
if
l
<=
0
{
l
=
int64
(
time
.
Second
)
*
10
}
res
:=
big
.
NewInt
(
c
)
tmp
:=
big
.
NewInt
(
l
)
res
.
Mul
(
res
,
tmp
)
res
.
Mul
(
res
,
pm
.
metric
)
return
res
}
var
_
SortablePeers
=
(
*
peerLatencyMetricList
)(
nil
)
...
...
routing.go
View file @
dd0bbb2c
...
...
@@ -608,7 +608,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key multihash
return
peers
,
nil
},
func
(
peerset
*
kpeerset
.
SortedPeerset
)
bool
{
return
ps
.
Size
()
>
count
return
ps
.
Size
()
>
=
count
},
)
...
...
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