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

Implement detached signal sender #56

Open
wants to merge 198 commits into
base: master
Choose a base branch
from

Conversation

jgrund
Copy link
Contributor

@jgrund jgrund commented Oct 18, 2022

Allow signals to be sent detached from the channel struct.

This is done using a higher-order function and by cloning the sender so it can be used independently of the Channel.

This is useful to be able to spawn a cancelation handler separately from the main Channel recieve loop.

Signed-off-by: Joe Grund [email protected]

@Eugeny
Copy link
Owner

Eugeny commented Oct 19, 2022

Isn't this something that can be solved with tokio::select? (for any commands, not just .signal())

let channel = ...
let (tx, rx) = mpsc::channel(1);

loop {
    tokio::select! {
        msg = channel.wait() => ...
        sig = rx.recv() => channel.signal(sig)
    }
}

...

tx.send(Sig::...)

@jgrund
Copy link
Contributor Author

jgrund commented Oct 19, 2022

Isn't this something that can be solved with tokio::select? (for any commands, not just .signal())

Not really, because I do not want to hold a Channel ref, only a way to send signals to it.

My usecase is a map of signal senders that I can use to interrupt open connections on demand (orchestration platform).

@Eugeny
Copy link
Owner

Eugeny commented Oct 19, 2022

You don't need to hold the ref for that - the ref can stay in the wait() loop, while you can move tx where you need it and use it to send signals

@jgrund
Copy link
Contributor Author

jgrund commented Oct 19, 2022

the ref can stay in the wait() loop

Yeah, this is the ref I was talking about.

It's honestly easier to have the channel return me a (scoped) sender directly than to have to create a layer of indirection that does the same thing.

@Eugeny
Copy link
Owner

Eugeny commented Oct 19, 2022

Can't merge this as it's a band-aid fix for one specific method that will eventually lead to duplication of every channel method.

However I'm open to adding a Channel.handle method that would return a handle object that's similar to Channel but only has "sender write" methods such as data/signal/close etc. Could even be a trait shared between it and Channel to avoid duplication.

Let me know if this is something you'd like to work on, otherwise I'll see if I can find time for it in the future.

@jgrund jgrund force-pushed the jgrund/detach-signal branch 2 times, most recently from e803532 to 7b12f66 Compare December 26, 2022 18:40
Eugeny and others added 22 commits August 17, 2023 19:30
OpenSSH server sends `CHANNEL_WINDOW_ADJUST` messages before window_size is 0.

Handle these message at each turn of the loop within `Channel.send_data`

Signed-off-by: Joe Grund <[email protected]>
Eugeny and others added 29 commits July 16, 2024 20:56
Bumps the dependency to at least 4.1.3 as per the advisory

[Advisory](https://rustsec.org/advisories/RUSTSEC-2024-0344.html) 

(even though this crate may not be using the function mentioned in the
advisory, it is better to bump it to ensure that there is no chance of
other dependencies pulling it)
It seems like the project ended up with two different dependencies
providing access to the home directory.
This PR consolidates these dependencies into a single dependency.

I've done so by using the `home` crate since on linux it has 0
dependencies and is well supported due to being a part of the cargo
repo.
But if you'd prefer I could swap this PR to use `dirs-next`.

I would like to avoid `dirs` since it is pulling in strange dependencies
dirs-dev/dirs-sys-rs#26
…eny#312)

I left a `// NEED HELP` comment on places where I didn't fully figure
out what to do, so I'd really appreciate it if some maintainers helped
me out in those places.

---------

Co-authored-by: Eugene <[email protected]>
…y#328)

Apologies. I accidentally left a stray dbg!() in when checking the glob
expansion logic of hosts in the russh-config SSH config parsing code.
This PR simply removes it.

Co-authored-by: Adam Chappell <[email protected]>
…the more specific error type when connection fails during kex phase
Allow signals to be sent detached from the channel struct.

This is done using a higher-order function and by cloning the sender so
it can be used independently of the `Channel`.

This is useful to be able to spawn a cancelation handler separately from
the main `Channel` recieve loop.

Signed-off-by: Joe Grund <[email protected]>
f08f74

Signed-off-by: Joe Grund <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.