Conversation
p2p/host/relay/autorelay_test.go
Outdated
| autonatpb "github.com/libp2p/go-libp2p-autonat/pb" | ||
| circuit "github.com/libp2p/go-libp2p-circuit" | ||
| host "github.com/libp2p/go-libp2p-host" | ||
| dht "github.com/libp2p/go-libp2p-kad-dht" |
There was a problem hiding this comment.
no, we can't depend on kad-dht; this creates a circular dependency.
There was a problem hiding this comment.
Hmm. We only need it for the usage example, but it's pretty important for the usage example. We can do something that mocks routing, but since we currently only have one real way of providing a routing option, and it is the DHT, it will be important to convey that. I will see what I can come up with
There was a problem hiding this comment.
@vyzo I brought the autorelay_test file into the relay package so that I could use the mock functions in the usage example
There was a problem hiding this comment.
can't do that either; the reason it is not there is that it causes a circular dependency between the top level package and the test...
There was a problem hiding this comment.
I see... relay -> libp2p -> config -> relay
I put the examples in relay_test. This seems a little brittle, no?
There was a problem hiding this comment.
it's ok, it's more of a go failing.
|
also, can we put the examples in their own file? I don't want them in the tests. |
@vyzo Unfortunately it seems that for usage examples to be properly formatted in GoDoc, they need to be in a file that ends in "_test". I can move them to something like "example_test", if you prefer |
|
yes please. |
p2p/host/relay/autorelay.go
Outdated
| } | ||
|
|
||
| // Warning: This function should not be used directly by clients activating | ||
| // autorelay. NewAutoRelayHost is used internally by the libp2p.config.NewNode |
There was a problem hiding this comment.
this should be libp2p.New constructor, the users don't call libp2p.conig.NewNode directly either.
p2p/host/relay/examples_test.go
Outdated
| func ExampleNewRelayHost() { | ||
| ctx := context.Background() | ||
|
|
||
| libp2p.New(ctx, libp2p.EnableRelay()) |
There was a problem hiding this comment.
that's incorrect in autorelay context, you need to pass EnableRelay(circuit.OptHop) and the routing option.
There was a problem hiding this comment.
and EnableAutoRelay of course.
There was a problem hiding this comment.
I have two examples, one for relay and one for autorelay. The autorelay example includes EnableAutoRelay and Routing. I changed the examples to provide an empty list of RelayOpts, since I can't find anywhere in the code where RelayOpts are required.
Are they required? What is the common case for relay options?
There was a problem hiding this comment.
I thought this was the example for the actual relay node (which is the RelayHost) -- in this case, these options are required.
Just enabling relay, without the autorelay options, creates a node that supports dialing/listening on the relay transport.
And we should definitely have an example for setting up the relay node itself.
There was a problem hiding this comment.
Ok, to clarify, are there cases where libp2p consuming developers will create instances of RelayHost outside of libp2p.New? If so, what are they? I can add a number of examples, but my assumption was that like with AutoRelay, the supported case was only libp2p.New
There was a problem hiding this comment.
No, it's only through the constructor; but there are use cases where developers enable relay without autorelay.
There was a problem hiding this comment.
Yea, definitely. Check examples_test.go again. There are two main examples, one for Relay and one for AutoRelay, via the libp2p.New constructor. I tried to use as few optional arguments as possible, but I can add RelayOpts if necessary.
There was a problem hiding this comment.
I think we need another example that constructs the relay node with autorelay.
p2p/host/relay/relay.go
Outdated
|
|
||
| // New constructs a new RelayHost | ||
| // Warning: This function should not be used directly by clients activating | ||
| // relay. NewRelayHost is used internally by the libp2p.config.NewNode |
|
Right, but I’m confused. Am I not looking at a relay with autorelay example in examples_test.go:20 ?
… On Jan 15, 2019, at 09:07, vyzo ***@***.***> wrote:
@vyzo commented on this pull request.
In p2p/host/relay/examples_test.go:
> @@ -0,0 +1,32 @@
+package relay_test
+
+import (
+ "context"
+
+ libp2p "github.com/libp2p/go-libp2p"
+
+ host "github.com/libp2p/go-libp2p-host"
+ routing "github.com/libp2p/go-libp2p-routing"
+)
+
+func ExampleNewRelayHost() {
+ ctx := context.Background()
+
+ libp2p.New(ctx, libp2p.EnableRelay())
I think we need another example that constructs the relay node with autorelay.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
It does, but I would like two examples for autorealy:
|
|
I see, I’ll add that soon
… On Jan 15, 2019, at 09:44, vyzo ***@***.***> wrote:
It does, but I would like two examples for autorealy:
one for constructing a "client" node
and one for constructing an actual relay
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
2a495e8 to
168325e
Compare
|
We have a full Relay example in go-libp2p-examples: Also working on getting a reasonable autorelay example in the examples repo: Any comments on the AR branch would be appreciated |
|
Closing this PR due to age. |
No description provided.