2019-03-05 22:54:08 +00:00
|
|
|
import
|
2019-12-18 01:11:20 +00:00
|
|
|
algorithm, typetraits, net,
|
2020-01-13 19:02:29 +00:00
|
|
|
stew/[varints,base58], stew/shims/[macros, tables], chronos, chronicles,
|
2020-01-15 21:06:17 +00:00
|
|
|
stint, faststreams/output_stream, serialization,
|
2019-06-24 15:13:48 +00:00
|
|
|
json_serialization/std/options, eth/p2p/p2p_protocol_dsl,
|
2019-12-13 17:30:39 +00:00
|
|
|
eth/p2p/discoveryv5/enr,
|
2019-11-03 23:02:27 +00:00
|
|
|
# TODO: create simpler to use libp2p modules that use re-exports
|
|
|
|
libp2p/[switch, multistream, connection,
|
2020-01-13 19:02:29 +00:00
|
|
|
multiaddress, peerinfo, peer,
|
2019-11-03 23:02:27 +00:00
|
|
|
crypto/crypto, protocols/identify, protocols/protocol],
|
|
|
|
libp2p/muxers/mplex/[mplex, types],
|
|
|
|
libp2p/protocols/secure/[secure, secio],
|
|
|
|
libp2p/protocols/pubsub/[pubsub, floodsub],
|
|
|
|
libp2p/transports/[transport, tcptransport],
|
2019-12-13 17:30:39 +00:00
|
|
|
libp2p_json_serialization, eth2_discovery, conf, ssz
|
|
|
|
|
|
|
|
import
|
|
|
|
eth/p2p/discoveryv5/protocol as discv5_protocol
|
2019-03-05 22:54:08 +00:00
|
|
|
|
|
|
|
export
|
2019-11-03 23:02:27 +00:00
|
|
|
p2pProtocol, libp2p_json_serialization, ssz
|
2019-03-05 22:54:08 +00:00
|
|
|
|
|
|
|
type
|
2019-12-09 15:28:57 +00:00
|
|
|
P2PStream = Connection
|
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
# TODO Is this really needed?
|
2019-03-05 22:54:08 +00:00
|
|
|
Eth2Node* = ref object of RootObj
|
2019-11-03 23:02:27 +00:00
|
|
|
switch*: Switch
|
2019-12-13 17:30:39 +00:00
|
|
|
discovery*: Eth2DiscoveryProtocol
|
|
|
|
wantedPeers*: int
|
2019-03-05 22:54:08 +00:00
|
|
|
peers*: Table[PeerID, Peer]
|
2019-12-13 17:30:39 +00:00
|
|
|
peersByDiscoveryId*: Table[Eth2DiscoveryId, Peer]
|
2019-03-05 22:54:08 +00:00
|
|
|
protocolStates*: seq[RootRef]
|
2019-11-03 23:02:27 +00:00
|
|
|
libp2pTransportLoops*: seq[Future[void]]
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-06-05 02:00:07 +00:00
|
|
|
EthereumNode = Eth2Node # needed for the definitions in p2p_backends_helpers
|
|
|
|
|
2019-03-05 22:54:08 +00:00
|
|
|
Peer* = ref object
|
2019-05-22 07:13:15 +00:00
|
|
|
network*: Eth2Node
|
2019-11-03 23:02:27 +00:00
|
|
|
info*: PeerInfo
|
2019-09-08 22:03:41 +00:00
|
|
|
wasDialed*: bool
|
2019-12-13 17:30:39 +00:00
|
|
|
discoveryId*: Eth2DiscoveryId
|
2019-05-22 07:13:15 +00:00
|
|
|
connectionState*: ConnectionState
|
2019-03-05 22:54:08 +00:00
|
|
|
protocolStates*: seq[RootRef]
|
2019-06-17 11:08:05 +00:00
|
|
|
maxInactivityAllowed*: Duration
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-06-05 02:00:07 +00:00
|
|
|
ConnectionState* = enum
|
|
|
|
None,
|
|
|
|
Connecting,
|
|
|
|
Connected,
|
|
|
|
Disconnecting,
|
|
|
|
Disconnected
|
|
|
|
|
2019-09-11 16:45:22 +00:00
|
|
|
UntypedResponder = object
|
2019-06-05 02:00:07 +00:00
|
|
|
peer*: Peer
|
2019-12-09 15:28:57 +00:00
|
|
|
stream*: P2PStream
|
2019-06-05 02:00:07 +00:00
|
|
|
|
|
|
|
Responder*[MsgType] = distinct UntypedResponder
|
|
|
|
|
|
|
|
MessageInfo* = object
|
|
|
|
name*: string
|
|
|
|
|
|
|
|
# Private fields:
|
2019-11-03 23:02:27 +00:00
|
|
|
libp2pCodecName: string
|
|
|
|
protocolMounter*: MounterProc
|
2019-06-05 02:00:07 +00:00
|
|
|
printer*: MessageContentPrinter
|
|
|
|
nextMsgResolver*: NextMsgResolver
|
2019-03-05 22:54:08 +00:00
|
|
|
|
|
|
|
ProtocolInfoObj* = object
|
|
|
|
name*: string
|
|
|
|
messages*: seq[MessageInfo]
|
|
|
|
index*: int # the position of the protocol in the
|
|
|
|
# ordered list of supported protocols
|
|
|
|
|
|
|
|
# Private fields:
|
|
|
|
peerStateInitializer*: PeerStateInitializer
|
|
|
|
networkStateInitializer*: NetworkStateInitializer
|
|
|
|
handshake*: HandshakeStep
|
|
|
|
disconnectHandler*: DisconnectionHandler
|
|
|
|
|
|
|
|
ProtocolInfo* = ptr ProtocolInfoObj
|
|
|
|
|
|
|
|
PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe.}
|
|
|
|
NetworkStateInitializer* = proc(network: EthereumNode): RootRef {.gcsafe.}
|
2019-12-09 15:28:57 +00:00
|
|
|
HandshakeStep* = proc(peer: Peer, stream: P2PStream): Future[void] {.gcsafe.}
|
2019-03-05 22:54:08 +00:00
|
|
|
DisconnectionHandler* = proc(peer: Peer): Future[void] {.gcsafe.}
|
2019-11-03 23:02:27 +00:00
|
|
|
ThunkProc* = LPProtoHandler
|
|
|
|
MounterProc* = proc(network: Eth2Node) {.gcsafe.}
|
2019-03-05 22:54:08 +00:00
|
|
|
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe.}
|
|
|
|
NextMsgResolver* = proc(msgData: SszReader, future: FutureBase) {.gcsafe.}
|
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
DisconnectionReason* = enum
|
|
|
|
ClientShutDown
|
|
|
|
IrrelevantNetwork
|
|
|
|
FaultOrError
|
2019-03-05 22:54:08 +00:00
|
|
|
|
|
|
|
PeerDisconnected* = object of CatchableError
|
|
|
|
reason*: DisconnectionReason
|
|
|
|
|
2019-06-24 02:34:01 +00:00
|
|
|
TransmissionError* = object of CatchableError
|
|
|
|
|
2019-12-18 01:11:20 +00:00
|
|
|
const
|
|
|
|
TCP = net.Protocol.IPPROTO_TCP
|
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
template `$`*(peer: Peer): string = id(peer.info)
|
2019-08-05 00:00:49 +00:00
|
|
|
chronicles.formatIt(Peer): $it
|
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
# TODO: This exists only as a compatibility layer between the daemon
|
|
|
|
# APIs and the native LibP2P ones. It won't be necessary once the
|
|
|
|
# daemon is removed.
|
|
|
|
#
|
|
|
|
template writeAllBytes(stream: P2PStream, bytes: seq[byte]): untyped =
|
|
|
|
write(stream, bytes)
|
2019-11-03 23:02:27 +00:00
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
template openStream(node: Eth2Node, peer: Peer, protocolId: string): untyped =
|
|
|
|
dial(node.switch, peer.info, protocolId)
|
2019-08-05 00:00:49 +00:00
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
proc peer(stream: P2PStream): PeerID =
|
2020-01-13 19:26:19 +00:00
|
|
|
# TODO: Can this be `nil`?
|
|
|
|
stream.peerInfo.peerId
|
2019-12-09 15:28:57 +00:00
|
|
|
#
|
|
|
|
# End of compatibility layer
|
|
|
|
|
|
|
|
proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer {.gcsafe.}
|
2019-08-05 00:00:49 +00:00
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
proc getPeer*(node: Eth2Node, peerInfo: PeerInfo): Peer {.gcsafe.} =
|
|
|
|
let peerId = peerInfo.peerId
|
2019-08-05 00:00:49 +00:00
|
|
|
result = node.peers.getOrDefault(peerId)
|
|
|
|
if result == nil:
|
2019-11-03 23:02:27 +00:00
|
|
|
result = Peer.init(node, peerInfo)
|
2019-08-05 00:00:49 +00:00
|
|
|
node.peers[peerId] = result
|
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
proc peerFromStream(network: Eth2Node, stream: P2PStream): Peer {.gcsafe.} =
|
2020-01-13 19:26:19 +00:00
|
|
|
# TODO: Can this be `nil`?
|
|
|
|
return network.getPeer(stream.peerInfo)
|
2019-09-11 15:01:36 +00:00
|
|
|
|
2019-08-05 00:00:49 +00:00
|
|
|
proc disconnect*(peer: Peer, reason: DisconnectionReason, notifyOtherPeer = false) {.async.} =
|
|
|
|
# TODO: How should we notify the other peer?
|
|
|
|
if peer.connectionState notin {Disconnecting, Disconnected}:
|
|
|
|
peer.connectionState = Disconnecting
|
2019-11-03 23:02:27 +00:00
|
|
|
await peer.network.switch.disconnect(peer.info)
|
2019-08-05 00:00:49 +00:00
|
|
|
peer.connectionState = Disconnected
|
2019-11-03 23:02:27 +00:00
|
|
|
peer.network.peers.del(peer.info.peerId)
|
2019-08-05 00:00:49 +00:00
|
|
|
|
2019-12-09 15:28:57 +00:00
|
|
|
proc safeClose(stream: P2PStream) {.async.} =
|
|
|
|
if not stream.closed:
|
|
|
|
await close(stream)
|
|
|
|
|
|
|
|
include eth/p2p/p2p_backends_helpers
|
|
|
|
include eth/p2p/p2p_tracing
|
|
|
|
include libp2p_backends_common
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-12-18 01:11:20 +00:00
|
|
|
proc toPeerInfo*(r: enr.TypedRecord): PeerInfo =
|
|
|
|
if r.secp256k1.isSome:
|
|
|
|
var peerId = PeerID.init r.secp256k1.get
|
|
|
|
var addresses = newSeq[MultiAddress]()
|
|
|
|
|
|
|
|
if r.ip.isSome and r.tcp.isSome:
|
|
|
|
let ip = IpAddress(family: IpAddressFamily.IPv4,
|
|
|
|
address_v4: r.ip.get)
|
|
|
|
addresses.add MultiAddress.init(ip, TCP, Port r.tcp.get)
|
|
|
|
|
|
|
|
if r.ip6.isSome:
|
|
|
|
let ip = IpAddress(family: IpAddressFamily.IPv6,
|
|
|
|
address_v6: r.ip6.get)
|
|
|
|
if r.tcp6.isSome:
|
|
|
|
addresses.add MultiAddress.init(ip, TCP, Port r.tcp6.get)
|
|
|
|
elif r.tcp.isSome:
|
|
|
|
addresses.add MultiAddress.init(ip, TCP, Port r.tcp.get)
|
|
|
|
else:
|
|
|
|
discard
|
|
|
|
|
|
|
|
if addresses.len > 0:
|
|
|
|
return PeerInfo.init(peerId, addresses)
|
|
|
|
|
|
|
|
proc toPeerInfo(r: Option[enr.TypedRecord]): PeerInfo =
|
|
|
|
if r.isSome:
|
|
|
|
return r.get.toPeerInfo
|
|
|
|
|
2019-12-13 17:30:39 +00:00
|
|
|
proc dialPeer*(node: Eth2Node, enr: enr.Record) {.async.} =
|
2019-12-18 01:11:20 +00:00
|
|
|
let peerInfo = enr.toTypedRecord.toPeerInfo
|
|
|
|
if peerInfo != nil:
|
|
|
|
discard await node.switch.dial(peerInfo)
|
|
|
|
var peer = node.getPeer(peerInfo)
|
|
|
|
peer.wasDialed = true
|
|
|
|
await initializeConnection(peer)
|
2019-12-13 17:30:39 +00:00
|
|
|
|
|
|
|
proc runDiscoveryLoop(node: Eth2Node) {.async.} =
|
|
|
|
while true:
|
|
|
|
if node.peersByDiscoveryId.len < node.wantedPeers:
|
|
|
|
let discoveredPeers = await node.discovery.lookupRandom()
|
|
|
|
for peer in discoveredPeers:
|
|
|
|
if peer.id notin node.peersByDiscoveryId:
|
|
|
|
# TODO do this in parallel
|
|
|
|
await node.dialPeer(peer.record)
|
|
|
|
|
|
|
|
await sleepAsync seconds(1)
|
|
|
|
|
|
|
|
proc init*(T: type Eth2Node, conf: BeaconNodeConf,
|
|
|
|
switch: Switch, privKey: PrivateKey): T =
|
2019-06-12 12:23:05 +00:00
|
|
|
new result
|
2019-11-03 23:02:27 +00:00
|
|
|
result.switch = switch
|
2019-06-21 16:32:52 +00:00
|
|
|
result.peers = initTable[PeerID, Peer]()
|
2019-12-13 17:30:39 +00:00
|
|
|
result.discovery = Eth2DiscoveryProtocol.new(conf, privKey.getBytes)
|
2019-12-18 01:11:20 +00:00
|
|
|
result.wantedPeers = conf.maxPeers
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-06-12 12:23:05 +00:00
|
|
|
newSeq result.protocolStates, allProtocols.len
|
2019-03-05 22:54:08 +00:00
|
|
|
for proto in allProtocols:
|
|
|
|
if proto.networkStateInitializer != nil:
|
2019-06-12 12:23:05 +00:00
|
|
|
result.protocolStates[proto.index] = proto.networkStateInitializer(result)
|
2019-03-05 22:54:08 +00:00
|
|
|
|
|
|
|
for msg in proto.messages:
|
2019-11-03 23:02:27 +00:00
|
|
|
if msg.protocolMounter != nil:
|
|
|
|
msg.protocolMounter result
|
|
|
|
|
2019-12-13 17:30:39 +00:00
|
|
|
proc addKnownPeer*(node: Eth2Node, peerEnr: enr.Record) =
|
|
|
|
node.discovery.addNode peerEnr
|
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
proc start*(node: Eth2Node) {.async.} =
|
2019-12-13 17:30:39 +00:00
|
|
|
node.discovery.open()
|
|
|
|
node.discovery.start()
|
2019-11-03 23:02:27 +00:00
|
|
|
node.libp2pTransportLoops = await node.switch.start()
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer =
|
2019-03-05 22:54:08 +00:00
|
|
|
new result
|
2019-11-03 23:02:27 +00:00
|
|
|
result.info = info
|
2019-03-05 22:54:08 +00:00
|
|
|
result.network = network
|
|
|
|
result.connectionState = Connected
|
2019-06-21 16:32:52 +00:00
|
|
|
result.maxInactivityAllowed = 15.minutes # TODO: Read this from the config
|
2019-03-05 22:54:08 +00:00
|
|
|
newSeq result.protocolStates, allProtocols.len
|
|
|
|
for i in 0 ..< allProtocols.len:
|
|
|
|
let proto = allProtocols[i]
|
|
|
|
if proto.peerStateInitializer != nil:
|
|
|
|
result.protocolStates[i] = proto.peerStateInitializer(result)
|
|
|
|
|
|
|
|
proc registerMsg(protocol: ProtocolInfo,
|
|
|
|
name: string,
|
2019-11-03 23:02:27 +00:00
|
|
|
mounter: MounterProc,
|
|
|
|
libp2pCodecName: string,
|
2019-03-05 22:54:08 +00:00
|
|
|
printer: MessageContentPrinter) =
|
|
|
|
protocol.messages.add MessageInfo(name: name,
|
2019-11-03 23:02:27 +00:00
|
|
|
protocolMounter: mounter,
|
|
|
|
libp2pCodecName: libp2pCodecName,
|
2019-03-05 22:54:08 +00:00
|
|
|
printer: printer)
|
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend =
|
2019-03-05 22:54:08 +00:00
|
|
|
var
|
2019-05-31 18:36:32 +00:00
|
|
|
Format = ident "SSZ"
|
2019-05-30 18:57:12 +00:00
|
|
|
Responder = bindSym "Responder"
|
2019-12-09 15:28:57 +00:00
|
|
|
P2PStream = bindSym "P2PStream"
|
2019-06-24 02:34:01 +00:00
|
|
|
OutputStream = bindSym "OutputStream"
|
2019-03-05 22:54:08 +00:00
|
|
|
Peer = bindSym "Peer"
|
2019-05-22 07:13:15 +00:00
|
|
|
Eth2Node = bindSym "Eth2Node"
|
2019-03-05 22:54:08 +00:00
|
|
|
messagePrinter = bindSym "messagePrinter"
|
2019-05-22 07:13:15 +00:00
|
|
|
milliseconds = bindSym "milliseconds"
|
|
|
|
registerMsg = bindSym "registerMsg"
|
|
|
|
initProtocol = bindSym "initProtocol"
|
|
|
|
bindSymOp = bindSym "bindSym"
|
2019-06-24 02:34:01 +00:00
|
|
|
errVar = ident "err"
|
|
|
|
msgVar = ident "msg"
|
|
|
|
msgBytesVar = ident "msgBytes"
|
2019-11-03 23:02:27 +00:00
|
|
|
networkVar = ident "network"
|
2019-05-22 07:13:15 +00:00
|
|
|
await = ident "await"
|
2019-11-03 23:02:27 +00:00
|
|
|
callUserHandler = ident "callUserHandler"
|
2019-06-03 17:07:50 +00:00
|
|
|
|
|
|
|
p.useRequestIds = false
|
2019-10-23 16:37:06 +00:00
|
|
|
p.useSingleRecordInlining = true
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
new result
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
result.PeerType = Peer
|
|
|
|
result.NetworkType = Eth2Node
|
|
|
|
result.registerProtocol = bindSym "registerProtocol"
|
|
|
|
result.setEventHandlers = bindSym "setEventHandlers"
|
2019-05-29 08:21:03 +00:00
|
|
|
result.SerializationFormat = Format
|
2019-05-30 18:57:12 +00:00
|
|
|
result.ResponderType = Responder
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
result.afterProtocolInit = proc (p: P2PProtocol) =
|
2019-12-09 15:28:57 +00:00
|
|
|
p.onPeerConnected.params.add newIdentDefs(streamVar, P2PStream)
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-30 18:57:12 +00:00
|
|
|
result.implementMsg = proc (msg: Message) =
|
2019-03-05 22:54:08 +00:00
|
|
|
let
|
2019-05-30 18:57:12 +00:00
|
|
|
protocol = msg.protocol
|
2019-06-05 02:00:07 +00:00
|
|
|
msgName = $msg.ident
|
2019-06-24 02:34:01 +00:00
|
|
|
msgNameLit = newLit msgName
|
2019-11-03 23:02:27 +00:00
|
|
|
MsgRecName = msg.recName
|
|
|
|
codecNameLit = getRequestProtoName(msg.procDef)
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-06-05 02:00:07 +00:00
|
|
|
if msg.procDef.body.kind != nnkEmpty and msg.kind == msgRequest:
|
2019-06-03 17:07:50 +00:00
|
|
|
# Request procs need an extra param - the stream where the response
|
|
|
|
# should be written:
|
2019-12-09 15:28:57 +00:00
|
|
|
msg.userHandler.params.insert(2, newIdentDefs(streamVar, P2PStream))
|
2019-06-03 17:07:50 +00:00
|
|
|
msg.initResponderCall.add streamVar
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-06-21 16:32:52 +00:00
|
|
|
##
|
2019-11-03 23:02:27 +00:00
|
|
|
## Implement the Thunk:
|
|
|
|
##
|
2019-12-09 15:28:57 +00:00
|
|
|
## The protocol handlers in nim-libp2p receive only a `P2PStream`
|
2019-11-03 23:02:27 +00:00
|
|
|
## parameter and there is no way to access the wider context (such
|
|
|
|
## as the current `Switch`). In our handlers, we may need to list all
|
|
|
|
## peers in the current network, so we must keep a reference to the
|
|
|
|
## network object in the closure environment of the installed handlers.
|
2019-06-21 16:32:52 +00:00
|
|
|
##
|
2019-11-03 23:02:27 +00:00
|
|
|
## For this reason, we define a `protocol mounter` proc that will
|
|
|
|
## initialize the network object by creating handlers bound to the
|
|
|
|
## specific network.
|
|
|
|
##
|
|
|
|
let
|
|
|
|
protocolMounterName = ident(msgName & "_mounter")
|
|
|
|
userHandlerCall = msg.genUserHandlerCall(msgVar, [peerVar, streamVar])
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
var mounter: NimNode
|
|
|
|
if msg.userHandler != nil:
|
|
|
|
protocol.outRecvProcs.add quote do:
|
|
|
|
template `callUserHandler`(`peerVar`: `Peer`,
|
2019-12-09 15:28:57 +00:00
|
|
|
`streamVar`: `P2PStream`,
|
2019-11-03 23:02:27 +00:00
|
|
|
`msgVar`: `MsgRecName`): untyped =
|
|
|
|
`userHandlerCall`
|
2019-09-09 23:55:01 +00:00
|
|
|
|
2019-11-03 23:02:27 +00:00
|
|
|
proc `protocolMounterName`(`networkVar`: `Eth2Node`) =
|
2019-12-09 15:28:57 +00:00
|
|
|
proc thunk(`streamVar`: `P2PStream`,
|
2019-11-03 23:02:27 +00:00
|
|
|
proto: string): Future[void] {.gcsafe.} =
|
|
|
|
return handleIncomingStream(`networkVar`, `streamVar`,
|
|
|
|
`MsgRecName`, `Format`)
|
|
|
|
|
|
|
|
mount `networkVar`.switch,
|
|
|
|
LPProtocol(codec: `codecNameLit`, handler: thunk)
|
|
|
|
|
|
|
|
mounter = protocolMounterName
|
|
|
|
else:
|
|
|
|
mounter = newNilLit()
|
2019-06-24 02:34:01 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
## Implement Senders and Handshake
|
|
|
|
##
|
|
|
|
if msg.kind == msgHandshake:
|
2019-09-08 22:03:41 +00:00
|
|
|
macros.error "Handshake messages are not supported in LibP2P protocols"
|
2019-06-24 02:34:01 +00:00
|
|
|
else:
|
|
|
|
var sendProc = msg.createSendProc()
|
|
|
|
implementSendProcBody sendProc
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-30 18:57:12 +00:00
|
|
|
protocol.outProcRegistrations.add(
|
2019-05-22 07:13:15 +00:00
|
|
|
newCall(registerMsg,
|
2019-05-30 18:57:12 +00:00
|
|
|
protocol.protocolInfoVar,
|
2019-06-24 02:34:01 +00:00
|
|
|
msgNameLit,
|
2019-11-03 23:02:27 +00:00
|
|
|
mounter,
|
|
|
|
codecNameLit,
|
|
|
|
newTree(nnkBracketExpr, messagePrinter, MsgRecName)))
|
2019-03-05 22:54:08 +00:00
|
|
|
|
2019-05-22 07:13:15 +00:00
|
|
|
result.implementProtocolInit = proc (p: P2PProtocol): NimNode =
|
|
|
|
return newCall(initProtocol, newLit(p.name), p.peerInit, p.netInit)
|
2019-03-05 22:54:08 +00:00
|
|
|
|