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-unixfs
Commits
2c3fb433
Commit
2c3fb433
authored
Jan 10, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: expose IpfsNode.Bootstrap() method
parent
4c2eda21
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
14 deletions
+32
-14
core/bootstrap.go
core/bootstrap.go
+2
-13
core/core.go
core/core.go
+30
-1
No files found.
core/bootstrap.go
View file @
2c3fb433
...
...
@@ -29,7 +29,7 @@ func superviseConnections(parent context.Context,
h
host
.
Host
,
route
*
dht
.
IpfsDHT
,
// TODO depend on abstract interface for testing purposes
store
peer
.
Peerstore
,
peers
[]
config
.
BootstrapPeer
)
error
{
peers
[]
peer
.
PeerInfo
)
error
{
for
{
ctx
,
_
:=
context
.
WithTimeout
(
parent
,
connectiontimeout
)
...
...
@@ -51,7 +51,7 @@ func bootstrap(ctx context.Context,
h
host
.
Host
,
r
*
dht
.
IpfsDHT
,
ps
peer
.
Peerstore
,
boots
[]
config
.
BootstrapPeer
)
error
{
boots
trapPeers
[]
peer
.
PeerInfo
)
error
{
connectedPeers
:=
h
.
Network
()
.
Peers
()
if
len
(
connectedPeers
)
>=
recoveryThreshold
{
...
...
@@ -66,17 +66,6 @@ func bootstrap(ctx context.Context,
log
.
Event
(
ctx
,
"bootstrapStart"
,
h
.
ID
())
log
.
Debugf
(
"%s bootstrapping to %d more nodes"
,
h
.
ID
(),
numCxnsToCreate
)
var
bootstrapPeers
[]
peer
.
PeerInfo
for
_
,
bootstrap
:=
range
boots
{
p
,
err
:=
toPeer
(
bootstrap
)
if
err
!=
nil
{
log
.
Event
(
ctx
,
"bootstrapError"
,
h
.
ID
(),
lgbl
.
Error
(
err
))
log
.
Errorf
(
"%s bootstrap error: %s"
,
h
.
ID
(),
err
)
return
err
}
bootstrapPeers
=
append
(
bootstrapPeers
,
p
)
}
var
notConnected
[]
peer
.
PeerInfo
for
_
,
p
:=
range
bootstrapPeers
{
if
h
.
Network
()
.
Connectedness
(
p
.
ID
)
!=
inet
.
Connected
{
...
...
core/core.go
View file @
2c3fb433
...
...
@@ -32,6 +32,7 @@ import (
ds2
"github.com/jbenet/go-ipfs/util/datastore2"
debugerror
"github.com/jbenet/go-ipfs/util/debugerror"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
lgbl
"github.com/jbenet/go-ipfs/util/eventlog/loggables"
)
const
IpnsValidatorTag
=
"ipns"
...
...
@@ -66,6 +67,11 @@ type IpfsNode struct {
Diagnostics
*
diag
.
Diagnostics
// the diagnostics service
ctxgroup
.
ContextGroup
// dht allows node to Bootstrap when dht is present
// TODO privatize before merging. This is here temporarily during the
// migration of the TestNet constructor
DHT
*
dht
.
IpfsDHT
}
// Mounts defines what the node's mount state is. This should
...
...
@@ -185,6 +191,7 @@ func (n *IpfsNode) StartOnlineServices() error {
dhtRouting
:=
dht
.
NewDHT
(
ctx
,
n
.
PeerHost
,
n
.
Datastore
)
dhtRouting
.
Validators
[
IpnsValidatorTag
]
=
namesys
.
ValidateIpnsRecord
n
.
Routing
=
dhtRouting
n
.
DHT
=
dhtRouting
n
.
AddChildGroup
(
dhtRouting
)
// setup exchange service
...
...
@@ -202,7 +209,17 @@ func (n *IpfsNode) StartOnlineServices() error {
// an Exchange, Network, or Routing component and have the constructor
// manage the wiring. In that scenario, this dangling function is a bit
// awkward.
go
superviseConnections
(
ctx
,
n
.
PeerHost
,
dhtRouting
,
n
.
Peerstore
,
n
.
Config
.
Bootstrap
)
var
bootstrapPeers
[]
peer
.
PeerInfo
for
_
,
bootstrap
:=
range
n
.
Config
.
Bootstrap
{
p
,
err
:=
toPeer
(
bootstrap
)
if
err
!=
nil
{
log
.
Event
(
ctx
,
"bootstrapError"
,
n
.
Identity
,
lgbl
.
Error
(
err
))
log
.
Errorf
(
"%s bootstrap error: %s"
,
n
.
Identity
,
err
)
return
err
}
bootstrapPeers
=
append
(
bootstrapPeers
,
p
)
}
go
superviseConnections
(
ctx
,
n
.
PeerHost
,
dhtRouting
,
n
.
Peerstore
,
bootstrapPeers
)
return
nil
}
...
...
@@ -245,6 +262,18 @@ func (n *IpfsNode) OnlineMode() bool {
return
n
.
onlineMode
}
func
(
n
*
IpfsNode
)
Bootstrap
(
ctx
context
.
Context
,
peers
[]
peer
.
PeerInfo
)
error
{
if
n
.
DHT
!=
nil
{
for
_
,
p
:=
range
peers
{
// TODO bootstrap(ctx, n.PeerHost, n.DHT, n.Peerstore, peers)
if
err
:=
n
.
DHT
.
Connect
(
ctx
,
p
.
ID
);
err
!=
nil
{
return
err
}
}
}
return
nil
}
func
(
n
*
IpfsNode
)
loadID
()
error
{
if
n
.
Identity
!=
""
{
return
debugerror
.
New
(
"identity already loaded"
)
...
...
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