Skip to content
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

feat(network scan): A working scanner with ping, port discovery, broadcast, and netbios #683

Merged
merged 46 commits into from
Feb 9, 2024

Conversation

irvingoujAtDevolution
Copy link
Contributor

@irvingoujAtDevolution irvingoujAtDevolution commented Feb 5, 2024

This PR contains code necessary for new functionalities, changes,improvement and refactoring of the network scan crates. Please see network-scan/examples for usages.

@CBenoit Let me know if smaller PR would be preferable, The main changes include

  1. uses DashMap to imporve the preformance of event loop
  2. add netbios,ping,port discovery and broadcast
  3. integrate everything to make a working scanner

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Let me know if smaller PR would be preferable

It would indeed be very much welcomed as smaller PRs. Probably it’s too much work for you to change that now so we can try to handle this the way it is now. I’ll not go through every change though.

1. uses DashMap to imporve the preformance of event loop

Did you perform any form of benchmarking before making this move?
I would be interested in seeing some numbers before we add this dependency.
(Following on the above: this alone could be a dedicated PR.)

I’ll continue reviewing tomorrow.

crates/network-scanner-net/src/runtime.rs Outdated Show resolved Hide resolved
crates/network-scanner/src/broadcast/block.rs Outdated Show resolved Hide resolved
crates/network-scanner/src/task_utils.rs Outdated Show resolved Hide resolved
@irvingoujAtDevolution
Copy link
Contributor Author

irvingoujAtDevolution commented Feb 5, 2024

Nice work!

Let me know if smaller PR would be preferable

It would indeed be very much welcomed as smaller PRs. Probably it’s too much work for you to change that now so we can try to handle this the way it is now. I’ll not go through every change though.

1. uses DashMap to imporve the preformance of event loop

Did you perform any form of benchmarking before making this move? I would be interested in seeing some numbers before we add this dependency. (Following on the above: this alone could be a dedicated PR.)

I’ll continue reviewing tomorrow.

I'll try give a benchmark, but notably,even if the performance is slightly worse, the logic is much more strightforward and now lock-free.

Plus, it gives our the potential ability to implement method like async fn writeable(&self) or async fn readable(&self) in the future, by checking if cetarin event exist in the event cache.

futures = "0.3.30"
parking_lot = "0.12.1"
polling = { git = "https://github.com/smol-rs/polling", rev = "62430fd56e668559d08ca7071ab13a0e116ba515" }
polling = { git = "https://github.com/irvingoujAtDevolution/polling.git", branch = "fix-linux-tcp-fail" }
Copy link
Contributor Author

@irvingoujAtDevolution irvingoujAtDevolution Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware the problem of Linux side until CI reported the error. :( , this is actually a hard one to fix.

This is currently necessary for linux TCP to work, see line 237 for reason in socket.rs.

I will try convince the repo owner of Polling to merge it, otherwise let's use a branch on our own repo for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to the issue / pull request you created on their side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem on polling is that they are trying to have a platform indepent interface for all polling mechanisms, so I guess they would particularly against have something like this. I have a better idea in mind to how to implement this so it is more acceptable for both us and them, I'll put on a update shortly.

Copy link
Contributor Author

@irvingoujAtDevolution irvingoujAtDevolution Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PR on polling smol-rs/polling#189

@@ -40,7 +41,7 @@ impl Drop for Socket2Runtime {
}
}

const QUEUE_CAPACITY: usize = 1024;
const QUEUE_CAPACITY: usize = 8024;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe too big?

Copy link
Member

@CBenoit CBenoit Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you changed? It wasn’t big enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was causing errors on registering the events.

return std::task::Poll::Ready(Ok(()));
// This is a special case, this happens when using epoll to wait for a unconnected TCP socket.
// We clearly needs to call connect function, so we break the loop and call connect.
#[cfg(target_os = "linux")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux and Windows have different behavior, Linux shots event to you even before you call connect, we need to identify if the event is "Connect failed" or "Connect successful" or something else (out and hup). Polling does not expose plateform dependent args, so we have to make a banch specific to our needs here. Will disguss with Polling's owner later.

@@ -15,7 +15,6 @@ use tokio::{
use crate::socket::AsyncRawSocket;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore = "TODO"]
async fn multiple_udp() -> anyhow::Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like all tests have passed. 😆
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

pub(crate) handles_sender: HandlesSender,
}

impl TaskExecutionContext {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is created purely for the sake of readability, it was super hard of keep track of things without it.

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clean up the dependencies before we merge. Incidentally, the dependency on futures is unrequired not only for network-scanner but also for network-scanner-net

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a conflict to fix with master, but otherwise I’m thinking about merging today

@irvingoujAtDevolution
Copy link
Contributor Author

We need to clean up the dependencies before we merge. Incidentally, the dependency on futures is unrequired not only for network-scanner but also for network-scanner-net

updated, removed all unsued dependencies

@irvingoujAtDevolution
Copy link
Contributor Author

There is also a conflict to fix with master, but otherwise I’m thinking about merging today

updated, thank you!

polling = { git = "https://github.com/devolutions/polling.git", branch = "fix-detect-connection-fail" }
polling = { git = "https://github.com/devolutions/polling.git", rev = "c04e8ee40415cad551fe044457270f4a2d7c491d" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s hardcode the commit rather than the branch

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s merge. Thank you for this work!
In the future, try to send single-purpose PRs, please.
It’s okay even if the PR is very small, it’ll be quick to review.

@CBenoit CBenoit disabled auto-merge February 9, 2024 16:50
@CBenoit CBenoit enabled auto-merge (squash) February 9, 2024 16:51
@CBenoit CBenoit merged commit 0f4894d into master Feb 9, 2024
16 checks passed
@CBenoit CBenoit deleted the Network-Scan-Scanner branch February 9, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants