Skip to content

A desktop client from a subscribe file

This recipe turns etemenanki-app into a proxy client for your own machine. A provider gives you a subscribe file that lists their nodes, a DNS setup and route groups, such as “Streaming” or “Ads”. Your own file adds two local proxies, a SOCKS5 port and an HTTP port, and says which node each route group uses. A small HTTP API on loopback lets a script or a tray application switch those picks while the proxy runs.

Use it when a provider hands out an etemenanki subscribe file and you want to keep your picks when the provider updates it. For the file format itself, see Subscribe files; for the API, REST API.

flowchart LR
  APP["Browser, other apps"] -->|"SOCKS5 :1080, HTTP :8080"| C["etemenanki-app"]
  C -->|"route group: Streaming, Proxy, …"| N["Provider's nodes"]
  C -->|"Local, Ads"| D["direct / blackhole"]
  S["curl, a tray app"] -->|"API :9090"| C
  • etemenanki-app on your machine, as described in Install. This page uses Linux paths; any directory works if you change the paths in the file.
  • The provider’s subscribe file, saved as /etc/etemenanki/subscribe.toml.
  • geoip.dat and geosite.dat from v2fly, when the provider’s route groups use geoip or geosite matchers. Split routing shows where to get them.
  • curl, for the API steps.
/etc/etemenanki/config.toml
# A desktop client: SOCKS5 and HTTP proxies on this machine, nodes and route
# groups from a provider's subscribe file, and a local API to switch which
# node a route group uses.
#
# Put the provider's file at the path in [subscribe]. Saving either file
# reloads; so does every route switch through the API.
[[inbound]]
tag = "socks-in"
protocol = "socks"
listen = "127.0.0.1"
port = 1080
[[inbound]]
tag = "http-in"
protocol = "http"
listen = "127.0.0.1"
port = 8080
# Routing comes from the subscribe file's route groups. [route] names the
# geodata files those groups use.
[route]
geoip = "/etc/etemenanki/geoip.dat"
geosite = "/etc/etemenanki/geosite.dat"
[subscribe]
path = "/etc/etemenanki/subscribe.toml"
# The API rewrites these picks. A group without a pick uses what it
# inherits in the subscribe file.
[subscribe.routes]
default = "vless-ws"
# Loopback only and no secret: every program on this machine may switch
# routes, nothing else can reach it.
[api]
listen = "127.0.0.1:9090"

The split is deliberate. The provider’s file holds everything that changes when the provider changes: the nodes, the DNS setup and the route groups. Your file holds what is yours: the local ports, the geodata paths, the picks and the API. When the provider sends a new file, you replace theirs and keep yours.

How the two combine:

  • Every node becomes an outbound tagged with the node’s name: vless-ws, trojan-tls, ss-2022, hy2 and wg here.
  • Route groups are the routing table. A flow goes to the first group whose matches match it. Your own [[route.rule]] entries, if you write any, are ignored while [subscribe] is set.
  • A group uses your pick, if [subscribe.routes] has one for it, and otherwise what the group inherits: another group ({ group = "Proxy" }), direct, blackhole, or default.
  • default is the pick for everything no group matches. Here it is vless-ws, and the Proxy group inherits it.
  1. Put both files in place and check them. --test reads the subscribe file too:

    Terminal window
    etemenanki-app --test -c /etc/etemenanki/config.toml
    Configuration OK.
  2. Start the proxy. In the foreground, or with the unit from Running in production:

    Terminal window
    etemenanki-app -c /etc/etemenanki/config.toml
    INFO etemenanki_supervisor::system::listener: inbound socks-in listening on 127.0.0.1:1080
    INFO etemenanki_supervisor::system::listener: inbound http-in listening on 127.0.0.1:8080
    INFO etemenanki_app::instance: config loaded: built [dns, outbound vless-ws@v1, outbound trojan-tls@v1, outbound ss-2022@v1, outbound hy2@v1, outbound wg@v1, outbound direct@v1, outbound blackhole@v1, route, inbound socks-in, inbound http-in]
    INFO etemenanki_app: API listening on 127.0.0.1:9090

    direct and blackhole appear as outbounds because the route groups name them; etemenanki-app creates them when no outbound of yours has those tags.

  3. Point your applications at it. Use socks5h://127.0.0.1:1080 where an application takes a SOCKS5 proxy, so that it sends names rather than addresses and the domain matchers see them, or http://127.0.0.1:8080 where it takes an HTTP proxy. From a shell:

    Terminal window
    curl --socks5-hostname 127.0.0.1:1080 https://example.com

GET /v1/routes shows every group, its pick, what it inherits, and where its traffic goes now:

Terminal window
curl -s http://127.0.0.1:9090/v1/routes
{
"default": { "pick": "vless-ws", "target": "vless-ws" },
"groups": [
{ "name": "Ads", "pick": null, "inherit": "blackhole", "target": "blackhole" },
{ "name": "Streaming", "pick": null, "inherit": { "group": "Proxy" }, "target": "vless-ws" },
{ "name": "Local", "pick": null, "inherit": "direct", "target": "direct" },
{ "name": "Proxy", "pick": null, "inherit": "default", "target": "vless-ws" }
],
"targets": [
{ "name": "vless-ws", "kind": "node" },
{ "name": "trojan-tls", "kind": "node" },
{ "name": "ss-2022", "kind": "node" },
{ "name": "hy2", "kind": "node" },
{ "name": "wg", "kind": "node" },
{ "name": "direct", "kind": "direct" },
{ "name": "blackhole", "kind": "blackhole" }
]
}

Streaming has no pick, so it follows Proxy, which follows default: its traffic goes to vless-ws. targets lists every name a pick may use.

Send streaming traffic through the Hysteria 2 node instead:

Terminal window
curl -s -X PUT -H 'Content-Type: application/json' \
-d '{"target": "hy2"}' http://127.0.0.1:9090/v1/routes/Streaming
{"status":"applied","built":["route"],"swapped":[],"drained":[],"rebound":[],"restarted":[],"removed":[],"reused":["dns","outbound vless-ws@v1","outbound trojan-tls@v1","outbound ss-2022@v1","outbound hy2@v1","outbound wg@v1","outbound direct@v1","outbound blackhole@v1","inbound socks-in","inbound http-in"]}

The API wrote the pick into your config, as one new line under [subscribe.routes], and reloaded:

/etc/etemenanki/config.toml (end)
[subscribe.routes]
default = "vless-ws"
Streaming = "hy2"

The answer is the reload report. Only the routing table was built again; every node and both listeners were reused, so no connection was dropped. Connections that were already open stay on the node they started on, and new streaming connections go to hy2. To close the open ones the switch moved, so their apps reconnect through hy2, add "close": true to the body; see Switching a route. Because the pick lives in the file, it survives a restart, and you can also change it by editing the file.

To go back to what the group inherits, remove its line from [subscribe.routes] and save the file. Percent-encode a group name with spaces in the path, for example /v1/routes/Video%20Streaming.

GET /v1/traffic is an event stream with one event a second: the bytes sent and received since the start, the rates over the last second and the number of live flows, in total and per inbound and outbound tag:

Terminal window
curl -sN http://127.0.0.1:9090/v1/traffic
event: traffic
data: {"tick":2,"interval_ms":1001,"up":0,"down":0,"up_rate":0,"down_rate":0,"flows":0,"inbounds":{},"outbounds":{}}

GET /v1/connections lists the live connections, and DELETE /v1/connections/{flow} closes one; see Endpoints.

Save the new subscribe file over the old one in one step, by writing it next to the old one and renaming it, so that the proxy never reads half a file. etemenanki-app watches the subscribe file’s directory and reloads. When the DNS setup is unchanged, nodes whose settings did not change keep running; changed ones are built anew, and new connections use them.

A pick must keep naming something. If the new file renames or removes a node you picked, or a group you have a pick for, the whole reload is refused and the proxy keeps running as it was:

ERROR etemenanki_app::instance: reload: subscribe: [subscribe.routes] "Streaming" = "hy2": no node, outbound or balancer has that name; keeping the running config

Fix the pick in your file, or remove it, and the next save loads both files.

Each of these appears after configuration invalid: under --test, after failed to start: at startup, and in a reload: …; keeping the running config line on a reload. The API answers a switch it cannot make with the same message in {"error": …}.

Message Cause Fix
subscribe file /etc/etemenanki/subscribe.toml: No such file or directory (os error 2) The subscribe file is not where [subscribe] path says Save it there, or fix the path
subscribe: [subscribe.routes] names "Video", which is not a route group in … A pick for a group the file does not have, often after the provider renamed it Rename or remove the pick
subscribe: [subscribe.routes] "Streaming" = "hy3": no node, outbound or balancer has that name A pick names a node that does not exist Pick a name from targets
[api] listen 0.0.0.0:9090: an API reachable from other hosts needs a secret; listen on a loopback address or a unix socket, or set one The API listens beyond loopback without a secret Keep it on 127.0.0.1, or set secret
failed to start: API on 127.0.0.1:9090: Address already in use (os error 98) Another program holds the API port Pick another port in [api] listen
building route failed: No such file or directory (os error 2) A geodata file the route groups need is missing Download it to the path in [route]
WARN … [subscribe] is set, so the config's 1 [[route.rule]] entries are ignored; … Your file still has [[route.rule]] entries Remove them; the route groups do the routing

The API’s own answers:

Answer Cause
404 {"error":"no route group named \"Video\""} The group in the path does not exist
422 {"error":"no node, outbound or balancer is named \"hy3\"; the route view lists them"} The target is not one of targets
409 The file changed since the ETag you sent in If-Match

Subscribe files lists the errors of the file format itself.