Changeset a3e16614
- Timestamp:
- Nov 8, 2015 6:30:51 PM (5 years ago)
- Branches:
- master
- Children:
- e120a8a
- Parents:
- bdde11c
- Location:
- router/java/src/net/i2p/router/transport/udp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
router/java/src/net/i2p/router/transport/udp/PacketBuilder.java
rbdde11c ra3e16614 784 784 */ 785 785 public UDPPacket buildSessionRequestPacket(OutboundEstablishState state) { 786 // TODO 787 //byte[] options = new byte[3]; 788 //UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE, options); 786 789 UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE); 787 790 DatagramPacket pkt = packet.getPacket(); 788 791 byte data[] = pkt.getData(); 789 int off = HEADER_SIZE; 792 int off = HEADER_SIZE; // + 1 + options.length; 790 793 791 794 byte toIP[] = state.getSentIP(); … … 1434 1437 * Create a new packet and add the flag byte and the time stamp. 1435 1438 * Caller should add data starting at HEADER_SIZE. 1436 * At this point, adding support for extended options and rekeying is unlikely, 1437 * but if we do, we'll have to change this. 1439 * Does not include extended options or rekeying. 1438 1440 * 1439 1441 * @param flagByte contains type and flags … … 1441 1443 */ 1442 1444 private UDPPacket buildPacketHeader(byte flagByte) { 1445 return buildPacketHeader(flagByte, null); 1446 } 1447 1448 /** 1449 * Create a new packet and add the flag byte and the time stamp. 1450 * Caller should add data starting at HEADER_SIZE. 1451 * (if extendedOptions != null, at HEADER_SIZE + 1 + extendedOptions.length) 1452 * Does not include rekeying. 1453 * 1454 * @param flagByte contains type and flags 1455 * @param extendedOptions May be null. If non-null, we will add the associated flag here. 1456 * 255 bytes max. 1457 * @since 0.9.24 1458 */ 1459 private UDPPacket buildPacketHeader(byte flagByte, byte[] extendedOptions) { 1443 1460 UDPPacket packet = UDPPacket.acquire(_context, false); 1444 1461 byte data[] = packet.getPacket().getData(); … … 1447 1464 1448 1465 // header 1466 if (extendedOptions != null) 1467 flagByte |= UDPPacket.HEADER_FLAG_EXTENDED_OPTIONS; 1449 1468 data[off] = flagByte; 1450 1469 off++; 1451 1470 long now = (_context.clock().now() + 500) / 1000; 1452 1471 DataHelper.toLong(data, off, 4, now); 1453 // todo: add support for rekeying and extended options 1472 // todo: add support for rekeying 1473 // extended options 1474 if (extendedOptions != null) { 1475 off+= 4; 1476 int len = extendedOptions.length; 1477 if (len > 255) 1478 throw new IllegalArgumentException(); 1479 data[off++] = (byte) len; 1480 System.arraycopy(extendedOptions, 0, data, off, len); 1481 } 1454 1482 return packet; 1455 1483 } -
router/java/src/net/i2p/router/transport/udp/UDPPacket.java
rbdde11c ra3e16614 90 90 public static final int PAYLOAD_TYPE_SESSION_DESTROY = 8; 91 91 92 // various flag fields for use in the header 93 /** 94 * Defined in the spec from the beginning, Unused 95 * @since 0.9.24 96 */ 97 public static final byte HEADER_FLAG_REKEY = (1 << 3); 98 /** 99 * Defined in the spec from the beginning, Used starting in 0.9.24 100 * @since 0.9.24 101 */ 102 public static final byte HEADER_FLAG_EXTENDED_OPTIONS = (1 << 2); 103 92 104 // various flag fields for use in the data packets 93 105 public static final byte DATA_FLAG_EXPLICIT_ACK = (byte)(1 << 7); 94 106 public static final byte DATA_FLAG_ACK_BITFIELDS = (1 << 6); 95 / / unused107 /** unused */ 96 108 public static final byte DATA_FLAG_ECN = (1 << 4); 97 109 public static final byte DATA_FLAG_WANT_ACKS = (1 << 3); 98 110 public static final byte DATA_FLAG_WANT_REPLY = (1 << 2); 99 / / unused111 /** unused */ 100 112 public static final byte DATA_FLAG_EXTENDED = (1 << 1); 101 113 -
router/java/src/net/i2p/router/transport/udp/UDPPacketReader.java
rbdde11c ra3e16614 68 68 } 69 69 70 /** does this packet include rekeying data? */ 71 public boolean readRekeying() { 72 return (_message[_payloadBeginOffset] & (1 << 3)) != 0; 73 } 74 75 public boolean readExtendedOptionsIncluded() { 76 return (_message[_payloadBeginOffset] & (1 << 2)) != 0; 70 /** 71 * Does this packet include rekeying data in the header? 72 * Unused, should always be false. 73 */ 74 public boolean isRekeyingIncluded() { 75 return (_message[_payloadBeginOffset] & UDPPacket.HEADER_FLAG_REKEY) != 0; 76 } 77 78 /** 79 * Does this packet include extended options in the header? 80 */ 81 public boolean isExtendedOptionsIncluded() { 82 return (_message[_payloadBeginOffset] & UDPPacket.HEADER_FLAG_EXTENDED_OPTIONS) != 0; 77 83 } 78 84 … … 82 88 } 83 89 84 public void readKeyingMaterial(byte target[], int targetOffset) { 85 if (!readRekeying()) 86 throw new IllegalStateException("This packet is not rekeying!"); 87 System.arraycopy(_message, _payloadBeginOffset + 1 + 4, target, targetOffset, KEYING_MATERIAL_LENGTH); 90 /** 91 * Returns rekeying data (64 bytes), or null if none. 92 * Unused, should always return null. 93 * 94 * @deprecated unused 95 */ 96 @Deprecated 97 public byte[] readKeyingMaterial() { 98 if (!isRekeyingIncluded()) 99 return null; 100 byte[] rv = new byte[KEYING_MATERIAL_LENGTH]; 101 System.arraycopy(_message, _payloadBeginOffset + 1 + 4, rv, 0, KEYING_MATERIAL_LENGTH); 102 return rv; 103 } 104 105 /** 106 * Returns extended option data, 0-255 bytes, or null if none. 107 * 108 * @return extended options or null if none is included 109 * @since 0.9.24 110 */ 111 public byte[] readExtendedOptions() { 112 if (!isExtendedOptionsIncluded()) 113 return null; 114 int offset = _payloadBeginOffset + 1 + 4; 115 if (isRekeyingIncluded()) 116 offset += KEYING_MATERIAL_LENGTH; 117 int optionsSize = _message[offset++] & 0xff; 118 byte[] rv = new byte[optionsSize]; 119 System.arraycopy(_message, offset, rv, 0, optionsSize); 120 return rv; 88 121 } 89 122 … … 91 124 private int readBodyOffset() { 92 125 int offset = _payloadBeginOffset + 1 + 4; 93 if ( readRekeying())126 if (isRekeyingIncluded()) 94 127 offset += KEYING_MATERIAL_LENGTH; 95 if ( readExtendedOptionsIncluded()) {96 int optionsSize = (int)DataHelper.fromLong(_message, offset, 1);128 if (isExtendedOptionsIncluded()) { 129 int optionsSize = _message[offset] & 0xff; 97 130 offset += optionsSize + 1; 98 131 }
Note: See TracChangeset
for help on using the changeset viewer.