mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
create waku_example
This commit is contained in:
parent
7f07a042f0
commit
a307bf225d
83
.gitignore
vendored
83
.gitignore
vendored
@ -4,3 +4,86 @@
|
|||||||
*.dSYM
|
*.dSYM
|
||||||
nimble.develop
|
nimble.develop
|
||||||
nimble.paths
|
nimble.paths
|
||||||
|
|
||||||
|
|
||||||
|
/nimcache
|
||||||
|
|
||||||
|
# Executables shall be put in an ignored build/ directory
|
||||||
|
/build
|
||||||
|
|
||||||
|
# Nimble packages
|
||||||
|
/vendor/.nimble
|
||||||
|
|
||||||
|
# Generated Files
|
||||||
|
*.generated.nim
|
||||||
|
|
||||||
|
# ntags/ctags output
|
||||||
|
/tags
|
||||||
|
|
||||||
|
# a symlink that can't be added to the repo because of Windows
|
||||||
|
/nim_chat_poc.nims
|
||||||
|
|
||||||
|
# Ignore dynamic, static libs and libtool archive files
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Ignore simulation generated metrics files
|
||||||
|
/metrics/prometheus
|
||||||
|
/metrics/waku-sim-all-nodes-grafana-dashboard.json
|
||||||
|
|
||||||
|
*.log
|
||||||
|
/package-lock.json
|
||||||
|
/package.json
|
||||||
|
node_modules/
|
||||||
|
/.update.timestamp
|
||||||
|
|
||||||
|
# Ignore Jetbrains IDE files
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# ignore vscode files
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# RLN / keystore
|
||||||
|
rlnKeystore.json
|
||||||
|
*.tar.gz
|
||||||
|
|
||||||
|
# Nimbus Build System
|
||||||
|
nimbus-build-system.paths
|
||||||
|
|
||||||
|
# sqlite db
|
||||||
|
*.db
|
||||||
|
*.db-shm
|
||||||
|
*.db-wal
|
||||||
|
*.sqlite3
|
||||||
|
*.sqlite3-shm
|
||||||
|
*.sqlite3-wal
|
||||||
|
|
||||||
|
/examples/nodejs/build/
|
||||||
|
/examples/rust/target/
|
||||||
|
|
||||||
|
|
||||||
|
# Coverage
|
||||||
|
coverage_html_report/
|
||||||
|
*.info
|
||||||
|
|
||||||
|
# Wildcard
|
||||||
|
*.ignore.*
|
||||||
|
|
||||||
|
# Ignore all possible node runner directories
|
||||||
|
**/keystore/
|
||||||
|
**/rln_tree/
|
||||||
|
**/certs/
|
||||||
|
|
||||||
|
# simple qt example
|
||||||
|
.qmake.stash
|
||||||
|
main-qt
|
||||||
|
waku_handler.moc.cpp
|
||||||
|
|
||||||
|
# Nix build result
|
||||||
|
result
|
||||||
|
|||||||
15
Makefile
15
Makefile
@ -1,5 +1,6 @@
|
|||||||
export BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
export BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
||||||
export EXCLUDED_NIM_PACKAGES := vendor/nim-dnsdisc/vendor
|
export EXCLUDED_NIM_PACKAGES := vendor/nwaku/vendor/nim-dnsdisc/vendor \
|
||||||
|
vendor/nwaku/vendor/nimbus-build-system
|
||||||
LINK_PCRE := 0
|
LINK_PCRE := 0
|
||||||
FORMAT_MSG := "\\x1B[95mFormatting:\\x1B[39m"
|
FORMAT_MSG := "\\x1B[95mFormatting:\\x1B[39m"
|
||||||
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
|
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
|
||||||
@ -60,14 +61,22 @@ NIM_PARAMS := $(NIM_PARAMS) -d:git_version=\"$(GIT_VERSION)\"
|
|||||||
.PHONY: build-waku-librln
|
.PHONY: build-waku-librln
|
||||||
|
|
||||||
build-waku-librln:
|
build-waku-librln:
|
||||||
make -C vendor/nwaku librln
|
@echo "Start building waku librln"
|
||||||
|
$(MAKE) -C vendor/nwaku librln
|
||||||
|
$(eval NIM_PARAMS += --passL:./vendor/nwaku/librln_v0.7.0.a --passL:-lm)
|
||||||
|
@echo "Completed building librln"
|
||||||
|
|
||||||
|
build-waku-nat:
|
||||||
|
@echo "Start building waku nat-libs"
|
||||||
|
$(MAKE) -C vendor/nwaku nat-libs
|
||||||
|
@echo "Completed building nat-libs"
|
||||||
|
|
||||||
##########
|
##########
|
||||||
## Example ##
|
## Example ##
|
||||||
##########
|
##########
|
||||||
.PHONY: waku_example
|
.PHONY: waku_example
|
||||||
|
|
||||||
waku_example: | build-waku-librln nim_chat_poc.nims
|
waku_example: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
\
|
\
|
||||||
$(ENV_SCRIPT) nim waku_example $(NIM_PARAMS) nim_chat_poc.nims
|
$(ENV_SCRIPT) nim waku_example $(NIM_PARAMS) nim_chat_poc.nims
|
||||||
|
|||||||
66
examples/waku_example.nim
Normal file
66
examples/waku_example.nim
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
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()
|
||||||
@ -9,20 +9,19 @@ bin = @["nim_chat_poc"]
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 2.2.4"
|
requires "nim >= 2.2.4",
|
||||||
|
"protobuf_serialization",
|
||||||
requires "protobuf_serialization"
|
"secp256k1",
|
||||||
requires "secp256k1"
|
"blake2",
|
||||||
requires "blake2"
|
"chronicles",
|
||||||
requires "chronicles"
|
"libp2p",
|
||||||
requires "libp2p"
|
"nimchacha20poly1305", # TODO: remove
|
||||||
requires "nimchacha20poly1305" # TODO: remove
|
"confutils",
|
||||||
requires "confutils"
|
"eth",
|
||||||
requires "eth"
|
"regex",
|
||||||
requires "regex"
|
"web3",
|
||||||
requires "web3"
|
"https://github.com/jazzz/nim-sds#exports",
|
||||||
requires "https://github.com/jazzz/nim-sds#exports"
|
"waku"
|
||||||
requires "naawaku"
|
|
||||||
|
|
||||||
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
||||||
if not dirExists "build":
|
if not dirExists "build":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user