mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-05-22 20:49:52 +00:00
use IRouting info for typing
This commit is contained in:
parent
b8867dee38
commit
d04130feb6
@ -5,10 +5,11 @@ import type {
|
|||||||
IMessage,
|
IMessage,
|
||||||
IMetaSetter,
|
IMetaSetter,
|
||||||
IProtoMessage,
|
IProtoMessage,
|
||||||
IRateLimitProof
|
IRateLimitProof,
|
||||||
|
IRoutingInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { proto_message as proto } from "@waku/proto";
|
import { proto_message as proto } from "@waku/proto";
|
||||||
import { isAutoShardingRoutingInfo, Logger, RoutingInfo } from "@waku/utils";
|
import { isAutoShardingRoutingInfo, Logger } from "@waku/utils";
|
||||||
|
|
||||||
const log = new Logger("message:version-0");
|
const log = new Logger("message:version-0");
|
||||||
const OneMillion = BigInt(1_000_000);
|
const OneMillion = BigInt(1_000_000);
|
||||||
@ -68,7 +69,7 @@ export type EncoderOptions = {
|
|||||||
/**
|
/**
|
||||||
* The routing information for messages to encode.
|
* The routing information for messages to encode.
|
||||||
*/
|
*/
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
/** The content topic to set on outgoing messages. */
|
/** The content topic to set on outgoing messages. */
|
||||||
contentTopic: string;
|
contentTopic: string;
|
||||||
/**
|
/**
|
||||||
@ -88,7 +89,7 @@ export class Encoder implements IEncoder {
|
|||||||
public constructor(
|
public constructor(
|
||||||
public contentTopic: string,
|
public contentTopic: string,
|
||||||
public ephemeral: boolean = false,
|
public ephemeral: boolean = false,
|
||||||
public routingInfo: RoutingInfo,
|
public routingInfo: IRoutingInfo,
|
||||||
public metaSetter?: IMetaSetter
|
public metaSetter?: IMetaSetter
|
||||||
) {
|
) {
|
||||||
if (!contentTopic || contentTopic === "") {
|
if (!contentTopic || contentTopic === "") {
|
||||||
@ -146,7 +147,7 @@ export function createEncoder({
|
|||||||
export class Decoder implements IDecoder<IDecodedMessage> {
|
export class Decoder implements IDecoder<IDecodedMessage> {
|
||||||
public constructor(
|
public constructor(
|
||||||
public contentTopic: string,
|
public contentTopic: string,
|
||||||
public routingInfo: RoutingInfo
|
public routingInfo: IRoutingInfo
|
||||||
) {
|
) {
|
||||||
if (!contentTopic || contentTopic === "") {
|
if (!contentTopic || contentTopic === "") {
|
||||||
throw new Error("Content topic must be specified");
|
throw new Error("Content topic must be specified");
|
||||||
@ -201,7 +202,7 @@ export class Decoder implements IDecoder<IDecodedMessage> {
|
|||||||
*/
|
*/
|
||||||
export function createDecoder(
|
export function createDecoder(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
routingInfo: RoutingInfo
|
routingInfo: IRoutingInfo
|
||||||
): Decoder {
|
): Decoder {
|
||||||
if (isAutoShardingRoutingInfo(routingInfo)) {
|
if (isAutoShardingRoutingInfo(routingInfo)) {
|
||||||
if (routingInfo.contentTopic !== contentTopic)
|
if (routingInfo.contentTopic !== contentTopic)
|
||||||
|
|||||||
@ -5,10 +5,11 @@ import {
|
|||||||
type IEncryptedMessage,
|
type IEncryptedMessage,
|
||||||
type IMessage,
|
type IMessage,
|
||||||
type IMetaSetter,
|
type IMetaSetter,
|
||||||
type IProtoMessage
|
type IProtoMessage,
|
||||||
|
type IRoutingInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { generatePrivateKey } from "./crypto/utils.js";
|
import { generatePrivateKey } from "./crypto/utils.js";
|
||||||
import { DecodedMessage } from "./decoded_message.js";
|
import { DecodedMessage } from "./decoded_message.js";
|
||||||
@ -33,7 +34,7 @@ const log = new Logger("message-encryption:ecies");
|
|||||||
class Encoder implements IEncoder {
|
class Encoder implements IEncoder {
|
||||||
public constructor(
|
public constructor(
|
||||||
public contentTopic: string,
|
public contentTopic: string,
|
||||||
public routingInfo: RoutingInfo,
|
public routingInfo: IRoutingInfo,
|
||||||
private publicKey: Uint8Array,
|
private publicKey: Uint8Array,
|
||||||
private sigPrivKey?: Uint8Array,
|
private sigPrivKey?: Uint8Array,
|
||||||
public ephemeral: boolean = false,
|
public ephemeral: boolean = false,
|
||||||
@ -82,7 +83,7 @@ export interface EncoderOptions {
|
|||||||
/**
|
/**
|
||||||
* The routing information for messages to encode.
|
* The routing information for messages to encode.
|
||||||
*/
|
*/
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
/** The content topic to set on outgoing messages. */
|
/** The content topic to set on outgoing messages. */
|
||||||
contentTopic: string;
|
contentTopic: string;
|
||||||
/**
|
/**
|
||||||
@ -135,7 +136,7 @@ export function createEncoder({
|
|||||||
class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
||||||
public constructor(
|
public constructor(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
routingInfo: RoutingInfo,
|
routingInfo: IRoutingInfo,
|
||||||
private privateKey: Uint8Array
|
private privateKey: Uint8Array
|
||||||
) {
|
) {
|
||||||
super(contentTopic, routingInfo);
|
super(contentTopic, routingInfo);
|
||||||
@ -206,11 +207,12 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
|||||||
* decode incoming messages.
|
* decode incoming messages.
|
||||||
*
|
*
|
||||||
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
||||||
|
* @param routingInfo
|
||||||
* @param privateKey The private key used to decrypt the message.
|
* @param privateKey The private key used to decrypt the message.
|
||||||
*/
|
*/
|
||||||
export function createDecoder(
|
export function createDecoder(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
routingInfo: RoutingInfo,
|
routingInfo: IRoutingInfo,
|
||||||
privateKey: Uint8Array
|
privateKey: Uint8Array
|
||||||
): Decoder {
|
): Decoder {
|
||||||
return new Decoder(contentTopic, routingInfo, privateKey);
|
return new Decoder(contentTopic, routingInfo, privateKey);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import type {
|
|||||||
IRoutingInfo
|
IRoutingInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { generateSymmetricKey } from "./crypto/utils.js";
|
import { generateSymmetricKey } from "./crypto/utils.js";
|
||||||
import { DecodedMessage } from "./decoded_message.js";
|
import { DecodedMessage } from "./decoded_message.js";
|
||||||
@ -83,7 +83,7 @@ export interface EncoderOptions {
|
|||||||
/**
|
/**
|
||||||
* The routing information for messages to encode.
|
* The routing information for messages to encode.
|
||||||
*/
|
*/
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
/** The content topic to set on outgoing messages. */
|
/** The content topic to set on outgoing messages. */
|
||||||
contentTopic: string;
|
contentTopic: string;
|
||||||
/**
|
/**
|
||||||
@ -136,7 +136,7 @@ export function createEncoder({
|
|||||||
class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
||||||
public constructor(
|
public constructor(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
routingInfo: RoutingInfo,
|
routingInfo: IRoutingInfo,
|
||||||
private symKey: Uint8Array
|
private symKey: Uint8Array
|
||||||
) {
|
) {
|
||||||
super(contentTopic, routingInfo);
|
super(contentTopic, routingInfo);
|
||||||
@ -212,7 +212,7 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
|
|||||||
*/
|
*/
|
||||||
export function createDecoder(
|
export function createDecoder(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
routingInfo: RoutingInfo,
|
routingInfo: IRoutingInfo,
|
||||||
symKey: Uint8Array
|
symKey: Uint8Array
|
||||||
): Decoder {
|
): Decoder {
|
||||||
return new Decoder(contentTopic, routingInfo, symKey);
|
return new Decoder(contentTopic, routingInfo, symKey);
|
||||||
|
|||||||
@ -17,12 +17,13 @@ import {
|
|||||||
IEncoder,
|
IEncoder,
|
||||||
IMessage,
|
IMessage,
|
||||||
IRelay,
|
IRelay,
|
||||||
|
type IRoutingInfo,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
PubsubTopic,
|
PubsubTopic,
|
||||||
SDKProtocolResult
|
SDKProtocolResult
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { isWireSizeUnderCap, RoutingInfo, toAsyncIterator } from "@waku/utils";
|
import { isWireSizeUnderCap, toAsyncIterator } from "@waku/utils";
|
||||||
import { pushOrInitMapSet } from "@waku/utils";
|
import { pushOrInitMapSet } from "@waku/utils";
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import { pEvent } from "p-event";
|
import { pEvent } from "p-event";
|
||||||
@ -39,7 +40,7 @@ export type Observer<T extends IDecodedMessage> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type RelayCreateOptions = CreateNodeOptions & {
|
export type RelayCreateOptions = CreateNodeOptions & {
|
||||||
routingInfos: RoutingInfo[];
|
routingInfos: IRoutingInfo[];
|
||||||
} & Partial<GossipsubOpts>;
|
} & Partial<GossipsubOpts>;
|
||||||
export type ContentTopic = string;
|
export type ContentTopic = string;
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,10 @@ import { createDecoder, createEncoder } from "@waku/core";
|
|||||||
import type {
|
import type {
|
||||||
ContentTopic,
|
ContentTopic,
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IMetaSetter
|
IMetaSetter,
|
||||||
|
IRoutingInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import init from "@waku/zerokit-rln-wasm";
|
import init from "@waku/zerokit-rln-wasm";
|
||||||
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ type WakuRLNEncoderOptions = {
|
|||||||
/**
|
/**
|
||||||
* The routing information for messages to encode.
|
* The routing information for messages to encode.
|
||||||
*/
|
*/
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
/** The content topic to set on outgoing messages. */
|
/** The content topic to set on outgoing messages. */
|
||||||
contentTopic: string;
|
contentTopic: string;
|
||||||
/**
|
/**
|
||||||
@ -108,7 +109,7 @@ export class RLNInstance extends RLNCredentialsManager {
|
|||||||
|
|
||||||
public createDecoder(
|
public createDecoder(
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
routingInfo: RoutingInfo
|
routingInfo: IRoutingInfo
|
||||||
): RLNDecoder<IDecodedMessage> {
|
): RLNDecoder<IDecodedMessage> {
|
||||||
return createRLNDecoder({
|
return createRLNDecoder({
|
||||||
rlnInstance: this,
|
rlnInstance: this,
|
||||||
|
|||||||
@ -10,12 +10,13 @@ import type {
|
|||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IProtoMessage,
|
IProtoMessage,
|
||||||
|
IRoutingInfo,
|
||||||
PeerIdStr,
|
PeerIdStr,
|
||||||
PubsubTopic
|
PubsubTopic
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { PeerManager, PeerManagerEventNames } from "../peer_manager/index.js";
|
import { PeerManager, PeerManagerEventNames } from "../peer_manager/index.js";
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ type AttemptUnsubscribeParams = {
|
|||||||
type Libp2pEventHandler = (e: CustomEvent<PeerId>) => void;
|
type Libp2pEventHandler = (e: CustomEvent<PeerId>) => void;
|
||||||
|
|
||||||
export class Subscription {
|
export class Subscription {
|
||||||
private readonly routingInfo: RoutingInfo;
|
private readonly routingInfo: IRoutingInfo;
|
||||||
private readonly pubsubTopic: PubsubTopic;
|
private readonly pubsubTopic: PubsubTopic;
|
||||||
private readonly protocol: FilterCore;
|
private readonly protocol: FilterCore;
|
||||||
private readonly peerManager: PeerManager;
|
private readonly peerManager: PeerManager;
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
import type { PeerId } from "@libp2p/interface";
|
import type { PeerId } from "@libp2p/interface";
|
||||||
import { type CoreProtocolResult, Protocols } from "@waku/interfaces";
|
import {
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
type CoreProtocolResult,
|
||||||
|
type IRoutingInfo,
|
||||||
|
Protocols
|
||||||
|
} from "@waku/interfaces";
|
||||||
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import type { PeerManager } from "../peer_manager/index.js";
|
import type { PeerManager } from "../peer_manager/index.js";
|
||||||
|
|
||||||
@ -15,7 +19,7 @@ type AttemptCallback = (peerId: PeerId) => Promise<CoreProtocolResult>;
|
|||||||
|
|
||||||
export type ScheduledTask = {
|
export type ScheduledTask = {
|
||||||
maxAttempts: number;
|
maxAttempts: number;
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
callback: AttemptCallback;
|
callback: AttemptCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ export class RetryManager {
|
|||||||
public push(
|
public push(
|
||||||
callback: AttemptCallback,
|
callback: AttemptCallback,
|
||||||
maxAttempts: number,
|
maxAttempts: number,
|
||||||
routingInfo: RoutingInfo
|
routingInfo: IRoutingInfo
|
||||||
): void {
|
): void {
|
||||||
this.queue.push({
|
this.queue.push({
|
||||||
maxAttempts,
|
maxAttempts,
|
||||||
|
|||||||
@ -12,11 +12,12 @@ import {
|
|||||||
} from "@waku/core";
|
} from "@waku/core";
|
||||||
import {
|
import {
|
||||||
CONNECTION_LOCKED_TAG,
|
CONNECTION_LOCKED_TAG,
|
||||||
|
type IRoutingInfo,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
Libp2pEventHandler,
|
Libp2pEventHandler,
|
||||||
Protocols
|
Protocols
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Logger, RoutingInfo } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
const log = new Logger("peer-manager");
|
const log = new Logger("peer-manager");
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ type PeerManagerParams = {
|
|||||||
|
|
||||||
type GetPeersParams = {
|
type GetPeersParams = {
|
||||||
protocol: Protocols;
|
protocol: Protocols;
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum PeerManagerEventNames {
|
export enum PeerManagerEventNames {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { messageHash, StoreCore } from "@waku/core";
|
|||||||
import {
|
import {
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
|
type IRoutingInfo,
|
||||||
IStore,
|
IStore,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
Protocols,
|
Protocols,
|
||||||
@ -12,7 +13,7 @@ import {
|
|||||||
StoreCursor,
|
StoreCursor,
|
||||||
StoreProtocolOptions
|
StoreProtocolOptions
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { isDefined, Logger, RoutingInfo } from "@waku/utils";
|
import { isDefined, Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { PeerManager } from "../peer_manager/index.js";
|
import { PeerManager } from "../peer_manager/index.js";
|
||||||
|
|
||||||
@ -181,7 +182,7 @@ export class Store implements IStore {
|
|||||||
private validateDecodersAndPubsubTopic<T extends IDecodedMessage>(
|
private validateDecodersAndPubsubTopic<T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T>[]
|
decoders: IDecoder<T>[]
|
||||||
): {
|
): {
|
||||||
routingInfo: RoutingInfo;
|
routingInfo: IRoutingInfo;
|
||||||
contentTopics: string[];
|
contentTopics: string[];
|
||||||
decodersAsMap: Map<string, IDecoder<T>>;
|
decodersAsMap: Map<string, IDecoder<T>>;
|
||||||
} {
|
} {
|
||||||
@ -232,7 +233,7 @@ export class Store implements IStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getPeerToUse(
|
private async getPeerToUse(
|
||||||
routingInfo: RoutingInfo
|
routingInfo: IRoutingInfo
|
||||||
): Promise<PeerId | undefined> {
|
): Promise<PeerId | undefined> {
|
||||||
const peers = await this.peerManager.getPeers({
|
const peers = await this.peerManager.getPeers({
|
||||||
protocol: Protocols.Store,
|
protocol: Protocols.Store,
|
||||||
@ -301,7 +302,7 @@ export class Store implements IStore {
|
|||||||
const isHashQuery =
|
const isHashQuery =
|
||||||
options?.messageHashes && options.messageHashes.length > 0;
|
options?.messageHashes && options.messageHashes.length > 0;
|
||||||
|
|
||||||
let routingInfo: RoutingInfo;
|
let routingInfo: IRoutingInfo;
|
||||||
let contentTopics: string[];
|
let contentTopics: string[];
|
||||||
let decodersAsMap: Map<string, IDecoder<T>>;
|
let decodersAsMap: Map<string, IDecoder<T>>;
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import type {
|
|||||||
IFilter,
|
IFilter,
|
||||||
ILightPush,
|
ILightPush,
|
||||||
IRelay,
|
IRelay,
|
||||||
|
IRoutingInfo,
|
||||||
IStore,
|
IStore,
|
||||||
IWaku,
|
IWaku,
|
||||||
IWakuEventEmitter,
|
IWakuEventEmitter,
|
||||||
@ -27,7 +28,7 @@ import {
|
|||||||
HealthStatus,
|
HealthStatus,
|
||||||
Protocols
|
Protocols
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { createRoutingInfo, Logger, RoutingInfo } from "@waku/utils";
|
import { createRoutingInfo, Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { Filter } from "../filter/index.js";
|
import { Filter } from "../filter/index.js";
|
||||||
import { HealthIndicator } from "../health_indicator/index.js";
|
import { HealthIndicator } from "../health_indicator/index.js";
|
||||||
@ -286,6 +287,6 @@ function getRoutingInfo(
|
|||||||
networkConfig: NetworkConfig,
|
networkConfig: NetworkConfig,
|
||||||
contentTopic?: string,
|
contentTopic?: string,
|
||||||
shardId?: number
|
shardId?: number
|
||||||
): RoutingInfo {
|
): IRoutingInfo {
|
||||||
return createRoutingInfo(networkConfig, { contentTopic, shardId });
|
return createRoutingInfo(networkConfig, { contentTopic, shardId });
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user