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
e9a7da27
Unverified
Commit
e9a7da27
authored
Sep 08, 2020
by
Sam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixLowPeers in bootstrap and before RefreshManager starts
parent
9304f557
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
47 deletions
+53
-47
dht.go
dht.go
+52
-47
dht_bootstrap.go
dht_bootstrap.go
+1
-0
No files found.
dht.go
View file @
e9a7da27
...
...
@@ -417,7 +417,7 @@ func (dht *IpfsDHT) Mode() ModeOpt {
return
dht
.
auto
}
// fixLowPeersRoutin
e tries to get more peers into the routing table if we're below the threshold
// fixLowPeersRoutin
g manages simultaneous requests to fixLowPeers
func
(
dht
*
IpfsDHT
)
fixLowPeersRoutine
(
proc
goprocess
.
Process
)
{
ticker
:=
time
.
NewTicker
(
periodicBootstrapInterval
)
defer
ticker
.
Stop
()
...
...
@@ -430,62 +430,67 @@ func (dht *IpfsDHT) fixLowPeersRoutine(proc goprocess.Process) {
return
}
if
dht
.
routingTable
.
Size
()
>
minRTRefreshThreshold
{
continue
}
dht
.
fixLowPeers
(
dht
.
Context
())
}
// we try to add all peers we are connected to to the Routing Table
// in case they aren't already there.
for
_
,
p
:=
range
dht
.
host
.
Network
()
.
Peers
()
{
dht
.
peerFound
(
dht
.
Context
(),
p
,
false
)
}
}
// TODO Active Bootstrapping
// We should first use non-bootstrap peers we knew of from previous
// snapshots of the Routing Table before we connect to the bootstrappers.
// See https://github.com/libp2p/go-libp2p-kad-dht/issues/387.
if
dht
.
routingTable
.
Size
()
==
0
{
if
len
(
dht
.
bootstrapPeers
)
==
0
{
// No point in continuing, we have no peers!
continue
}
// fixLowPeers tries to get more peers into the routing table if we're below the threshold
func
(
dht
*
IpfsDHT
)
fixLowPeers
(
ctx
context
.
Context
)
{
if
dht
.
routingTable
.
Size
()
>
minRTRefreshThreshold
{
return
}
found
:=
0
for
_
,
i
:=
range
rand
.
Perm
(
len
(
dht
.
bootstrapPeers
))
{
ai
:=
dht
.
bootstrapPeers
[
i
]
err
:=
dht
.
Host
()
.
Connect
(
dht
.
Context
(),
ai
)
if
err
==
nil
{
found
++
}
else
{
logger
.
Warnw
(
"failed to bootstrap"
,
"peer"
,
ai
.
ID
,
"error"
,
err
)
}
// we try to add all peers we are connected to to the Routing Table
// in case they aren't already there.
for
_
,
p
:=
range
dht
.
host
.
Network
()
.
Peers
()
{
dht
.
peerFound
(
ctx
,
p
,
false
)
}
// Wait for two bootstrap peers, or try them all.
//
// Why two? In theory, one should be enough
// normally. However, if the network were to
// restart and everyone connected to just one
// bootstrapper, we'll end up with a mostly
// partitioned network.
//
// So we always bootstrap with two random peers.
if
found
==
maxNBoostrappers
{
break
}
}
// TODO Active Bootstrapping
// We should first use non-bootstrap peers we knew of from previous
// snapshots of the Routing Table before we connect to the bootstrappers.
// See https://github.com/libp2p/go-libp2p-kad-dht/issues/387.
if
dht
.
routingTable
.
Size
()
==
0
{
if
len
(
dht
.
bootstrapPeers
)
==
0
{
// No point in continuing, we have no peers!
return
}
// if we still don't have peers in our routing table(probably because Identify hasn't completed),
// there is no point in triggering a Refresh.
if
dht
.
routingTable
.
Size
()
==
0
{
continue
}
found
:=
0
for
_
,
i
:=
range
rand
.
Perm
(
len
(
dht
.
bootstrapPeers
))
{
ai
:=
dht
.
bootstrapPeers
[
i
]
err
:=
dht
.
Host
()
.
Connect
(
ctx
,
ai
)
if
err
==
nil
{
found
++
}
else
{
logger
.
Warnw
(
"failed to bootstrap"
,
"peer"
,
ai
.
ID
,
"error"
,
err
)
}
if
dht
.
autoRefresh
{
dht
.
rtRefreshManager
.
RefreshNoWait
()
// Wait for two bootstrap peers, or try them all.
//
// Why two? In theory, one should be enough
// normally. However, if the network were to
// restart and everyone connected to just one
// bootstrapper, we'll end up with a mostly
// partitioned network.
//
// So we always bootstrap with two random peers.
if
found
==
maxNBoostrappers
{
break
}
}
}
// if we still don't have peers in our routing table(probably because Identify hasn't completed),
// there is no point in triggering a Refresh.
if
dht
.
routingTable
.
Size
()
==
0
{
return
}
if
dht
.
autoRefresh
{
dht
.
rtRefreshManager
.
RefreshNoWait
()
}
}
// TODO This is hacky, horrible and the programmer needs to have his mother called a hamster.
...
...
dht_bootstrap.go
View file @
e9a7da27
...
...
@@ -58,6 +58,7 @@ func GetDefaultBootstrapPeerAddrInfos() []peer.AddrInfo {
// Bootstrap tells the DHT to get into a bootstrapped state satisfying the
// IpfsRouter interface.
func
(
dht
*
IpfsDHT
)
Bootstrap
(
ctx
context
.
Context
)
error
{
dht
.
fixLowPeers
(
ctx
)
dht
.
rtRefreshManager
.
RefreshNoWait
()
return
nil
}
...
...
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