Skip to content
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

Added a Default listener #378

Merged
merged 11 commits into from
Jul 27, 2018
Merged

Added a Default listener #378

merged 11 commits into from
Jul 27, 2018

Conversation

upperwal
Copy link
Contributor

Solving #377

Added IPV4 - TCP on a random port as a default listener (/ip4/0.0.0.0/tcp/0)

@Stebalien can you please review.

defaults.go Outdated
@@ -52,6 +53,15 @@ var RandomIdentity = func(cfg *Config) error {
return cfg.Apply(Identity(priv))
}

// DefaultListenAddrs configures libp2p to use default listen address
var DefaultListenAddrs = func(cfg *Config) error {
defaultListenAddr, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/0")
Copy link
Member

Choose a reason for hiding this comment

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

This should also support ip6.

defaults.go Outdated
@@ -80,6 +90,10 @@ var defaults = []struct {
fallback: func(cfg *Config) bool { return cfg.Peerstore == nil },
opt: DefaultPeerstore,
},
{
fallback: func(cfg *Config) bool { return cfg.ListenAddrs == nil },
Copy link
Member

Choose a reason for hiding this comment

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

We should probably only apply these if we are using the default transports. I'd put this before the default transport section and check to see if Transports is nil.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

LGTM. Just one more thing, can we get a test?

@upperwal
Copy link
Contributor Author

@Stebalien done.

@@ -39,6 +40,39 @@ func TestInsecure(t *testing.T) {
h.Close()
}

func TestDefaultListenAddrs(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Should have a "correctly set the default listeners" test (i.e., make sure this actually works).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like this?

h, err := New(ctx)
if err != nil {
	t.Fatal(err)
}
if len(h.Addrs()) != 2 {
	t.Error("expected 2 default listen addrs")
}
h.Close()

Is length of h.Addrs() sufficient for tests or should they be compared with the actual strings?

Copy link
Member

Choose a reason for hiding this comment

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

That's probably good enough. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I think that test error is due to how we expand ALL addresses using the interface addresses in Host.Addrs(). Try calling h.Network().ListenAddresses(). In that case, we should even be able to verify that they are the correct addresses.

@upperwal
Copy link
Contributor Author

@Stebalien Is jenkins only responsible for tests w/o compiling?

Stebalien
Stebalien previously approved these changes Jul 26, 2018
@@ -39,6 +40,39 @@ func TestInsecure(t *testing.T) {
h.Close()
}

func TestDefaultListenAddrs(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

That's probably good enough. Thanks!

@Stebalien Stebalien dismissed their stale review July 26, 2018 21:42

(tests not passing...)

@upperwal
Copy link
Contributor Author

@Stebalien My assumption was incorrect. I was assuming that if New is executed with two listener addresses, something like

host, err := libp2p.New(
	ctx,
	libp2p.ListenAddrStrings("ip4/0.0.0.0/tcp/0", "ip6/0.0.0.0/tcp/0"),
)

then len(host.Addrs()) would be 2 where one would be for ip4 interface and the other one for ip6 interface but it turns out that because I don't have an ipv6 connection host.Addrs() corresponds to my ipv4 interface with one being 127.0.0.1 and the other one 192.168.x.x.

For ip6/0.0.0.0/tcp/0, AddListenAddr returns no suitable address found because I don't have any ipv6 connection.

So all my tests are incorrect. What do you suggest. How should I test?

Test could be designed in a way that if either one of /ip4/0.0.0.0/tcp/x or /ip6/0.0.0.0/tcp/x is found in host.Network().ListenAddresses() it would be a success. This could be done by searching for /ip4/0.0.0.0/tcp/ and /ip6/0.0.0.0/tcp/ string in host.Network().ListenAddresses(). Do you agree?

@Stebalien
Copy link
Member

I'd check for /ip4/0.0.0.0/tcp/x in Network().ListenAddresses() and leave it at that. Nobody disables IPv4.

defaults.go Outdated
return err
}

defaultIP6ListenAddr, err := multiaddr.NewMultiaddr("/ip6/0.0.0.0/tcp/0")
Copy link
Member

Choose a reason for hiding this comment

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

This should be /ip6/::/tcp/0 (sorry for not noticing earlier). You'll also have to fix the test. 0.0.0.0 will use the IP4 over IP6 ALL address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aah, my bad.

@Stebalien Stebalien merged commit c984cc6 into libp2p:master Jul 27, 2018
@upperwal
Copy link
Contributor Author

Thanks @Stebalien

@upperwal upperwal deleted the default_listener branch July 28, 2018 06:26
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

Successfully merging this pull request may close these issues.

2 participants