private void receivePing(Packet packet) { boolean ok = packet.verifySignature(_context, packet.getOptionalFrom(), null); if (!ok) { if (_log.shouldLog(Log.WARN)) { if (packet.getOptionalFrom() == null) _log.warn( "Ping with no from (flagged? " + packet.isFlagSet(Packet.FLAG_FROM_INCLUDED) + ")"); else if (packet.getOptionalSignature() == null) _log.warn( "Ping with no signature (flagged? " + packet.isFlagSet(Packet.FLAG_SIGNATURE_INCLUDED) + ")"); else _log.warn( "Forged ping, discard (from=" + packet.getOptionalFrom().calculateHash().toBase64() + " sig=" + packet.getOptionalSignature().toBase64() + ")"); } } else { PacketLocal pong = new PacketLocal(_context, packet.getOptionalFrom()); pong.setFlag(Packet.FLAG_ECHO, true); pong.setFlag(Packet.FLAG_SIGNATURE_INCLUDED, false); pong.setReceiveStreamId(packet.getSendStreamId()); _manager.getPacketQueue().enqueue(pong); } }
/** * This sends a reset back to the place this packet came from. If the packet has no 'optional * from' or valid signature, this does nothing. This is not associated with a connection, so no * con stats are updated. */ private void sendReset(Packet packet) { Destination from = packet.getOptionalFrom(); if (from == null) return; boolean ok = packet.verifySignature(_context, from, null); if (!ok) { if (_log.shouldLog(Log.WARN)) _log.warn("Can't send reset after recv spoofed packet: " + packet); return; } PacketLocal reply = new PacketLocal(_context, from); reply.setFlag(Packet.FLAG_RESET); reply.setFlag(Packet.FLAG_SIGNATURE_INCLUDED); reply.setSendStreamId(packet.getReceiveStreamId()); reply.setReceiveStreamId(packet.getSendStreamId()); reply.setOptionalFrom(_manager.getSession().getMyDestination()); // this just sends the packet - no retries or whatnot _manager.getPacketQueue().enqueue(reply); }
private void sendReset(Packet packet) { boolean ok = packet.verifySignature(_context, packet.getOptionalFrom(), null); if (!ok) { if (_log.shouldLog(Log.WARN)) _log.warn("Received a spoofed SYN packet: they said they were " + packet.getOptionalFrom()); return; } PacketLocal reply = new PacketLocal(_context, packet.getOptionalFrom()); reply.setFlag(Packet.FLAG_RESET); reply.setFlag(Packet.FLAG_SIGNATURE_INCLUDED); reply.setAckThrough(packet.getSequenceNum()); reply.setSendStreamId(packet.getReceiveStreamId()); reply.setReceiveStreamId(0); reply.setOptionalFrom(_manager.getSession().getMyDestination()); if (_log.shouldLog(Log.DEBUG)) _log.debug("Sending RST: " + reply + " because of " + packet); // this just sends the packet - no retries or whatnot _manager.getPacketQueue().enqueue(reply); }