-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Libp2p] Add Libp2p module (part 4) #545
Conversation
9af1fb5
to
4f9f13f
Compare
a329579
to
0791d1a
Compare
4f9f13f
to
d4b0c6e
Compare
0791d1a
to
77f2b78
Compare
This PR is based off of the |
d4b0c6e
to
6074b77
Compare
libp2p/module.go
Outdated
func (mod *libp2pModule) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | ||
logger.Global.Print("Creating libp2p-backed network module") | ||
|
||
*mod = libp2pModule{ | ||
cfg: bus.GetRuntimeMgr().GetConfig().P2P, | ||
} |
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.
How about:
func (mod *libp2pModule) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | |
logger.Global.Print("Creating libp2p-backed network module") | |
*mod = libp2pModule{ | |
cfg: bus.GetRuntimeMgr().GetConfig().P2P, | |
} | |
func (*libp2pModule) Create(bus modules.Bus, options ...modules.ModuleOption) (modules.Module, error) { | |
logger.Global.Debug().Msg("Creating libp2p-backed network module") | |
mod := &libp2pModule{ | |
cfg: bus.GetRuntimeMgr().GetConfig().P2P, | |
logger: logger.Global.CreateLoggerForModule(modules.P2PModuleName), | |
} |
?
More consistent with other modules.
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.
💯 agreed. We need to update the shared modules docs to reflect this new convention, as currently, it effectively says that logger initialization should happen in #Start()
:
When defining the start function for the module, it is essential to initialise a namespace logger as well:
Do you think this is covered by #509, specifically the first goal?:
Add godoc comments to the various interfaces, functions, methods involved in the module creation process
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.
💯 agreed. We need to update the shared modules docs to reflect this new convention, as currently, it effectively says that logger initialization should happen in
#Start()
:When defining the start function for the module, it is essential to initialise a namespace logger as well:
Totally, thanks for pointing that out!
Do you think this is covered by #509, specifically the first goal?:
Add godoc comments to the various interfaces, functions, methods involved in the module creation process
Agreed, I have clarified the scope so I don't forget :) Thanks buddy!
|
||
// NB: time out if no data is sent to free resources. | ||
if err := stream.SetReadDeadline(newReadStreamDeadline()); err != nil { | ||
mod.logger.Error().Err(err).Msg("setting stream read deadline") |
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.
It seems that we are settling on this pattern (Added the Bool(true)) for this kind of thing to help with 🪵 🔍
mod.logger.Error().Err(err).Msg("setting stream read deadline") | |
mod.logger.Error().Err(err). | |
Bool("TODO", true). | |
Msg("setting stream read deadline") |
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.
@deblasis can you elaborate on (or link to) the thinking behind this?
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.
Of course.
We have a bunch of places in our codebase where we log a message and we also attach a TODO
: true
As we mature our observability stack, it could be useful to search for these and also to inform the users that something is still in development and the log entries are merely placeholders for future real functionality
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 also have #478
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.
Good job @bryanchriswhite! 🚀
Some minor changes, nits, mostly for consistency
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👍
8561324
to
42f8e74
Compare
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.
Easy to understand, a big step forward and great documentation in terms of what we have and what's next. Great job Bryan 👏
@@ -154,6 +154,7 @@ func (m *p2pModule) Broadcast(msg *anypb.Any) error { | |||
c := &messaging.PocketEnvelope{ | |||
Content: msg, | |||
} | |||
//TECHDEBT: use shared/codec for marshalling |
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.
Thank you for adding these
|
||
var _ modules.P2PModule = &libp2pModule{} | ||
|
||
type libp2pModule struct { |
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.
nice comments on the sattributes
mod.listenAddrs = libp2p.NoListenAddrs | ||
default: | ||
return nil, fmt.Errorf( | ||
// DISCUSS: rename to "transport protocol" instead. |
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.
Let's do it
} | ||
|
||
func (mod *libp2pModule) Start() error { | ||
// IMPROVE: receive context in interface methods. |
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.
💯
|
||
// NB: time out if no data is sent to free resources. | ||
if err := stream.SetReadDeadline(newReadStreamDeadline()); err != nil { | ||
mod.logger.Error().Err(err).Msg("setting stream read deadline") |
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 also have #478
Description
This is another of a series of PRs split out from #500. Here we add a new
modules.P2PModule
implementation which utilizes thetypesP2P.Network
implementation which was added in #540. It will be utilized together with the config changes introduced by #535 in forthcoming changes to the node and debug CLI.Issue
#347
Type of change
Please mark the relevant option(s):
List of changes
modules.P2PModule
implementation to thelibp2p
module directoryTesting
make develop_test
README
Required Checklist
If Applicable Checklist
shared/docs/*
if I updatedshared/*
README(s)