The README gains a Plugins section: what a plugin is, the six that ship with the tree, how one is configured as an outbound, why `path` must have a directory part, why nothing is ever scanned for, why leaf refuses a library anyone can rewrite, and why the optional `sha256` is worth setting. It says plainly what none of that buys -- a plugin runs with leaf's privileges, so the checks establish which file was loaded, not that it is friendly -- and how to vet one with `--verify-plugin` first. It also covers building a leaf that can load plugins at all, which neither the releases nor CI produce: the Linux releases are static against musl and have no dynamic loader to call. examples/ carries configs that run. The shadowsocks one connects through the Rust plugin; the TLS ones chain a transport plugin under Trojan across the Rust and Go implementations, with Windows variants where the paths differ, and both READMEs give the server side needed to try them.
Shadowsocks C ABI Examples
This directory shows how to use the shadowsocks-cabi-rs plugin as a Leaf outbound.
This directory currently includes the following runnable example:
client.json- Uses the Rust
shadowsocks-cabi-rsplugin for both TCP and UDP traffic
- Uses the Rust
The local SOCKS5 inbound listens on 127.0.0.1:1080.
Files
client.json
Configuration for the Rust shadowsocks-cabi-rs plugin. The plugin path defaults to:
./target/debug/libshadowsocks_cabi_rs.dylib
Quick Test
The macOS/Linux blocks below assume you run them from the project root /opt/rust/leaf.
For Windows, open PowerShell in the repository root and copy the PowerShell blocks directly. They generate a temporary client.windows.json file so you do not need to edit the plugin .dylib path by hand.
macOS/Linux, Terminal 1:
cd /opt/rust/leaf
cargo build -p shadowsocks-cabi-rs
cargo run -p leaf-cli --features leaf/plugin -- -c examples/shadowsocks-cabi/client.json
macOS/Linux, Terminal 2:
curl --socks5-hostname 127.0.0.1:1080 -I https://example.com/ --max-time 20
Windows PowerShell, Terminal 1:
$config = Get-Content .\examples\shadowsocks-cabi\client.json -Raw
$config = $config.Replace("./target/debug/libshadowsocks_cabi_rs.dylib", "./target/debug/shadowsocks_cabi_rs.dll")
[System.IO.File]::WriteAllText((Join-Path (Get-Location) "examples\shadowsocks-cabi\client.windows.json"), $config, [System.Text.UTF8Encoding]::new($false))
cargo build -p shadowsocks-cabi-rs
cargo run -p leaf-cli --features leaf/plugin -- -c .\examples\shadowsocks-cabi\client.windows.json
Windows PowerShell, Terminal 2:
curl.exe --socks5-hostname 127.0.0.1:1080 -I https://example.com/ --max-time 20
On success you should see output similar to:
HTTP/2 200
Change Server Parameters
If you want to use your own Shadowsocks server, update these fields in client.json:
"host": "remote_host",
"port": 8388,
"args": "cipher;password"
Optional prefix form:
cipher;password;prefix
Example:
host = 203.0.113.10
port = 8388
args = aes-128-gcm;test-password
Build Only
If you only want to build the plugin without starting Leaf:
macOS/Linux:
cd /opt/rust/leaf
cargo build -p shadowsocks-cabi-rs
Windows PowerShell:
cargo build -p shadowsocks-cabi-rs
Notes
- The same plugin dynamic library exports both the TCP stream engine and the UDP datagram engine.
- The example keeps a single
client.json, which covers both TCP and UDP traffic.
Troubleshooting
- If Leaf reports that the plugin file does not exist, make sure the dynamic library path matches the
pathfield inclient.json. - On Windows, the example config in this directory still points to
.dylib, so use the PowerShell commands above to generateclient.windows.jsonwith the matching.dllpath. - If
leaf-clireports that thepluginfeature is missing, use-F leaf/pluginor--features leaf/plugin. - If the remote server does not respond, double-check the
argsvalue inclient.json, especially the host, port, cipher, and password.