Skip to content

How do I test autorelay? #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cannium opened this issue Nov 19, 2018 · 6 comments
Closed

How do I test autorelay? #487

cannium opened this issue Nov 19, 2018 · 6 comments

Comments

@cannium
Copy link
Contributor

cannium commented Nov 19, 2018

In go-ipfs, DHT service is initialized after libp2p, in startOnlineServicesWithHost:

	peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, libp2pOpts...)


	if err != nil {
		return err
	}


	if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption, pubsub, ipnsps); err != nil {
		return err
	}

(https://github.com/ipfs/go-ipfs/blob/31099e882469fab12a98f2069e38c847f0b1188c/core/core.go#L264-L272)

But the new autorelay feature requires cfg.Routing, which is DHT service:

go-libp2p/config/config.go

Lines 169 to 198 in 4341acb

if cfg.Routing != nil {
router, err := cfg.Routing(h)
if err != nil {
h.Close()
return nil, err
}
crouter, ok := router.(routing.ContentRouting)
if ok {
if cfg.Relay {
discovery := discovery.NewRoutingDiscovery(crouter)
hop := false
for _, opt := range cfg.RelayOpts {
if opt == circuit.OptHop {
hop = true
break
}
}
if hop {
h = relay.NewRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery)
} else {
h = relay.NewAutoRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery)
}
}
}
h = routed.Wrap(h, router)
}

So we have a dependency loop here(the reason why refactoring is necessary) and I just can't enable the feature. Now I only need a somewhat hacky way to test the feature, I'd like to know what did you do in your tests?

(btw, I had an idea about refactoring, I'll write some snippets to elaborate the idea if interested)

@vyzo
Copy link
Contributor

vyzo commented Nov 19, 2018

There is no dependency loop; you pass it a constructor which takes a host, and can then construct the dht from that host.

@vyzo
Copy link
Contributor

vyzo commented Nov 19, 2018

Btw, I am working on adding the feature to ipfs, will open pr in the next couple of days.

@cannium
Copy link
Contributor Author

cannium commented Nov 19, 2018

The only concrete type I could find implements PeerRouting is IpfsDHT, and its initialization requires libp2p Host. Could you fill me more info?

@vyzo
Copy link
Contributor

vyzo commented Nov 19, 2018

You have a Host object in the constructor.
So:

libp2p.New(..., libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
  // make the DHT with the given Host
  return dht.New(ctx, h, opts...)
}))

@cannium
Copy link
Contributor Author

cannium commented Nov 19, 2018 via email

@vyzo
Copy link
Contributor

vyzo commented Nov 19, 2018

For ipfs integration see ipfs/kubo#5785

@cannium cannium closed this as completed Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants