[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.
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.
💯 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.
💯 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.
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.
@deblasis can you elaborate on (or link to) the thinking behind this?
There was a problem hiding this comment.
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
deblasis
left a comment
There was a problem hiding this comment.
Good job @bryanchriswhite! 🚀
Some minor changes, nits, mostly for consistency
8561324 to
42f8e74
Compare
Olshansk
left a comment
There was a problem hiding this comment.
Easy to understand, a big step forward and great documentation in terms of what we have and what's next. Great job Bryan 👏
| c := &messaging.PocketEnvelope{ | ||
| Content: msg, | ||
| } | ||
| //TECHDEBT: use shared/codec for marshalling |
There was a problem hiding this comment.
Thank you for adding these
|
|
||
| var _ modules.P2PModule = &libp2pModule{} | ||
|
|
||
| type libp2pModule struct { |
There was a problem hiding this comment.
nice comments on the sattributes
| mod.listenAddrs = libp2p.NoListenAddrs | ||
| default: | ||
| return nil, fmt.Errorf( | ||
| // DISCUSS: rename to "transport protocol" instead. |
| } | ||
|
|
||
| func (mod *libp2pModule) Start() error { | ||
| // IMPROVE: receive context in interface methods. |
|
|
||
| // 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") |


Description
This is another of a series of PRs split out from #500. Here we add a new
modules.P2PModuleimplementation which utilizes thetypesP2P.Networkimplementation 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.P2PModuleimplementation to thelibp2pmodule directoryTesting
make develop_testREADMERequired Checklist
If Applicable Checklist
shared/docs/*if I updatedshared/*README(s)