-
Notifications
You must be signed in to change notification settings - Fork 29
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 CLI options with argh and implemented cli capturing #160
base: main
Are you sure you want to change the base?
Conversation
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 the PR!
Command line capture is definitely a feature we want to have. I have some issues with the way you've implemented it, but I do think you've done very well to get this working, given that you're both new to Rust and new to the project. I hope that the rest of my feedback manages to be helpful rather than overly discouraging.
The good news is that the code as it stands can be simplified quite a lot.
You're creating a capture database with create_capture
, and decoding packets into it, but that's not actually necessary. It would be sufficient to take each packet and timestamp you get from stream_handle
, and just feed them directly to the pcap::Writer
, without ever constructing a capture read/write pair, or a decoder. There's no need to decode the packets, or to store them anywhere except into the output file, and doing so will just use up extra CPU and temporary storage.
The ctrlc_watchdog
thread also isn't necessary. You should be able to move the original stop_handle
into the closure that you pass to ctrlc::set_handler
, and have that closure call the stop_handle.stop()
method to end the capture.
The command line handling changes I'm not too sure about, and should perhaps be a separate PR. We've been using the built-in command line parsing provided by gio::Application
for file handling and usage info, and I'm not sure if we want to switch away from that, or if so, whether argh
is the library we'd want to choose for that. Right now this is using a mix of both, and that doesn't seem like a great idea.
I'm also a bit wary of accepting both subcommands (packetry capture
etc) and filenames (packetry foo.pcap
) at the top level, because it makes it ambiguous about whether something is supposed to be a subcommand or a filename (particularly one that doesn't have an extension). Unless we're going to have a specific subcommand for opening files (packetry open filename
), I think we may want to stick to the --option
approach.
I like the devices table, but the code generating it could use some improvement. Rather than creating a Vec
for each field in DeviceInfo
, you should be able to just construct a Vec<DeviceInfo>
as you go.
One last small thing: the indentation is a bit all over the place in this PR. Please try to stick to the style used in the rest of the project (four spaces per indent).
Thanks for the feedback. I really appreciate it. Regarding the command line parsing, I can totally understand why this needs to be a separate PR, as your system right now works for you. For CLI capturing, however, I need a separate crate (from the beginning) as my code does not create a GTK app for obvious reasons, and your Seeing your latest work with
Please tell me if this is a direction that works for you. Additionally:
Looking forward to your feedback. I'm gonna change this PR to a draft in the meantime. |
This breaks the I'll look into your suggestion of not using subcommands but rather |
This looks a lot better with the changes you've made already - nice! On the issues about how to structure this going forwards, there's a few reasons behind the way things are done right now that really won't be obvious from just reading the code, so I should probably start by explaining the history a bit. BackstoryThe key thing to understand is that we'd been trying for a while to avoid having more than one binary target in the package. That was specifically due to some limitations of the Rust tooling, as follows. Previously, we had multiple binary targets. Both
Option 1 turned out not to work well, because it produced a lot of spurious So we went with option 2 instead. But that required us to have a library crate, with a public API. And we learned that would automatically end up on docs.rs as soon as we made a release, whether we wanted it there or not! That would include a lot of internal things, that are still too in flux for us to commit to a public API for them yet. And we didn't really trust people not to start using that, and demanding support for it, even if we documented it as unstable and unsupported. So as the deadline approached for the initial 0.1.0 release, I did a big push to get us down to a single binary target and get rid of the unwanted library target:
But that still left us with the problem of Windows, where we couldn't have command-line functionality on a GUI binary. So I wrote #154 to add Next stepsThe question of how things should be done in I quite like your approach of importing just But invoking the wrapping code in the case of The case in which we need that wrapping code is where we want to get console output from the GUI binary. And currently that's only necessary when we want to run it with So I think there's two basic options for how to proceed:
In the case of In the case of If we can successfully move all the console functionality to As far as the argument handling goes, I think it makes sense to split this up, such that we use a Rust-native solution for I've had a look at the other options listed on that rosetta-rs page, and I agree that |
Thanks for the backstory. It helped me understand the current problems. I've removed You mentioned you didn't get dead_code issues. Even before my changes, I saw some, so I don't know why you didn't get any. Right now, they are definitely present. If I move For me, the state that the CLI version is in works, as I only needed the Wireshark piping for a project, and I'd be more than happy if a developer with more Rust experience would take it from here. I honestly didn't open the PR to be an active developer on this project/feature as I don't really like Rust and don't have the time to like it more. There was just no excuse not to share the code. I hope this is somewhat understandable. |
It looks like the latest release of Rust may have fixed the I was building your branch with 1.80.0, and didn't see any So it looks like they may have fixed this, such that it now understands the code is in use if any of the targets being built uses it. That would be really great news.
That's totally fine. I think you've done some great work on this and we can see about taking it forward from here. Thank you! |
As mentioned in #136, it should be possible to operate packetry via the terminal. This PR tries to address that and a bit more :P
A little warning first: I'm a total rust newbie, and the code is probably highly unoptimized and may contain flat-out bad code. The capturing stuff was pieced together by reading
ui.rs
. I've tested this on Linux and with the newest branch, the one which already haspacketry-cli
.New Stuff
version
andtest-cynthion
commands were ported from your codedevices
will search for and list all Cynthions found in a table. For this, the dependency tabled was added. (technically optional)capture
command does what it says. For stopping captures withCTRL+C
, the dependency ctrlc was added.Previews
Here are some CLI previews:
Changes
println
needed to becomeeprintln
as the piping to, for example, Wireshark would not work. (stderr
vs.stdout
)Speed
, which enables me to look up the speed in a nicer fashion from the CLI argument.