class PacketBuilder2 extends Object
Modifier and Type | Field and Description |
---|---|
static int |
IP_HEADER_SIZE
IPv4 only
|
static int |
IPV6_HEADER_SIZE |
static int |
MIN_DATA_PACKET_OVERHEAD
60
|
static int |
MIN_IPV6_DATA_PACKET_OVERHEAD
80
|
(package private) static int |
PRIORITY_HIGH |
(package private) static int |
TYPE_ACK |
(package private) static int |
TYPE_CONF |
(package private) static int |
TYPE_CREAT |
(package private) static int |
TYPE_DESTROY |
(package private) static int |
TYPE_FIRST
For debugging and stats only - does not go out on the wire.
|
(package private) static int |
TYPE_INTRO |
(package private) static int |
TYPE_PUNCH |
(package private) static int |
TYPE_RESP |
(package private) static int |
TYPE_RREQ |
(package private) static int |
TYPE_SREQ |
(package private) static int |
TYPE_TBC |
(package private) static int |
TYPE_TCB |
(package private) static int |
TYPE_TFA |
(package private) static int |
TYPE_TTA |
static int |
UDP_HEADER_SIZE
Same 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) |
UDPPacket |
buildPacket(List<PacketBuilder.Fragment> fragments,
PeerState2 peer) |
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 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 final int TYPE_FIRST
static final int TYPE_ACK
static final int TYPE_PUNCH
static final int TYPE_RESP
static final int TYPE_INTRO
static final int TYPE_RREQ
static final int TYPE_TCB
static final int TYPE_TBC
static final int TYPE_TTA
static final int TYPE_TFA
static final int TYPE_CONF
static final int TYPE_SREQ
static final int TYPE_CREAT
static final int TYPE_DESTROY
public static final int IP_HEADER_SIZE
public static final int UDP_HEADER_SIZE
public static final int MIN_DATA_PACKET_OVERHEAD
public static final int IPV6_HEADER_SIZE
public static final int MIN_IPV6_DATA_PACKET_OVERHEAD
static final int PRIORITY_HIGH
public PacketBuilder2(RouterContext ctx, UDPTransport transport)
transport
- may be null for unit testing onlypublic static int getMaxAdditionalFragmentSize(PeerState peer, int numFragments, int curDataSize)
numFragments
- >= 1public UDPPacket buildPacket(OutboundMessageState state, int fragment, PeerState2 peer) throws IOException
IOException
- if peer is deadpublic UDPPacket buildPacket(List<PacketBuilder.Fragment> fragments, PeerState2 peer) throws IOException
IOException
public UDPPacket buildPacket(List<PacketBuilder.Fragment> fragments, List<SSU2Payload.Block> otherBlocks, SSU2Sender peer) throws IOException
IOException
public UDPPacket buildPing(PeerState2 peer) throws IOException
IOException
- if peer is deadpublic UDPPacket buildACK(PeerState2 peer) throws IOException
IOException
- if peer is deadpublic UDPPacket buildSessionDestroyPacket(int reason, SSU2Sender peer) throws IOException
IOException
- if peer is deadpublic UDPPacket buildTokenRequestPacket(OutboundEstablishState2 state)
public UDPPacket buildSessionRequestPacket(OutboundEstablishState2 state)
public UDPPacket buildSessionCreatedPacket(InboundEstablishState2 state)
public 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 terminationCode)
terminationCode
- must be greater than zeropublic UDPPacket[] buildSessionConfirmedPackets(OutboundEstablishState2 state, RouterInfo ourInfo)
public 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(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 buildPeerTestToAlice(InetAddress aliceIP, int alicePort, SessionKey introKey, boolean firstSend, long sendID, long rcvID, byte[] signedData)
public UDPPacket buildPeerTestToCharlie(Hash aliceHash, byte[] signedData, SSU2Payload.Block riBlock, PeerState2 charlie) throws IOException
riBlock
- to include, may be nullIOException
- if peer is deadpublic UDPPacket buildPeerTestToBob(int code, byte[] signedData, PeerState2 bob) throws IOException
IOException
- if peer is deadUDPPacket buildRelayRequest(byte[] signedData, PeerState2 bob) throws IOException
signedData
- flag + signed dataIOException
- 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 buildRelayResponse(byte[] signedData, PeerState2 state) throws IOException
signedData
- flag + response code + signed data + optional tokenstate
- Alice or BobIOException
- if peer is deadpublic UDPPacket buildHolePunch(InetAddress to, int port, SessionKey introKey, long sendID, long rcvID, byte[] signedData)