Package net.i2p.router.transport.udp
Class PacketBuilder2
java.lang.Object
net.i2p.router.transport.udp.PacketBuilder2
SSU2 only
- Since:
- 0.9.54
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
IPv4 onlystatic final int
static final int
60static final int
80(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
For debugging and stats only - does not go out on the wire.(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
static final int
Same for IPv4 and IPv6 -
Constructor Summary
ConstructorDescriptionPacketBuilder2
(RouterContext ctx, UDPTransport transport) No state, all methods are thread-safe. -
Method Summary
Modifier and TypeMethodDescriptionbuildACK
(PeerState2 peer) Build the ack packet.buildHolePunch
(InetAddress to, int port, SessionKey introKey, long sendID, long rcvID, byte[] signedData) Out-of-session, containing a RelayResponse block.buildPacket
(List<PacketBuilder.Fragment> fragments, List<SSU2Payload.Block> otherBlocks, PeerState2 peer) buildPacket
(List<PacketBuilder.Fragment> fragments, PeerState2 peer) buildPacket
(OutboundMessageState state, int fragment, PeerState2 peer) This builds a data packet (PAYLOAD_TYPE_DATA).buildPeerTestFromAlice
(byte[] signedData, PeerState2 bob) Build a packet as Alice, to Bob to begin a peer test.buildPeerTestFromAlice
(InetAddress toIP, int toPort, SessionKey introKey, long sendID, long rcvID, byte[] signedData) Build a packet as Alice to Charlie.buildPeerTestToAlice
(int code, Hash charlieHash, byte[] signedData, PeerState2 alice) Build a packet as Bob to Alice, with the response from Charlie, or a rejection by Bob.buildPeerTestToAlice
(InetAddress aliceIP, int alicePort, SessionKey introKey, boolean firstSend, long sendID, long rcvID, byte[] signedData) Build a packet as Charlie to Alice.buildPeerTestToBob
(int code, byte[] signedData, PeerState2 bob) Build a packet as Charlie to Bob verifying that we will help test Alice.buildPeerTestToCharlie
(Hash aliceHash, byte[] signedData, PeerState2 charlie) Build a packet as Bob to Charlie to help test Alice.buildPing
(PeerState2 peer) A DATA packet with padding only.(package private) UDPPacket
buildRelayIntro
(byte[] signedData, PeerState2 charlie) From Bob to Charlie.(package private) UDPPacket
buildRelayRequest
(byte[] signedData, PeerState2 bob) From Alice to Bob.(package private) UDPPacket
buildRelayResponse
(byte[] signedData, PeerState2 state) From Charlie to Bob or Bob to Alice.buildRetryPacket
(InboundEstablishState2 state, int terminationCode) Build a new Retry packet for the given peer, encrypting it as necessary.buildSessionConfirmedPackets
(OutboundEstablishState2 state, RouterInfo ourInfo) Build a new series of SessionConfirmed packets for the given peer, encrypting it as necessary.Build a new SessionCreated packet for the given peer, encrypting it as necessary.buildSessionDestroyPacket
(int reason, PeerState2 peer) Build a data packet with a termination block.Build a new SessionRequest packet for the given peer, encrypting it as necessary.Build a new SessionRequest packet for the given peer, encrypting it as necessary.static int
getMaxAdditionalFragmentSize
(PeerState peer, int numFragments, int curDataSize) Will a packet to 'peer' that already has 'numFragments' fragments totalling 'curDataSize' bytes fit another fragment? This includes the 3 byte block overhead, but NOT the 5 byte followon fragment overhead.
-
Field Details
-
TYPE_FIRST
static final int TYPE_FIRSTFor debugging and stats only - does not go out on the wire. These are chosen to be higher than the highest I2NP message type, as a data packet is set to the underlying I2NP message type.- See Also:
-
TYPE_ACK
static final int TYPE_ACK- See Also:
-
TYPE_PUNCH
static final int TYPE_PUNCH- See Also:
-
TYPE_RESP
static final int TYPE_RESP- See Also:
-
TYPE_INTRO
static final int TYPE_INTRO- See Also:
-
TYPE_RREQ
static final int TYPE_RREQ- See Also:
-
TYPE_TCB
static final int TYPE_TCB- See Also:
-
TYPE_TBC
static final int TYPE_TBC- See Also:
-
TYPE_TTA
static final int TYPE_TTA- See Also:
-
TYPE_TFA
static final int TYPE_TFA- See Also:
-
TYPE_CONF
static final int TYPE_CONF- See Also:
-
TYPE_SREQ
static final int TYPE_SREQ- See Also:
-
TYPE_CREAT
static final int TYPE_CREAT- See Also:
-
TYPE_DESTROY
static final int TYPE_DESTROY- See Also:
-
IP_HEADER_SIZE
public static final int IP_HEADER_SIZEIPv4 only- See Also:
-
UDP_HEADER_SIZE
public static final int UDP_HEADER_SIZESame for IPv4 and IPv6- See Also:
-
MIN_DATA_PACKET_OVERHEAD
public static final int MIN_DATA_PACKET_OVERHEAD60- See Also:
-
IPV6_HEADER_SIZE
public static final int IPV6_HEADER_SIZE- See Also:
-
MIN_IPV6_DATA_PACKET_OVERHEAD
public static final int MIN_IPV6_DATA_PACKET_OVERHEAD80- See Also:
-
PRIORITY_HIGH
static final int PRIORITY_HIGH- See Also:
-
-
Constructor Details
-
PacketBuilder2
No state, all methods are thread-safe.- Parameters:
transport
- may be null for unit testing only
-
-
Method Details
-
getMaxAdditionalFragmentSize
Will a packet to 'peer' that already has 'numFragments' fragments totalling 'curDataSize' bytes fit another fragment? This includes the 3 byte block overhead, but NOT the 5 byte followon fragment overhead. This doesn't leave anything for acks or anything else.- Parameters:
numFragments
- >= 1- Returns:
- max additional fragment size
-
buildPacket
This builds a data packet (PAYLOAD_TYPE_DATA). See the methods below for the other message types. Note that while the UDP message spec allows for more than one fragment in a message, this method writes exactly one fragment. For no fragments use buildAck().- Returns:
- null on error
-
buildPacket
-
buildPacket
public UDPPacket buildPacket(List<PacketBuilder.Fragment> fragments, List<SSU2Payload.Block> otherBlocks, PeerState2 peer) -
buildPing
A DATA packet with padding only. We use this for keepalive purposes. -
buildACK
Build the ack packet. An ack packet is just a data packet with no data. See buildPacket() for format. -
buildSessionDestroyPacket
Build a data packet with a termination block. This will also include acks, a new token block, and padding. -
buildTokenRequestPacket
Build a new SessionRequest packet for the given peer, encrypting it as necessary.- Returns:
- ready to send packet, or null if there was a problem
-
buildSessionRequestPacket
Build a new SessionRequest packet for the given peer, encrypting it as necessary.- Returns:
- ready to send packet, or null if there was a problem
-
buildSessionCreatedPacket
Build a new SessionCreated packet for the given peer, encrypting it as necessary.- Returns:
- ready to send packet, or null if there was a problem
-
buildRetryPacket
Build a new Retry packet for the given peer, encrypting it as necessary.- Parameters:
terminationCode
- 0 normally, nonzero to send termination block- Returns:
- ready to send packet, or null if there was a problem
-
buildSessionConfirmedPackets
Build a new series of SessionConfirmed packets for the given peer, encrypting it as necessary. If the RI is large enough that it is fragmented, this will still only return a single Session Confirmed message. The remaining RI blocks will be passed to the establish state via confirmedPacketsSent(), and the state will transmit them via the new PeerState2.- Returns:
- ready to send packets, or null if there was a problem
-
buildPeerTestFromAlice
Build a packet as Alice, to Bob to begin a peer test. In-session, message 1.- Returns:
- ready to send packet, or null if there was a problem
-
buildPeerTestFromAlice
public UDPPacket buildPeerTestFromAlice(InetAddress toIP, int toPort, SessionKey introKey, long sendID, long rcvID, byte[] signedData) Build a packet as Alice to Charlie. Out-of-session, message 6.- Returns:
- ready to send packet, or null if there was a problem
-
buildPeerTestToAlice
public UDPPacket buildPeerTestToAlice(int code, Hash charlieHash, byte[] signedData, PeerState2 alice) Build a packet as Bob to Alice, with the response from Charlie, or a rejection by Bob. In-session, message 4.- Parameters:
charlieHash
- fake hash (all zeros) if rejected by bob- Returns:
- ready to send packet, or null if there was a problem
-
buildPeerTestToAlice
public UDPPacket buildPeerTestToAlice(InetAddress aliceIP, int alicePort, SessionKey introKey, boolean firstSend, long sendID, long rcvID, byte[] signedData) Build a packet as Charlie to Alice. Out-of-session, messages 5 and 7.- Returns:
- ready to send packet, or null if there was a problem
-
buildPeerTestToCharlie
Build a packet as Bob to Charlie to help test Alice. In-session, message 2.- Returns:
- ready to send packet, or null if there was a problem
-
buildPeerTestToBob
Build a packet as Charlie to Bob verifying that we will help test Alice. In-session, message 3.- Returns:
- ready to send packet, or null if there was a problem
-
buildRelayRequest
From Alice to Bob. In-session.- Parameters:
signedData
- flag + signed data- Returns:
- null on failure
-
buildRelayIntro
From Bob to Charlie. In-session.- Parameters:
signedData
- flag + alice hash + signed data- Returns:
- null on failure
-
buildRelayResponse
From Charlie to Bob or Bob to Alice. In-session.- Parameters:
signedData
- flag + response code + signed data + optional tokenstate
- Alice or Bob- Returns:
- null on failure
-
buildHolePunch
public UDPPacket buildHolePunch(InetAddress to, int port, SessionKey introKey, long sendID, long rcvID, byte[] signedData) Out-of-session, containing a RelayResponse block.
-