Add extra options to nimbus_start()

This commit is contained in:
kdeme 2019-11-04 13:56:24 +01:00 committed by zah
parent a8ca7d1d7f
commit 7ac8b98ce9
5 changed files with 15 additions and 11 deletions

View File

@ -56,10 +56,11 @@ typedef void (*received_msg_handler)(received_message* msg, void* udata);
*/
void NimMain();
/** Start Ethereum node with Whisper capability, start discovery and
/** Start Ethereum node with Whisper capability, optionally start discovery and
* connect to Status fleet.
*/
void nimbus_start(uint16_t port);
void nimbus_start(uint16_t port, bool startListening, bool enableDiscovery,
double minPow);
/** Add peers to connect to - must be called after nimbus_start */
void nimbus_add_peer(const char* nodeId);

View File

@ -109,7 +109,9 @@ proc subscribeChannel(
# except:
# notice "no luck parsing", message=getCurrentExceptionMsg()
proc nimbus_start(port: uint16 = 30303) {.exportc.} =
proc nimbus_start(port: uint16, startListening: bool, enableDiscovery: bool,
minPow: float64)
{.exportc.} =
let address = Address(
udpPort: port.Port, tcpPort: port.Port, ip: parseIpAddress("0.0.0.0"))
@ -117,7 +119,7 @@ proc nimbus_start(port: uint16 = 30303) {.exportc.} =
node = newEthereumNode(keys, address, 1, nil, addAllCapabilities = false)
node.addCapability Whisper
node.protocolState(Whisper).config.powRequirement = 0.000001
node.protocolState(Whisper).config.powRequirement = minPow
# TODO: should we start the node with an empty bloomfilter?
# var bloom: Bloom
# node.protocolState(Whisper).config.bloom = bloom
@ -128,14 +130,14 @@ proc nimbus_start(port: uint16 = 30303) {.exportc.} =
discard initENode(nodeId, bootnode)
bootnodes.add(bootnode)
asyncCheck node.connectToNetwork(bootnodes, true, true)
traceAsyncErrors node.connectToNetwork(bootnodes, startListening, enableDiscovery)
# main network has mostly non SHH nodes, so we connect directly to SHH nodes
for nodeId in WhisperNodes:
var whisperENode: ENode
discard initENode(nodeId, whisperENode)
var whisperNode = newNode(whisperENode)
asyncCheck node.peerPool.connectToNode(whisperNode)
traceAsyncErrors node.peerPool.connectToNode(whisperNode)
proc nimbus_poll() {.exportc.} =
poll()
@ -189,7 +191,7 @@ proc nimbus_add_peer(nodeId: cstring) {.exportc.} =
discard initENode($nodeId, whisperENode)
var whisperNode = newNode(whisperENode)
asyncCheck node.peerPool.connectToNode(whisperNode)
traceAsyncErrors node.peerPool.connectToNode(whisperNode)
# Whisper API (Similar to Whisper RPC API)
# Mostly an example for now, lots of things to fix if continued like this.

View File

@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
time_t lastmsg;
NimMain();
nimbus_start(30303);
nimbus_start(30303, false, false, 0.002);
nimbus_join_public_chat(channel, print_msg);

View File

@ -32,13 +32,14 @@ func poll() {
//export receiveHandler
func receiveHandler(msg *C.received_message) {
fmt.Printf("[nim-status] received message %s\n", C.GoStringN((*C.char)(msg.decoded), (C.int)(msg.decodedLen)) )
receivedMsg := C.GoBytes(unsafe.Pointer(msg.decoded), C.int(msg.decodedLen))
fmt.Printf("[nim-status] received message %s\n", string(receivedMsg))
}
func Start() {
C.NimMain()
fmt.Println("[nim-status] Start Nimbus")
C.nimbus_start(30306)
C.nimbus_start(30306, false, false, 0.002)
peer1 := "enode://2d3e27d7846564f9b964308038dfadd4076e4373ac938e020708ad8819fd4fd90e5eb8314140768f782db704cb313b60707b968f8b61108a6fecd705b041746d@192.168.0.33:30303"
peer2 := "enode://4ea35352702027984a13274f241a56a47854a7fd4b3ba674a596cff917d3c825506431cf149f9f2312a293bb7c2b1cca55db742027090916d01529fe0729643b@206.189.243.178:443"

View File

@ -45,7 +45,7 @@ func receiveHandler(msg *C.received_message, udata unsafe.Pointer) {
func Start() {
C.NimMain()
fmt.Println("[nim-status] Start Nimbus")
C.nimbus_start(30306)
C.nimbus_start(30306, false, false, 0.002)
}
func StatusListenAndPost(channel string) {