define and enable netcat operating mode#1149
define and enable netcat operating mode#1149f97ada87 wants to merge 1 commit intoBitmessage:v0.6from f97ada87:opmode-netcat
Conversation
|
Can you check the Codacy report and fix the issues? |
|
I fixed all the Codacy warnings that made sense. IMO the two remaining "issues" are needed to retain human readability of the code and fixing them will not improve the source code quality. |
|
Apparently the best practice for an unused variable in situations like this is to use the |
|
I know, I'm just being pragmatic here. As both a code writer and reader, if I were to choose between:
I will always prefer the former, even if it causes a lint warning. Thanks. |
|
I need to think about it as I'm in the process of formalising the coding standards. |
|
How about this: you use Like this: Even though in this case, even better would be to use some sort of parser function and then work on the result of that function. |
|
Great. Please allow a couple of days for the review, I'll explain afterwards. |
|
Thanks, and agreed on the parser function. I saw your work in 96d58f3 etc but wasn't 100% confident to use it, so I reverted to old-style parsing instead, for now. Can be refactored later in a separate PR. |
It probably wouldn't work correctly as that parser is integrated into the network buffer handling.
Yes, that's for a later stage, at this moment I'd prefer to handle new features and refactoring separately. |
| if state.netcatmode: | ||
| # publish object to inventory and advertise | ||
| Inventory()[inventoryHash] = (objectType, streamNumber, binObject, eTime,'') | ||
| PendingUpload().add(inventoryHash) |
There was a problem hiding this comment.
PendingUpload is deprecated, just remove this line.
|
I have an uneasy feeling about this.
|
|
Most decisions are inline with the Unix doctrine: do one thing and do it well, design for interoperation, your output is someone else's input. The purpose of the netcat mode is to minimize the footprint and exploitable surface of the PyBitmessage network-facing process, for security reasons. This is achieved by short-circuiting several classes and process threads, including the objectProcessor in its entirety. There is no API, no POW either. The patchset is designed to minimize codebase bloat. The I chose the hex one-line format for several reasons:
More exotic I/O formats may be introduced later if needed, selected by command-line options ( Happy to discuss any objections or counterpoints to the above. |
|
I would like this to work more in a pluggable model rather than a wide range of code flow changes triggered bye a single variable. For this, we need a new class which acts like a queue, but allows multiple "subscribers". Then objectProcessor and the stdOut (or whatever you want to call it) could subscribe/launch independently. The same problem exists with the UI queue which prevents the GUI and the SMTP thread from working simulaneously. The output shouldn't happen in the receivedata thread but in a separate one. So this requires some refactoring of existing code. You could use threading.local to store the queues. Here is some pseudocode: Regarding input, I suppose it's ok for now. Perhaps at first you could add more runtime variables, one for enabling stdin/out IO, one for enabling/disabling object processor, one for the worker thread, and so on. The netcat mode would then set all the variables accordingly. |
|
@PeterSurda - I have added the modular switches as suggested (as |
|
@f97ada87 I need to review it in a bit more detail, but in general it appears to be like I asked. |
|
Thanks @PeterSurda . Please do not merge right now as I have some fixes to upload, mainly relevant to your output queuing suggestion. I'll confirm when it's ready to go. |
|
Hi @PeterSurda , this is complete and ready to go.
As the conventional objectProcessor and the netcat mode are mutually exclusive by definition, the subscriberQueue logic seems YAGNI at this stage. I used a simple if/else construct instead, hope it's OK. |
|
Not having a SubscriberQueue is ok for the time being. The rest I'll look at tomorrow. |
|
There are a couple of conflicts currently:
You can solve them like me or maybe propose a better solution. Some style questions also:
|
|
Short answer: Scope creep :) Long answers:
As for conflict solving, I'm planning to close this PR and resubmit as a series of smaller ones, more targeted and less scope-creepy :) |
I would definitely prefer it this way. I promise I'll allocate time earlier for review so that you don't have to wait that long again for feedback. |
|
@PeterSurda , by "this way", do you mean as it is now, just rebased and with conflicts resolved as suggested by @g1itch ? |
|
@f97ada87 I mean I prefer it split into separate PRs. In case I end up wanting changes, I can still merge a part of the PRs and make progress. |
|
Sounds good. Closing this for now. |
This PR enables a special headless operating mode ("netcat" mode) where all object processing is disabled. Instead, raw objects received from the network are output to STDOUT unprocessed, also, any valid raw objects received on STDIN are broadcast to the network.
The STDOUT format is one object per line, formatted as:
The STDIN format is one object per line, which can be either a single HEX-encoded object or the format described for STDOUT above (in the latter case the timestamp will be ignored).
Example:
000000005aa29ada 00000000014f5b6a000000005aa7c646000000000401c5a40f3411817a9ba03df27d7839dd98b854d4fea089f6ffa9c251456e1f61e5This is part of a larger effort to compartmentalize the PyBitmessage operating layers in order to better contain network-borne attacks, and from this perspective it is an incomplete solution.
However, it also provides some immediate benefits such as the ability to generate a timestamped full record of network traffic for later examination/replay, as well as enabling developers to broadcast protocol objects generated externally.
As usual, all comments and questions will be appreciated.