Log unknown field tags for sync messages we havent handled
This commit is contained in:
parent
a7a058bb73
commit
f1a632263a
2 changed files with 50 additions and 1 deletions
|
@ -123,6 +123,7 @@ import { getStoriesBlocked } from '../util/stories';
|
|||
import { isNotNil } from '../util/isNotNil';
|
||||
import { chunk } from '../util/iterables';
|
||||
import { isOlderThan } from '../util/timestamp';
|
||||
import { inspectUnknownFieldTags } from '../util/inspectProtobufs';
|
||||
|
||||
const GROUPV1_ID_LENGTH = 16;
|
||||
const GROUPV2_ID_LENGTH = 32;
|
||||
|
@ -3068,8 +3069,10 @@ export default class MessageReceiver
|
|||
}
|
||||
|
||||
this.removeFromCache(envelope);
|
||||
const envelopeId = getEnvelopeId(envelope);
|
||||
const unknownFieldTags = inspectUnknownFieldTags(syncMessage).join(',');
|
||||
log.warn(
|
||||
`handleSyncMessage/${getEnvelopeId(envelope)}: Got empty SyncMessage`
|
||||
`handleSyncMessage/${envelopeId}: Got unknown SyncMessage (Unknown field tags: ${unknownFieldTags})`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
46
ts/util/inspectProtobufs.ts
Normal file
46
ts/util/inspectProtobufs.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { Reader } from 'protobufjs';
|
||||
|
||||
type MessageWithUnknownFields = {
|
||||
__unknownFields?: ReadonlyArray<Uint8Array>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an array of the tags of unknown fields in a protobuf message.
|
||||
*
|
||||
* Clients may use slightly different definitions of our protos, in cases where
|
||||
* we don't recognize a field, we store it in `__unknownFields`.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* ```proto
|
||||
* // Our proto definition
|
||||
* message Foo {
|
||||
* optional string bar = 1;
|
||||
* }
|
||||
*
|
||||
* // Their proto definition
|
||||
* message Foo {
|
||||
* optional string bar = 1;
|
||||
* optional string baz = 2;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* If we receive a message with `baz` set, we'll store it in `__unknownFields`.
|
||||
*
|
||||
* This function will then return `[2]`.
|
||||
*/
|
||||
export function inspectUnknownFieldTags(
|
||||
message: MessageWithUnknownFields
|
||||
): Array<number> {
|
||||
return (
|
||||
message.__unknownFields?.map(field => {
|
||||
// https://protobuf.dev/programming-guides/encoding/
|
||||
// The first byte of a field is a varint encoding the tag bit-shifted << 3
|
||||
// eslint-disable-next-line no-bitwise
|
||||
return new Reader(field).uint32() >>> 3;
|
||||
}) ?? []
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue