mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
Remove the use of ByteList in PortalStream and for FoundContent (#937)
This commit is contained in:
parent
3909675f29
commit
d2f56463ce
@ -41,11 +41,11 @@ proc getContent*(n: HistoryNetwork, key: ContentKey):
|
|||||||
|
|
||||||
# When content is found and is in the radius range, store it.
|
# When content is found and is in the radius range, store it.
|
||||||
if content.isSome() and contentInRange:
|
if content.isSome() and contentInRange:
|
||||||
n.contentDB.put(contentId, content.get().asSeq())
|
n.contentDB.put(contentId, content.get())
|
||||||
|
|
||||||
# TODO: for now returning bytes, ultimately it would be nice to return proper
|
# TODO: for now returning bytes, ultimately it would be nice to return proper
|
||||||
# domain types.
|
# domain types.
|
||||||
return content.map(x => x.asSeq())
|
return content
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type HistoryNetwork,
|
T: type HistoryNetwork,
|
||||||
|
@ -41,11 +41,11 @@ proc getContent*(n: StateNetwork, key: ContentKey):
|
|||||||
|
|
||||||
# When content is found on the network and is in the radius range, store it.
|
# When content is found on the network and is in the radius range, store it.
|
||||||
if content.isSome() and contentInRange:
|
if content.isSome() and contentInRange:
|
||||||
n.contentDB.put(contentId, content.get().asSeq())
|
n.contentDB.put(contentId, content.get())
|
||||||
|
|
||||||
# TODO: for now returning bytes, ultimately it would be nice to return proper
|
# TODO: for now returning bytes, ultimately it would be nice to return proper
|
||||||
# domain types.
|
# domain types.
|
||||||
return content.map(x => x.asSeq())
|
return content
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type StateNetwork,
|
T: type StateNetwork,
|
||||||
|
@ -66,7 +66,7 @@ type
|
|||||||
FoundContent* = object
|
FoundContent* = object
|
||||||
case kind*: FoundContentKind
|
case kind*: FoundContentKind
|
||||||
of Content:
|
of Content:
|
||||||
content*: ByteList
|
content*: seq[byte]
|
||||||
of Nodes:
|
of Nodes:
|
||||||
nodes*: seq[Node]
|
nodes*: seq[Node]
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ proc handleFindContent(
|
|||||||
encodeMessage(ContentMessage(
|
encodeMessage(ContentMessage(
|
||||||
contentMessageType: contentType, content: ByteList(content)))
|
contentMessageType: contentType, content: ByteList(content)))
|
||||||
else:
|
else:
|
||||||
let connectionId = p.stream.addContentRequest(srcId, ByteList(content))
|
let connectionId = p.stream.addContentRequest(srcId, content)
|
||||||
|
|
||||||
encodeMessage(ContentMessage(
|
encodeMessage(ContentMessage(
|
||||||
contentMessageType: connectionIdType, connectionId: connectionId))
|
contentMessageType: connectionIdType, connectionId: connectionId))
|
||||||
@ -392,12 +392,12 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList):
|
|||||||
if await readData.withTimeout(p.stream.readTimeout):
|
if await readData.withTimeout(p.stream.readTimeout):
|
||||||
let content = readData.read
|
let content = readData.read
|
||||||
await socket.destroyWait()
|
await socket.destroyWait()
|
||||||
return ok(FoundContent(kind: Content, content: ByteList.init(content)))
|
return ok(FoundContent(kind: Content, content: content))
|
||||||
else:
|
else:
|
||||||
socket.close()
|
socket.close()
|
||||||
return err("Reading data from socket timed out, content request failed")
|
return err("Reading data from socket timed out, content request failed")
|
||||||
of contentType:
|
of contentType:
|
||||||
return ok(FoundContent(kind: Content, content: m.content))
|
return ok(FoundContent(kind: Content, content: m.content.asSeq()))
|
||||||
of enrsType:
|
of enrsType:
|
||||||
let records = recordsFromBytes(m.enrs)
|
let records = recordsFromBytes(m.enrs)
|
||||||
if records.isOk():
|
if records.isOk():
|
||||||
@ -544,7 +544,7 @@ proc lookup*(p: PortalProtocol, target: NodeId): Future[seq[Node]] {.async.} =
|
|||||||
# networks will probably be very similar. Extract lookup function to separate module
|
# networks will probably be very similar. Extract lookup function to separate module
|
||||||
# and make it more generaic
|
# and make it more generaic
|
||||||
proc contentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
|
proc contentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
|
||||||
Future[Option[ByteList]] {.async.} =
|
Future[Option[seq[byte]]] {.async.} =
|
||||||
## Perform a lookup for the given target, return the closest n nodes to the
|
## Perform a lookup for the given target, return the closest n nodes to the
|
||||||
## target. Maximum value for n is `BUCKET_SIZE`.
|
## target. Maximum value for n is `BUCKET_SIZE`.
|
||||||
# `closestNodes` holds the k closest nodes to target found, sorted by distance
|
# `closestNodes` holds the k closest nodes to target found, sorted by distance
|
||||||
@ -614,7 +614,7 @@ proc contentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
|
|||||||
# query?
|
# query?
|
||||||
discard
|
discard
|
||||||
|
|
||||||
return none[ByteList]()
|
return none[seq[byte]]()
|
||||||
|
|
||||||
proc query*(p: PortalProtocol, target: NodeId, k = BUCKET_SIZE): Future[seq[Node]]
|
proc query*(p: PortalProtocol, target: NodeId, k = BUCKET_SIZE): Future[seq[Node]]
|
||||||
{.async.} =
|
{.async.} =
|
||||||
|
@ -27,7 +27,7 @@ type
|
|||||||
ContentRequest = object
|
ContentRequest = object
|
||||||
connectionId: uint16
|
connectionId: uint16
|
||||||
nodeId: NodeId
|
nodeId: NodeId
|
||||||
content: ByteList
|
content: seq[byte]
|
||||||
timeout: Moment
|
timeout: Moment
|
||||||
|
|
||||||
ContentOffer = object
|
ContentOffer = object
|
||||||
@ -74,7 +74,7 @@ proc addContentOffer*(
|
|||||||
return connectionId
|
return connectionId
|
||||||
|
|
||||||
proc addContentRequest*(
|
proc addContentRequest*(
|
||||||
stream: PortalStream, nodeId: NodeId, content: ByteList): Bytes2 =
|
stream: PortalStream, nodeId: NodeId, content: seq[byte]): Bytes2 =
|
||||||
var connectionId: Bytes2
|
var connectionId: Bytes2
|
||||||
brHmacDrbgGenerate(stream.rng[], connectionId)
|
brHmacDrbgGenerate(stream.rng[], connectionId)
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ proc registerIncomingSocketCallback(
|
|||||||
for i, request in stream.contentRequests:
|
for i, request in stream.contentRequests:
|
||||||
if request.connectionId == client.connectionId and
|
if request.connectionId == client.connectionId and
|
||||||
request.nodeId == client.remoteAddress.id:
|
request.nodeId == client.remoteAddress.id:
|
||||||
let fut = client.writeAndClose(request.content.asSeq())
|
let fut = client.writeAndClose(request.content)
|
||||||
stream.contentRequests.del(i)
|
stream.contentRequests.del(i)
|
||||||
return fut
|
return fut
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ proc installPortalApiHandlers*(
|
|||||||
case foundContent.kind:
|
case foundContent.kind:
|
||||||
of Content:
|
of Content:
|
||||||
return (
|
return (
|
||||||
some("0x" & foundContent.content.asSeq().toHex()),
|
some("0x" & foundContent.content.toHex()),
|
||||||
none(seq[Record]))
|
none(seq[Record]))
|
||||||
of Nodes:
|
of Nodes:
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user