-
Notifications
You must be signed in to change notification settings - Fork 31
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
Hulto eldritch feature pivot ncat #44
Conversation
This PR also includes stubs for the pivot library. |
use tokio::net::{TcpStream, UdpSocket}; | ||
|
||
// Since we cannot go from async (test) -> sync (ncat) `block_on` -> async (handle_ncat) without getting an error "cannot create runtime in current runtime since current thread is calling async code." | ||
async fn handle_ncat(address: String, port: i32, data: String, protocol: String) -> Result<String> { |
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.
The working portion and the primary function have been separated to make testing async code easier.
// Since we cannot go from async (test) -> sync (ncat) `block_on` -> async (handle_ncat) without getting an error "cannot create runtime in current runtime since current thread is calling async code." | ||
async fn handle_ncat(address: String, port: i32, data: String, protocol: String) -> Result<String> { | ||
// If the response is longer than 4096 bytes it will be truncated. | ||
let mut response_buffer = [0; 4096]; |
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.
Not sure if there's a better way to receive more bytes.
If not should we add a truncated indicator? Eg. "I got. lots of bytes of data ...trunc...
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.
Can we use read_exact
either to read enough header to determine the packet size, or alternatively read_exact in a loop?
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 suggestion.
Do you know of a good way to read an undefined number of bytes? I think this still uses a fixed length buffer.
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!
// Connect to remote host | ||
|
||
// Setting the bind address to unspecified should leave it up to the OS to decide. | ||
// https://stackoverflow.com/a/67084977 |
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 do not want to make this async since it would require we make all of the starlark bindings async. |
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 to know :blob_salute:
Hulto eldritch feature pivot ncat (#44) * ncat tcp test seems to be setup. * test echo server works for tcp. * TCP and UDP tests work. * Test cover ncat not just async handle. * Added windows error catch * Added unused port allocation to avoid overlap. * TCP buffered reader instead of set buffer size.
What type of PR is this?
What this PR does / why we need it:
This PR adds support for eldritch to send UDP / TCP data to an arbitrary host / port. If the host/port responds with any data that data will be returned to the user.