fix(core): make c2c file 0xE37_800 finalize best-effort, not fatal (#157)
Real-machine retest showed a plain c2c file send (NotOnlineFile only, no field6) is already downloadable — the original #157 'fix' made the 0xE37_800 finalize a hard dependency, so any finalize error would now fail a send that would otherwise succeed (a regression, same speculative-NapCat-parity trap as the #145 force-full). Wrap the finalize in try/catch: on success we still attach field6 (extra download routing that mirrors NapCat and may help some receiver clients); on failure we log and send without it. field6 is now enrichment, not a requirement. Adds a regression test: a failing 0xE37_800 still produces a PbSendMsg with the file and no field6.
This commit is contained in:
2 files changed
+75
-16
No files matched your search
@@ -13,6 +13,7 @@ import { FinalizeOfflineFile } from '@snowluma/protocol/oidb-services/group-file
|
|||||||
import type { MessageElement, QQEventVariant } from '@snowluma/protocol/events';
|
import type { MessageElement, QQEventVariant } from '@snowluma/protocol/events';
|
||||||
import { fetchC2cMessageRange, fetchGroupMessageRange } from '@snowluma/protocol/msg-push';
|
import { fetchC2cMessageRange, fetchGroupMessageRange } from '@snowluma/protocol/msg-push';
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import { createLogger } from '@snowluma/common/logger';
|
||||||
import type { BridgeContext } from '../bridge-context';
|
import type { BridgeContext } from '../bridge-context';
|
||||||
// `Bridge` is imported as a type only so we can narrow `ctx` back to
|
// `Bridge` is imported as a type only so we can narrow `ctx` back to
|
||||||
// the concrete Bridge instance when passing it to `buildSendElems`
|
// the concrete Bridge instance when passing it to `buildSendElems`
|
||||||
@@ -26,6 +27,8 @@ import type { Bridge, SendMessageReceipt } from '../bridge';
|
|||||||
|
|
||||||
const SEND_MSG_CMD = 'MessageSvc.PbSendMsg';
|
const SEND_MSG_CMD = 'MessageSvc.PbSendMsg';
|
||||||
|
|
||||||
|
const log = createLogger('Bridge.Message');
|
||||||
|
|
||||||
type GroupMessage = Extract<QQEventVariant, { kind: 'group_message' }>;
|
type GroupMessage = Extract<QQEventVariant, { kind: 'group_message' }>;
|
||||||
type FriendMessage = Extract<QQEventVariant, { kind: 'friend_message' }>;
|
type FriendMessage = Extract<QQEventVariant, { kind: 'friend_message' }>;
|
||||||
|
|
||||||
@@ -240,10 +243,11 @@ export class MessageApi {
|
|||||||
* - `dangerEvel: 0` — virus-scan severity, always 0 client-side
|
* - `dangerEvel: 0` — virus-scan severity, always 0 client-side
|
||||||
* - `expireTime` — 7 days from now (Lagrange convention)
|
* - `expireTime` — 7 days from now (Lagrange convention)
|
||||||
*
|
*
|
||||||
* Beyond NotOnlineFile (`FileExtra.file`), the message MUST also carry
|
* `FileExtra.file` alone makes the file downloadable (verified on a live
|
||||||
* `FileExtra.field6` — the server-issued download routing. We obtain it by
|
* account). We ALSO attach `FileExtra.field6` — extra server-issued download
|
||||||
* running the 0xE37_800 finalize first; without it the recipient sees
|
* routing from a best-effort 0xE37_800 finalize that mirrors NapCat and may
|
||||||
* "文件传输失败" even though PbSendMsg returns ok (issue #157).
|
* help some receiver clients. The finalize is non-fatal: if it fails we send
|
||||||
|
* without field6 rather than failing the send (issue #157).
|
||||||
*/
|
*/
|
||||||
async sendC2cFile(
|
async sendC2cFile(
|
||||||
userUin: number,
|
userUin: number,
|
||||||
@@ -262,22 +266,31 @@ export class MessageApi {
|
|||||||
}
|
}
|
||||||
if (!selfUid) throw new Error('self uid unavailable for c2c file send');
|
if (!selfUid) throw new Error('self uid unavailable for c2c file send');
|
||||||
|
|
||||||
// Finalize the offline file (0xE37_800) to obtain the server-issued
|
// The file is already downloadable from the `NotOnlineFile` reference
|
||||||
// download routing. The apply + Highway upload alone leave the file
|
// alone — verified on a live account: a plain c2c file send (no field6)
|
||||||
// un-downloadable; `field6` below carries the credential the recipient
|
// downloads fine. `field6` is EXTRA server-issued download routing (from
|
||||||
// needs (see finalize-offline-file.ts). Mirrors NapCat's upload→finalize
|
// the 0xE37_800 finalize) that mirrors NapCat and may help some receiver
|
||||||
// →send sequence (issue #157).
|
// clients. So fetch it BEST-EFFORT: if the finalize fails, send without
|
||||||
|
// field6 rather than failing the whole send. (issue #157 — the finalize
|
||||||
|
// was originally fatal, which could regress a send that would otherwise
|
||||||
|
// succeed.)
|
||||||
const fileHash = info.fileHash ?? '';
|
const fileHash = info.fileHash ?? '';
|
||||||
const meta = await FinalizeOfflineFile.invoke(this.ctx, {
|
let meta: Awaited<ReturnType<typeof FinalizeOfflineFile.invoke>> | null = null;
|
||||||
|
try {
|
||||||
|
meta = await FinalizeOfflineFile.invoke(this.ctx, {
|
||||||
senderUid: selfUid,
|
senderUid: selfUid,
|
||||||
receiverUid: userUid,
|
receiverUid: userUid,
|
||||||
fileUuid: info.fileId,
|
fileUuid: info.fileId,
|
||||||
fileHash,
|
fileHash,
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('c2c file finalize (0xE37_800) failed, sending without field6: %s',
|
||||||
|
err instanceof Error ? err.message : String(err));
|
||||||
|
}
|
||||||
|
|
||||||
const nowSec = Math.floor(Date.now() / 1000);
|
const nowSec = Math.floor(Date.now() / 1000);
|
||||||
const sevenDaysSec = 7 * 24 * 60 * 60;
|
const sevenDaysSec = 7 * 24 * 60 * 60;
|
||||||
const fileExtraBytes = protobuf_encode<FileExtra>({
|
const fileExtra: FileExtra = {
|
||||||
file: {
|
file: {
|
||||||
fileType: 0,
|
fileType: 0,
|
||||||
fileUuid: info.fileId,
|
fileUuid: info.fileId,
|
||||||
@@ -289,7 +302,9 @@ export class MessageApi {
|
|||||||
expireTime: nowSec + sevenDaysSec,
|
expireTime: nowSec + sevenDaysSec,
|
||||||
fileHash,
|
fileHash,
|
||||||
},
|
},
|
||||||
field6: {
|
};
|
||||||
|
if (meta) {
|
||||||
|
fileExtra.field6 = {
|
||||||
field2: {
|
field2: {
|
||||||
field1: meta.field110,
|
field1: meta.field110,
|
||||||
fileUuid: info.fileId,
|
fileUuid: info.fileId,
|
||||||
@@ -302,8 +317,9 @@ export class MessageApi {
|
|||||||
selfUid,
|
selfUid,
|
||||||
destUid: userUid,
|
destUid: userUid,
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
});
|
}
|
||||||
|
const fileExtraBytes = protobuf_encode<FileExtra>(fileExtra);
|
||||||
|
|
||||||
const request = protobuf_encode<SendMessageRequest>({
|
const request = protobuf_encode<SendMessageRequest>({
|
||||||
routingHead: {
|
routingHead: {
|
||||||
|
|||||||
@@ -136,8 +136,9 @@ describe('Bridge private media routing', () => {
|
|||||||
// expireTime is now+7d; just sanity-check it landed (non-zero, plausible)
|
// expireTime is now+7d; just sanity-check it landed (non-zero, plausible)
|
||||||
expect(fileExtra?.file?.expireTime).toBeGreaterThan(Math.floor(Date.now() / 1000));
|
expect(fileExtra?.file?.expireTime).toBeGreaterThan(Math.floor(Date.now() / 1000));
|
||||||
|
|
||||||
// issue #157: the finalize (0xE37_800) must run, and its download routing
|
// issue #157: when the 0xE37_800 finalize succeeds, its download routing
|
||||||
// must ride along in field6 — without it the recipient can't download.
|
// rides along in field6 (best-effort enrichment on top of the always-
|
||||||
|
// present NotOnlineFile).
|
||||||
expect(bridge.finalizeCmd).toBe('OidbSvcTrpcTcp.0xe37_800');
|
expect(bridge.finalizeCmd).toBe('OidbSvcTrpcTcp.0xe37_800');
|
||||||
expect(fileExtra?.field6?.field2).toMatchObject({
|
expect(fileExtra?.field6?.field2).toMatchObject({
|
||||||
fileUuid: 'uuid-abc-123',
|
fileUuid: 'uuid-abc-123',
|
||||||
@@ -157,4 +158,46 @@ describe('Bridge private media routing', () => {
|
|||||||
// c2c-file path.
|
// c2c-file path.
|
||||||
expect(request?.contentHead?.c2cCmd ?? 0).toBe(0);
|
expect(request?.contentHead?.c2cCmd ?? 0).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('c2c file send survives a failing 0xE37_800 finalize — sends without field6 (#157 best-effort)', async () => {
|
||||||
|
const { Bridge } = await import('../src/bridge/bridge');
|
||||||
|
const { IdentityService } = await import('@snowluma/protocol/identity-service');
|
||||||
|
|
||||||
|
class TestBridge extends Bridge {
|
||||||
|
capturedBody: Uint8Array | null = null;
|
||||||
|
|
||||||
|
override async resolveUserUid(uin: number): Promise<string> {
|
||||||
|
return uin === 10000 ? 'u_self' : `u_${uin}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
override async sendRawPacket(cmd: string, body: Uint8Array): Promise<SendPacketResult> {
|
||||||
|
// Finalize fails (server error → OidbError). The send must NOT fail
|
||||||
|
// because of it.
|
||||||
|
if (cmd.includes('0xe37_800')) {
|
||||||
|
return { success: false, gotResponse: true, errorCode: 9999, errorMessage: 'finalize boom', responseData: Buffer.alloc(0) };
|
||||||
|
}
|
||||||
|
this.capturedBody = body;
|
||||||
|
return {
|
||||||
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||||
|
responseData: Buffer.from(protobuf_encode<SendMessageResponse>({
|
||||||
|
result: 0, errMsg: '', privateSequence: 88, timestamp1: 1710000000,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const bridge = new TestBridge(IdentityService.memory('10000'));
|
||||||
|
|
||||||
|
// Should resolve (not throw) despite the finalize error.
|
||||||
|
await bridge.apis.message.sendC2cFile(67890, 'u_peer_xyz', {
|
||||||
|
fileId: 'uuid-abc-123', fileName: 'doc.txt', fileSize: 1024,
|
||||||
|
fileMd5: new Uint8Array([1, 2, 3, 4]), fileHash: 'hash-xyz',
|
||||||
|
});
|
||||||
|
|
||||||
|
// PbSendMsg still went out, carrying the file but NO field6.
|
||||||
|
expect(bridge.capturedBody).toBeInstanceOf(Uint8Array);
|
||||||
|
const request = protobuf_decode<SendMessageRequest>(bridge.capturedBody as Uint8Array);
|
||||||
|
const fileExtra = protobuf_decode<FileExtra>(request!.messageBody!.msgContent as Uint8Array);
|
||||||
|
expect(fileExtra?.file?.fileUuid).toBe('uuid-abc-123');
|
||||||
|
expect(fileExtra?.field6 ?? undefined).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user