private void HandleZeroMessage <T>(T msg, int messageCode) where T : MessageBase { IByteBuffer getBlockHeadersPacket = _svc.ZeroSerialize(msg); getBlockHeadersPacket.ReadByte(); _handler.HandleMessage(new ZeroPacket(getBlockHeadersPacket) { PacketType = (byte)messageCode }); }
public void Enqueue <T>(T message) where T : P2PMessage { if (!_context.Channel.Active) { return; } IByteBuffer buffer = _messageSerializationService.ZeroSerialize(message); _context.WriteAndFlushAsync(buffer).ContinueWith(t => { if (t.IsFaulted) { if (_context.Channel != null && !_context.Channel.Active) { if (_logger.IsTrace) { _logger.Trace($"Channel is not active - {t.Exception.Message}"); } } else if (_logger.IsError) { _logger.Error("Channel is active", t.Exception); } } else if (t.IsCompleted) { // if (_logger.IsTrace) _logger.Trace($"Packet ({packet.Protocol}.{packet.PacketType}) pushed"); } }); }
private Context ReceiveStatus(StatusMessage msg) { IByteBuffer statusPacket = _serializer.ZeroSerialize(msg); statusPacket.ReadByte(); _currentSession.ReceiveMessage(new ZeroPacket(statusPacket) {PacketType = Eth62MessageCode.Status + 16}); return this; }
public void Receiving_request_before_status_fails() { var msg = new GetBlockHeadersMessage(); msg.StartBlockHash = TestItem.KeccakA; msg.MaxHeaders = 3; msg.Skip = 1; msg.Reverse = 1; IByteBuffer packet = _svc.ZeroSerialize(msg); packet.ReadByte(); Assert.Throws <SubprotocolException>( () => _handler.HandleMessage(new ZeroPacket(packet) { PacketType = Eth62MessageCode.GetBlockHeaders })); }
public int Enqueue <T>(T message) where T : P2PMessage { if (!_context.Channel.Active) { return(0); } IByteBuffer buffer = _messageSerializationService.ZeroSerialize(message); int length = buffer.ReadableBytes; _context.WriteAndFlushAsync(buffer).ContinueWith(t => { if (t.IsFaulted) { if (_context.Channel is { Active: false }) { if (_logger.IsTrace) { _logger.Trace($"Channel is not active - {t.Exception.Message}"); } }