/** what IP Alice is reachable on */ public int readPort() { int offset = readBodyOffset() + NONCE_LENGTH; int size = _message[offset] & 0xff; offset++; offset += size; // skip the IP return (int) DataHelper.fromLong(_message, offset, 2); }
public long readACK(int index) { if (!readACKsIncluded()) return -1; int off = readBodyOffset() + 1; // int num = (int)DataHelper.fromLong(_message, off, 1); off++; return DataHelper.fromLong(_message, off + (4 * index), 4); }
private int getFragmentBegin(int fragmentNum) throws DataFormatException { int off = readBodyOffset() + 1; if (readACKsIncluded()) { int numACKs = _message[off] & 0xff; off++; off += 4 * numACKs; } if (readACKBitfieldsIncluded()) { int numBitfields = _message[off] & 0xff; off++; PacketACKBitfield bf[] = new PacketACKBitfield[numBitfields]; for (int i = 0; i < numBitfields; i++) { bf[i] = new PacketACKBitfield(off); off += bf[i].getByteLength(); } } if (readExtendedDataIncluded()) { int size = _message[off] & 0xff; off++; off += size; } off++; // # fragments if (fragmentNum > 0) { for (int i = 0; i < fragmentNum; i++) { off += 5; // messageId+info off += ((int) DataHelper.fromLong(_message, off, 2)) & 0x3FFF; off += 2; } } return off; }
public void readMessageFragment(int fragmentNum, byte target[], int targetOffset) throws DataFormatException { int off = getFragmentBegin(fragmentNum); off += 5; // messageId + fragment info int size = ((int) DataHelper.fromLong(_message, off, 2)) & 0x3FFF; off += 2; System.arraycopy(_message, off, target, targetOffset, size); }
public int readPort() { int offset = readBodyOffset() + 4; offset += _message[offset] & 0xff; offset++; int rv = (int) DataHelper.fromLong(_message, offset, 2); if (_log.shouldLog(Log.DEBUG)) _log.debug("read alice port: " + rv); return rv; }
@Override public String toString() { StringBuilder buf = new StringBuilder(64); if (_receiveTunnelId != null) { buf.append("recv on "); buf.append(DataHelper.fromLong(_receiveTunnelId, 0, 4)); buf.append(" "); } if (_sendTo != null) { buf.append("send to ").append(_sendTo.toBase64().substring(0, 4)).append(":"); if (_sendTunnelId != null) buf.append(DataHelper.fromLong(_sendTunnelId, 0, 4)); } buf.append(" expiring on ").append(TunnelCreatorConfig.format(_expiration)); buf.append(" having transferred ").append(_messagesProcessed).append("KB"); return buf.toString(); }
public long readNonce() { int offset = readBodyOffset(); offset += _message[offset] & 0xff; offset += 1 + 2; int sz = _message[offset] & 0xff; offset += 1 + 2; // sz + port offset += sz; return DataHelper.fromLong(_message, offset, 4); }
/** * Note that for efficiency at the IBGW, this does not fully deserialize the included I2NP * Message. It just puts it in an UnknownI2NPMessage. * * @param handler unused, may be null */ @Override public void readMessage( byte data[], int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException { if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message"); int curIndex = offset; _tunnelId = new TunnelId(DataHelper.fromLong(data, curIndex, 4)); curIndex += 4; if (_tunnelId.getTunnelId() <= 0) throw new I2NPMessageException("Invalid tunnel Id " + _tunnelId); int len = (int) DataHelper.fromLong(data, curIndex, 2); curIndex += 2; if (len <= 1 || curIndex + len > data.length || len > dataSize - 6) throw new I2NPMessageException( "I2NP length in TGM: " + len + " but remaining bytes: " + Math.min(data.length - curIndex, dataSize - 6)); // OLD WAY full message parsing and instantiation // handler.readMessage(data, curIndex); // _msg = handler.lastRead(); // if (_msg == null) // throw new I2NPMessageException("impossible? message read has no payload?!"); // NEW WAY save lots of effort at the IBGW by reading as an UnknownI2NPMessage instead // This will save a lot of object churn and processing, // primarily for unencrypted msgs (V)TBRM, DatabaseStoreMessage, and DSRMs. // DatabaseStoreMessages in particluar are intensive for readBytes() // since the RI is decompressed. // For a zero-hop IB tunnel, where we do need the real thing, // it is converted to a real message class in TunnelGatewayZeroHop // using UnknownI2NPMessage.convert() in TunnelGatewayZeroHop. // We also skip processing the checksum as it's covered by the TGM checksum. // If a zero-hop, the checksum will be verified in convert(). int utype = data[curIndex++] & 0xff; UnknownI2NPMessage umsg = new UnknownI2NPMessage(_context, utype); umsg.readBytes(data, utype, curIndex); _msg = umsg; }
public void toRawString(StringBuilder buf) throws DataFormatException { UDPPacketReader.this.toRawString(buf); buf.append(" payload: "); int off = getFragmentBegin(0); // first fragment off += 4 + 1; // messageId + fragment info int size = ((int) DataHelper.fromLong(_message, off, 2)) & 0x3FFF; off += 2; buf.append(Base64.encode(_message, off, size)); }
/** @deprecated unused */ @Deprecated public int readAlicePort() { int offset = readBodyOffset(); offset += _message[offset] & 0xff; offset += 1 + 2; int sz = _message[offset] & 0xff; offset++; offset += sz; return (int) DataHelper.fromLong(_message, offset, 2); }
public long readNonce() { int offset = readBodyOffset() + 4; offset += _message[offset] & 0xff; offset += 1 + 2; int sz = _message[offset] & 0xff; offset++; offset += sz; offset += SessionKey.KEYSIZE_BYTES; long rv = DataHelper.fromLong(_message, offset, 4); if (_log.shouldLog(Log.DEBUG)) _log.debug("read request nonce: " + rv); return rv; }
public void streamDataReceived(int id, byte data[], int offset, int length) { Flooder flooder = null; synchronized (_remotePeers) { flooder = (Flooder) _remotePeers.get(new Integer(id)); } long value = DataHelper.fromLong(data, 0, 4); if (flooder != null) { flooder.received(length, value); } else { _log.error("not connected to " + id + " but we received " + value + "?"); } }
public long readSignedOnTime() { int offset = readBodyOffset() + Y_LENGTH + 1 + readIPSize() + 2 + 4; long rv = DataHelper.fromLong(_message, offset, 4); if (_log.shouldLog(Log.DEBUG)) _log.debug( "Signed on time offset: " + offset + " val: " + rv + "\nRawCreated: " + Base64.encode(_message, _payloadBeginOffset, _payloadLength)); return rv; }
/** what port charlie is reachable on */ public int readCharliePort() { int offset = readBodyOffset(); offset += _message[offset] & 0xff; offset++; return (int) DataHelper.fromLong(_message, offset, 2); }
/** @return seconds */ public long readTimestamp() { // Note, this is unsigned, so we're good until February 2106 return DataHelper.fromLong(_message, _payloadBeginOffset + 1, 4); }
private static TunnelId getTunnel(byte id[]) { if (id == null) return null; else return new TunnelId(DataHelper.fromLong(id, 0, id.length)); }
public long readTag() { long rv = DataHelper.fromLong(_message, readBodyOffset(), 4); if (_log.shouldLog(Log.DEBUG)) _log.debug("read alice tag: " + rv); return rv; }
/** what port do they think we are coming from? */ public int readPort() { int offset = readBodyOffset() + Y_LENGTH + 1 + readIPSize(); return (int) DataHelper.fromLong(_message, offset, 2); }
public long readNonce() { int readOffset = readBodyOffset(); return DataHelper.fromLong(_message, readOffset, NONCE_LENGTH); }
/** * Read the time at which the signature was generated. TODO must be completely in final * fragment. Time and sig cannot be split across fragments. */ public long readFinalFragmentSignedOnTime() { if (readCurrentFragmentNum() != readTotalFragmentNum() - 1) throw new IllegalStateException("This is not the final fragment"); int readOffset = readBodyOffset() + 1 + 2 + readCurrentFragmentSize(); return DataHelper.fromLong(_message, readOffset, 4); }
@Override public String toString() { StringBuilder buf = new StringBuilder(512); long msAgo = _context.clock().now() - readTimestamp() * 1000; buf.append("Data packet sent ").append(msAgo).append("ms ago "); buf.append("IV "); buf.append( Base64.encode(_message, _payloadBeginOffset - UDPPacket.IV_SIZE, UDPPacket.IV_SIZE)); buf.append(" "); int off = readBodyOffset() + 1; if (readACKsIncluded()) { int numACKs = _message[off] & 0xff; off++; buf.append("with ACKs for "); for (int i = 0; i < numACKs; i++) { buf.append(DataHelper.fromLong(_message, off, 4)).append(' '); off += 4; } } if (readACKBitfieldsIncluded()) { int numBitfields = _message[off] & 0xff; off++; buf.append("with partial ACKs for "); try { for (int i = 0; i < numBitfields; i++) { PacketACKBitfield bf = new PacketACKBitfield(off); buf.append(bf.getMessageId()).append(' '); off += bf.getByteLength(); } } catch (DataFormatException dfe) { buf.append("CORRUPT"); return buf.toString(); } } if (readExtendedDataIncluded()) { int size = _message[off] & 0xff; off++; buf.append("with extended size of "); buf.append(size); buf.append(' '); off += size; } int numFragments = _message[off] & 0xff; off++; buf.append("with fragmentCount of "); buf.append(numFragments); buf.append(' '); for (int i = 0; i < numFragments; i++) { buf.append("containing messageId "); buf.append(DataHelper.fromLong(_message, off, 4)); off += 4; int fragNum = (_message[off] & 0xFF) >>> 1; boolean isLast = (_message[off] & 1) != 0; off++; buf.append(" frag# ").append(fragNum); buf.append(" isLast? ").append(isLast); buf.append(" info ").append(_message[off - 1]); int size = ((int) DataHelper.fromLong(_message, off, 2)) & 0x3FFF; off += 2; buf.append(" with ").append(size).append(" bytes; "); off += size; } return buf.toString(); }
/** read in the 4 byte relayAs tag */ public long readRelayTag() { int offset = readBodyOffset() + Y_LENGTH + 1 + readIPSize() + 2; return DataHelper.fromLong(_message, offset, 4); }
public int readMessageFragmentSize(int fragmentNum) throws DataFormatException { int off = getFragmentBegin(fragmentNum); off += 5; // messageId + fragment info return ((int) DataHelper.fromLong(_message, off, 2)) & 0x3FFF; }
public long readMessageId(int fragmentNum) throws DataFormatException { int fragmentBegin = getFragmentBegin(fragmentNum); return DataHelper.fromLong(_message, fragmentBegin, 4); }
public long getMessageId() { return DataHelper.fromLong(_message, _start, 4); }
public int readCurrentFragmentSize() { int readOffset = readBodyOffset() + 1; return (int) DataHelper.fromLong(_message, readOffset, 2); }