Repository navigation
feat: add MTProto backend type and Mtproto proxy (field 8) - #26
Conversation
Sync service.proto with the PasarGuard node's MTProto backend:
- BackendType.MTPROTO = 2
- message Mtproto { secret = 1; user_ad_tag = 2; max_tcp_conns = 3;
max_unique_ips = 4 }; quota and expiry stay panel-owned
- Proxy.mtproto = 8 (Masque keeps 7)
- Wireguard.pre_shared_key = 3, on node dev since node#64
All additions are new field numbers and a new enum value, so existing
fields keep their wire format. Regenerated with make generate_grpc_code
(grpcio-tools 1.80.0, protoc 31.1, same generator as the checked-in
code); service_grpc.py is unchanged because no rpc changed.
Add mtproto_secret, mtproto_user_ad_tag, mtproto_max_tcp_conns and mtproto_max_unique_ips keyword arguments. Proxy.mtproto is set only when mtproto_secret is a non-empty string, so callers that do not pass a secret get the same Proxy, and the same bytes, as before. Tests cover the unchanged bytes for existing fields, the four Mtproto fields, the empty secret case, field 8 on the wire with Masque on 7, BackendType.MTPROTO and the Wireguard pre_shared_key round trip.
A whitespace-only mtproto_secret now leaves Proxy.mtproto unset, the same as None or an empty string; the node trims the secret and would skip such a user anyway. A valid secret is still sent as given. mtproto_max_tcp_conns and mtproto_max_unique_ips are now typed int | None = None and send 0 for None, since the panel passes dict.get() values. 0 means no per-user limit on the node.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Protobuf contract and generated declarations PasarGuardNodeBridge/common/service.proto, PasarGuardNodeBridge/common/service_pb2.py, PasarGuardNodeBridge/common/service_pb2.pyi, tests/test_utils_proxy.py |
The protobuf contract adds the MTPROTO backend, an Mtproto message, and Proxy.mtproto. It also adds Wireguard.pre_shared_key. Generated declarations and tests cover the fields and their wire numbers. |
MTProto proxy construction PasarGuardNodeBridge/utils.py, tests/test_utils_proxy.py, README.md |
create_proxy accepts an MTProto secret, user tag, and connection/IP limits. It leaves MTProto unset for blank secrets and defaults falsy limits to 0. Tests check construction and legacy behavior. The README documents the configuration and backend. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Suggested reviewers: immohammad20000
Merge Risk: 
Minimal · up to 35d9b
-
No actionable merge-blocking issue is established from the supplied evidence. The MTProto changes remain subject to normal validation before merging.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed -
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the secret’s trim,
Then packs the fields, each neat and slim.
The wire numbers line up right,
Old proxy bytes still serialize tight.
New backend joins the hopping trail,
With README notes to tell the tale.
Comment @coderabbitai help to get the list of available commands.
Upstream v0.10.0 (779f9b9, PasarGuard#26) gives BackendType 2 to MTPROTO and Proxy field 8 to an Mtproto message. On the fork, 2 is SING_BOX and 8 is OpenVpnUser in every fork node tag from v0.5.3-singbox2 to v0.8.22 and on fork node main. Fork node v0.8.22's generated Go code decodes upstream's MTPROTO backend type as SING_BOX, and its OpenVPN backend reads upstream's Mtproto user as a login whose username is the MTProto secret. The test pins BackendType 0 to 5, Proxy fields 1 to 11 with their message types, the MtprotoUser, OpenVpnUser and Hysteria2 layouts, the field each credential travels on, alone and with every credential set at once, and that create_proxy refuses upstream's MTProto-only keyword arguments instead of dropping them. It fails when MTPROTO and SING_BOX swap numbers, when open_vpn and mtproto swap fields, when create_proxy accepts unknown keywords, and when create_proxy puts the OpenVPN password into MtprotoUser for a user that has both.
…bers the node reserved are still in use Upstream 779f9b9 (PasarGuard#26, in v0.9.5 and v0.10.0) gives message Wireguard a string pre_shared_key = 3. Fork node main carries it since c755202a, and since 641d19c1 it reserves BackendType 4 and Proxy field 9 by number and by name, where the fork's own MTProto backend used to sit. On this head the bridge has neither: Wireguard has only public_key and peer_ips, BackendType still holds MTPROTO = 4, Proxy still holds MtprotoUser mtproto = 9, and create_proxy sets an mtproto section on every proxy it builds, so each of them carries an empty field 9, the bytes 4a 00. test_utils_proxy.py carries upstream's own WireguardPreSharedKeyTest unchanged. test_wire_dialect.py now pins the node's numbering exactly: the whole BackendType and Proxy layout, 4 and 9 reserved by number and name, pre_shared_key on Wireguard field 3, no payload with a field 9, the MTProto arguments refused, and a payload bridge 0.9.2 built still decoding. test_masque_proxy.py drops mtproto from its field map. On this head, on python 3.14.7 with protobuf 6.33.6: 23 tests, 14 failures and 2 errors.
… 9 reserved, synced from node cf15f11d Port of the WireGuard half of upstream 779f9b9 (PasarGuard#26, released in v0.9.5 and v0.10.0): message Wireguard gains string pre_shared_key = 3, the field upstream added, on the number upstream gave it, which is free on both sides. Like upstream, create_proxy takes no new argument; a caller sets proxy.wireguard.pre_shared_key. The bridge proto is synced from the fork node, so the field comes with the node's proto as it stands: scripts/sync_proto.sh pinned Free-Guy-IR/node cf15f11d9b75386339bd09cae00c86816ee85cc0, the head of node branch release/v0.6.24 (NodeVersion 0.6.24), whose common/service.proto is blob 98fb3cf and byte-identical to node main 7b1e62baa804. That proto also reserves BackendType 4 and Proxy field 9 by number and by name since node 641d19c1 removed the fork's MTProto backend, so the bridge drops MTPROTO = 4, MtprotoUser and its mtproto = 9 field, and create_proxy drops mtproto_username and mtproto_secret. A proxy create_proxy builds no longer carries the empty field 9 section, the bytes 4a 00, that it carried before. The MTProto half of 779f9b9 stays refused, as recorded in the panel's bridge ledger: upstream's BackendType MTPROTO = 2 and Proxy mtproto = 8 are the fork's SING_BOX = 2 and open_vpn = 8, and the fork no longer has an MTProto backend. service_pb2.py and service_pb2.pyi are protoc output from grpcio-tools 1.80.0 as locked in uv.lock; service_grpc.py is unchanged because no rpc changed. The README states the reserved numbers. check_proto_drift.sh with PROTO_FRESHNESS=1: integrity ok against cf15f11d, every stub matches protoc output, freshness ok against node main 7b1e62ba. Locally on python 3.14.7 with protobuf 6.33.6 and without uvloop: 226 tests, the uvloop one skipped, the rest pass. Payloads from this tree, decoded with the fork node's own generated common/service.pb.go and protobuf-go v1.36.12, at each node proto since 2d8e11f3: at 2d8e11f3 (NodeVersion 0.6.20, image tag v0.8.20-degraded-start), 7752b0df (0.6.22) and 641d19c1 (0.6.23) every credential reads as before and pre_shared_key stays an unknown field; at cf15f11d (0.6.24) pre_shared_key is read. A payload bridge 0.9.2 built still decodes at cf15f11d, its 4a 00 kept as an unknown field.
The public part moves from 0.9.2 to 0.10.0 in one step because that is upstream's own release line: upstream v0.10.0 (c5632b6) is a version-only bump over v0.9.5, and every upstream release commit from v0.9.2 to v0.10.0 is now carried here or refused on record. Carried, each re-checked against this tree: PasarGuard#23 maintenance timeouts (b7df83f), every hunk of which that upstream v0.10.0 still has is here; PasarGuard#24 Masque (33276ea, f707f09), all of it except Masque masque = 7, which rides Proxy field 12 because field 7 is Hysteria2 here; PasarGuard#27 rejected-user isolation (67b35df, e4fe5b1, c8b6707), whose sorted changed lines equal a01bdbb's, 934 lines, and which later fork commits build on; PasarGuard#32 lifecycle lease confirmation (d6f43c7), whose _lifecycle_lease_still_held is upstream's line for line while the renewal loop ends on the lease's release rather than on any cancel request; and the WireGuard pre_shared_key of PasarGuard#26 (4ee34d0). Refused on record: the MTProto half of PasarGuard#26, BackendType MTPROTO = 2 and Proxy mtproto = 8, because 2 and 8 are SING_BOX and open_vpn here and the fork has no MTProto backend. Not taken: the bridge's own development uv.lock refresh of v0.9.5; the panel resolves those libraries from its own lock. The local label restarts at singbox.1 on the new public version.
What
Sync
service.protowith the PasarGuard node's MTProto backend, and letcreate_proxybuild the MTProto proxy message.Proto additions (the file is now semantically identical to the node's
common/service.protoon the MTProto branch):BackendType.MTPROTO = 2message Mtproto { string secret = 1; string user_ad_tag = 2; uint32 max_tcp_conns = 3; uint32 max_unique_ips = 4; }. Quota and expiry stay panel-owned, as for Xray and WireGuard.Proxy.mtproto = 8(Masque keeps 7)Wireguard.pre_shared_key = 3(already on node dev since node #64)The stubs were regenerated with
make generate_grpc_code, using the same generator as the checked-in code (grpcio-tools 1.80.0, protobuf 6.31.1 gencode).service_grpc.pyis unchanged: no rpc changed.create_proxygets four new keyword arguments:mtproto_secretmtproto_user_ad_tagmtproto_max_tcp_conns(int | None;Noneis sent as 0, which means no per-user limit)mtproto_max_unique_ips(same as above)Proxy.mtprotois set only whenmtproto_secretis not blank (None, empty and whitespace-only are all treated as missing). A valid secret is sent as given. The README mentionsBackendType.MTPROTOand these arguments.Why
The panel needs this to drive nodes running the MTProto backend.
Compatibility
Proxyand the same bytes as before (tested against aProxybuilt the old way).BackendType.MTPROTOneeds a node with the MTProto backend.proxies.mtproto. The node rejects that user the same way it rejects an invalid secret: a single-user sync returns the error, and a batch sync skips and logs that user.Tests
tests/test_utils_proxy.pyhas 21 tests:Nonelimits0x42), with Masque still on 7BackendType.MTPROTO == 2pre_shared_keyround tripFull suite: 92 tests OK. main (0.9.4) is merged into this branch; the proto is unchanged by it.
Release
This needs a minor release, 0.10.0, before the panel can use it.
Supersedes #15, which used field 7 (now Masque) and always set the sub-message.
Timing
The node side is PasarGuard/node#120 and the panel side is PasarGuard/panel#1113 (draft). The panel uses this PR's commit through a git source until 0.10.0 is on PyPI, so releasing 0.10.0 is what unblocks it. This change is additive, so it can be released before the node and panel PRs are merged.
Summary by CodeRabbit
New Features
Documentation
Tests