Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: discourage the use of relay in browsers #1778

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./relay": {
"types": "./dist/relay/index.d.ts",
"import": "./dist/relay/index.js"
}
},
"typesVersions": {
"*": {
"*": [
"*",
"dist/*",
"dist/*/index"
]
}
},
"type": "module",
Expand Down
42 changes: 0 additions & 42 deletions packages/sdk/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Libp2pComponents,
LightNode,
ProtocolCreateOptions,
RelayNode,
ShardingParams
} from "@waku/interfaces";
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
Expand Down Expand Up @@ -136,47 +135,6 @@
) as LightNode;
}

/**
* Create a Waku node that uses Waku Relay to send and receive messages,
* enabling some privacy preserving properties.
*/
export async function createRelayNode(
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<RelayNode> {
options = options ?? {};

if (options.shardInfo) {
ensureShardingConfigured(options.shardInfo);
}

const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
if (options?.defaultBootstrap) {
peerDiscovery.push(...defaultPeerDiscoveries());
Object.assign(libp2pOptions, { peerDiscovery });
}

const libp2p = await defaultLibp2p(
options.shardInfo,
wakuGossipSub(options),
libp2pOptions,
options?.userAgent
);

const relay = wakuRelay(options);

return new WakuNode(
options,
options.pubsubTopics,
libp2p,
options.shardInfo,
undefined,
undefined,
undefined,
relay
) as RelayNode;
}

/**
* Create a Waku node that uses all Waku protocols.
*
Expand Down Expand Up @@ -293,5 +251,5 @@
...pubsubService,
...options?.services
}
}) as any as Libp2p; // TODO: make libp2p include it;

Check warning on line 254 in packages/sdk/src/create.ts

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type

Check warning on line 254 in packages/sdk/src/create.ts

View workflow job for this annotation

GitHub Actions / proto

Unexpected any. Specify a different type
}
48 changes: 48 additions & 0 deletions packages/sdk/src/relay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { WakuNode, WakuOptions } from "@waku/core";
import type { ProtocolCreateOptions, RelayNode } from "@waku/interfaces";
import { RelayCreateOptions, wakuGossipSub, wakuRelay } from "@waku/relay";

import { defaultLibp2p, defaultPeerDiscoveries } from "../create.js";

/**
* Create a Waku node that uses Waku Relay to send and receive messages,
* enabling some privacy preserving properties.
* * @remarks
* This function creates a Relay Node using the Waku Relay protocol.
* While it is technically possible to use this function in a browser environment,
* it is not recommended due to potential performance issues and limited browser capabilities.
* If you are developing a browser-based application, consider alternative approaches like creating a Light Node
* or use this function with caution.
*/
export async function createRelayNode(
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>
): Promise<RelayNode> {
options = options ?? {};

const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
if (options?.defaultBootstrap) {
peerDiscovery.push(...defaultPeerDiscoveries());
Object.assign(libp2pOptions, { peerDiscovery });
}

const libp2p = await defaultLibp2p(
options.shardInfo,
wakuGossipSub(options),
libp2pOptions,
options?.userAgent
);

const relay = wakuRelay(options);

return new WakuNode(
options,
options.pubsubTopics,
libp2p,
options.shardInfo,
undefined,
undefined,
undefined,
relay
) as RelayNode;
}
2 changes: 1 addition & 1 deletion packages/tests/tests/enr.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { waitForRemotePeer } from "@waku/core";
import { EnrDecoder } from "@waku/enr";
import type { RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai";

import { makeLogFileName, NOISE_KEY_1, tearDownNodes } from "../src/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/relay/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createDecoder as createSymDecoder,
createEncoder as createSymEncoder
} from "@waku/message-encryption/symmetric";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/relay/interop.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PeerId } from "@libp2p/interface/peer-id";
import { DecodedMessage, waitForRemotePeer } from "@waku/core";
import { DefaultPubsubTopic, Protocols, RelayNode } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/relay/multiple_pubsub.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SingleShardInfo
} from "@waku/interfaces";
import { Protocols } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import {
contentTopicToPubsubTopic,
singleShardInfoToPubsubTopic
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/relay/publish.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createEncoder } from "@waku/core";
import { IRateLimitProof, RelayNode, SendError } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/relay/subscribe.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createDecoder, createEncoder } from "@waku/core";
import { DefaultPubsubTopic, RelayNode } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";

Expand Down
3 changes: 2 additions & 1 deletion packages/tests/tests/wait_for_remote_peer.node.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { waitForRemotePeer } from "@waku/core";
import type { LightNode, RelayNode } from "@waku/interfaces";
import { DefaultPubsubTopic, Protocols } from "@waku/interfaces";
import { createLightNode, createRelayNode } from "@waku/sdk";
import { createLightNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai";

import {
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/waku.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
} from "@waku/message-encryption/symmetric";
import {
createLightNode,
createEncoder as createPlainEncoder,
createRelayNode
createEncoder as createPlainEncoder
} from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay";
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";

Expand Down
Loading