Adjust portal FindContent JSON-RPC according to latest specs (#1566)
Also remove the FindContentFull unspecced JSON-RPC as the new FindContent specification replaces this functionality basically.
This commit is contained in:
parent
acc2d53b52
commit
2ba974a7cd
|
@ -182,6 +182,7 @@ type
|
|||
case kind*: FoundContentKind
|
||||
of Content:
|
||||
content*: seq[byte]
|
||||
utpTransfer*: bool
|
||||
of Nodes:
|
||||
nodes*: seq[Node]
|
||||
|
||||
|
@ -651,7 +652,8 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList):
|
|||
debug "Socket read fully",
|
||||
socketKey = socket.socketKey
|
||||
socket.destroy()
|
||||
return ok(FoundContent(src: dst, kind: Content, content: content))
|
||||
return ok(FoundContent(
|
||||
src: dst, kind: Content, content: content, utpTransfer: true))
|
||||
else :
|
||||
debug "Socket read time-out",
|
||||
socketKey = socket.socketKey
|
||||
|
@ -667,7 +669,9 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList):
|
|||
socket.close()
|
||||
raise exc
|
||||
of contentType:
|
||||
return ok(FoundContent(src: dst, kind: Content, content: m.content.asSeq()))
|
||||
return ok(FoundContent(
|
||||
src: dst,
|
||||
kind: Content, content: m.content.asSeq(), utpTransfer: false))
|
||||
of enrsType:
|
||||
let records = recordsFromBytes(m.enrs)
|
||||
if records.isOk():
|
||||
|
|
|
@ -9,13 +9,7 @@ proc portal_stateLookupEnr(nodeId: NodeId): Record
|
|||
proc portal_statePing(enr: Record): tuple[
|
||||
enrSeq: uint64, customPayload: string]
|
||||
proc portal_stateFindNodes(enr: Record): seq[Record]
|
||||
proc portal_stateFindContent(enr: Record, contentKey: string): tuple[
|
||||
connectionId: Option[string],
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_stateFindContentFull(enr: Record, contentKey: string): tuple[
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_stateFindContent(enr: Record, contentKey: string): JsonNode
|
||||
proc portal_stateOffer(
|
||||
enr: Record, contentKey: string, contentValue: string): string
|
||||
proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||
|
@ -35,13 +29,7 @@ proc portal_historyLookupEnr(nodeId: NodeId): Record
|
|||
proc portal_historyPing(enr: Record): tuple[
|
||||
enrSeq: uint64, customPayload: string]
|
||||
proc portal_historyFindNodes(enr: Record): seq[Record]
|
||||
proc portal_historyFindContent(enr: Record, contentKey: string): tuple[
|
||||
connectionId: Option[string],
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_historyFindContentFull(enr: Record, contentKey: string): tuple[
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_historyFindContent(enr: Record, contentKey: string): JsonNode
|
||||
proc portal_historyOffer(
|
||||
enr: Record, contentKey: string, contentValue: string): string
|
||||
proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||
|
@ -61,13 +49,7 @@ proc portal_beaconLightClientLookupEnr(nodeId: NodeId): Record
|
|||
proc portal_beaconLightClientPing(enr: Record): tuple[
|
||||
enrSeq: uint64, customPayload: string]
|
||||
proc portal_beaconLightClientFindNodes(enr: Record): seq[Record]
|
||||
proc portal_beaconLightClientFindContent(enr: Record, contentKey: string): tuple[
|
||||
connectionId: Option[string],
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_beaconLightClientFindContentFull(enr: Record, contentKey: string): tuple[
|
||||
content: Option[string],
|
||||
enrs: Option[seq[Record]]]
|
||||
proc portal_beaconLightClientFindContent(enr: Record, contentKey: string): JsonNode
|
||||
proc portal_beaconLightClientOffer(
|
||||
enr: Record, contentKey: string, contentValue: string): string
|
||||
proc portal_beaconLightClientRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||
|
|
|
@ -111,36 +111,10 @@ proc installPortalApiHandlers*(
|
|||
|
||||
rpcServer.rpc("portal_" & network & "FindContent") do(
|
||||
enr: Record, contentKey: string) -> JsonNode:
|
||||
let
|
||||
node = toNodeWithAddress(enr)
|
||||
res = await p.findContentImpl(
|
||||
node, ByteList.init(hexToSeqByte(contentKey)))
|
||||
type ContentInfo = object
|
||||
content: string
|
||||
utpTransfer: bool
|
||||
|
||||
if res.isErr():
|
||||
raise newException(ValueError, $res.error)
|
||||
|
||||
var rpcRes = newJObject()
|
||||
let contentMessage = res.get()
|
||||
case contentMessage.contentMessageType:
|
||||
of connectionIdType:
|
||||
rpcRes["connectionId"] = %contentMessage.connectionId.to0xHex()
|
||||
of contentType:
|
||||
rpcRes["content"] = %contentMessage.content.asSeq().to0xHex()
|
||||
of enrsType:
|
||||
let records = recordsFromBytes(contentMessage.enrs)
|
||||
if records.isErr():
|
||||
raise newException(ValueError, $records.error)
|
||||
else:
|
||||
let nodes = verifyNodesRecords(
|
||||
records.get(), node, enrsResultLimit).map(
|
||||
proc(n: Node): Record = n.record)
|
||||
rpcRes["enrs"] = %nodes
|
||||
|
||||
return rpcRes
|
||||
|
||||
rpcServer.rpc("portal_" & network & "FindContentFull") do(
|
||||
enr: Record, contentKey: string) -> JsonNode:
|
||||
# Note: unspecified RPC, but useful as we can get content from uTP also
|
||||
let
|
||||
node = toNodeWithAddress(enr)
|
||||
foundContentResult = await p.findContent(
|
||||
|
@ -149,15 +123,17 @@ proc installPortalApiHandlers*(
|
|||
if foundContentResult.isErr():
|
||||
raise newException(ValueError, $foundContentResult.error)
|
||||
else:
|
||||
var rpcRes = newJObject()
|
||||
let foundContent = foundContentResult.get()
|
||||
case foundContent.kind:
|
||||
of Content:
|
||||
rpcRes["content"] = %foundContent.content.to0xHex()
|
||||
return %ContentInfo(
|
||||
content: foundContent.content.to0xHex(),
|
||||
utpTransfer: foundContent.utpTransfer
|
||||
)
|
||||
of Nodes:
|
||||
var rpcRes = newJObject()
|
||||
rpcRes["enrs"] = %foundContent.nodes.map(proc(n: Node): Record = n.record)
|
||||
|
||||
return rpcRes
|
||||
return rpcRes
|
||||
|
||||
rpcServer.rpc("portal_" & network & "Offer") do(
|
||||
enr: Record, contentKey: string, contentValue: string) -> string:
|
||||
|
|
Loading…
Reference in New Issue