Merge branch 'wrappers' into devel

This commit is contained in:
Ștefan Talpalaru 2019-08-03 14:42:01 +02:00
commit b63bcb2e26
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
13 changed files with 123 additions and 101 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
nimcache
/nimcache
# Executables shall be put in an ignored build/ directory
/build

View File

@ -49,7 +49,7 @@ TOOLS_DIRS := premix tests
# comma-separated values for the "clean" target
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
.PHONY: all $(TOOLS) deps sanity-checks github-ssh build-nim update status ntags ctags nimbus testsuite test clean mrproper fetch-dlls test-libp2p-daemon nat-libs libminiupnpc.a libnatpmp.a go-checks
.PHONY: all $(TOOLS) deps sanity-checks github-ssh build-nim update status ntags ctags nimbus testsuite test clean mrproper fetch-dlls test-libp2p-daemon nat-libs libminiupnpc.a libnatpmp.a go-checks libnimbus.so libnimbus.a wrappers
# default target, because it's the first one that doesn't start with '.'
all: $(TOOLS) nimbus
@ -128,7 +128,7 @@ test-reproducibility:
# usual cleaning
clean:
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*.exe} vendor/go/bin \
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*.exe,*.so,*.so.0,*_wrapper_test} vendor/go/bin \
$(NIMBLE_DIR) $(NIM_BINARY) $(NIM_DIR)/nimcache nimcache
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc clean $(HANDLE_OUTPUT)
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp clean $(HANDLE_OUTPUT)
@ -197,6 +197,29 @@ test-libp2p-daemon: | vendor/go/bin/p2pd deps
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) tests/testdaemon.nim && \
rm -f tests/testdaemon
libnimbus.so: | build deps nat-libs
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim c --app:lib --noMain --nimcache:nimcache/libnimbus $(NIM_PARAMS) -o:build/$@.0 wrappers/libnimbus.nim && \
rm -f build/$@ && \
ln -s $@.0 build/$@
wrappers: | build deps nat-libs libnimbus.so go-checks
echo -e $(BUILD_MSG) "build/C_wrapper_example" && \
$(CC) wrappers/wrapper_example.c -Wl,-rpath,'$$ORIGIN' -Lbuild -lnimbus -lm -g -o build/C_wrapper_example
echo -e $(BUILD_MSG) "build/go_wrapper_example" && \
go build -linkshared -o build/go_wrapper_example wrappers/wrapper_example.go
libnimbus.a: | build deps nat-libs
echo -e $(BUILD_MSG) "build/$@" && \
rm -f build/$@ && \
$(ENV_SCRIPT) nim c --app:staticlib --noMain --nimcache:nimcache/libnimbus $(NIM_PARAMS) -o:build/$@ wrappers/libnimbus.nim
wrappers-static: | build deps nat-libs libnimbus.a go-checks
echo -e $(BUILD_MSG) "build/C_wrapper_example_static" && \
$(CC) wrappers/wrapper_example.c -static -pthread -Lbuild -lnimbus -lm -ldl -g -o build/C_wrapper_example_static
echo -e $(BUILD_MSG) "build/go_wrapper_example_static" && \
go build -ldflags "-linkmode external -extldflags '-static -ldl'" -o build/go_wrapper_example_static wrappers/wrapper_example.go
# https://bitbucket.org/nimcontrib/ntags/ - currently fails with "out of memory"
ntags:
ntags -R .

View File

@ -1,2 +0,0 @@
status_api_test
libnimbus_api.so

View File

@ -1,7 +0,0 @@
This folder contains an experimental C API for using parts of the nimbus
code from C/go in the status console client:
https://github.com/status-im/status-console-client/
It serves mainly as a proof-of-concept for now - there are several unresolved
issues surrounding threading, inter-language communication, callbacks etc.

View File

@ -1,2 +0,0 @@
#!/bin/sh
go build --ldflags '-extldflags "-static"' -o test main.go

View File

@ -1,12 +0,0 @@
#!/bin/sh
echo "[Cleaning up caches...]"
rm -rf nimcache/
rm -f libnimbus_api.so
# ../env.sh nim c --opt:speed --lineTrace:off --verbosity:2 status_api
# gcc status_api.c ./libnimbus_api.so -lm -o xx
# debug info
../../env.sh nim c --debuginfo --opt:speed --lineTrace:off --verbosity:2 status_api
gcc status_api.c ./libnimbus_api.so -lm -g -o status_api_test

View File

@ -1,4 +0,0 @@
-app:lib
o:"libnimbus_api.so"
noMain
-d:"chronicles_sinks=textlines"

View File

@ -752,7 +752,8 @@ LOGGING AND DEBUGGING OPTIONS:
$ord(defaultNetwork)
]
proc processArguments*(msg: var string): ConfigStatus =
when declared(os.paramCount): # not available with `--app:lib`
proc processArguments*(msg: var string): ConfigStatus =
## Process command line argument and update `NimbusConfiguration`.
let config = getConfiguration()

27
wrappers/README.md Normal file
View File

@ -0,0 +1,27 @@
This folder contains an experimental C wrapper for using parts of the Nimbus
code from C/Go in the Status console client:
https://github.com/status-im/status-console-client/
It serves mainly as a proof-of-concept for now - there are several unresolved
issues surrounding threading, inter-language communication, callbacks etc.
To build the wrappers and the example programs, run from the top level directory:
```bash
make wrappers
```
Now you can run the example programs:
```bash
build/C_wrapper_example
build/go_wrapper_example
```
To build statically linked versions:
```bash
make wrappers-static
```

View File

@ -1,6 +1,13 @@
#ifndef __LIBNIMBUS_H__
#define __LIBNIMBUS_H__
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint8_t* decoded;
size_t decodedLen;
@ -30,3 +37,10 @@ void nimbus_poll();
void nimbus_post(const char* channel, const char* payload);
void nimbus_subscribe(const char* channel, received_msg_handler msg);
#ifdef __cplusplus
}
#endif
#endif //__LIBNIMBUS_H__

View File

@ -12,7 +12,7 @@ import
nimcrypto/[bcmode, hmac, rijndael, pbkdf2, sha2, sysrand, utils, keccak, hash],
eth/[keys, rlp, p2p], eth/p2p/rlpx_protocols/[whisper_protocol],
eth/p2p/[discovery, enode, peer_pool], chronicles,
../config
../nimbus/config
type
CReceivedMessage* = object
@ -28,22 +28,6 @@ proc `$`*(digest: SymKey): string =
for c in digest: result &= hexChar(c.byte)
const
# Can't import config.nim from here..
# TODO: refactor in nimbus, then move this.
MainnetBootnodes = [
# Ethereum Foundation Go Bootnodes
"enode://d860a01f9722d78051619d1e2351aba3f43f943f6f00718d1b9baa4101932a1f5011f16bb2b1bb35db20d6fe28fa0bf09636d26a87d31de9ec6203eeedb1f666@18.138.108.67:30303", # bootnode-aws-ap-southeast-1-001
"enode://22a8232c3abc76a16ae9d6c3b164f98775fe226f0917b0ca871128a74a8e9630b458460865bab457221f1d448dd9791d24c4e5d88786180ac185df813a68d4de@3.209.45.79:30303", # bootnode-aws-us-east-1-001
"enode://ca6de62fce278f96aea6ec5a2daadb877e51651247cb96ee310a318def462913b653963c155a0ef6c7d50048bba6e6cea881130857413d9f50a621546b590758@34.255.23.113:30303", # bootnode-aws-eu-west-1-001
"enode://279944d8dcd428dffaa7436f25ca0ca43ae19e7bcf94a8fb7d1641651f92d121e972ac2e8f381414b80cc8e5555811c2ec6e1a99bb009b3f53c4c69923e11bd8@35.158.244.151:30303", # bootnode-aws-eu-central-1-001
"enode://8499da03c47d637b20eee24eec3c356c9a2e6148d6fe25ca195c7949ab8ec2c03e3556126b0d7ed644675e78c4318b08691b7b57de10e5f0d40d05b09238fa0a@52.187.207.27:30303", # bootnode-azure-australiaeast-001
"enode://103858bdb88756c71f15e9b5e09b56dc1be52f0a5021d46301dbbfb7e130029cc9d0d6f73f693bc29b665770fff7da4d34f3c6379fe12721b5d7a0bcb5ca1fc1@191.234.162.198:30303", # bootnode-azure-brazilsouth-001
"enode://715171f50508aba88aecd1250af392a45a330af91d7b90701c436b618c86aaa1589c9184561907bebbb56439b8f8787bc01f49a7c77276c58c1b09822d75e8e8@52.231.165.108:30303", # bootnode-azure-koreasouth-001
"enode://5d6d7cd20d6da4bb83a1d28cadb5d409b64edf314c0335df658c1a54e32c7c4a7ab7823d57c39b6a757556e68ff1df17c748b698544a55cb488b52479a92b60f@104.42.217.25:30303", # bootnode-azure-westus-001
# Ethereum Foundation C++ Bootnodes
"enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303" # DE
]
# Whisper nodes taken from:
# curl -s https://raw.githubusercontent.com/status-im/status-react/develop/resources/config/fleets.json | jq '"\"" + .fleets["eth.beta"].whisper[] + "\","' -r
WhisperNodes* = [

View File

@ -4,7 +4,7 @@
#include <unistd.h>
#include <time.h>
#include "status_api.h"
#include "libnimbus.h"
void NimMain();

View File

@ -6,8 +6,8 @@ import (
"time"
)
// #cgo LDFLAGS: /home/oskarth/git/nimbus/nimbus/libnimbus_api.so -lm
// #include "libnim.h"
// #cgo LDFLAGS: -Wl,-rpath,'$ORIGIN' -L${SRCDIR}/../build -lnimbus -lm
// #include "libnimbus.h"
import "C"
// Arrange that main.main runs on main thread.