-
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 default muxer in case when none was provided. #264
Conversation
Should fix 'echo' example.
Ok, it will allow example pass, and won't display stacktrace. |
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 it would be better to just fix the example to specify a muxer?
Sounds like it's a required config argument.
// If secio is disabled, don't add our private key to the peerstore | ||
if !cfg.DisableSecio { | ||
ps.AddPrivKey(pid, cfg.PeerKey) | ||
ps.AddPubKey(pid, cfg.PeerKey.GetPublic()) | ||
} | ||
|
||
swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, cfg.Muxer, cfg.Reporter) | ||
swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, muxer, cfg.Reporter) |
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 looks inconsistent.
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.
Not really. With the protector/reporter, we default to nil. This is the one case where we don't.
@@ -180,13 +180,19 @@ func newWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { | |||
ps = pstore.NewPeerstore() | |||
} | |||
|
|||
// Set default muxer if none was passed in | |||
muxer := cfg.Muxer |
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.
for consistency with the code below, it would be better to set it in the cfg
object directly:
if cfg.Muxer == nil {
cfg.Muxer = DefaultMuxer()
}
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.
Hm. But that would modify the user's config. I prefer it this way.
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.
@@ -180,13 +180,19 @@ func newWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { | |||
ps = pstore.NewPeerstore() | |||
} | |||
|
|||
// Set default muxer if none was passed in | |||
muxer := cfg.Muxer |
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.
Hm. But that would modify the user's config. I prefer it this way.
// If secio is disabled, don't add our private key to the peerstore | ||
if !cfg.DisableSecio { | ||
ps.AddPrivKey(pid, cfg.PeerKey) | ||
ps.AddPubKey(pid, cfg.PeerKey.GetPublic()) | ||
} | ||
|
||
swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, cfg.Muxer, cfg.Reporter) | ||
swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, muxer, cfg.Reporter) |
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.
Not really. With the protector/reporter, we default to nil. This is the one case where we don't.
@vyzo given that we provide the DefaultMuxer method, I see no reason not to use it here. |
fair enough. |
Thanks! |
Should fix 'echo' example.