Skip to content

Conversation

@grimsteel
Copy link
Contributor

Summary

This PR essentially splits src/main.rs into three files:

  1. src/lib.rs - code that takes the config structs and launches tunnels
  2. src/config.rs - Client and Server config structs
  3. wstunnel-cli/src/main.rs - code specific to CLI operation

Cargo project structure changes

I've made the root Cargo project (the library) a workspace, and added a wstunnel-cli binary subpackage to this workspace. It depends on the root library, with the clap feature enabled.

This clap feature on the root library project adds the clap dependency and enables clap attributes on Client and Server in config.rs. This is because clap functionality will not be needed for most usages of the library.

In order to build/run the CLI from the root of this repo, you need to run cargo run --package wstunnel-cli. I've updated the README accordingly.

Library usage

  1. Create a Client or Server struct with all of the required fields specified.
  2. Pass this struct to either wstunnel::run_client or wstunnel::run_server.
  3. These functions will not terminate unless an error causes them to stop (run_client will stop when all of the tunnels it spawns stop)

Problems

I'm not sure what to do about the stdio listener. I've left the code for launching an stdio tunnel in lib.rs with all of the other protocol types, but it of course doesn't make sense inside the library.


All of the tests still pass, and I verified that the demo in the README still works.

This will break #393

Fixes #286

- copied all config structs into config.rs, along with all `use`
statements
- made everything `pub`
- changed main.rs to import these structs
- make root package a cargo workspace
- move code to start client/server tunnels into lib.rs
- move rest of main.rs into wstunnel-cli bin package
- move "Wstunnel" config struct into bin package
  - the fields here are only applicable to the CLI
@grimsteel grimsteel changed the title Add library target Restructure and add library target Jan 4, 2025
@erebe
Copy link
Owner

erebe commented Jan 4, 2025

Thanks a lot for this amazing work. I am going to try to find some time in the weekend to take a look at it.
Can't wait

@erebe erebe merged commit 3fa806d into erebe:main Jan 6, 2025
13 checks passed
@erebe
Copy link
Owner

erebe commented Jan 6, 2025

It is merged, thanks a lot for your work ! 💌

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.

Library usage

2 participants