mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-05 19:43:41 +00:00
Further chat2 improvements (#405)
This commit is contained in:
parent
1eb1cbaaa8
commit
cc962f2dd5
71
docs/tutorial/chat2.md
Normal file
71
docs/tutorial/chat2.md
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Using the `chat2` application
|
||||||
|
|
||||||
|
## Background
|
||||||
|
|
||||||
|
The `chat2` application is a basic command-line chat app using the [Waku v2 suite of protocols](https://specs.vac.dev/specs/waku/v2/waku-v2). It connects to a [fleet of test nodes](fleets.status.im) to provide end-to-end p2p chat capabilities. The Waku team is currently using this application for internal testing. If you want try our protocols, or join the dogfooding fun, follow the instructions below.
|
||||||
|
|
||||||
|
## Preparation
|
||||||
|
|
||||||
|
Ensure you have cloned the `nim-waku` repository and installed all prerequisites as per [these instructions](https://github.com/status-im/nim-waku).
|
||||||
|
|
||||||
|
Make the `chat2` target.
|
||||||
|
|
||||||
|
```
|
||||||
|
make chat2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Basic application usage
|
||||||
|
|
||||||
|
To start the `chat2` application in its most basic form, run the following from the project directory
|
||||||
|
|
||||||
|
```
|
||||||
|
./build/chat2
|
||||||
|
```
|
||||||
|
|
||||||
|
You should be prompted to provide a nickname for the chat session.
|
||||||
|
|
||||||
|
```
|
||||||
|
Choose a nickname >>
|
||||||
|
```
|
||||||
|
|
||||||
|
After entering a nickname, the app will randomly select and connect to a peer from the test fleet.
|
||||||
|
|
||||||
|
```
|
||||||
|
No static peers configured. Choosing one at random from test fleet...
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait for the chat prompt (`>>`) and chat away!
|
||||||
|
|
||||||
|
## Retrieving historical messages
|
||||||
|
|
||||||
|
The `chat2` application can retrieve historical chat messages from a node supporting and running the [Waku v2 store protocol](https://specs.vac.dev/specs/waku/v2/waku-store). Just specify the selected node's `multiaddr` as `storenode` when starting the app:
|
||||||
|
|
||||||
|
```
|
||||||
|
./build/chat2 --storenode:/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, the `chat2` application will select a random `storenode` for you from the test fleet if the `store` option is set to `true` and `storenode` left unspecified.
|
||||||
|
|
||||||
|
```
|
||||||
|
./build/chat2 --store:true
|
||||||
|
```
|
||||||
|
|
||||||
|
> *NOTE: Currently (Mar 3, 2021) the only node in the test fleet that provides reliable store functionality is `/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ`. We're working on fixing this.*
|
||||||
|
|
||||||
|
## Specifying a static peer
|
||||||
|
|
||||||
|
In order to connect to a *specific* node as [`relay`](https://specs.vac.dev/specs/waku/v2/waku-relay) peer, define that node's `multiaddr` as a `staticnode` when starting the app:
|
||||||
|
|
||||||
|
```
|
||||||
|
./build/chat2 --staticnode:/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
||||||
|
```
|
||||||
|
|
||||||
|
This will bypass the random peer selection process and connect to the specified node.
|
||||||
|
|
||||||
|
## In-chat options
|
||||||
|
|
||||||
|
| Command | Effect |
|
||||||
|
| --- | --- |
|
||||||
|
| `/help` | displays available in-chat commands |
|
||||||
|
| `/connect` | interactively connect to a new peer |
|
||||||
|
| `/nick` | change nickname for current chat session |
|
@ -25,11 +25,10 @@ import ../../waku/v2/node/[config, wakunode2, waku_payload],
|
|||||||
../../waku/common/utils/nat
|
../../waku/common/utils/nat
|
||||||
|
|
||||||
const Help = """
|
const Help = """
|
||||||
Commands: /[?|help|connect|disconnect|exit]
|
Commands: /[?|help|connect|nick]
|
||||||
help: Prints this help
|
help: Prints this help
|
||||||
connect: dials a remote peer
|
connect: dials a remote peer
|
||||||
disconnect: ends current session
|
nick: change nickname for current chat session
|
||||||
exit: closes the chat
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -166,8 +165,8 @@ proc writeAndPrint(c: Chat) {.async.} =
|
|||||||
else:
|
else:
|
||||||
# XXX connected state problematic
|
# XXX connected state problematic
|
||||||
if c.started:
|
if c.started:
|
||||||
# Get message timestamp
|
# Get message date and timestamp
|
||||||
let time = getTime().utc().format("'<'HH:mm'>'")
|
let time = now().utc().format("'<'MMM' 'dd,' 'HH:mm'>'")
|
||||||
|
|
||||||
c.publish(time & " " & c.nick & ": " & line)
|
c.publish(time & " " & c.nick & ": " & line)
|
||||||
# TODO Connect to peer logic?
|
# TODO Connect to peer logic?
|
||||||
@ -234,10 +233,21 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
|
|||||||
if conf.swap:
|
if conf.swap:
|
||||||
node.mountSwap()
|
node.mountSwap()
|
||||||
|
|
||||||
if conf.storenode != "":
|
if (conf.storenode != "") or (conf.store == true):
|
||||||
node.mountStore()
|
node.mountStore()
|
||||||
|
|
||||||
node.wakuStore.setPeer(parsePeerInfo(conf.storenode))
|
var storenode: string
|
||||||
|
|
||||||
|
if conf.storenode != "":
|
||||||
|
storenode = conf.storenode
|
||||||
|
else:
|
||||||
|
echo "Store enabled, but no store nodes configured. Choosing one at random from test fleet..."
|
||||||
|
|
||||||
|
storenode = selectRandomNode()
|
||||||
|
|
||||||
|
echo "Connecting to storenode: " & storenode
|
||||||
|
|
||||||
|
node.wakuStore.setPeer(parsePeerInfo(storenode))
|
||||||
|
|
||||||
proc storeHandler(response: HistoryResponse) {.gcsafe.} =
|
proc storeHandler(response: HistoryResponse) {.gcsafe.} =
|
||||||
for msg in response.messages:
|
for msg in response.messages:
|
||||||
|
@ -19,7 +19,7 @@ import
|
|||||||
|
|
||||||
export waku_store_types
|
export waku_store_types
|
||||||
|
|
||||||
declarePublicGauge waku_store_messages, "number of historical messages"
|
declarePublicGauge waku_store_messages, "number of historical messages", ["type"]
|
||||||
declarePublicGauge waku_store_peers, "number of store peers"
|
declarePublicGauge waku_store_peers, "number of store peers"
|
||||||
declarePublicGauge waku_store_errors, "number of store protocol errors", ["type"]
|
declarePublicGauge waku_store_errors, "number of store protocol errors", ["type"]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user