mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-26 02:45:29 +00:00
Remove the ForeightThreadGC as the teardown was used faulty + lets make it explicit that this should be run only on 1 thread
This commit is contained in:
parent
e5eeecb3c9
commit
11a24885a5
@ -111,8 +111,6 @@ proc subscribeChannel(
|
|||||||
# notice "no luck parsing", message=getCurrentExceptionMsg()
|
# notice "no luck parsing", message=getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc nimbus_start(port: uint16 = 30303) {.exportc.} =
|
proc nimbus_start(port: uint16 = 30303) {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
let address = Address(
|
let address = Address(
|
||||||
udpPort: port.Port, tcpPort: port.Port, ip: parseIpAddress("0.0.0.0"))
|
udpPort: port.Port, tcpPort: port.Port, ip: parseIpAddress("0.0.0.0"))
|
||||||
|
|
||||||
@ -140,20 +138,12 @@ proc nimbus_start(port: uint16 = 30303) {.exportc.} =
|
|||||||
|
|
||||||
asyncCheck node.peerPool.connectToNode(whisperNode)
|
asyncCheck node.peerPool.connectToNode(whisperNode)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_poll() {.exportc.} =
|
proc nimbus_poll() {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
poll()
|
poll()
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_join_public_chat(channel: cstring,
|
proc nimbus_join_public_chat(channel: cstring,
|
||||||
handler: proc (msg: ptr CReceivedMessage)
|
handler: proc (msg: ptr CReceivedMessage)
|
||||||
{.gcsafe, cdecl.}) {.exportc.} =
|
{.gcsafe, cdecl.}) {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
if handler.isNil:
|
if handler.isNil:
|
||||||
subscribeChannel($channel, nil)
|
subscribeChannel($channel, nil)
|
||||||
else:
|
else:
|
||||||
@ -172,13 +162,9 @@ proc nimbus_join_public_chat(channel: cstring,
|
|||||||
|
|
||||||
subscribeChannel($channel, c_handler)
|
subscribeChannel($channel, c_handler)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
# TODO: Add signing key as parameter
|
# TODO: Add signing key as parameter
|
||||||
# TODO: How would we do key management? In nimbus (like in rpc) or in status go?
|
# TODO: How would we do key management? In nimbus (like in rpc) or in status go?
|
||||||
proc nimbus_post_public(channel: cstring, payload: cstring) {.exportc.} =
|
proc nimbus_post_public(channel: cstring, payload: cstring) {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
let encPrivateKey = initPrivateKey("5dc5381cae54ba3174dc0d46040fe11614d0cc94d41185922585198b4fcef9d3")
|
let encPrivateKey = initPrivateKey("5dc5381cae54ba3174dc0d46040fe11614d0cc94d41185922585198b4fcef9d3")
|
||||||
|
|
||||||
var ctx: HMAC[sha256]
|
var ctx: HMAC[sha256]
|
||||||
@ -199,97 +185,65 @@ proc nimbus_post_public(channel: cstring, payload: cstring) {.exportc.} =
|
|||||||
payload = npayload,
|
payload = npayload,
|
||||||
powTarget = 0.002)
|
powTarget = 0.002)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_add_peer(nodeId: cstring) {.exportc.} =
|
proc nimbus_add_peer(nodeId: cstring) {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var whisperENode: ENode
|
var whisperENode: ENode
|
||||||
discard initENode($nodeId, whisperENode)
|
discard initENode($nodeId, whisperENode)
|
||||||
var whisperNode = newNode(whisperENode)
|
var whisperNode = newNode(whisperENode)
|
||||||
|
|
||||||
asyncCheck node.peerPool.connectToNode(whisperNode)
|
asyncCheck node.peerPool.connectToNode(whisperNode)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
# Whisper API (Similar to Whisper RPC API)
|
# Whisper API (Similar to Whisper RPC API)
|
||||||
# Mostly an example for now, lots of things to fix if continued like this.
|
# Mostly an example for now, lots of things to fix if continued like this.
|
||||||
|
|
||||||
proc nimbus_string_to_topic(s: cstring): CTopic {.exportc.} =
|
proc nimbus_string_to_topic(s: cstring): CTopic {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
let hash = digest(keccak256, $s)
|
let hash = digest(keccak256, $s)
|
||||||
for i in 0..<4:
|
for i in 0..<4:
|
||||||
result.topic[i] = hash.data[i]
|
result.topic[i] = hash.data[i]
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
# Asymmetric Keys API
|
# Asymmetric Keys API
|
||||||
|
|
||||||
proc nimbus_new_keypair(): cstring {.exportc.} =
|
proc nimbus_new_keypair(): cstring {.exportc.} =
|
||||||
## It is important that the caller makes a copy of the returned cstring before
|
## It is important that the caller makes a copy of the returned cstring before
|
||||||
## doing any other API calls.
|
## doing any other API calls.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
result = generateRandomID()
|
result = generateRandomID()
|
||||||
whisperKeys.asymKeys.add($result, newKeyPair())
|
whisperKeys.asymKeys.add($result, newKeyPair())
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_add_keypair(key: ptr PrivateKey):
|
proc nimbus_add_keypair(key: ptr PrivateKey):
|
||||||
cstring {.exportc.} =
|
cstring {.exportc.} =
|
||||||
## It is important that the caller makes a copy of the returned cstring before
|
## It is important that the caller makes a copy of the returned cstring before
|
||||||
## doing any other API calls.
|
## doing any other API calls.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
result = generateRandomID()
|
result = generateRandomID()
|
||||||
|
|
||||||
# Creating a KeyPair here does a copy of the key and so does the add
|
# Creating a KeyPair here does a copy of the key and so does the add
|
||||||
whisperKeys.asymKeys.add($result, KeyPair(seckey: key[],
|
whisperKeys.asymKeys.add($result, KeyPair(seckey: key[],
|
||||||
pubkey: key[].getPublicKey()))
|
pubkey: key[].getPublicKey()))
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_delete_keypair(id: cstring): bool {.exportc.} =
|
proc nimbus_delete_keypair(id: cstring): bool {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var unneeded: KeyPair
|
var unneeded: KeyPair
|
||||||
result = whisperKeys.asymKeys.take($id, unneeded)
|
result = whisperKeys.asymKeys.take($id, unneeded)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_get_private_key(id: cstring, privateKey: ptr PrivateKey):
|
proc nimbus_get_private_key(id: cstring, privateKey: ptr PrivateKey):
|
||||||
bool {.exportc.} =
|
bool {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
privateKey[] = whisperKeys.asymkeys[$id].seckey
|
privateKey[] = whisperKeys.asymkeys[$id].seckey
|
||||||
result = true
|
result = true
|
||||||
except KeyError:
|
except KeyError:
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
# Symmetric Keys API
|
# Symmetric Keys API
|
||||||
|
|
||||||
proc nimbus_add_symkey(key: ptr SymKey): cstring {.exportc.} =
|
proc nimbus_add_symkey(key: ptr SymKey): cstring {.exportc.} =
|
||||||
## It is important that the caller makes a copy of the returned cstring before
|
## It is important that the caller makes a copy of the returned cstring before
|
||||||
## doing any other API calls.
|
## doing any other API calls.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
result = generateRandomID().cstring
|
result = generateRandomID().cstring
|
||||||
|
|
||||||
# Copy of key happens at add
|
# Copy of key happens at add
|
||||||
whisperKeys.symKeys.add($result, key[])
|
whisperKeys.symKeys.add($result, key[])
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_add_symkey_from_password(password: cstring):
|
proc nimbus_add_symkey_from_password(password: cstring):
|
||||||
cstring {.exportc.} =
|
cstring {.exportc.} =
|
||||||
## It is important that the caller makes a copy of the returned cstring before
|
## It is important that the caller makes a copy of the returned cstring before
|
||||||
## doing any other API calls.
|
## doing any other API calls.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var ctx: HMAC[sha256]
|
var ctx: HMAC[sha256]
|
||||||
var symKey: SymKey
|
var symKey: SymKey
|
||||||
if pbkdf2(ctx, $password, "", 65356, symKey) != sizeof(SymKey):
|
if pbkdf2(ctx, $password, "", 65356, symKey) != sizeof(SymKey):
|
||||||
@ -299,36 +253,24 @@ proc nimbus_add_symkey_from_password(password: cstring):
|
|||||||
|
|
||||||
whisperKeys.symKeys.add($result, symKey)
|
whisperKeys.symKeys.add($result, symKey)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_delete_symkey(id: cstring): bool {.exportc.} =
|
proc nimbus_delete_symkey(id: cstring): bool {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var unneeded: SymKey
|
var unneeded: SymKey
|
||||||
result = whisperKeys.symKeys.take($id, unneeded)
|
result = whisperKeys.symKeys.take($id, unneeded)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_get_symkey(id: cstring, symKey: ptr SymKey):
|
proc nimbus_get_symkey(id: cstring, symKey: ptr SymKey):
|
||||||
bool {.exportc.} =
|
bool {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
symKey[] = whisperKeys.symkeys[$id]
|
symKey[] = whisperKeys.symkeys[$id]
|
||||||
result = true
|
result = true
|
||||||
except KeyError:
|
except KeyError:
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
# Whisper message posting and receiving API
|
# Whisper message posting and receiving API
|
||||||
|
|
||||||
proc nimbus_post(message: ptr CPostMessage): bool {.exportc.} =
|
proc nimbus_post(message: ptr CPostMessage): bool {.exportc.} =
|
||||||
## Encryption is not mandatory.
|
## Encryption is not mandatory.
|
||||||
## A symKey, an asymKey, or nothing can be provided. asymKey has precedence.
|
## A symKey, an asymKey, or nothing can be provided. asymKey has precedence.
|
||||||
## Providing a payload is mandatory.
|
## Providing a payload is mandatory.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var
|
var
|
||||||
sigPrivKey: Option[PrivateKey]
|
sigPrivKey: Option[PrivateKey]
|
||||||
asymKey: Option[PublicKey]
|
asymKey: Option[PublicKey]
|
||||||
@ -366,15 +308,11 @@ proc nimbus_post(message: ptr CPostMessage): bool {.exportc.} =
|
|||||||
powTime = message.powTime,
|
powTime = message.powTime,
|
||||||
powTarget = message.powTarget)
|
powTarget = message.powTarget)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_subscribe_filter(options: ptr CFilterOptions,
|
proc nimbus_subscribe_filter(options: ptr CFilterOptions,
|
||||||
handler: proc (msg: ptr CReceivedMessage, udata: pointer) {.gcsafe, cdecl.},
|
handler: proc (msg: ptr CReceivedMessage, udata: pointer) {.gcsafe, cdecl.},
|
||||||
udata: pointer = nil): cstring {.exportc.} =
|
udata: pointer = nil): cstring {.exportc.} =
|
||||||
## In case of a passed handler, the received msg needs to be copied before the
|
## In case of a passed handler, the received msg needs to be copied before the
|
||||||
## handler ends.
|
## handler ends.
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
var
|
var
|
||||||
src: Option[PublicKey]
|
src: Option[PublicKey]
|
||||||
symKey: Option[SymKey]
|
symKey: Option[SymKey]
|
||||||
@ -422,25 +360,11 @@ proc nimbus_subscribe_filter(options: ptr CFilterOptions,
|
|||||||
# TODO: better to have an "adding" proc here
|
# TODO: better to have an "adding" proc here
|
||||||
traceAsyncErrors node.setBloomFilter(node.filtersToBloom())
|
traceAsyncErrors node.setBloomFilter(node.filtersToBloom())
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_unsubscribe_filter(id: cstring): bool {.exportc.} =
|
proc nimbus_unsubscribe_filter(id: cstring): bool {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
result = node.unsubscribeFilter($id)
|
result = node.unsubscribeFilter($id)
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_get_min_pow(): float64 {.exportc.} =
|
proc nimbus_get_min_pow(): float64 {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
result = node.protocolState(Whisper).config.powRequirement
|
result = node.protocolState(Whisper).config.powRequirement
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
|
||||||
proc nimbus_get_bloom_filter(bloom: ptr Bloom) {.exportc.} =
|
proc nimbus_get_bloom_filter(bloom: ptr Bloom) {.exportc.} =
|
||||||
setupForeignThreadGc()
|
|
||||||
|
|
||||||
bloom[] = node.protocolState(Whisper).config.bloom
|
bloom[] = node.protocolState(Whisper).config.bloom
|
||||||
|
|
||||||
tearDownForeignThreadGc()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user