XDRIVE — Xray-core
XDRIVE is a transport (streamSettings.network: "xdrive") that carries a proxy connection through a remote storage service instead of a direct link. The client writes its data as objects into a shared folder; the server polls the same folder, picks the data up and writes its replies back the same way. Neither side ever connects to the other — both only talk to the storage service's API (Google Drive, an S3-compatible bucket, any HTTP API described by a template, or a local directory) — so the server needs no reachable address or open port. XDRIVE runs only under VLESS with VLESS Encryption, and the client must use Mux.
xdriveSettings
Set under streamSettings.xdriveSettings, on both the VLESS outbound and the VLESS inbound:
| Field | Type | Default | Allowed values | Description |
|---|---|---|---|---|
remoteFolder | string | (required) | <Drive folder id> | <key prefix> | <directory> | Where both sides meet. google-drive: the id of a Drive folder; s3: the object-key prefix inside the bucket (relative, without empty, . or .. segments); template: the value of {folder}; local: a directory, created if missing. Client and server must point at the same place. |
service | string | (required) | google-drive | s3 | template | local | Storage backend. "Google Drive" is accepted as a deprecated spelling of google-drive; any other value fails at startup. |
secrets | []string | [] | [<string>, …] | Credentials, by backend. google-drive: exactly three, in this order — OAuth client ID, client secret, refresh token — none empty. s3: access key ID, secret access key and an optional session token. template: free-form, referenced as {secret0}, {secret1}, … local: unused. |
segmentBytes | uint32 | 524288 | <bytes> | ≤ 16777216 | Largest object one write is cut into (512 KiB; values above 16 MiB are capped). On Google Drive a session starts with small segments — up to 14 KiB travel inline in the slot's description — and grows them up to this size while data keeps flowing. |
flushIntervalMs | uint32 | 20 (google-drive: 10) | <ms> | Tick for flushing buffered data that hasn't filled a segment. While writes keep arriving, a flush is held back for up to 8 ticks so they coalesce. |
pollIntervalMs | uint32 | 50 | <ms> | Shortest wait between listings: how fast the server notices new sessions and, on the segment backends, how fast a reader picks up new segments. While nothing happens the interval doubles up to maxPollIntervalMs. |
maxPollIntervalMs | uint32 | 500 (google-drive: 200) | <ms> | Ceiling for idle polling. Never lower than pollIntervalMs. |
sessionTtlSeconds | uint32 | 300 | <seconds> | Session bookkeeping on the server: announcements still listed after this long are deleted, and so are the objects of sessions idle this long (checked every half TTL). Google Drive clients also keep up to two pre-built spare sessions, renewed well within this TTL. |
concurrency | uint32 | 8 (google-drive: 64) | 1–256 | Segment backends: parallel uploads, downloads and deletions per direction. Google Drive: the number of slots in each direction of a session's ring (at least 2), chosen by the client. Values above 256 are capped. |
eagerWindowMs | uint32 | 2000 | <ms> | How long polling stays at pollIntervalMs after the last activity before it backs off. |
holeTimeoutMs | uint32 | 30000 | <ms> | Segment backends only: how long a segment may stay missing while later ones are already there before the connection fails with segment N never arrived while later ones did. |
template | json.RawMessage | (template only) | <object> | Required for service: "template": describes the storage API's HTTP requests — see Template backend below. |
s3 | *XDriveS3Config | (s3 only) | XDriveS3Config | Required for service: "s3". |
xmux | XmuxConfig | {maxConnections: 1, hMaxReusableSecs: 1800-3000} | XmuxConfig | Pool of HTTP connections to the storage service, shared by the sessions. Empty → one connection (four for google-drive unless HTTP/3 is used), each retired after 1800–3000 s. maxConnections (connections) and maxConcurrency (sessions per connection) can't both be set. A positive hKeepAlivePeriod sets the HTTP/2 PING / HTTP/3 keep-alive interval in seconds; a negative one turns HTTP/2 PINGs off. |
Source: infra/conf/transport_method.go:989-1007 · pinned at v26.11.9 (676eaf6)
s3
| Field | Type | Default | Allowed values | Description |
|---|---|---|---|---|
endpoint | string | (required) | https://<host>[/<path>] | http://<host>[/<path>] | S3 API endpoint URL, without credentials, query or fragment; a path prefix is allowed. |
region | string | us-east-1 | <region> | SigV4 signing region. |
bucket | string | (required) | <bucket> | Bucket name, without /. With pathStyle: false it must be DNS-compatible (lower-case letters, digits, - and .). |
pathStyle | *bool | true | true | false | true: path-style URLs (<endpoint>/<bucket>/<key>). false: virtual-hosted style (<bucket>.<endpoint host>), which needs a DNS name rather than an IP in endpoint. |
Source: infra/conf/transport_method.go:1009-1014 · pinned at v26.11.9 (676eaf6)
Backends
google-drive—remoteFolderis a Drive folder id andsecretsholds an OAuth client ID, client secret and refresh token; Xray trades the refresh token for access tokens itself. Sessions run in a ring of pre-created files per direction (concurrencyslots), so neither side lists the folder for every segment.s3— any S3-compatible service, signed with SigV4. Objects go under<remoteFolder>/inbucket; the credentials need to list, put, get and delete objects there. Redirects aren't followed.template— any HTTP API that can put, get, delete and list objects, described by thetemplateobject (below).local—remoteFolderis a directory on the local filesystem that both sides can read and write.
The segment backends (s3, template, local) carry each direction as numbered objects (<seq>.seg, closed by an .end marker, or .err when an upload failed) that the reader lists, fetches in order and deletes.
Template backend
template is a JSON object with these keys:
put,get,delete,list— required operations, each{ "method", "url", "headers", "hrefPath", "hrefMethod" }, plusbodyforput;methoddefaults toGET.listalso needsnamesRegex, whose first capture group picks every object name out of the response body.- Variables, substituted in
url,headers,put.bodyand theauthstrings:{folder}(remoteFolder),{secret0},{secret1}, … (secrets),{name}(the object, input/get/delete),{prefix}(inlist) and{data}— whenput.bodyis set it becomes the request body with{data}as the base64 payload; otherwise the raw bytes are sent. hrefPathmakes an operation two-step: the first request answers with JSON, and the URL found at that dot-separated path is called withhrefMethod(GETby default), carrying the payload, with neither auth nor extra headers.auth.type:none(default),static(headermap),basic(username/password) oroauth2—formis POSTed totokenUrl, the token is read attokenPath(defaultaccess_token) and its lifetime in seconds atexpiryPath(default 3600), thenheaderis sent with{token}. A401drops the token and retries.flatten: truereplaces/in object names with~, for services without folders.concurrencycaps parallel requests (64 by default, at most 256).retry.statuslists HTTP statuses to retry;retry.rateReasonis a dot path into a403body — a403with a string there is retried too.
Requirements
These are checked at startup:
- Only VLESS may use
network: "xdrive"; any other protocol fails withthe xdrive transport can only be used by VLESS. - VLESS Encryption is mandatory: the outbound's
encryptionand the inbound'sdecryptioncan't benone—xray vlessencprints a matching pair. See VLESS. - No
flow(on the outbound, the inbound or its clients), and notestpreon the outbound. - The outbound needs
muxwithenabled: true, no negativeconcurrencyorxudpConcurrency, andxudpProxyUDP443other thanskip— unless VLESSreverseis configured, which opens its own mux. See Outbounds. - The inbound may listen on only one port.
tlsSettings.alpn: ["h3"](exactly that) switches the storage connections to HTTP/3. Thenfinalmask.quicParams.congestioncan only bebbr(the default) orreno(brutalandforce-brutalare rejected), and withgoogle-drivethe only UDP finalmask allowed isnoise.alpn: ["http/1.1"]withoutechConfigListlogs a warning: unless thefingerprintis Go's or a randomized one, the ClientHello carries the fingerprint's own ALPN and the service may still pick HTTP/2.
Examples
Client — VLESS with Encryption and Mux, over Google Drive (address / port are never dialed, any valid value works):
{
"outbounds": [
{
"tag": "xdrive-out",
"protocol": "vless",
"settings": {
"address": "127.0.0.1",
"port": 443,
"id": "<uuid>",
"encryption": "mlkem768x25519plus.native.0rtt.<client key>"
},
"mux": { "enabled": true },
"streamSettings": {
"network": "xdrive",
"xdriveSettings": {
"service": "google-drive",
"remoteFolder": "<Drive folder id>",
"secrets": ["<client id>", "<client secret>", "<refresh token>"]
}
}
}
]
}Server — same folder; it binds nothing, so listen / port are placeholders:
{
"inbounds": [
{
"tag": "xdrive-in",
"listen": "127.0.0.1",
"port": 10000,
"protocol": "vless",
"settings": {
"clients": [{ "id": "<uuid>" }],
"decryption": "mlkem768x25519plus.native.600s.<server key>"
},
"streamSettings": {
"network": "xdrive",
"xdriveSettings": {
"service": "google-drive",
"remoteFolder": "<Drive folder id>",
"secrets": ["<client id>", "<client secret>", "<refresh token>"]
}
}
}
],
"outbounds": [
{ "protocol": "freedom" }
]
}xdriveSettings for an S3-compatible bucket:
{
"service": "s3",
"remoteFolder": "xdrive",
"secrets": ["<access key id>", "<secret access key>"],
"s3": {
"endpoint": "https://s3.example.com",
"region": "us-east-1",
"bucket": "my-bucket"
}
}xdriveSettings for a WebDAV-style API through the template backend:
{
"service": "template",
"remoteFolder": "folder",
"secrets": ["<user>", "<password>"],
"template": {
"flatten": true,
"auth": { "type": "basic", "username": "{secret0}", "password": "{secret1}" },
"put": { "method": "PUT", "url": "https://dav.example/{folder}/{name}" },
"get": { "method": "GET", "url": "https://dav.example/{folder}/{name}" },
"delete": { "method": "DELETE", "url": "https://dav.example/{folder}/{name}" },
"list": { "method": "PROPFIND", "url": "https://dav.example/{folder}/", "namesRegex": "<d:href>/folder/([^<]+)</d:href>" }
}
}Notes
- How a connection travels. Every dial opens a session: the client announces it under
sessions/in the folder and the data flows understreams/<session>/c2sandstreams/<session>/s2c. The server pollssessions/, claims new announcements and deletes them. Because every connection is a session with objects of its own, the client must multiplex its traffic with Mux, and because the objects sit with a third party, VLESS Encryption is mandatory. - The server binds nothing. The inbound's
listen/portonly satisfy the inbound syntax (a single port), and the outbound'saddress/portare never dialed — only the storage service is. - Connections to the storage service.
security,tlsSettings,sockoptandfinalmaskshape the HTTPS requests to the service's API, on both sides. The SNI is the API host unlessserverNameis set, the TLSfingerprintis Chrome's when unset, requests carry Chrome's HTTP headers, and HTTP/2 is preferred with an HTTP/1.1 fallback (HTTP/3 only withalpn: ["h3"], sending a Chrome-like QUIC ClientHello unlessfinalmask.quicParams.disableChromeParrotis set).securitymay be left out — default TLS settings are used then; REALITY can't be used. - Domain fronting. When
streamSettings.address(and optionallystreamSettings.port) is set, every API request dials that address instead while keeping the service's host name in the request; together withtlsSettings.serverNamethis fronts the API behind another host. - Latency. Every byte goes through API writes and polls, so round trips are far slower than a direct link.
flushIntervalMs,pollIntervalMs,maxPollIntervalMsandeagerWindowMstrade API requests for latency; they act on the side that sets them, while the Google Drive ring size comes from the client. - Google Drive credentials. If Google rejects them (
invalid_grant,invalid_client,unauthorized_client), XDRIVE logs the error and stops retrying with those credentials — create a new refresh token and restart.
Cross-core notes
- sing-box and mihomo have no storage-backed transport; their transports are covered on Transport — sing-box and Transport — mihomo.
Source: infra/conf/transport_method.go:989-1088 · v26.11.9 (676eaf6)
