mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
Update portal wire protocol ids to latest spec (#873)
This commit is contained in:
parent
2b6658b0d6
commit
4b85c73f43
@ -14,7 +14,7 @@ import
|
||||
./history_content
|
||||
|
||||
const
|
||||
HistoryProtocolId* = "portal:history".toBytes()
|
||||
HistoryProtocolId* = [byte 0x50, 0x0B]
|
||||
|
||||
# TODO: Extract common parts from the different networks
|
||||
type HistoryNetwork* = ref object
|
||||
|
@ -15,7 +15,7 @@ import
|
||||
./state_distance
|
||||
|
||||
const
|
||||
StateProtocolId* = "portal:state".toBytes()
|
||||
StateProtocolId* = [byte 0x50, 0x0A]
|
||||
|
||||
type StateNetwork* = ref object
|
||||
portalProtocol*: PortalProtocol
|
||||
|
@ -5,8 +5,8 @@
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
# As per spec:
|
||||
# https://github.com/ethereum/stateless-ethereum-specs/blob/master/state-network.md#wire-protocol
|
||||
## Definitions and encoding of the messages of the Portal wire protocol:
|
||||
## https://github.com/ethereum/portal-network-specs/blob/master/portal-wire-protocol.md#request---response-messages
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
## Implementation of the Portal wire protocol as specified at:
|
||||
## https://github.com/ethereum/portal-network-specs/blob/master/portal-wire-protocol.md
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
@ -50,8 +53,10 @@ type
|
||||
ContentHandler* =
|
||||
proc(contentKey: ByteList): ContentResult {.raises: [Defect], gcsafe.}
|
||||
|
||||
PortalProtocolId* = array[2, byte]
|
||||
|
||||
PortalProtocol* = ref object of TalkProtocol
|
||||
protocolId: seq[byte]
|
||||
protocolId: PortalProtocolId
|
||||
routingTable*: RoutingTable
|
||||
baseProtocol*: protocol.Protocol
|
||||
dataRadius*: UInt256
|
||||
@ -200,7 +205,7 @@ proc messageHandler*(protocol: TalkProtocol, request: seq[byte],
|
||||
|
||||
proc new*(T: type PortalProtocol,
|
||||
baseProtocol: protocol.Protocol,
|
||||
protocolId: seq[byte],
|
||||
protocolId: PortalProtocolId,
|
||||
contentHandler: ContentHandler,
|
||||
dataRadius = UInt256.high(),
|
||||
bootstrapRecords: openarray[Record] = [],
|
||||
@ -216,7 +221,7 @@ proc new*(T: type PortalProtocol,
|
||||
handleContentRequest: contentHandler,
|
||||
bootstrapRecords: @bootstrapRecords)
|
||||
|
||||
proto.baseProtocol.registerTalkProtocol(proto.protocolId, proto).expect(
|
||||
proto.baseProtocol.registerTalkProtocol(@(proto.protocolId), proto).expect(
|
||||
"Only one protocol should have this id")
|
||||
|
||||
return proto
|
||||
@ -229,7 +234,7 @@ proc reqResponse[Request: SomeMessage, Response: SomeMessage](
|
||||
request: Request
|
||||
): Future[PortalResult[Response]] {.async.} =
|
||||
let talkresp =
|
||||
await talkreq(p.baseProtocol, toNode, p.protocolId, encodeMessage(request))
|
||||
await talkreq(p.baseProtocol, toNode, @(p.protocolId), encodeMessage(request))
|
||||
|
||||
# Note: Failure of `decodeMessage` might also simply mean that the peer is
|
||||
# not supporting the specific talk protocol, as according to specification
|
||||
|
@ -14,7 +14,7 @@ import
|
||||
../network/wire/portal_protocol,
|
||||
./test_helpers
|
||||
|
||||
const protocolId = "portal".toBytes()
|
||||
const protocolId = [byte 0x50, 0x00]
|
||||
|
||||
type Default2NodeTest = ref object
|
||||
node1: discv5_protocol.Protocol
|
||||
|
@ -182,7 +182,8 @@ proc run(config: DiscoveryConf) =
|
||||
|
||||
d.open()
|
||||
|
||||
let portal = PortalProtocol.new(d, "portal".toBytes(), testHandler,
|
||||
# TODO: Configurable protocol id
|
||||
let portal = PortalProtocol.new(d, [byte 0x50, 0x0A], testHandler,
|
||||
bootstrapRecords = config.portalBootnodes)
|
||||
|
||||
if config.metricsEnabled:
|
||||
|
Loading…
x
Reference in New Issue
Block a user