func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption RoutingOption, hostOption HostOption, do DiscoveryOption) error { if n.PeerHost != nil { // already online. return errors.New("node already online") } // load private key if err := n.LoadPrivateKey(); err != nil { return err } // Set reporter n.Reporter = metrics.NewBandwidthCounter() // get undialable addrs from config cfg, err := n.Repo.Config() if err != nil { return err } var addrfilter []*net.IPNet for _, s := range cfg.Swarm.AddrFilters { f, err := mamask.NewMask(s) if err != nil { return fmt.Errorf("incorrectly formatter address filter in config: %s", s) } addrfilter = append(addrfilter, f) } peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter, addrfilter) if err != nil { return err } if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption); err != nil { return err } // Ok, now we're ready to listen. if err := startListening(ctx, n.PeerHost, cfg); err != nil { return err } n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore) go n.Reprovider.ProvideEvery(ctx, kReprovideFrequency) // setup local discovery if do != nil { service, err := do(n.PeerHost) if err != nil { log.Error("mdns error: ", err) } else { service.RegisterNotifee(n) n.Discovery = service } } return n.Bootstrap(DefaultBootstrapConfig) }
func (s *Swarm) AddAddrFilter(f string) error { m, err := mafilter.NewMask(f) if err != nil { return err } s.Filters.AddDialFilter(m) return nil }
return } if n.PeerHost == nil { res.SetError(errNotOnline, cmds.ErrNormal) return } snet, ok := n.PeerHost.Network().(*swarm.Network) if !ok { res.SetError(errors.New("failed to cast network to swarm network"), cmds.ErrNormal) return } for _, arg := range req.Arguments() { mask, err := mafilter.NewMask(arg) if err != nil { res.SetError(err, cmds.ErrNormal) return } snet.Filters.AddDialFilter(mask) } }, } var swarmFiltersRmCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "remove an address filter", ShortDescription: ` 'ipfs swarm filters rm' will remove an address filter from the daemons swarm.