mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-08-02 13:13:12 +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
|
* @deprecated Use ParticipantId instead. SenderId has been renamed to ParticipantId
|
||||||
* to better reflect that it represents a channel participant, not just a message sender.
|
* 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 };
|
export { BloomFilter };
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export type MessageChannelEvents = {
|
|||||||
}>;
|
}>;
|
||||||
[MessageChannelEvent.RepairRequestReceived]: CustomEvent<{
|
[MessageChannelEvent.RepairRequestReceived]: CustomEvent<{
|
||||||
messageIds: MessageId[];
|
messageIds: MessageId[];
|
||||||
fromSenderId?: string;
|
fromSenderId?: ParticipantId;
|
||||||
}>;
|
}>;
|
||||||
[MessageChannelEvent.RepairResponseQueued]: CustomEvent<{
|
[MessageChannelEvent.RepairResponseQueued]: CustomEvent<{
|
||||||
messageId: MessageId;
|
messageId: MessageId;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const log = new Logger("sds:repair:buffers");
|
|||||||
interface OutgoingBufferEntry {
|
interface OutgoingBufferEntry {
|
||||||
entry: HistoryEntry;
|
entry: HistoryEntry;
|
||||||
tReq: number; // Timestamp when this repair request should be sent
|
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
|
// Check buffer size limit
|
||||||
if (this.items.length >= this.maxSize) {
|
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()!;
|
const evicted = this.items.pop()!;
|
||||||
log.warn(
|
log.warn(
|
||||||
`Buffer full, evicted furthest entry ${evicted.entry.messageId} with T_req ${evicted.tReq}`
|
`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
|
* Returns up to maxRequests entries from the front of the sorted array
|
||||||
* Marks returned entries as requested but keeps them in buffer until received
|
* 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[] = [];
|
const eligible: HistoryEntry[] = [];
|
||||||
|
|
||||||
// Iterate from front of sorted array (earliest T_req first)
|
// 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
|
* 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 hash = combinedHash(this.participantId, messageId);
|
||||||
const range = BigInt(this.config.tMax - this.config.tMin);
|
const range = BigInt(this.config.tMax - this.config.tMin);
|
||||||
const offset = bigintToNumber(hash % range) + 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
|
* Handle missing dependencies by adding them to outgoing repair buffer
|
||||||
* Called when causal dependencies are detected as missing
|
* Called when causal dependencies are detected as missing
|
||||||
*/
|
*/
|
||||||
public onMissingDependencies(
|
public markDependenciesMissing(
|
||||||
missingEntries: HistoryEntry[],
|
missingEntries: HistoryEntry[],
|
||||||
currentTime = Date.now()
|
currentTime = Date.now()
|
||||||
): void {
|
): void {
|
||||||
@ -170,7 +170,7 @@ export class RepairManager {
|
|||||||
* Handle receipt of a message - remove from repair buffers
|
* Handle receipt of a message - remove from repair buffers
|
||||||
* Called when a message is successfully received
|
* 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
|
// Remove from both buffers as we no longer need to request or respond
|
||||||
const wasInOutgoing = this.outgoingBuffer.has(messageId);
|
const wasInOutgoing = this.outgoingBuffer.has(messageId);
|
||||||
const wasInIncoming = this.incomingBuffer.has(messageId);
|
const wasInIncoming = this.incomingBuffer.has(messageId);
|
||||||
@ -338,7 +338,7 @@ export class RepairManager {
|
|||||||
!Number.isInteger(numParticipants)
|
!Number.isInteger(numParticipants)
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
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 { 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
|
* ParticipantId can be a string or converted to a numeric representation for XOR operations
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user