fix: consistent use of MessageId and ParticipantId

This commit is contained in:
jm-clius 2025-10-24 19:56:08 +01:00
parent 56fc501925
commit 8cf03d3eb4
No known key found for this signature in database
GPG Key ID: 5FCD9D5211B952DA
4 changed files with 19 additions and 17 deletions

View File

@ -10,9 +10,9 @@ const log = new Logger("sds:message");
export class Message implements proto_sds_message.SdsMessage {
public constructor(
public messageId: string,
public messageId: MessageId,
public channelId: string,
public senderId: string,
public senderId: ParticipantId,
public causalHistory: proto_sds_message.HistoryEntry[],
public lamportTimestamp?: bigint | undefined,
public bloomFilter?: Uint8Array<ArrayBufferLike> | undefined,
@ -95,9 +95,9 @@ export class Message implements proto_sds_message.SdsMessage {
export class SyncMessage extends Message {
public constructor(
public messageId: string,
public messageId: MessageId,
public channelId: string,
public senderId: string,
public senderId: ParticipantId,
public causalHistory: proto_sds_message.HistoryEntry[],
public lamportTimestamp: bigint,
public bloomFilter: Uint8Array<ArrayBufferLike> | undefined,
@ -141,9 +141,9 @@ export function isSyncMessage(
export class EphemeralMessage extends Message {
public constructor(
public messageId: string,
public messageId: MessageId,
public channelId: string,
public senderId: string,
public senderId: ParticipantId,
public causalHistory: proto_sds_message.HistoryEntry[],
public lamportTimestamp: undefined,
public bloomFilter: Uint8Array<ArrayBufferLike> | undefined,
@ -191,9 +191,9 @@ function testEphemeralMessage(message: {
export class ContentMessage extends Message {
public constructor(
public messageId: string,
public messageId: MessageId,
public channelId: string,
public senderId: string,
public senderId: ParticipantId,
public causalHistory: proto_sds_message.HistoryEntry[],
public lamportTimestamp: bigint,
public bloomFilter: Uint8Array<ArrayBufferLike> | undefined,

View File

@ -1,6 +1,6 @@
import { Logger } from "@waku/utils";
import type { HistoryEntry } from "../message.js";
import type { HistoryEntry, MessageId } from "../message.js";
const log = new Logger("sds:repair:buffers");
@ -74,7 +74,7 @@ export class OutgoingRepairBuffer {
/**
* Remove a message from the buffer (e.g., when received)
*/
public remove(messageId: string): void {
public remove(messageId: MessageId): void {
this.items = this.items.filter(
(item) => item.entry.messageId !== messageId
);
@ -121,7 +121,7 @@ export class OutgoingRepairBuffer {
/**
* Check if a message is in the buffer
*/
public has(messageId: string): boolean {
public has(messageId: MessageId): boolean {
return this.items.some((item) => item.entry.messageId === messageId);
}
@ -205,7 +205,7 @@ export class IncomingRepairBuffer {
/**
* Remove a message from the buffer
*/
public remove(messageId: string): void {
public remove(messageId: MessageId): void {
this.items = this.items.filter(
(item) => item.entry.messageId !== messageId
);
@ -243,7 +243,7 @@ export class IncomingRepairBuffer {
/**
* Check if a message is in the buffer
*/
public has(messageId: string): boolean {
public has(messageId: MessageId): boolean {
return this.items.some((item) => item.entry.messageId === messageId);
}

View File

@ -96,7 +96,7 @@ export class RepairManager {
*/
public calculateTResp(
senderId: ParticipantId,
messageId: string,
messageId: MessageId,
currentTime = Date.now()
): number {
const distance = calculateXorDistance(this.participantId, senderId);
@ -113,7 +113,7 @@ export class RepairManager {
*/
public isInResponseGroup(
senderId: ParticipantId,
messageId: string
messageId: MessageId
): boolean {
if (!senderId) {
// Cannot determine response group without sender_id
@ -170,7 +170,7 @@ export class RepairManager {
* Handle receipt of a message - remove from repair buffers
* Called when a message is successfully received
*/
public markMessageReceived(messageId: string): void {
public markMessageReceived(messageId: MessageId): void {
// Remove from both buffers as we no longer need to request or respond
const wasInOutgoing = this.outgoingBuffer.has(messageId);
const wasInIncoming = this.incomingBuffer.has(messageId);

View File

@ -1,6 +1,8 @@
import { sha256 } from "@noble/hashes/sha2";
import { bytesToHex } from "@waku/utils/bytes";
import type { MessageId } from "../message.js";
/**
* ParticipantId can be a string or converted to a numeric representation for XOR operations
*/
@ -23,7 +25,7 @@ export function hashToInteger(input: string): bigint {
*/
export function combinedHash(
participantId: ParticipantId,
messageId: string
messageId: MessageId
): bigint {
const combined = `${participantId}${messageId}`;
return hashToInteger(combined);