Skip to content

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:

FieldTypeDefaultAllowed valuesDescription
remoteFolderstring(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.
servicestring(required)google-drive | s3 | template | localStorage 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.
segmentBytesuint32524288<bytes> | ≤ 16777216Largest 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.
flushIntervalMsuint3220 (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.
pollIntervalMsuint3250<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.
maxPollIntervalMsuint32500 (google-drive: 200)<ms>Ceiling for idle polling. Never lower than pollIntervalMs.
sessionTtlSecondsuint32300<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.
concurrencyuint328 (google-drive: 64)1–256Segment 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.
eagerWindowMsuint322000<ms>How long polling stays at pollIntervalMs after the last activity before it backs off.
holeTimeoutMsuint3230000<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.
templatejson.RawMessage(template only)<object>Required for service: "template": describes the storage API's HTTP requests — see Template backend below.
s3*XDriveS3Config(s3 only)XDriveS3ConfigRequired for service: "s3".
xmuxXmuxConfig{maxConnections: 1, hMaxReusableSecs: 1800-3000}XmuxConfigPool 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 ​

FieldTypeDefaultAllowed valuesDescription
endpointstring(required)https://<host>[/<path>] | http://<host>[/<path>]S3 API endpoint URL, without credentials, query or fragment; a path prefix is allowed.
regionstringus-east-1<region>SigV4 signing region.
bucketstring(required)<bucket>Bucket name, without /. With pathStyle: false it must be DNS-compatible (lower-case letters, digits, - and .).
pathStyle*booltruetrue | falsetrue: 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 — remoteFolder is a Drive folder id and secrets holds 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 (concurrency slots), so neither side lists the folder for every segment.
  • s3 — any S3-compatible service, signed with SigV4. Objects go under <remoteFolder>/ in bucket; 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 the template object (below).
  • local — remoteFolder is 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" }, plus body for put; method defaults to GET. list also needs namesRegex, whose first capture group picks every object name out of the response body.
  • Variables, substituted in url, headers, put.body and the auth strings: {folder} (remoteFolder), {secret0}, {secret1}, … (secrets), {name} (the object, in put / get / delete), {prefix} (in list) and {data} — when put.body is set it becomes the request body with {data} as the base64 payload; otherwise the raw bytes are sent.
  • hrefPath makes an operation two-step: the first request answers with JSON, and the URL found at that dot-separated path is called with hrefMethod (GET by default), carrying the payload, with neither auth nor extra headers.
  • auth.type: none (default), static (header map), basic (username / password) or oauth2 — form is POSTed to tokenUrl, the token is read at tokenPath (default access_token) and its lifetime in seconds at expiryPath (default 3600), then header is sent with {token}. A 401 drops the token and retries.
  • flatten: true replaces / in object names with ~, for services without folders.
  • concurrency caps parallel requests (64 by default, at most 256).
  • retry.status lists HTTP statuses to retry; retry.rateReason is a dot path into a 403 body — a 403 with a string there is retried too.

Requirements ​

These are checked at startup:

  • Only VLESS may use network: "xdrive"; any other protocol fails with the xdrive transport can only be used by VLESS.
  • VLESS Encryption is mandatory: the outbound's encryption and the inbound's decryption can't be none — xray vlessenc prints a matching pair. See VLESS.
  • No flow (on the outbound, the inbound or its clients), and no testpre on the outbound.
  • The outbound needs mux with enabled: true, no negative concurrency or xudpConcurrency, and xudpProxyUDP443 other than skip — unless VLESS reverse is 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. Then finalmask.quicParams.congestion can only be bbr (the default) or reno (brutal and force-brutal are rejected), and with google-drive the only UDP finalmask allowed is noise.
  • alpn: ["http/1.1"] without echConfigList logs a warning: unless the fingerprint is 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):

json
{
  "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:

json
{
  "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:

json
{
  "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:

json
{
  "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 under streams/<session>/c2s and streams/<session>/s2c. The server polls sessions/, 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 / port only satisfy the inbound syntax (a single port), and the outbound's address / port are never dialed — only the storage service is.
  • Connections to the storage service. security, tlsSettings, sockopt and finalmask shape the HTTPS requests to the service's API, on both sides. The SNI is the API host unless serverName is set, the TLS fingerprint is Chrome's when unset, requests carry Chrome's HTTP headers, and HTTP/2 is preferred with an HTTP/1.1 fallback (HTTP/3 only with alpn: ["h3"], sending a Chrome-like QUIC ClientHello unless finalmask.quicParams.disableChromeParrot is set). security may be left out — default TLS settings are used then; REALITY can't be used.
  • Domain fronting. When streamSettings.address (and optionally streamSettings.port) is set, every API request dials that address instead while keeping the service's host name in the request; together with tlsSettings.serverName this 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, maxPollIntervalMs and eagerWindowMs trade 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 ​

Source: infra/conf/transport_method.go:989-1088 · v26.11.9 (676eaf6)

Core Tutorial by Argsment