Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,88 @@
/waku_vibe_template.dSYM
/nim_chat_poc
*.dSYM
nimble.develop
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
11 changes: 8 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[submodule "vendor/waku"]
path = vendor/waku
url = https://[email protected]/jazzz/nwaku
[submodule "vendor/nimbus-build-system"]
path = vendor/nimbus-build-system
url = https://github.com/status-im/nimbus-build-system.git
[submodule "vendor/nwaku"]
path = vendor/nwaku
url = https://github.com/waku-org/nwaku.git
ignore = untracked
branch = master
86 changes: 86 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
export BUILD_SYSTEM_DIR := vendor/nimbus-build-system
export EXCLUDED_NIM_PACKAGES := vendor/nwaku/vendor/nim-dnsdisc/vendor \
vendor/nwaku/vendor/nimbus-build-system
LINK_PCRE := 0
FORMAT_MSG := "\\x1B[95mFormatting:\\x1B[39m"
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk

ifeq ($(NIM_PARAMS),)
# "variables.mk" was not included, so we update the submodules.
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
.DEFAULT:
+@ echo -e "Git submodules not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \
$(GIT_SUBMODULE_UPDATE); \
echo
# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself:
# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
#
# After restarting, it will execute its original goal, so we don't have to start a child Make here
# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great?

else # "variables.mk" was included. Business as usual until the end of this file.

##########
## Main ##
##########
.PHONY: all update clean

# default target, because it's the first one that doesn't start with '.'
all: | waku_example

test_file := $(word 2,$(MAKECMDGOALS))
define test_name
$(shell echo '$(MAKECMDGOALS)' | cut -d' ' -f3-)
endef

nim_chat_poc.nims:
ln -s nim_chat_poc.nimble $@

update: | update-common
rm -rf nim_chat_poc.nims && \
$(MAKE) nim_chat_poc.nims $(HANDLE_OUTPUT)

clean:
rm -rf build

# must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk

## Possible values: prod; debug
TARGET ?= prod

## Git version
GIT_VERSION ?= $(shell git describe --abbrev=6 --always --tags)
## Compilation parameters. If defined in the CLI the assignments won't be executed
NIM_PARAMS := $(NIM_PARAMS) -d:git_version=\"$(GIT_VERSION)\"

##################
## Dependencies ##
##################
.PHONY: build-waku-librln

build-waku-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 ##
##########
.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

endif


66 changes: 66 additions & 0 deletions examples/waku_example.nim
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 0 additions & 8 deletions initialize.sh

This file was deleted.

16 changes: 0 additions & 16 deletions nim.cfg

This file was deleted.

55 changes: 32 additions & 23 deletions nim_chat_poc.nimble
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
# Package

version = "0.1.0"
author = "jazzz"
description = "An example of the chat sdk in Nim"
license = "MIT"
srcDir = "src"
bin = @["nim_chat_poc"]
version = "0.1.0"
author = "jazzz"
description = "An example of the chat sdk in Nim"
license = "MIT"
srcDir = "src"
bin = @["nim_chat_poc"]

# Dependencies

# Basic build task
task initialize, "Initialize the project after cloning":
exec "./initialize.sh"

requires "nim >= 2.2.4",
"protobuf_serialization",
"secp256k1",
"blake2",
"chronicles",
"libp2p",
"nimchacha20poly1305", # TODO: remove
"confutils",
"eth",
"regex",
"web3",
"https://github.com/jazzz/nim-sds#exports",
"waku"

# Dependencies
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
if not dirExists "build":
mkDir "build"
# allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims"
var extra_params = params
for i in 2 ..< paramCount():
extra_params &= " " & paramStr(i)

requires "nim >= 2.2.4"
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
srcDir & name & ".nim"

requires "protobuf_serialization"
requires "secp256k1"
requires "blake2"
requires "chronicles"
requires "libp2p"
requires "nimchacha20poly1305" # TODO: remove
requires "confutils"
requires "eth"
requires "regex"
requires "web3"
requires "https://github.com/jazzz/nim-sds#exports"
task waku_example, "Build Waku based simple example":
let name = "waku_example"
buildBinary name, "examples/", " -d:chronicles_log_level='TRACE' "
1 change: 1 addition & 0 deletions vendor/nimbus-build-system
Submodule nimbus-build-system added at e6c2c9
1 change: 1 addition & 0 deletions vendor/nwaku
Submodule nwaku added at 41146a
1 change: 0 additions & 1 deletion vendor/waku
Submodule waku deleted from 41bdc3