Merge branch 'gcsafe'

This commit is contained in:
Ștefan Talpalaru 2019-04-23 20:50:13 +02:00
commit db11331df8
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
2 changed files with 7 additions and 7 deletions

View File

@ -207,7 +207,7 @@ proc recvNeighbours(d: DiscoveryProtocol, node: Node,
neighbours.add(newNode(pk, Address(ip: ip, udpPort: udpPort, tcpPort: tcpPort)))
d.kademlia.recvNeighbours(node, neighbours)
proc recvFindNode(d: DiscoveryProtocol, node: Node, payload: Bytes) {.inline.} =
proc recvFindNode(d: DiscoveryProtocol, node: Node, payload: Bytes) {.inline, gcsafe.} =
let rlp = rlpFromBytes(payload.toRange)
trace "<<< find_node from ", node
let rng = rlp.listElem(0).toBytes
@ -219,7 +219,7 @@ proc expirationValid(rlpEncodedPayload: seq[byte]): bool {.inline.} =
let expiration = rlp.listElem(rlp.listLen - 1).toInt(uint32)
result = epochTime() <= expiration.float
proc receive(d: DiscoveryProtocol, a: Address, msg: Bytes) =
proc receive(d: DiscoveryProtocol, a: Address, msg: Bytes) {.gcsafe.} =
var msgHash: MDigest[256]
if validateMsgHash(msg, msgHash):
var remotePubkey: PublicKey

View File

@ -240,7 +240,7 @@ proc newKademliaProtocol*[Wire](thisNode: Node,
proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async.}
proc updateRoutingTable(k: KademliaProtocol, n: Node) =
proc updateRoutingTable(k: KademliaProtocol, n: Node) {.gcsafe.} =
## Update the routing table entry for the given node.
let evictionCandidate = k.routing.addNode(n)
if not evictionCandidate.isNil:
@ -250,7 +250,7 @@ proc updateRoutingTable(k: KademliaProtocol, n: Node) =
# replacement cache.
asyncCheck k.bond(evictionCandidate)
proc doSleep(p: proc()) {.async.} =
proc doSleep(p: proc() {.gcsafe.}) {.async, gcsafe.} =
await sleepAsync(REQUEST_TIMEOUT)
p()
@ -275,7 +275,7 @@ proc ping(k: KademliaProtocol, n: Node): seq[byte] =
doAssert(n != k.thisNode)
result = k.wire.sendPing(n)
proc waitPing(k: KademliaProtocol, n: Node): Future[bool] =
proc waitPing(k: KademliaProtocol, n: Node): Future[bool] {.gcsafe.} =
result = newFuture[bool]("waitPing")
doAssert(n notin k.pingFutures)
k.pingFutures[n] = result
@ -317,7 +317,7 @@ proc populateNotFullBuckets(k: KademliaProtocol) =
for node in bucket.replacementCache:
asyncCheck k.bond(node)
proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async.} =
proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async, gcsafe.} =
## Bond with the given node.
##
## Bonding consists of pinging the node, waiting for a pong and maybe a ping as well.
@ -469,7 +469,7 @@ proc recvNeighbours*(k: KademliaProtocol, remote: Node, neighbours: seq[Node]) =
else:
trace "Unexpected neighbours, probably came too late", remote
proc recvFindNode*(k: KademliaProtocol, remote: Node, nodeId: NodeId) =
proc recvFindNode*(k: KademliaProtocol, remote: Node, nodeId: NodeId) {.gcsafe.} =
if remote notin k.routing:
# FIXME: This is not correct; a node we've bonded before may have become unavailable
# and thus removed from self.routing, but once it's back online we should accept