Commit 2c3fb433 authored by Brian Tiger Chow's avatar Brian Tiger Chow

feat: expose IpfsNode.Bootstrap() method

parent 4c2eda21
......@@ -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 {
bootstrapPeers []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 {
......
......@@ -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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment