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
|
case kind*: FoundContentKind
|
||||||
of Content:
|
of Content:
|
||||||
content*: seq[byte]
|
content*: seq[byte]
|
||||||
|
utpTransfer*: bool
|
||||||
of Nodes:
|
of Nodes:
|
||||||
nodes*: seq[Node]
|
nodes*: seq[Node]
|
||||||
|
|
||||||
|
@ -651,7 +652,8 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList):
|
||||||
debug "Socket read fully",
|
debug "Socket read fully",
|
||||||
socketKey = socket.socketKey
|
socketKey = socket.socketKey
|
||||||
socket.destroy()
|
socket.destroy()
|
||||||
return ok(FoundContent(src: dst, kind: Content, content: content))
|
return ok(FoundContent(
|
||||||
|
src: dst, kind: Content, content: content, utpTransfer: true))
|
||||||
else :
|
else :
|
||||||
debug "Socket read time-out",
|
debug "Socket read time-out",
|
||||||
socketKey = socket.socketKey
|
socketKey = socket.socketKey
|
||||||
|
@ -667,7 +669,9 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList):
|
||||||
socket.close()
|
socket.close()
|
||||||
raise exc
|
raise exc
|
||||||
of contentType:
|
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:
|
of enrsType:
|
||||||
let records = recordsFromBytes(m.enrs)
|
let records = recordsFromBytes(m.enrs)
|
||||||
if records.isOk():
|
if records.isOk():
|
||||||
|
|
|
@ -9,13 +9,7 @@ proc portal_stateLookupEnr(nodeId: NodeId): Record
|
||||||
proc portal_statePing(enr: Record): tuple[
|
proc portal_statePing(enr: Record): tuple[
|
||||||
enrSeq: uint64, customPayload: string]
|
enrSeq: uint64, customPayload: string]
|
||||||
proc portal_stateFindNodes(enr: Record): seq[Record]
|
proc portal_stateFindNodes(enr: Record): seq[Record]
|
||||||
proc portal_stateFindContent(enr: Record, contentKey: string): tuple[
|
proc portal_stateFindContent(enr: Record, contentKey: string): JsonNode
|
||||||
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_stateOffer(
|
proc portal_stateOffer(
|
||||||
enr: Record, contentKey: string, contentValue: string): string
|
enr: Record, contentKey: string, contentValue: string): string
|
||||||
proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||||
|
@ -35,13 +29,7 @@ proc portal_historyLookupEnr(nodeId: NodeId): Record
|
||||||
proc portal_historyPing(enr: Record): tuple[
|
proc portal_historyPing(enr: Record): tuple[
|
||||||
enrSeq: uint64, customPayload: string]
|
enrSeq: uint64, customPayload: string]
|
||||||
proc portal_historyFindNodes(enr: Record): seq[Record]
|
proc portal_historyFindNodes(enr: Record): seq[Record]
|
||||||
proc portal_historyFindContent(enr: Record, contentKey: string): tuple[
|
proc portal_historyFindContent(enr: Record, contentKey: string): JsonNode
|
||||||
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_historyOffer(
|
proc portal_historyOffer(
|
||||||
enr: Record, contentKey: string, contentValue: string): string
|
enr: Record, contentKey: string, contentValue: string): string
|
||||||
proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||||
|
@ -61,13 +49,7 @@ proc portal_beaconLightClientLookupEnr(nodeId: NodeId): Record
|
||||||
proc portal_beaconLightClientPing(enr: Record): tuple[
|
proc portal_beaconLightClientPing(enr: Record): tuple[
|
||||||
enrSeq: uint64, customPayload: string]
|
enrSeq: uint64, customPayload: string]
|
||||||
proc portal_beaconLightClientFindNodes(enr: Record): seq[Record]
|
proc portal_beaconLightClientFindNodes(enr: Record): seq[Record]
|
||||||
proc portal_beaconLightClientFindContent(enr: Record, contentKey: string): tuple[
|
proc portal_beaconLightClientFindContent(enr: Record, contentKey: string): JsonNode
|
||||||
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_beaconLightClientOffer(
|
proc portal_beaconLightClientOffer(
|
||||||
enr: Record, contentKey: string, contentValue: string): string
|
enr: Record, contentKey: string, contentValue: string): string
|
||||||
proc portal_beaconLightClientRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
proc portal_beaconLightClientRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||||
|
|
|
@ -111,36 +111,10 @@ proc installPortalApiHandlers*(
|
||||||
|
|
||||||
rpcServer.rpc("portal_" & network & "FindContent") do(
|
rpcServer.rpc("portal_" & network & "FindContent") do(
|
||||||
enr: Record, contentKey: string) -> JsonNode:
|
enr: Record, contentKey: string) -> JsonNode:
|
||||||
let
|
type ContentInfo = object
|
||||||
node = toNodeWithAddress(enr)
|
content: string
|
||||||
res = await p.findContentImpl(
|
utpTransfer: bool
|
||||||
node, ByteList.init(hexToSeqByte(contentKey)))
|
|
||||||
|
|
||||||
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
|
let
|
||||||
node = toNodeWithAddress(enr)
|
node = toNodeWithAddress(enr)
|
||||||
foundContentResult = await p.findContent(
|
foundContentResult = await p.findContent(
|
||||||
|
@ -149,14 +123,16 @@ proc installPortalApiHandlers*(
|
||||||
if foundContentResult.isErr():
|
if foundContentResult.isErr():
|
||||||
raise newException(ValueError, $foundContentResult.error)
|
raise newException(ValueError, $foundContentResult.error)
|
||||||
else:
|
else:
|
||||||
var rpcRes = newJObject()
|
|
||||||
let foundContent = foundContentResult.get()
|
let foundContent = foundContentResult.get()
|
||||||
case foundContent.kind:
|
case foundContent.kind:
|
||||||
of Content:
|
of Content:
|
||||||
rpcRes["content"] = %foundContent.content.to0xHex()
|
return %ContentInfo(
|
||||||
|
content: foundContent.content.to0xHex(),
|
||||||
|
utpTransfer: foundContent.utpTransfer
|
||||||
|
)
|
||||||
of Nodes:
|
of Nodes:
|
||||||
|
var rpcRes = newJObject()
|
||||||
rpcRes["enrs"] = %foundContent.nodes.map(proc(n: Node): Record = n.record)
|
rpcRes["enrs"] = %foundContent.nodes.map(proc(n: Node): Record = n.record)
|
||||||
|
|
||||||
return rpcRes
|
return rpcRes
|
||||||
|
|
||||||
rpcServer.rpc("portal_" & network & "Offer") do(
|
rpcServer.rpc("portal_" & network & "Offer") do(
|
||||||
|
|
Loading…
Reference in New Issue