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
98cf9149
Commit
98cf9149
authored
Nov 05, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(bootstrap): remove unecessary request structure
parent
632f3c5c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
20 deletions
+8
-20
dht.go
dht.go
+2
-2
dht_bootstrap.go
dht_bootstrap.go
+4
-16
notif.go
notif.go
+2
-2
No files found.
dht.go
View file @
98cf9149
...
...
@@ -70,7 +70,7 @@ type IpfsDHT struct {
bootstrapCfg
opts
.
BootstrapConfig
triggerAutoBootstrap
bool
triggerBootstrap
chan
*
bootstrapReq
triggerBootstrap
chan
struct
{}
latestSelfWalk
time
.
Time
// the last time we looked-up our own peerID in the network
}
...
...
@@ -163,7 +163,7 @@ func makeDHT(ctx context.Context, h host.Host, dstore ds.Batching, protocols []p
routingTable
:
rt
,
protocols
:
protocols
,
bucketSize
:
bucketSize
,
triggerBootstrap
:
make
(
chan
*
bootstrapReq
),
triggerBootstrap
:
make
(
chan
struct
{}
),
}
dht
.
ctx
=
dht
.
newContextWithLocalTags
(
ctx
)
...
...
dht_bootstrap.go
View file @
98cf9149
...
...
@@ -43,15 +43,6 @@ func init() {
}
}
type
bootstrapReq
struct
{
errChan
chan
error
}
func
makeBootstrapReq
()
*
bootstrapReq
{
errChan
:=
make
(
chan
error
,
1
)
return
&
bootstrapReq
{
errChan
}
}
// Bootstrap i
func
(
dht
*
IpfsDHT
)
startBootstrapping
()
error
{
// scan the RT table periodically & do a random walk on k-buckets that haven't been queried since the given bucket period
...
...
@@ -78,13 +69,10 @@ func (dht *IpfsDHT) startBootstrapping() error {
if
err
:=
dht
.
doBootstrap
(
ctx
,
walkSelf
);
err
!=
nil
{
logger
.
Warning
(
"bootstrap error: %s"
,
err
)
}
case
req
:=
<-
dht
.
triggerBootstrap
:
case
<-
dht
.
triggerBootstrap
:
logger
.
Infof
(
"triggering a bootstrap: RT has %d peers"
,
dht
.
routingTable
.
Size
())
err
:=
dht
.
doBootstrap
(
ctx
,
true
)
select
{
case
req
.
errChan
<-
err
:
close
(
req
.
errChan
)
default
:
if
err
:=
dht
.
doBootstrap
(
ctx
,
true
);
err
!=
nil
{
logger
.
Warning
(
"bootstrap error: %s"
,
err
)
}
case
<-
ctx
.
Done
()
:
return
...
...
@@ -190,7 +178,7 @@ func (dht *IpfsDHT) selfWalk(ctx context.Context) error {
// Note: the context is ignored.
func
(
dht
*
IpfsDHT
)
Bootstrap
(
_
context
.
Context
)
error
{
select
{
case
dht
.
triggerBootstrap
<-
makeBootstrapReq
()
:
case
dht
.
triggerBootstrap
<-
struct
{}{}
:
default
:
}
return
nil
...
...
notif.go
View file @
98cf9149
...
...
@@ -36,7 +36,7 @@ func (nn *netNotifiee) Connected(n network.Network, v network.Conn) {
dht
.
Update
(
dht
.
Context
(),
p
)
if
bootstrap
&&
dht
.
triggerAutoBootstrap
{
select
{
case
dht
.
triggerBootstrap
<-
makeBootstrapReq
()
:
case
dht
.
triggerBootstrap
<-
struct
{}{}
:
default
:
}
}
...
...
@@ -82,7 +82,7 @@ func (nn *netNotifiee) testConnection(v network.Conn) {
dht
.
Update
(
dht
.
Context
(),
p
)
if
bootstrap
&&
dht
.
triggerAutoBootstrap
{
select
{
case
dht
.
triggerBootstrap
<-
makeBootstrapReq
()
:
case
dht
.
triggerBootstrap
<-
struct
{}{}
:
default
:
}
}
...
...
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