mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-04 07:03:13 +00:00
parent
7ee12eb250
commit
d7af4e09ec
8
Makefile
8
Makefile
@ -28,7 +28,7 @@ else # "variables.mk" was included. Business as usual until the end of this file
|
|||||||
.PHONY: all update clean
|
.PHONY: all update clean
|
||||||
|
|
||||||
# default target, because it's the first one that doesn't start with '.'
|
# default target, because it's the first one that doesn't start with '.'
|
||||||
all: | waku_example tui bot_echo pingpong
|
all: | bot_echo pingpong
|
||||||
|
|
||||||
test_file := $(word 2,$(MAKECMDGOALS))
|
test_file := $(word 2,$(MAKECMDGOALS))
|
||||||
define test_name
|
define test_name
|
||||||
@ -81,12 +81,6 @@ tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
|||||||
##########
|
##########
|
||||||
## Example ##
|
## Example ##
|
||||||
##########
|
##########
|
||||||
.PHONY: waku_example
|
|
||||||
|
|
||||||
waku_example: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
|
||||||
\
|
|
||||||
$(ENV_SCRIPT) nim waku_example $(NIM_PARAMS) nim_chat_poc.nims
|
|
||||||
|
|
||||||
# Ensure there is a nimble task with a name that matches the target
|
# Ensure there is a nimble task with a name that matches the target
|
||||||
tui bot_echo pingpong: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
tui bot_echo pingpong: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
This is the technical proof of a modular e2ee chat protocol using Waku. You can find discussion and details [here](https://github.com/waku-org/specs/pull/73)
|
This is the technical proof of a modular e2ee chat protocol using Waku. You can find discussion and details [here](https://github.com/waku-org/specs/pull/73)
|
||||||
|
|
||||||
See [EchoBot](./examples/bot_echo.nim) for a minimal client side usage example.
|
See [EchoBot](./examples/bot_echo.nim) for a minimal client side usage example.
|
||||||
|
See [Client](./src/chat/client.nim) for the main entry point to the SDK
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
@ -17,8 +17,8 @@ make all
|
|||||||
# Run tests
|
# Run tests
|
||||||
make tests
|
make tests
|
||||||
|
|
||||||
# Run the Text Interface
|
# Run an example of two clients communicating
|
||||||
./build/tui --name=<unique_id>
|
./build/pingpong
|
||||||
```
|
```
|
||||||
|
|
||||||
## Details
|
## Details
|
||||||
|
|||||||
@ -3,26 +3,23 @@
|
|||||||
import chronicles
|
import chronicles
|
||||||
import chronos
|
import chronos
|
||||||
|
|
||||||
import chat_sdk
|
import chat
|
||||||
import content_types
|
import content_types
|
||||||
|
|
||||||
import ./tui/persistence # Temporary Workaround for PeerDiscovery
|
|
||||||
|
|
||||||
proc main() {.async.} =
|
proc main() {.async.} =
|
||||||
|
|
||||||
let cfg = await getCfg("EchoBot")
|
|
||||||
let dsConfig = DefaultConfig()
|
let dsConfig = DefaultConfig()
|
||||||
let ident = createIdentity("EchoBot")
|
let ident = createIdentity("EchoBot")
|
||||||
var chatClient = newClient(dsConfig, ident)
|
var chatClient = newClient(dsConfig, ident)
|
||||||
|
|
||||||
chatClient.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
chatClient.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
||||||
info "New Message: ", convoId = convo.id(), msg= msg
|
info "New Message: ", convoId = convo.id(), msg= msg
|
||||||
discard await convo.sendMessage(chatClient.ds, msg.content)
|
discard await convo.sendMessage(msg.content)
|
||||||
)
|
)
|
||||||
|
|
||||||
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
|
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||||
info "New Conversation Initiated: ", convoId = convo.id()
|
info "New Conversation Initiated: ", convoId = convo.id()
|
||||||
discard await convo.sendMessage(chatClient.ds, initTextFrame("Hello!").toContentFrame())
|
discard await convo.sendMessage(initTextFrame("Hello!").toContentFrame().encode())
|
||||||
)
|
)
|
||||||
|
|
||||||
await chatClient.start()
|
await chatClient.start()
|
||||||
|
|||||||
@ -1,66 +0,0 @@
|
|||||||
import
|
|
||||||
std/[options, strutils, sequtils, net],
|
|
||||||
chronicles,
|
|
||||||
chronos,
|
|
||||||
metrics,
|
|
||||||
system/ansi_c,
|
|
||||||
libp2p/crypto/crypto
|
|
||||||
import waku as waku_module
|
|
||||||
|
|
||||||
logScope:
|
|
||||||
topics = "waku example main"
|
|
||||||
|
|
||||||
const git_version* {.strdefine.} = "n/a"
|
|
||||||
|
|
||||||
proc mm() {.async.} =
|
|
||||||
await sleepAsync(1000)
|
|
||||||
echo "Hello, world!"
|
|
||||||
|
|
||||||
when isMainModule:
|
|
||||||
const versionString = "version / git commit hash: " & waku.git_version
|
|
||||||
|
|
||||||
var wakuNodeConf = WakuNodeConf.load(version = versionString).valueOr:
|
|
||||||
error "failure while loading the configuration", error = error
|
|
||||||
quit(QuitFailure)
|
|
||||||
|
|
||||||
## Also called within Waku.new. The call to startRestServerEssentials needs the following line
|
|
||||||
logging.setupLog(wakuNodeConf.logLevel, wakuNodeConf.logFormat)
|
|
||||||
|
|
||||||
let conf = wakuNodeConf.toWakuConf().valueOr:
|
|
||||||
error "Waku configuration failed", error = error
|
|
||||||
quit(QuitFailure)
|
|
||||||
|
|
||||||
var waku = (waitFor Waku.new(conf)).valueOr:
|
|
||||||
error "Waku initialization failed", error = error
|
|
||||||
quit(QuitFailure)
|
|
||||||
|
|
||||||
(waitFor startWaku(addr waku)).isOkOr:
|
|
||||||
error "Starting waku failed", error = error
|
|
||||||
quit(QuitFailure)
|
|
||||||
|
|
||||||
debug "Setting up shutdown hooks"
|
|
||||||
proc asyncStopper(waku: Waku) {.async: (raises: [Exception]).} =
|
|
||||||
await waku.stop()
|
|
||||||
quit(QuitSuccess)
|
|
||||||
|
|
||||||
# Handle Ctrl-C SIGINT
|
|
||||||
proc handleCtrlC() {.noconv.} =
|
|
||||||
when defined(windows):
|
|
||||||
# workaround for https://github.com/nim-lang/Nim/issues/4057
|
|
||||||
setupForeignThreadGc()
|
|
||||||
notice "Shutting down after receiving SIGINT"
|
|
||||||
asyncSpawn asyncStopper(waku)
|
|
||||||
|
|
||||||
setControlCHook(handleCtrlC)
|
|
||||||
|
|
||||||
# Handle SIGTERM
|
|
||||||
when defined(posix):
|
|
||||||
proc handleSigterm(signal: cint) {.noconv.} =
|
|
||||||
notice "Shutting down after receiving SIGTERM"
|
|
||||||
asyncSpawn asyncStopper(waku)
|
|
||||||
|
|
||||||
c_signal(ansi_c.SIGTERM, handleSigterm)
|
|
||||||
|
|
||||||
info "Node setup complete"
|
|
||||||
|
|
||||||
runForever()
|
|
||||||
@ -14,3 +14,4 @@ export client, conversations, identity, links, waku_client
|
|||||||
export MessageId
|
export MessageId
|
||||||
|
|
||||||
export toHex
|
export toHex
|
||||||
|
export crypto.`$`
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import results
|
|||||||
import utils
|
import utils
|
||||||
|
|
||||||
export PublicKey, PrivateKey, bytes, createRandomKey, loadPrivateKeyFromBytes, loadPublicKeyFromBytes,
|
export PublicKey, PrivateKey, bytes, createRandomKey, loadPrivateKeyFromBytes, loadPublicKeyFromBytes,
|
||||||
getPublicKey, Dh, Result, get_addr
|
getPublicKey, Dh, Result, get_addr, `$`
|
||||||
|
|
||||||
|
|
||||||
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
|
proc encrypt_plain*[T: EncryptableTypes](frame: T): EncryptedPayload =
|
||||||
|
|||||||
@ -15,8 +15,7 @@ import
|
|||||||
errors,
|
errors,
|
||||||
identity,
|
identity,
|
||||||
proto_types,
|
proto_types,
|
||||||
types,
|
types
|
||||||
utils
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "chat inbox"
|
topics = "chat inbox"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user