-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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") |
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
@Stebalien done. |
@@ -39,6 +40,39 @@ func TestInsecure(t *testing.T) { | |||
h.Close() | |||
} | |||
|
|||
func TestDefaultListenAddrs(t *testing.T) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
@Stebalien Is jenkins only responsible for tests w/o compiling? |
@@ -39,6 +40,39 @@ func TestInsecure(t *testing.T) { | |||
h.Close() | |||
} | |||
|
|||
func TestDefaultListenAddrs(t *testing.T) { |
There was a problem hiding this comment.
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 My assumption was incorrect. I was assuming that if host, err := libp2p.New(
ctx,
libp2p.ListenAddrStrings("ip4/0.0.0.0/tcp/0", "ip6/0.0.0.0/tcp/0"),
) then For 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 |
I'd check for |
defaults.go
Outdated
return err | ||
} | ||
|
||
defaultIP6ListenAddr, err := multiaddr.NewMultiaddr("/ip6/0.0.0.0/tcp/0") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aah, my bad.
Thanks @Stebalien |
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.