mirror of
https://github.com/status-im/js-waku.git
synced 2025-02-22 09:58:10 +00:00
Remove faulty fleet feature
It does not work as it can lead to infinite loops due to the handling of the Waku instance. It should disconnect and reconnect to peers instead of starting a new waku instance.
This commit is contained in:
parent
b61e7311af
commit
53ef23362c
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- Examples (web-chat): Remove broken `/fleet` command.
|
||||||
|
|
||||||
## [0.9.0] - 2021-07-26
|
## [0.9.0] - 2021-07-26
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -2,8 +2,8 @@ import PeerId from 'peer-id';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import {
|
import {
|
||||||
getStatusFleetNodes,
|
|
||||||
Environment,
|
Environment,
|
||||||
|
getStatusFleetNodes,
|
||||||
StoreCodec,
|
StoreCodec,
|
||||||
Waku,
|
Waku,
|
||||||
WakuMessage,
|
WakuMessage,
|
||||||
@ -81,17 +81,16 @@ export default function App() {
|
|||||||
const persistedNick = window.localStorage.getItem('nick');
|
const persistedNick = window.localStorage.getItem('nick');
|
||||||
return persistedNick !== null ? persistedNick : generate();
|
return persistedNick !== null ? persistedNick : generate();
|
||||||
});
|
});
|
||||||
const [fleetEnv, setFleetEnv] = useState<Environment>(defaultFleetEnv);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem('nick', nick);
|
localStorage.setItem('nick', nick);
|
||||||
}, [nick]);
|
}, [nick]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initWaku(fleetEnv, setWaku)
|
initWaku(setWaku)
|
||||||
.then(() => console.log('Waku init done'))
|
.then(() => console.log('Waku init done'))
|
||||||
.catch((e) => console.log('Waku init failed ', e));
|
.catch((e) => console.log('Waku init failed ', e));
|
||||||
}, [fleetEnv]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!waku) return;
|
if (!waku) return;
|
||||||
@ -160,15 +159,8 @@ export default function App() {
|
|||||||
nick={nick}
|
nick={nick}
|
||||||
newMessages={newMessages}
|
newMessages={newMessages}
|
||||||
archivedMessages={archivedMessages}
|
archivedMessages={archivedMessages}
|
||||||
fleetEnv={fleetEnv}
|
|
||||||
commandHandler={(input: string) => {
|
commandHandler={(input: string) => {
|
||||||
const { command, response } = handleCommand(
|
const { command, response } = handleCommand(input, waku, setNick);
|
||||||
input,
|
|
||||||
waku,
|
|
||||||
setNick,
|
|
||||||
fleetEnv,
|
|
||||||
setFleetEnv
|
|
||||||
);
|
|
||||||
const commandMessages = response.map((msg) => {
|
const commandMessages = response.map((msg) => {
|
||||||
return Message.fromUtf8String(command, msg);
|
return Message.fromUtf8String(command, msg);
|
||||||
});
|
});
|
||||||
@ -181,7 +173,7 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initWaku(fleetEnv: Environment, setter: (waku: Waku) => void) {
|
async function initWaku(setter: (waku: Waku) => void) {
|
||||||
try {
|
try {
|
||||||
const waku = await Waku.create({
|
const waku = await Waku.create({
|
||||||
libp2p: {
|
libp2p: {
|
||||||
@ -196,7 +188,7 @@ async function initWaku(fleetEnv: Environment, setter: (waku: Waku) => void) {
|
|||||||
|
|
||||||
setter(waku);
|
setter(waku);
|
||||||
|
|
||||||
const nodes = await getStatusFleetNodes(fleetEnv);
|
const nodes = await getStatusFleetNodes(selectFleetEnv());
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
nodes.map((addr) => {
|
nodes.map((addr) => {
|
||||||
return waku.dial(addr);
|
return waku.dial(addr);
|
||||||
@ -207,7 +199,7 @@ async function initWaku(fleetEnv: Environment, setter: (waku: Waku) => void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultFleetEnv() {
|
function selectFleetEnv() {
|
||||||
// Works with react-scripts
|
// Works with react-scripts
|
||||||
if (process?.env?.NODE_ENV === 'development') {
|
if (process?.env?.NODE_ENV === 'development') {
|
||||||
return Environment.Test;
|
return Environment.Test;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ChatMessage, Environment, WakuMessage } from 'js-waku';
|
import { ChatMessage, WakuMessage } from 'js-waku';
|
||||||
import { ChatContentTopic } from './App';
|
import { ChatContentTopic } from './App';
|
||||||
import ChatList from './ChatList';
|
import ChatList from './ChatList';
|
||||||
import MessageInput from './MessageInput';
|
import MessageInput from './MessageInput';
|
||||||
@ -11,7 +11,6 @@ interface Props {
|
|||||||
archivedMessages: Message[];
|
archivedMessages: Message[];
|
||||||
commandHandler: (cmd: string) => void;
|
commandHandler: (cmd: string) => void;
|
||||||
nick: string;
|
nick: string;
|
||||||
fleetEnv: Environment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Room(props: Props) {
|
export default function Room(props: Props) {
|
||||||
@ -30,7 +29,7 @@ export default function Room(props: Props) {
|
|||||||
style={{ height: '98vh', display: 'flex', flexDirection: 'column' }}
|
style={{ height: '98vh', display: 'flex', flexDirection: 'column' }}
|
||||||
>
|
>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
leftIcons={`Peers: ${relayPeers} relay, ${storePeers} store. Fleet: ${props.fleetEnv}`}
|
leftIcons={`Peers: ${relayPeers} relay, ${storePeers} store.`}
|
||||||
title="Waku v2 chat app"
|
title="Waku v2 chat app"
|
||||||
/>
|
/>
|
||||||
<ChatList
|
<ChatList
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { multiaddr } from 'multiaddr';
|
import { multiaddr } from 'multiaddr';
|
||||||
import PeerId from 'peer-id';
|
import PeerId from 'peer-id';
|
||||||
import { Environment, Waku } from 'js-waku';
|
import { Waku } from 'js-waku';
|
||||||
|
|
||||||
function help(): string[] {
|
function help(): string[] {
|
||||||
return [
|
return [
|
||||||
'/nick <nickname>: set a new nickname',
|
'/nick <nickname>: set a new nickname',
|
||||||
'/info: some information about the node',
|
'/info: some information about the node',
|
||||||
'/connect <Multiaddr>: connect to the given peer',
|
'/connect <Multiaddr>: connect to the given peer',
|
||||||
'/fleet <prod|test>: connect to this fleet; beware it restarts waku node.',
|
|
||||||
'/help: Display this help',
|
'/help: Display this help',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -23,14 +22,11 @@ function nick(
|
|||||||
return [`New nick: ${nick}`];
|
return [`New nick: ${nick}`];
|
||||||
}
|
}
|
||||||
|
|
||||||
function info(waku: Waku | undefined, fleetEnv: Environment): string[] {
|
function info(waku: Waku | undefined): string[] {
|
||||||
if (!waku) {
|
if (!waku) {
|
||||||
return ['Waku node is starting'];
|
return ['Waku node is starting'];
|
||||||
}
|
}
|
||||||
return [
|
return [`PeerId: ${waku.libp2p.peerId.toB58String()}`];
|
||||||
`PeerId: ${waku.libp2p.peerId.toB58String()}`,
|
|
||||||
`Fleet environment: ${fleetEnv}`,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect(peer: string | undefined, waku: Waku | undefined): string[] {
|
function connect(peer: string | undefined, waku: Waku | undefined): string[] {
|
||||||
@ -82,28 +78,6 @@ function peers(waku: Waku | undefined): string[] {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fleet(
|
|
||||||
newFleetEnv: string | undefined,
|
|
||||||
currFleetEnv: Environment,
|
|
||||||
setFleetEnv: (fleetEnv: Environment) => void
|
|
||||||
): string[] {
|
|
||||||
switch (newFleetEnv) {
|
|
||||||
case Environment.Test:
|
|
||||||
setFleetEnv(newFleetEnv);
|
|
||||||
break;
|
|
||||||
case Environment.Prod:
|
|
||||||
setFleetEnv(newFleetEnv);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return [
|
|
||||||
`Incorrect values, acceptable values are ${Environment.Test}, ${Environment.Prod}`,
|
|
||||||
`Current fleet environment is ${currFleetEnv}`,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [`New fleet Environment: ${newFleetEnv}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
function connections(waku: Waku | undefined): string[] {
|
function connections(waku: Waku | undefined): string[] {
|
||||||
if (!waku) {
|
if (!waku) {
|
||||||
return ['Waku node is starting'];
|
return ['Waku node is starting'];
|
||||||
@ -133,9 +107,7 @@ function connections(waku: Waku | undefined): string[] {
|
|||||||
export default function handleCommand(
|
export default function handleCommand(
|
||||||
input: string,
|
input: string,
|
||||||
waku: Waku | undefined,
|
waku: Waku | undefined,
|
||||||
setNick: (nick: string) => void,
|
setNick: (nick: string) => void
|
||||||
currFleetEnv: Environment,
|
|
||||||
setFleetEnv: (fleetEnv: Environment) => void
|
|
||||||
): { command: string; response: string[] } {
|
): { command: string; response: string[] } {
|
||||||
let response: string[] = [];
|
let response: string[] = [];
|
||||||
const args = parseInput(input);
|
const args = parseInput(input);
|
||||||
@ -148,7 +120,7 @@ export default function handleCommand(
|
|||||||
nick(args.shift(), setNick).map((str) => response.push(str));
|
nick(args.shift(), setNick).map((str) => response.push(str));
|
||||||
break;
|
break;
|
||||||
case '/info':
|
case '/info':
|
||||||
info(waku, currFleetEnv).map((str) => response.push(str));
|
info(waku).map((str) => response.push(str));
|
||||||
break;
|
break;
|
||||||
case '/connect':
|
case '/connect':
|
||||||
connect(args.shift(), waku).map((str) => response.push(str));
|
connect(args.shift(), waku).map((str) => response.push(str));
|
||||||
@ -159,11 +131,6 @@ export default function handleCommand(
|
|||||||
case '/connections':
|
case '/connections':
|
||||||
connections(waku).map((str) => response.push(str));
|
connections(waku).map((str) => response.push(str));
|
||||||
break;
|
break;
|
||||||
case '/fleet':
|
|
||||||
fleet(args.shift(), currFleetEnv, setFleetEnv).map((str) =>
|
|
||||||
response.push(str)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
response.push(`Unknown Command '${command}'`);
|
response.push(`Unknown Command '${command}'`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user