mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 08:43:09 +00:00
fix: suggestions from code review
Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com> Co-authored-by: fryorcraken <110212804+fryorcraken@users.noreply.github.com>
This commit is contained in:
parent
04e93856ff
commit
f34cfe87f3
@ -22,6 +22,6 @@ export {
|
||||
* @deprecated Use ParticipantId instead. SenderId has been renamed to ParticipantId
|
||||
* to better reflect that it represents a channel participant, not just a message sender.
|
||||
*/
|
||||
export type SenderId = import("./message_channel/index.js").ParticipantId;
|
||||
export type { ParticipantId as SenderId } from "./message_channel/index.js";
|
||||
|
||||
export { BloomFilter };
|
||||
|
||||
@ -43,7 +43,7 @@ export type MessageChannelEvents = {
|
||||
}>;
|
||||
[MessageChannelEvent.RepairRequestReceived]: CustomEvent<{
|
||||
messageIds: MessageId[];
|
||||
fromSenderId?: string;
|
||||
fromSenderId?: ParticipantId;
|
||||
}>;
|
||||
[MessageChannelEvent.RepairResponseQueued]: CustomEvent<{
|
||||
messageId: MessageId;
|
||||
|
||||
@ -10,7 +10,7 @@ const log = new Logger("sds:repair:buffers");
|
||||
interface OutgoingBufferEntry {
|
||||
entry: HistoryEntry;
|
||||
tReq: number; // Timestamp when this repair request should be sent
|
||||
requested: boolean; // Whether this repair has been requested already
|
||||
requested: boolean; // Whether this repair has already been requested by the local node
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +55,7 @@ export class OutgoingRepairBuffer {
|
||||
|
||||
// Check buffer size limit
|
||||
if (this.items.length >= this.maxSize) {
|
||||
// Evict furthest T_req entry (last in sorted array) to preserve most urgent repairs
|
||||
// Evict furthest T_req entry (last in sorted array) to preserve repairs that need to be sent the soonest
|
||||
const evicted = this.items.pop()!;
|
||||
log.warn(
|
||||
`Buffer full, evicted furthest entry ${evicted.entry.messageId} with T_req ${evicted.tReq}`
|
||||
@ -88,7 +88,7 @@ export class OutgoingRepairBuffer {
|
||||
* Returns up to maxRequests entries from the front of the sorted array
|
||||
* Marks returned entries as requested but keeps them in buffer until received
|
||||
*/
|
||||
public getEligible(currentTime: number, maxRequests = 3): HistoryEntry[] {
|
||||
public getEligible(currentTime: number = Date.now(), maxRequests = 3): HistoryEntry[] {
|
||||
const eligible: HistoryEntry[] = [];
|
||||
|
||||
// Iterate from front of sorted array (earliest T_req first)
|
||||
|
||||
@ -80,9 +80,9 @@ export class RepairManager {
|
||||
|
||||
/**
|
||||
* Calculate T_req - when to request repair for a missing message
|
||||
* Per spec (with bug fix): T_req = current_time + hash(participant_id, message_id) % (T_max - T_min) + T_min
|
||||
* Per spec: T_req = current_time + hash(participant_id, message_id) % (T_max - T_min) + T_min
|
||||
*/
|
||||
public calculateTReq(messageId: string, currentTime = Date.now()): number {
|
||||
public calculateTReq(messageId: MessageId, currentTime = Date.now()): number {
|
||||
const hash = combinedHash(this.participantId, messageId);
|
||||
const range = BigInt(this.config.tMax - this.config.tMin);
|
||||
const offset = bigintToNumber(hash % range) + this.config.tMin;
|
||||
@ -137,7 +137,7 @@ export class RepairManager {
|
||||
* Handle missing dependencies by adding them to outgoing repair buffer
|
||||
* Called when causal dependencies are detected as missing
|
||||
*/
|
||||
public onMissingDependencies(
|
||||
public markDependenciesMissing(
|
||||
missingEntries: HistoryEntry[],
|
||||
currentTime = Date.now()
|
||||
): void {
|
||||
@ -170,7 +170,7 @@ export class RepairManager {
|
||||
* Handle receipt of a message - remove from repair buffers
|
||||
* Called when a message is successfully received
|
||||
*/
|
||||
public onMessageReceived(messageId: string): void {
|
||||
public markMessageReceived(messageId: string): 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);
|
||||
@ -338,7 +338,7 @@ export class RepairManager {
|
||||
!Number.isInteger(numParticipants)
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid numParticipants: ${numParticipants}. Must be a non-negative integer.`
|
||||
`Invalid numParticipants: ${numParticipants}. Must be a positive integer.`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { sha256 } from "@noble/hashes/sha2";
|
||||
import { bytesToHex } from "@noble/hashes/utils";
|
||||
import { bytesToHex } from "@waku/utils/bytes";
|
||||
|
||||
/**
|
||||
* ParticipantId can be a string or converted to a numeric representation for XOR operations
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user