Commit 1bd69b19 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

core: make sure to call swarm.FilterAddrs

also move network setup into its own self-contained func
parent 66f1a5a9
......@@ -150,26 +150,9 @@ func (n *IpfsNode) StartOnlineServices() error {
return err
}
// setup the network
listenAddrs, err := listenAddresses(n.Config)
if err != nil {
return debugerror.Wrap(err)
}
network, err := swarm.NewNetwork(ctx, listenAddrs, n.Identity, n.Peerstore)
if err != nil {
return debugerror.Wrap(err)
}
n.AddChildGroup(network.CtxGroup())
n.PeerHost = p2pbhost.New(network)
// explicitly set these as our listen addrs.
// (why not do it inside inet.NewNetwork? because this way we can
// listen on addresses without necessarily advertising those publicly.)
addrs, err := n.PeerHost.Network().InterfaceListenAddresses()
if err != nil {
return debugerror.Wrap(err)
if err := n.startNetwork(); err != nil {
return err
}
n.Peerstore.AddAddresses(n.Identity, addrs)
// setup diagnostics service
n.Diagnostics = diag.NewDiagnostics(n.Identity, n.PeerHost)
......@@ -199,6 +182,34 @@ func (n *IpfsNode) StartOnlineServices() error {
return nil
}
func (n *IpfsNode) startNetwork() error {
ctx := n.Context()
// setup the network
listenAddrs, err := listenAddresses(n.Config)
if err != nil {
return debugerror.Wrap(err)
}
// make sure we dont error out if our config includes some addresses we cant use.
listenAddrs = swarm.FilterAddrs(listenAddrs)
network, err := swarm.NewNetwork(ctx, listenAddrs, n.Identity, n.Peerstore)
if err != nil {
return debugerror.Wrap(err)
}
n.AddChildGroup(network.CtxGroup())
n.PeerHost = p2pbhost.New(network)
// explicitly set these as our listen addrs.
// (why not do it inside inet.NewNetwork? because this way we can
// listen on addresses without necessarily advertising those publicly.)
addrs, err := n.PeerHost.Network().InterfaceListenAddresses()
if err != nil {
return debugerror.Wrap(err)
}
n.Peerstore.AddAddresses(n.Identity, addrs)
return nil
}
func (n *IpfsNode) teardown() error {
if err := n.Datastore.Close(); err != nil {
return err
......
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