2023-01-20 15:01:29 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
|
|
|
import
|
|
|
|
chronicles,
|
|
|
|
chronos,
|
2023-01-30 17:50:58 +00:00
|
|
|
eth/p2p,
|
2023-01-20 15:01:29 +00:00
|
|
|
../protocol,
|
2023-01-30 17:50:58 +00:00
|
|
|
../protocol/snap/snap_types,
|
2023-01-20 15:01:29 +00:00
|
|
|
../../core/chain
|
|
|
|
|
2023-01-30 22:10:23 +00:00
|
|
|
{.push raises: [].}
|
2023-01-20 15:01:29 +00:00
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "wire-protocol"
|
|
|
|
|
|
|
|
type
|
|
|
|
SnapWireRef* = ref object of SnapWireBase
|
|
|
|
chain: ChainRef
|
|
|
|
peerPool: PeerPool
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions: helper functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc notImplemented(name: string) =
|
|
|
|
debug "snapWire: hHandler method not implemented", meth=name
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private functions: peer observer
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#proc onPeerConnected(ctx: SnapWireRef, peer: Peer) =
|
|
|
|
# debug "snapWire: add peer", peer
|
|
|
|
# discard
|
|
|
|
#
|
|
|
|
#proc onPeerDisconnected(ctx: SnapWireRef, peer: Peer) =
|
|
|
|
# debug "snapWire: remove peer", peer
|
|
|
|
# discard
|
|
|
|
#
|
|
|
|
#proc setupPeerObserver(ctx: SnapWireRef) =
|
|
|
|
# var po = PeerObserver(
|
|
|
|
# onPeerConnected:
|
|
|
|
# proc(p: Peer) {.gcsafe.} =
|
|
|
|
# ctx.onPeerConnected(p),
|
|
|
|
# onPeerDisconnected:
|
|
|
|
# proc(p: Peer) {.gcsafe.} =
|
|
|
|
# ctx.onPeerDisconnected(p))
|
|
|
|
# po.setProtocol protocol.snap
|
|
|
|
# ctx.peerPool.addObserver(ctx, po)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructor/destructor
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc init*(
|
|
|
|
T: type SnapWireRef;
|
|
|
|
chain: ChainRef;
|
|
|
|
peerPool: PeerPool;
|
|
|
|
): T =
|
|
|
|
## Constructor (uses `init()` as suggested in style guide.)
|
|
|
|
let ctx = T(
|
|
|
|
chain: chain,
|
|
|
|
peerPool: peerPool)
|
|
|
|
|
|
|
|
#ctx.setupPeerObserver()
|
|
|
|
ctx
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions: snap wire protocol handlers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
method getAccountRange*(
|
|
|
|
ctx: SnapWireRef;
|
|
|
|
root: Hash256;
|
|
|
|
origin: Hash256;
|
|
|
|
limit: Hash256;
|
|
|
|
replySizeMax: uint64;
|
|
|
|
): (seq[SnapAccount], SnapAccountProof)
|
|
|
|
{.gcsafe.} =
|
|
|
|
notImplemented("getAccountRange")
|
|
|
|
|
|
|
|
method getStorageRanges*(
|
|
|
|
ctx: SnapWireRef;
|
|
|
|
root: Hash256;
|
|
|
|
accounts: openArray[Hash256];
|
|
|
|
origin: openArray[byte];
|
|
|
|
limit: openArray[byte];
|
|
|
|
replySizeMax: uint64;
|
|
|
|
): (seq[seq[SnapStorage]], SnapStorageProof)
|
|
|
|
{.gcsafe.} =
|
|
|
|
notImplemented("getStorageRanges")
|
|
|
|
|
|
|
|
method getByteCodes*(
|
|
|
|
ctx: SnapWireRef;
|
|
|
|
nodes: openArray[Hash256];
|
|
|
|
replySizeMax: uint64;
|
|
|
|
): seq[Blob]
|
|
|
|
{.gcsafe.} =
|
|
|
|
notImplemented("getByteCodes")
|
|
|
|
|
|
|
|
method getTrieNodes*(
|
|
|
|
ctx: SnapWireRef;
|
|
|
|
root: Hash256;
|
|
|
|
paths: openArray[seq[Blob]];
|
|
|
|
replySizeMax: uint64;
|
|
|
|
): seq[Blob]
|
|
|
|
{.gcsafe.} =
|
|
|
|
notImplemented("getTrieNodes")
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|