From 537a2b73a772af79efdd50b492acbe6599ae670f Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 18 May 2021 13:26:42 +1000 Subject: [PATCH 1/4] Use prod nodes by default instead of test --- CHANGELOG.md | 1 + src/lib/discover.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd6b4b1fa..cbc2da8624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Testing: Upgrade nim-waku node to v0.3. - **Breaking**: Modify `WakuStore.queryHistory()` to accept one `Object` instead of multiple individual arguments. +- `getStatusFleetNodes` return prod nodes by default, instead of test nodes. ## [0.3.0] - 2021-05-15 diff --git a/src/lib/discover.ts b/src/lib/discover.ts index cfa46052c2..b532630a36 100644 --- a/src/lib/discover.ts +++ b/src/lib/discover.ts @@ -15,7 +15,7 @@ export enum Environment { } export async function getStatusFleetNodes( - env: Environment = Environment.Test, + env: Environment = Environment.Prod, protocol: Protocol = Protocol.websocket ): Promise { const res = await axios.get('https://fleets.status.im/', { From 2cd87b561d6690b73c4a0403e871f5359c2ff111 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 18 May 2021 13:45:49 +1000 Subject: [PATCH 2/4] Expose `Enviroment` & `Protocol` enums to pass to `getStatusFleetNodes` --- CHANGELOG.md | 3 +++ src/index.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc2da8624..bf31a27ebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: Modify `WakuStore.queryHistory()` to accept one `Object` instead of multiple individual arguments. - `getStatusFleetNodes` return prod nodes by default, instead of test nodes. +### Fixed +- Expose `Enviroment` and `Protocol` enums to pass to `getStatusFleetNodes`. + ## [0.3.0] - 2021-05-15 ### Added diff --git a/src/index.ts b/src/index.ts index b507f04fe5..a9194a64ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { getStatusFleetNodes } from './lib/discover'; +export { getStatusFleetNodes, Environment, Protocol } from './lib/discover'; export { Waku } from './lib/waku'; export { WakuMessage } from './lib/waku_message'; From a69c483c46cc741aa807640236691da7f52f3f46 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 18 May 2021 13:47:16 +1000 Subject: [PATCH 3/4] Connect to prod fleet by default, test fleet for local development --- CHANGELOG.md | 1 + examples/web-chat/src/App.tsx | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf31a27ebb..2317c72c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Testing: Upgrade nim-waku node to v0.3. - **Breaking**: Modify `WakuStore.queryHistory()` to accept one `Object` instead of multiple individual arguments. - `getStatusFleetNodes` return prod nodes by default, instead of test nodes. +- Examples (web chat): Connect to prod fleet by default, test fleet for local development. ### Fixed - Expose `Enviroment` and `Protocol` enums to pass to `getStatusFleetNodes`. diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index ff697af13f..6169d25483 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -3,10 +3,11 @@ import { useEffect, useState } from 'react'; import './App.css'; import { ChatMessage, - WakuMessage, + getStatusFleetNodes, + Environment, StoreCodec, Waku, - getStatusFleetNodes, + WakuMessage, } from 'js-waku'; import handleCommand from './command'; import Room from './Room'; @@ -171,7 +172,7 @@ async function initWaku(setter: (waku: Waku) => void) { setter(waku); - const nodes = await getStatusFleetNodes(); + const nodes = await getNodes(); await Promise.all( nodes.map((addr) => { return waku.dial(addr); @@ -181,3 +182,12 @@ async function initWaku(setter: (waku: Waku) => void) { console.log('Issue starting waku ', e); } } + +function getNodes() { + // Works with react-scripts + if (process?.env?.NODE_ENV === 'development') { + return getStatusFleetNodes(Environment.Test); + } else { + return getStatusFleetNodes(Environment.Prod); + } +} From c4c259f47ab560e8095116881e43e13361257c41 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 18 May 2021 13:50:36 +1000 Subject: [PATCH 4/4] Connect cli chat to prod fleet upon passing `--prod` --- CHANGELOG.md | 1 + examples/cli-chat/src/chat.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2317c72c1d..b247d0b60b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: Modify `WakuStore.queryHistory()` to accept one `Object` instead of multiple individual arguments. - `getStatusFleetNodes` return prod nodes by default, instead of test nodes. - Examples (web chat): Connect to prod fleet by default, test fleet for local development. +- Examples (cli chat): Connect to test fleet by default, use `--prod` to connect to prod fleet. ### Fixed - Expose `Enviroment` and `Protocol` enums to pass to `getStatusFleetNodes`. diff --git a/examples/cli-chat/src/chat.ts b/examples/cli-chat/src/chat.ts index 5fbba8ec18..825a10874a 100644 --- a/examples/cli-chat/src/chat.ts +++ b/examples/cli-chat/src/chat.ts @@ -3,6 +3,7 @@ import util from 'util'; import { ChatMessage, + Environment, getStatusFleetNodes, StoreCodec, Waku, @@ -105,6 +106,7 @@ interface Options { staticNodes: Multiaddr[]; listenAddr: string; autoDial: boolean; + prod: boolean; } function processArguments(): Options { @@ -114,6 +116,7 @@ function processArguments(): Options { listenAddr: '/ip4/0.0.0.0/tcp/0', staticNodes: [], autoDial: false, + prod: false, }; while (passedArgs.length) { @@ -128,6 +131,9 @@ function processArguments(): Options { case '--autoDial': opts.autoDial = true; break; + case '--prod': + opts.prod = true; + break; default: console.log(`Unsupported argument: ${arg}`); process.exit(1); @@ -149,7 +155,9 @@ export function formatMessage(chatMsg: ChatMessage): string { } async function addFleetNodes(opts: Options): Promise { - await getStatusFleetNodes().then((nodes) => + await getStatusFleetNodes( + opts.prod ? Environment.Prod : Environment.Test + ).then((nodes) => nodes.map((addr) => { opts.staticNodes.push(multiaddr(addr)); })