class PacketBuilder2 extends Object
| Modifier and Type | Field and Description |
|---|---|
static int | IP_HEADER_SIZEIPv4 only |
static int | IPV6_HEADER_SIZEIPv6 header size in bytes. |
static int | MIN_DATA_PACKET_OVERHEADMinimum IPv4 data packet overhead with MAC in bytes (60). |
static int | MIN_IPV6_DATA_PACKET_OVERHEADMinimum IPv6 data packet overhead with MAC in bytes (80). |
(package private) static int | PRIORITY_HIGHHigher than all other OutNetMessage priorities, but still droppable,
and will be shown in the codel.UDP-Sender.drop.500 stat. |
(package private) static int | TYPE_ACKSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_CONFSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_CREATSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_DESTROYSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_FIRSTFor debugging and stats only - does not go out on the wire. |
(package private) static int | TYPE_INTROSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_PUNCHSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_RESPSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_RREQSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_SREQSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_TBCSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_TCBSSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_TFASSU2 packet type constant for debugging/stats |
(package private) static int | TYPE_TTASSU2 packet type constant for debugging/stats |
static int | UDP_HEADER_SIZESame for IPv4 and IPv6 |
| Constructor and Description |
|---|
PacketBuilder2(RouterContext ctx,
UDPTransport transport)No state, all methods are thread-safe. |
| Modifier and Type | Method and Description |
|---|---|
UDPPacket | buildACK(PeerState2 peer)Build the ack packet. |
UDPPacket | buildHolePunch(InetAddress to,
int port,
SessionKey introKey,
long sendID,
long rcvID,
byte[] signedData)Out-of-session, containing a RelayResponse block. |
UDPPacket | buildPacket(List<PacketBuilder.Fragment> fragments,
List<SSU2Payload.Block> otherBlocks,
SSU2Sender peer)Build a packet from multiple fragments and optional other blocks. |
UDPPacket | buildPacket(List<PacketBuilder.Fragment> fragments,
PeerState2 peer)Build a packet from multiple fragments. |
UDPPacket | buildPacket(OutboundMessageState state,
int fragment,
PeerState2 peer)This builds a data packet (PAYLOAD_TYPE_DATA). |
UDPPacket | buildPeerTestFromAlice(byte[] signedData,
PeerState2 bob)Build a packet as Alice, to Bob to begin a peer test. |
UDPPacket | buildPeerTestFromAlice(InetAddress toIP,
int toPort,
SessionKey introKey,
long sendID,
long rcvID,
byte[] signedData)Build a packet as Alice to Charlie. |
UDPPacket | buildPeerTestToAlice(InetAddress aliceIP,
int alicePort,
SessionKey introKey,
boolean firstSend,
long sendID,
long rcvID,
byte[] signedData)Build a packet as Charlie to Alice. |
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. |
UDPPacket | buildPeerTestToAlice(int code,
Hash charlieHash,
byte[] signedData,
SSU2Payload.Block riBlock,
PeerState2 alice)Build a packet as Bob to Alice, with the response from Charlie,
or a rejection by Bob. |
UDPPacket | buildPeerTestToBob(int code,
byte[] signedData,
PeerState2 bob)Build a packet as Charlie to Bob verifying that we will help test Alice. |
UDPPacket | buildPeerTestToCharlie(Hash aliceHash,
byte[] signedData,
SSU2Payload.Block riBlock,
PeerState2 charlie)Build a packet as Bob to Charlie to help test Alice. |
UDPPacket | buildPing(PeerState2 peer)A DATA packet with padding only. |
(package private) UDPPacket | buildRelayIntro(byte[] signedData,
SSU2Payload.Block riBlock,
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. |
UDPPacket | buildRetryPacket(InboundEstablishState2 state,
int terminationCode)Build a new Retry packet for the given peer, encrypting it
as necessary. |
UDPPacket | buildRetryPacket(RemoteHostId to,
SocketAddress toAddr,
long destID,
long srcID,
int version,
int terminationCode)Build a new Retry packet with a termination code, for a rejection
direct from the EstablishmentManager. |
UDPPacket[] | buildSessionConfirmedPackets(OutboundEstablishState2 state,
RouterInfo ourInfo)Build a new series of SessionConfirmed packets for the given peer,
encrypting it as necessary. |
UDPPacket | buildSessionCreatedPacket(InboundEstablishState2 state)Build a new SessionCreated packet for the given peer, encrypting it
as necessary. |
UDPPacket | buildSessionDestroyPacket(int reason,
SSU2Sender peer)Build a data packet with a termination block. |
UDPPacket | buildSessionRequestPacket(OutboundEstablishState2 state)Build a new SessionRequest packet for the given peer, encrypting it
as necessary. |
UDPPacket | buildTokenRequestPacket(OutboundEstablishState2 state)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. |
static int | getMaxDataSize(PeerState peer)Calculates the maximum payload size that can be sent to this peer in a single data packet. |
public static final int IP_HEADER_SIZE
public static final int IPV6_HEADER_SIZE
public static final int MIN_DATA_PACKET_OVERHEAD
public static final int MIN_IPV6_DATA_PACKET_OVERHEAD
static final int PRIORITY_HIGH
static final int TYPE_ACK
static final int TYPE_CONF
static final int TYPE_CREAT
static final int TYPE_DESTROY
static final int TYPE_FIRST
static final int TYPE_INTRO
static final int TYPE_PUNCH
static final int TYPE_RESP
static final int TYPE_RREQ
static final int TYPE_SREQ
static final int TYPE_TBC
static final int TYPE_TCB
static final int TYPE_TFA
static final int TYPE_TTA
public static final int UDP_HEADER_SIZE
public PacketBuilder2(RouterContext ctx, UDPTransport transport)
transport - may be null for unit testing onlypublic UDPPacket buildACK(PeerState2 peer) throws IOException
IOException - if peer is deadpublic UDPPacket buildHolePunch(InetAddress to, int port, SessionKey introKey, long sendID, long rcvID, byte[] signedData)
public UDPPacket buildPacket(List<PacketBuilder.Fragment> fragments, List<SSU2Payload.Block> otherBlocks, SSU2Sender peer) throws IOException
otherBlocks - may be null or emptyIOException - if peer is deadpublic UDPPacket buildPacket(List<PacketBuilder.Fragment> fragments, PeerState2 peer) throws IOException
IOException - if peer is deadpublic UDPPacket buildPacket(OutboundMessageState state, int fragment, PeerState2 peer) throws IOException
IOException - if peer is deadpublic UDPPacket buildPeerTestFromAlice(byte[] signedData, PeerState2 bob) throws IOException
IOException - if peer is deadpublic UDPPacket buildPeerTestFromAlice(InetAddress toIP, int toPort, SessionKey introKey, long sendID, long rcvID, byte[] signedData)
public UDPPacket buildPeerTestToAlice(InetAddress aliceIP, int alicePort, SessionKey introKey, boolean firstSend, long sendID, long rcvID, byte[] signedData)
public UDPPacket buildPeerTestToAlice(int code, Hash charlieHash, byte[] signedData, PeerState2 alice) throws IOException
charlieHash - fake hash (all zeros) if rejected by bobIOException - if peer is deadpublic UDPPacket buildPeerTestToAlice(int code, Hash charlieHash, byte[] signedData, SSU2Payload.Block riBlock, PeerState2 alice) throws IOException
charlieHash - fake hash (all zeros) if rejected by bobriBlock - to include, may be nullIOException - if peer is deadpublic UDPPacket buildPeerTestToBob(int code, byte[] signedData, PeerState2 bob) throws IOException
IOException - if peer is deadpublic UDPPacket buildPeerTestToCharlie(Hash aliceHash, byte[] signedData, SSU2Payload.Block riBlock, PeerState2 charlie) throws IOException
riBlock - to include, may be nullIOException - if peer is deadpublic UDPPacket buildPing(PeerState2 peer) throws IOException
IOException - if peer is deadUDPPacket buildRelayIntro(byte[] signedData, SSU2Payload.Block riBlock, PeerState2 charlie) throws IOException
signedData - flag + alice hash + signed datariBlock - to include, may be nullIOException - if peer is deadUDPPacket buildRelayRequest(byte[] signedData, PeerState2 bob) throws IOException
signedData - flag + signed dataIOException - if peer is deadUDPPacket buildRelayResponse(byte[] signedData, PeerState2 state) throws IOException
signedData - flag + response code + signed data + optional tokenstate - Alice or BobIOException - if peer is deadpublic UDPPacket buildRetryPacket(InboundEstablishState2 state, int terminationCode)
terminationCode - 0 normally, nonzero to send termination blockpublic UDPPacket buildRetryPacket(RemoteHostId to, SocketAddress toAddr, long destID, long srcID, int version, int terminationCode)
terminationCode - must be greater than zeropublic UDPPacket[] buildSessionConfirmedPackets(OutboundEstablishState2 state, RouterInfo ourInfo)
public UDPPacket buildSessionCreatedPacket(InboundEstablishState2 state)
public UDPPacket buildSessionDestroyPacket(int reason, SSU2Sender peer) throws IOException
IOException - if peer is deadpublic UDPPacket buildSessionRequestPacket(OutboundEstablishState2 state)
public UDPPacket buildTokenRequestPacket(OutboundEstablishState2 state)
public static int getMaxAdditionalFragmentSize(PeerState peer, int numFragments, int curDataSize)
numFragments - >= 1public static int getMaxDataSize(PeerState peer)