English
clients
What is handed out to the host's clients: a new WireGuard peer (keys, a tunnel address, the peer entry) and its configuration in client formats; links and a subscription for the users of the vless, hysteria2, tuic inbounds. It works on top of the loaded configuration and does not live with the instance: it is called by the Admin API (/api/v1/clients…) and ours client (CLI).
| Crate | ours-mod-clients, modules/config/clients |
| Binary feature | clients (in default, enables wireguard) |
| Crate features | none |
requires
wireguard: the endpoint's options (WireGuardEndpointOptions, already merged with config_file), parsing and writing the wg/awg file (conf).
provides
Nothing: the module is functions over Config that the binary takes (app/ours/src/clients.rs).
Dependencies
ours-mod-wireguard, ours-wireguard (keys: keys::generate — like wg genkey, keys::random — the PSK), ours-net-info (wan — the address for auto), ours-native-config (runtime — the view of inbounds; fragment/replace — editing YAML), x25519-dalek (the REALITY public key from the private one), base64, qrcodegen (QR, without dependencies).
Design
src/lib.rs—list,add,remove,export; the answer isReply { value, change, warnings },Change::File(a newconfig_filetext) orChange::Source(new YAML).persistwrites through a temporary file in the same directory andrename, keeping the permissions.check_writable: the file is opened for appending and a probe file is created in the directory; otherwise adding and removing clients is the error "not writable … disabled".- Where a peer is stored. With
config_file— a[Peer]section is appended to the end of the file (conf::append_peer, the rest of the text byte for byte), and removal takes out only its section. Without it — in the YAML, by the same mechanism as an edit in the dashboard: the endpoint'speersare appended as a block list (fragment+replacefromnative-config, comments outsidepeersstay intact); the Admin API applies the new YAML and saves it to the file if the running configuration was saved (otherwise a warning: unsaved dashboard edits are not written without asking), andours clientwrites it to the-cfile. There is no separate state file: a peer is an ordinary part of the configuration. - The client's private key exists only in the
addanswer; the file and the YAML have the public key and the PSK.exportof an existing peer writes a placeholder instead of the key. src/wg.rs— the address: in every subnet of the endpoint (one per family,/31,/32,/127,/128are skipped) the smallest host address that is not the network or broadcast address, not the endpoint's address and not inside a peer'sallowed_ipsno wider than the subnet (a peer with0.0.0.0/0does not take an address); the search is limited to 2^20 addresses.public_endpoint:host:port,host(the port islisten_port),auto/empty — the WAN address, public before private, IPv4 before IPv6; a private or CGNAT one — a warning. Formats:wg(wg-quick),awg(awg-quick, with the endpoint'sawgparameters andCiphers),qr(an SVG of the.conf),sing-box(anendpointselement, 1.11+),xray(anoutboundselement).wg,sing-box,xrayare unavailable if the endpoint has AmneziaWG orcipherslackschacha20-poly1305; the reason is inunavailable.src/links.rs— by the inbound's kind fromours_native_config::runtime:vless://uuid@host:port?…(securityrealitywithpbkfrom the private key,sid,fp=chrome;tlswithsni,alpn;typetcp/ws/httpupgrade/grpc/http/xhttpwithpath,host,serviceName,mode;flow),hysteria2://password@host:port/?sni&obfs&obfs-password,tuic://uuid:password@host:port?congestion_control&udp_relay_mode&sni&alpn; the name is the fragment#user. The host: from the request, otherwisetls.server_name(except REALITY), otherwise the WAN address. The subscription is the links line by line in base64 (as v2rayN serves and reads it). VLESS Encryption is not handed out as a link (the client's string cannot be derived from the server'sdecryption).src/qr.rs— an SVG as onepath, a 4-module border, error correction level L (long AWG configurations with I1–I5 do not fit otherwise).
Tests
src/tests.rs: golden files of the formats (tests/golden, OURS_BLESS=1 overwrites them), the awg file is read back by conf::parse; adding to YAML (the next address, comments intact, the key not stored, removal, an endpoint without peers); adding to config_file and removal (the text appended, no temporary files, a read-only file is an error); links — a golden file and parsing the subscription with the subscriptions module (the server fields match); exporting an existing peer without the key; the list. src/wg.rs: address allocation, public_endpoint.