fix(file-upload): read upload host from rtpMediaPlatformUploadAddress (NT 2026 rollout)
The 2026 QQ-NT server has stopped populating *every* legacy host field (uploadIp / uploadDomain / uploadIpList / uploadHttpsDomain / uploadDns). The host now arrives in the new field 210 `rtpMediaPlatformUploadAddress` — a repeated `IPv4` message carrying `inIP`/`inPort` (LAN) and `outIP`/`outPort` (WAN). Coworker's debugging hint "host 好像是 fix64" was the 8-12-byte length-delimited IPv4 message looking like a fixed-width field on the wire. Cross-referenced acidify (https://github.com/LagrangeDev/acidify) — the only NT-protocol fork that's tracked this change (refactored in their 2026-04 protobuf rewrite). They read `inIP`+`inPort` exclusively because that's the address the highway PUT actually needs to reach (same DC as the OIDB endpoint). LagrangeGo / Lagrange.Core / NapCat still ship the old schema and would fail the same way against this server build. Changes: - Proton schema: add `IPv4` message (fields 1-5: outIP/outPort/inIP/ inPort/iPType, all int32 varint) + field 210 on the upload response - Consumer: prefer `rtpMediaPlatformUploadAddress[0].inIP`+`inPort` before falling back through the legacy host chain - New helper `int32ToIpv4Dotted` reverses acidify's `Int.toIpString()` (little-endian byte order, `>>>` for unsigned shift so high-bit IPs don't render as negative octets) - Diagnostic warn-log now dumps the rtp address array too - Regression test: 192.168.1.1 (LE-packed 0x0101A8C0 = 16885952) + inPort=8080 should reach highway PUT
This commit is contained in:
3 files changed
+119
-22
No files matched your search
@@ -83,6 +83,19 @@ function bytesToHexUpper(data: unknown): string {
|
||||
return toHexUpper(data);
|
||||
}
|
||||
|
||||
// Reverses acidify's `Int.toIpString()`: the 32-bit IP arrives
|
||||
// little-endian-packed (byte0 = first dotted octet) and we unpack it the
|
||||
// same way. Force-unsigned the shift to keep negative ints (high bit set)
|
||||
// rendering correctly — JS `>>` is arithmetic and would turn 0xFF000000
|
||||
// into a negative number.
|
||||
function int32ToIpv4Dotted(value: number): string {
|
||||
const b1 = value & 0xFF;
|
||||
const b2 = (value >>> 8) & 0xFF;
|
||||
const b3 = (value >>> 16) & 0xFF;
|
||||
const b4 = (value >>> 24) & 0xFF;
|
||||
return `${b1}.${b2}.${b3}.${b4}`;
|
||||
}
|
||||
|
||||
function normalizeUploadFileName(name: string, fallback: string): string {
|
||||
const trimmed = name.trim();
|
||||
if (trimmed) return trimmed;
|
||||
@@ -440,36 +453,64 @@ export async function uploadPrivateFile(
|
||||
if (!fileId) throw new Error('private file upload response missing file_id');
|
||||
|
||||
if (!upload.boolFileExist && uploadFile) {
|
||||
// The server normally returns the highway host in `uploadIp` (field
|
||||
// 60). LagrangeGo / Lagrange.Core both read that field directly with
|
||||
// no fallback. We've seen real captures where the server picks one
|
||||
// of the parallel host fields (uploadDomain / uploadIpList[0] /
|
||||
// uploadHttpsDomain / uploadDns) instead — likely a rollout
|
||||
// difference. Walk them in order rather than die with "upload host
|
||||
// is invalid" when the server gives us a perfectly usable host
|
||||
// through a different slot. The highway client uses HTTP PUT so we
|
||||
// can pair any of these with the regular `uploadPort`; we only fall
|
||||
// back to `uploadHttpsPort` if we picked the HTTPS-flavored host.
|
||||
// Host selection.
|
||||
//
|
||||
// Current QQ-NT server rollout has stopped populating the legacy
|
||||
// `uploadIp` (field 60) entirely. The host now arrives as the first
|
||||
// entry of `rtpMediaPlatformUploadAddress` (field 210, repeated
|
||||
// IPv4 message) — same place acidify reads it from since their
|
||||
// 2026-04 protobuf refactor. Each IPv4 has paired `inIP`/`inPort`
|
||||
// (LAN, same DC as the OIDB endpoint) and `outIP`/`outPort` (WAN);
|
||||
// acidify uses `inIP`/`inPort` exclusively and so do we, because
|
||||
// that's the address the highway PUT actually needs to reach.
|
||||
//
|
||||
// The 32-bit IPs are little-endian-packed (byte0 = first octet)
|
||||
// per acidify's `Int.toIpString()`. Cross-checked the byte order
|
||||
// by inspecting their highway flow — there's no separate htonl
|
||||
// step, so the integer is already in network-octet-first order.
|
||||
//
|
||||
// Older server versions still populate the legacy string fields
|
||||
// (uploadIp / uploadDomain / uploadIpList[0] / uploadHttpsDomain /
|
||||
// uploadDns), so we fall through to those after rtpMediaPlatform.
|
||||
// Pair an HTTPS-flavored host with `uploadHttpsPort` if that's
|
||||
// what we picked.
|
||||
const rtpFirst = (Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
||||
&& upload.rtpMediaPlatformUploadAddress[0])
|
||||
? upload.rtpMediaPlatformUploadAddress[0] : null;
|
||||
const rtpInIP = rtpFirst && typeof rtpFirst.inIP === 'number' && rtpFirst.inIP !== 0
|
||||
? int32ToIpv4Dotted(rtpFirst.inIP) : '';
|
||||
const rtpInPort = rtpFirst && typeof rtpFirst.inPort === 'number'
|
||||
? rtpFirst.inPort : 0;
|
||||
const ipListFirst = (Array.isArray(upload.uploadIpList) && upload.uploadIpList[0])
|
||||
? upload.uploadIpList[0] : '';
|
||||
const uploadHost = (typeof upload.uploadIp === 'string' && upload.uploadIp)
|
||||
const uploadHost = (rtpInIP)
|
||||
|| (typeof upload.uploadIp === 'string' && upload.uploadIp)
|
||||
|| (typeof upload.uploadDomain === 'string' && upload.uploadDomain)
|
||||
|| (ipListFirst)
|
||||
|| (typeof upload.uploadHttpsDomain === 'string' && upload.uploadHttpsDomain)
|
||||
|| (typeof upload.uploadDns === 'string' && upload.uploadDns)
|
||||
|| '';
|
||||
const httpsHostUsed = !upload.uploadIp && !upload.uploadDomain && !ipListFirst
|
||||
const httpsHostUsed = !rtpInIP && !upload.uploadIp && !upload.uploadDomain && !ipListFirst
|
||||
&& typeof upload.uploadHttpsDomain === 'string' && !!upload.uploadHttpsDomain;
|
||||
const uploadPort = httpsHostUsed && toInt(upload.uploadHttpsPort) > 0
|
||||
? toInt(upload.uploadHttpsPort)
|
||||
: toInt(upload.uploadPort);
|
||||
const uploadPort = rtpInIP && rtpInPort > 0
|
||||
? rtpInPort
|
||||
: httpsHostUsed && toInt(upload.uploadHttpsPort) > 0
|
||||
? toInt(upload.uploadHttpsPort)
|
||||
: toInt(upload.uploadPort);
|
||||
if (!uploadHost || uploadPort <= 0) {
|
||||
// Surface every host-bearing field we know about so a user
|
||||
// hitting this can show us exactly which slot the server filled
|
||||
// (or whether it returned nothing at all — which would point at
|
||||
// a request mismatch rather than a missing decoder).
|
||||
const rtpDump = Array.isArray(upload.rtpMediaPlatformUploadAddress)
|
||||
? JSON.stringify(upload.rtpMediaPlatformUploadAddress.map((e) => ({
|
||||
outIP: e.outIP, outPort: e.outPort, inIP: e.inIP, inPort: e.inPort,
|
||||
iPType: e.iPType,
|
||||
})))
|
||||
: '[]';
|
||||
log.warn(
|
||||
'private file upload host missing — ip=%s domain=%s ipList=%s httpsDomain=%s dns=%s lanip=%s port=%s httpsPort=%s',
|
||||
'private file upload host missing — rtp=%s ip=%s domain=%s ipList=%s httpsDomain=%s dns=%s lanip=%s port=%s httpsPort=%s',
|
||||
rtpDump,
|
||||
upload.uploadIp ?? '', upload.uploadDomain ?? '',
|
||||
JSON.stringify(upload.uploadIpList ?? []),
|
||||
upload.uploadHttpsDomain ?? '', upload.uploadDns ?? '',
|
||||
|
||||
@@ -643,6 +643,21 @@ export interface OidbPrivateFileUploadReq {
|
||||
flagSupportMediaPlatform?: pb<200, int_32>;
|
||||
}
|
||||
|
||||
// IPv4 wire message used inside ApplyUploadRespV3.rtpMediaPlatformUploadAddress
|
||||
// (field 210). Sourced from acidify's `IPv4` class — outIP/inIP are
|
||||
// little-endian-packed 32-bit IPv4 addresses (byte order: low byte = first
|
||||
// octet), decoded via the standard `(ip & 0xFF).(ip>>8 & 0xFF)....` recipe.
|
||||
// outPort/inPort are the matching port for each leg (out = WAN, in = LAN).
|
||||
// iPType is the address family hint (1 = IPv4, etc — acidify treats it
|
||||
// purely as metadata, no behavior).
|
||||
export interface IPv4 {
|
||||
outIP?: pb<1, int_32>;
|
||||
outPort?: pb<2, int_32>;
|
||||
inIP?: pb<3, int_32>;
|
||||
inPort?: pb<4, int_32>;
|
||||
iPType?: pb<5, int_32>;
|
||||
}
|
||||
|
||||
export interface OidbPrivateFileUploadRespBody {
|
||||
retCode?: pb<10, int_32>;
|
||||
retMsg?: pb<20, string>;
|
||||
@@ -651,12 +666,13 @@ export interface OidbPrivateFileUploadRespBody {
|
||||
// quota numbers don't drive any code path.
|
||||
uploadIp?: pb<60, string>;
|
||||
// Cross-checked against LagrangeGo `OidbSvcTrpcTcp0xE37_800.proto`
|
||||
// (fields 60-170 enumerated below) + NapCat `Oidb.0XE37_800.ts`.
|
||||
// Real server has been observed to leave `uploadIp` empty while
|
||||
// populating `uploadDomain` / `uploadIpList[0]` instead (likely a
|
||||
// server-side rollout difference). Decoding all of these lets us
|
||||
// fall through in the consumer rather than die with "upload host
|
||||
// is invalid" when the server picks a different field.
|
||||
// (fields 60-170 enumerated below) + NapCat `Oidb.0XE37_800.ts` +
|
||||
// acidify (most recent NT-protocol fork, 2026-04). Real server in
|
||||
// 2026 has been observed to leave the legacy host fields empty and
|
||||
// put the host into the new field 210 (`rtpMediaPlatformUploadAddress`,
|
||||
// repeated IPv4 messages) instead — the consumer walks them in that
|
||||
// order. Decoding the legacy fields too means we keep working against
|
||||
// older server rollouts.
|
||||
uploadDomain?: pb<70, string>;
|
||||
uploadPort?: pb<80, uint_32>;
|
||||
uuid?: pb<90, string>;
|
||||
@@ -667,7 +683,18 @@ export interface OidbPrivateFileUploadRespBody {
|
||||
uploadHttpsDomain?: pb<150, string>;
|
||||
uploadDns?: pb<160, string>;
|
||||
uploadLanip?: pb<170, string>;
|
||||
// Field 200 — acidify renamed this to `fileIdCrc` in their 2026-04
|
||||
// refactor; we keep `fileAddon` because the wire bytes are identical
|
||||
// and our callers already read `fileAddon` as the file-hash blob (it's
|
||||
// a hex string in practice). Worth renaming if a consumer ever needs
|
||||
// the new semantic.
|
||||
fileAddon?: pb<200, string>;
|
||||
// Field 210 — the new "host carrier" the NT server actually populates
|
||||
// in current rollouts. Each IPv4 entry has `inIP`/`inPort` (LAN) +
|
||||
// `outIP`/`outPort` (WAN). acidify reads `inIP`+`inPort` exclusively;
|
||||
// we follow suit because that's what the highway HTTP PUT needs to
|
||||
// reach (same datacenter as the OIDB endpoint that returned this).
|
||||
rtpMediaPlatformUploadAddress?: pb_repeated<210, IPv4>;
|
||||
mediaPlatformUploadKey?: pb<220, bytes>;
|
||||
}
|
||||
|
||||
|
||||
@@ -242,6 +242,35 @@ describe('actions/group-file', () => {
|
||||
expect(bridge.sendC2cFileMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uploadPrivateFile reads host from rtpMediaPlatformUploadAddress[0].inIP when populated', async () => {
|
||||
// The 2026 QQ-NT server rollout moved the upload host out of the
|
||||
// legacy `uploadIp` (field 60) string into the new
|
||||
// `rtpMediaPlatformUploadAddress` (field 210, repeated IPv4 message).
|
||||
// Mirrors acidify's `UploadPrivateFile.kt` consumer logic — read
|
||||
// `inIP` (LAN, same DC as the OIDB endpoint) and pair with `inPort`.
|
||||
// The int is little-endian-packed: 0x0101A8C0 → 192.168.1.1.
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(bridge.resolveUserUid).mockResolvedValueOnce('target-uid');
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<OidbPrivateFileUploadResp>>({
|
||||
body: {
|
||||
upload: {
|
||||
uuid: 'pfid',
|
||||
fileAddon: 'phash',
|
||||
// boolFileExist defaults to false — forces highway path
|
||||
// 192.168.1.1 little-endian packed = (1 << 24) | (1 << 16) | (168 << 8) | 192 = 16885952
|
||||
rtpMediaPlatformUploadAddress: [
|
||||
{ outIP: 0, outPort: 0, inIP: 16885952, inPort: 8080, iPType: 1 },
|
||||
],
|
||||
mediaPlatformUploadKey: new Uint8Array([1, 2, 3]),
|
||||
} as any,
|
||||
},
|
||||
}),
|
||||
);
|
||||
await groupFile.uploadPrivateFile(bridge as any, 67890, '/path/file.bin');
|
||||
expect(highwayClient.uploadHighwayHttp).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('uploadPrivateFile falls back to uploadDomain when uploadIp is empty', async () => {
|
||||
// Regression: the server has been observed in the wild returning the
|
||||
// highway host in `uploadDomain` (field 70) instead of `uploadIp`
|
||||
|
||||
Reference in new issue
Block a user