public static void SendRpcResponse(this IMothraLibp2p mothraLibp2p, string method, string peer,
                                    ReadOnlySpan <byte> data)
 {
     byte[] methodUtf8 = Encoding.UTF8.GetBytes(method);
     byte[] peerUtf8   = Encoding.UTF8.GetBytes(peer);
     mothraLibp2p.SendRpcResponse(methodUtf8, peerUtf8, data);
 }
Пример #2
0
        public Task SendBlockAsync(string peerId, SignedBeaconBlock signedBlock)
        {
            byte[] peerUtf8 = Encoding.UTF8.GetBytes(peerId);

            Span <byte> encoded = new byte[Ssz.Ssz.SignedBeaconBlockLength(signedBlock)];

            Ssz.Ssz.Encode(encoded, signedBlock);

            if (_logger.IsDebug())
            {
                LogDebug.RpcSend(_logger, RpcDirection.Response, nameof(MethodUtf8.BeaconBlocksByRange), peerId,
                                 encoded.Length, null);
            }

            if (!_mothraLibp2p.SendRpcResponse(MethodUtf8.BeaconBlocksByRange, peerUtf8, encoded))
            {
                if (_logger.IsWarn())
                {
                    Log.RpcResponseNotSentAsPeeeringNotStarted(_logger, nameof(MethodUtf8.BeaconBlocksByRange), null);
                }
            }

            return(Task.CompletedTask);
        }