mirror of https://github.com/waku-org/js-waku.git
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]
|
||||
|
||||
### Removed
|
||||
- Examples (web-chat): Remove broken `/fleet` command.
|
||||
|
||||
## [0.9.0] - 2021-07-26
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -2,8 +2,8 @@ import PeerId from 'peer-id';
|
|||
import { useEffect, useState } from 'react';
|
||||
import './App.css';
|
||||
import {
|
||||
getStatusFleetNodes,
|
||||
Environment,
|
||||
getStatusFleetNodes,
|
||||
StoreCodec,
|
||||
Waku,
|
||||
WakuMessage,
|
||||
|
@ -81,17 +81,16 @@ export default function App() {
|
|||
const persistedNick = window.localStorage.getItem('nick');
|
||||
return persistedNick !== null ? persistedNick : generate();
|
||||
});
|
||||
const [fleetEnv, setFleetEnv] = useState<Environment>(defaultFleetEnv);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('nick', nick);
|
||||
}, [nick]);
|
||||
|
||||
useEffect(() => {
|
||||
initWaku(fleetEnv, setWaku)
|
||||
initWaku(setWaku)
|
||||
.then(() => console.log('Waku init done'))
|
||||
.catch((e) => console.log('Waku init failed ', e));
|
||||
}, [fleetEnv]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!waku) return;
|
||||
|
@ -160,15 +159,8 @@ export default function App() {
|
|||
nick={nick}
|
||||
newMessages={newMessages}
|
||||
archivedMessages={archivedMessages}
|
||||
fleetEnv={fleetEnv}
|
||||
commandHandler={(input: string) => {
|
||||
const { command, response } = handleCommand(
|
||||
input,
|
||||
waku,
|
||||
setNick,
|
||||
fleetEnv,
|
||||
setFleetEnv
|
||||
);
|
||||
const { command, response } = handleCommand(input, waku, setNick);
|
||||
const commandMessages = response.map((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 {
|
||||
const waku = await Waku.create({
|
||||
libp2p: {
|
||||
|
@ -196,7 +188,7 @@ async function initWaku(fleetEnv: Environment, setter: (waku: Waku) => void) {
|
|||
|
||||
setter(waku);
|
||||
|
||||
const nodes = await getStatusFleetNodes(fleetEnv);
|
||||
const nodes = await getStatusFleetNodes(selectFleetEnv());
|
||||
await Promise.all(
|
||||
nodes.map((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
|
||||
if (process?.env?.NODE_ENV === 'development') {
|
||||
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 ChatList from './ChatList';
|
||||
import MessageInput from './MessageInput';
|
||||
|
@ -11,7 +11,6 @@ interface Props {
|
|||
archivedMessages: Message[];
|
||||
commandHandler: (cmd: string) => void;
|
||||
nick: string;
|
||||
fleetEnv: Environment;
|
||||
}
|
||||
|
||||
export default function Room(props: Props) {
|
||||
|
@ -30,7 +29,7 @@ export default function Room(props: Props) {
|
|||
style={{ height: '98vh', display: 'flex', flexDirection: 'column' }}
|
||||
>
|
||||
<TitleBar
|
||||
leftIcons={`Peers: ${relayPeers} relay, ${storePeers} store. Fleet: ${props.fleetEnv}`}
|
||||
leftIcons={`Peers: ${relayPeers} relay, ${storePeers} store.`}
|
||||
title="Waku v2 chat app"
|
||||
/>
|
||||
<ChatList
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import { multiaddr } from 'multiaddr';
|
||||
import PeerId from 'peer-id';
|
||||
import { Environment, Waku } from 'js-waku';
|
||||
import { Waku } from 'js-waku';
|
||||
|
||||
function help(): string[] {
|
||||
return [
|
||||
'/nick <nickname>: set a new nickname',
|
||||
'/info: some information about the node',
|
||||
'/connect <Multiaddr>: connect to the given peer',
|
||||
'/fleet <prod|test>: connect to this fleet; beware it restarts waku node.',
|
||||
'/help: Display this help',
|
||||
];
|
||||
}
|
||||
|
@ -23,14 +22,11 @@ function nick(
|
|||
return [`New nick: ${nick}`];
|
||||
}
|
||||
|
||||
function info(waku: Waku | undefined, fleetEnv: Environment): string[] {
|
||||
function info(waku: Waku | undefined): string[] {
|
||||
if (!waku) {
|
||||
return ['Waku node is starting'];
|
||||
}
|
||||
return [
|
||||
`PeerId: ${waku.libp2p.peerId.toB58String()}`,
|
||||
`Fleet environment: ${fleetEnv}`,
|
||||
];
|
||||
return [`PeerId: ${waku.libp2p.peerId.toB58String()}`];
|
||||
}
|
||||
|
||||
function connect(peer: string | undefined, waku: Waku | undefined): string[] {
|
||||
|
@ -82,28 +78,6 @@ function peers(waku: Waku | undefined): string[] {
|
|||
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[] {
|
||||
if (!waku) {
|
||||
return ['Waku node is starting'];
|
||||
|
@ -133,9 +107,7 @@ function connections(waku: Waku | undefined): string[] {
|
|||
export default function handleCommand(
|
||||
input: string,
|
||||
waku: Waku | undefined,
|
||||
setNick: (nick: string) => void,
|
||||
currFleetEnv: Environment,
|
||||
setFleetEnv: (fleetEnv: Environment) => void
|
||||
setNick: (nick: string) => void
|
||||
): { command: string; response: string[] } {
|
||||
let response: string[] = [];
|
||||
const args = parseInput(input);
|
||||
|
@ -148,7 +120,7 @@ export default function handleCommand(
|
|||
nick(args.shift(), setNick).map((str) => response.push(str));
|
||||
break;
|
||||
case '/info':
|
||||
info(waku, currFleetEnv).map((str) => response.push(str));
|
||||
info(waku).map((str) => response.push(str));
|
||||
break;
|
||||
case '/connect':
|
||||
connect(args.shift(), waku).map((str) => response.push(str));
|
||||
|
@ -159,11 +131,6 @@ export default function handleCommand(
|
|||
case '/connections':
|
||||
connections(waku).map((str) => response.push(str));
|
||||
break;
|
||||
case '/fleet':
|
||||
fleet(args.shift(), currFleetEnv, setFleetEnv).map((str) =>
|
||||
response.push(str)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
response.push(`Unknown Command '${command}'`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue