Skip to content

Updating usage docs for relay/autorelay#520

Closed
mvid wants to merge 4 commits intomasterfrom
feat/autorelay-docs
Closed

Updating usage docs for relay/autorelay#520
mvid wants to merge 4 commits intomasterfrom
feat/autorelay-docs

Conversation

@mvid
Copy link
Copy Markdown

@mvid mvid commented Jan 14, 2019

No description provided.

@mvid mvid requested review from bigs and vyzo January 14, 2019 02:58
@ghost ghost assigned mvid Jan 14, 2019
@ghost ghost added the status/in-progress In progress label Jan 14, 2019
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"
Copy link
Copy Markdown
Contributor

@vyzo vyzo Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we can't depend on kad-dht; this creates a circular dependency.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vyzo I brought the autorelay_test file into the relay package so that I could use the mock functions in the usage example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... relay -> libp2p -> config -> relay

I put the examples in relay_test. This seems a little brittle, no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok, it's more of a go failing.

@vyzo
Copy link
Copy Markdown
Contributor

vyzo commented Jan 14, 2019

also, can we put the examples in their own file? I don't want them in the tests.

@mvid
Copy link
Copy Markdown
Author

mvid commented Jan 14, 2019

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

@vyzo
Copy link
Copy Markdown
Contributor

vyzo commented Jan 14, 2019

yes please.

}

// Warning: This function should not be used directly by clients activating
// autorelay. NewAutoRelayHost is used internally by the libp2p.config.NewNode
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be libp2p.New constructor, the users don't call libp2p.conig.NewNode directly either.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

func ExampleNewRelayHost() {
ctx := context.Background()

libp2p.New(ctx, libp2p.EnableRelay())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's incorrect in autorelay context, you need to pass EnableRelay(circuit.OptHop) and the routing option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and EnableAutoRelay of course.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's only through the constructor; but there are use cases where developers enable relay without autorelay.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need another example that constructs the relay node with autorelay.


// 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here about libp2p.New.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

@mvid
Copy link
Copy Markdown
Author

mvid commented Jan 15, 2019 via email

@vyzo
Copy link
Copy Markdown
Contributor

vyzo commented Jan 15, 2019

It does, but I would like two examples for autorealy:

  • one for constructing a "client" node
  • and one for constructing an actual relay

@mvid
Copy link
Copy Markdown
Author

mvid commented Jan 15, 2019 via email

@mvid mvid force-pushed the feat/autorelay-docs branch from 2a495e8 to 168325e Compare February 13, 2019 22:46
@mvid
Copy link
Copy Markdown
Author

mvid commented Feb 13, 2019

We have a full Relay example in go-libp2p-examples:
libp2p/go-libp2p-examples#49

Also working on getting a reasonable autorelay example in the examples repo:
libp2p/go-libp2p-examples#50

Any comments on the AR branch would be appreciated

@marten-seemann
Copy link
Copy Markdown
Contributor

marten-seemann commented Feb 7, 2022

Closing this PR due to age.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants