Skip to content

The grpc transport ​

gRPC "lite": each protocol stream is an HTTP/2 request POST /<service_name>/Tun with content-type: application/grpc, and the data are protobuf messages with bytes. Compatible with sing-box grpc and Xray/V2Ray gRPC (gun). Passes through CDNs that support gRPC.

Looks like a grpc-go server to anything that is not a client (same status codes and trailers). The server also accepts /<service_name>/TunMulti (Xray multiMode) and gzip-compressed messages; the client sends Tun and does not compress.

The outbound's streams go in HTTP/2 sessions with the server, laid out as session_mode says. HTTP/2 is required: with TLS by ALPN h2, without TLS as unencrypted HTTP/2 (prior knowledge); the server rejects an HTTP/1.1 request.

Fields ​

FieldTypeDefaultMeaning
service_namestring""The service name; the request path is /<service_name>/Tun
idle_timeoutduration0 (off)After how much idleness without streams to check the session with a ping
ping_timeoutduration15sHow long to wait for the ping answer before closing the session
permit_without_streamboolfalseSend pings even when there are no streams
session_modestringper_shardHow the client lays out streams across HTTP/2 sessions (an ours extension, see below)
session_per_shardboolfalseDeprecated: the same as session_mode: per_shard
share_sessionboolfalseDeprecated: the same as session_mode: shared

The values of session_mode:

  • per_shard — a session of its own for each execution thread (shard) of the client, opened with the shard's first stream; all of the shard's streams go in it. The session itself may run on another shard. A session that closed or got a GOAWAY is replaced by the shard with a new one. There are as many connections as shards in use.
  • shared — one session per outbound for all streams, as in sing-box and Xray: the fewest handshakes and connections through a CDN, but everything is bound by one core.
  • per_stream — a stream does not share a busy session: if there is no free one, another one is opened, and it is closed with a GOAWAY together with its last stream; the first one stays even without streams. The result is a connection per simultaneous stream.

Each session uses one core; see runtime.stream_placement.

The deprecated flags are accepted with a warning in the log; session_per_shard together with share_session, or a flag that contradicts session_mode, is a configuration error.

Example ​

yaml
inbounds:
  trojan-grpc:
    trojan:
      listen: ":443"
      users:
        - password: secret
      tls:
        certificate_path: /etc/ours/cert.pem
        key_path: /etc/ours/key.pem
      transport:
        grpc:
          service_name: TunService
outbounds:
  grpc-out:
    trojan:
      server: grpc.example.com:443
      password: secret
      tls:
        sni: grpc.example.com
      transport:
        grpc:
          service_name: TunService
          idle_timeout: 60s
          ping_timeout: 20s
route:
  final:
    outbound: grpc-out

GPL-3.0-or-later