mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 08:43:09 +00:00
fix: consistent use of MessageId and ParticipantId
This commit is contained in:
parent
56fc501925
commit
8cf03d3eb4
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user