## net.i2p.router.transport.udp
Class PacketBuilder

    java.lang.Object
      net.i2p.router.transport.udp.PacketBuilder

public class PacketBuilder
extends java.lang.Object

Big ol' class to do all our packet formatting. The UDPPackets generated are fully authenticated, encrypted, and configured for delivery to the peer.

Field Summary
`(package private) static int` `PROTOCOL_VERSION` we only talk to people of the right version

Constructor Summary
`PacketBuilder(I2PAppContext ctx, UDPTransport transport)`

Method Summary
`UDPPacket` `buildACK(PeerState peer, java.util.List ackBitfields)`
`UDPPacket` `buildHolePunch(UDPPacketReader reader)`
`UDPPacket` `buildPacket(OutboundMessageState state, int fragment, PeerState peer)`
`UDPPacket` `buildPacket(OutboundMessageState state, int fragment, PeerState peer, java.util.List ackIdsRemaining, java.util.List partialACKsRemaining)`
`UDPPacket` `buildPeerTestFromAlice(java.net.InetAddress toIP, int toPort, SessionKey toIntroKey, long nonce, SessionKey aliceIntroKey)` Build a packet as if we are Alice and we either want Bob to begin a peer test or Charlie to finish a peer test.
`UDPPacket` `buildPeerTestFromAlice(java.net.InetAddress toIP, int toPort, SessionKey toCipherKey, SessionKey toMACKey, long nonce, SessionKey aliceIntroKey)`
`UDPPacket` `buildPeerTestToAlice(java.net.InetAddress aliceIP, int alicePort, SessionKey aliceIntroKey, SessionKey charlieIntroKey, long nonce)` Build a packet as if we are either Bob or Charlie and we are helping test Alice.
`UDPPacket` `buildPeerTestToBob(java.net.InetAddress bobIP, int bobPort, java.net.InetAddress aliceIP, int alicePort, SessionKey aliceIntroKey, long nonce, SessionKey bobCipherKey, SessionKey bobMACKey)` Build a packet as if we are Charlie sending Bob a packet verifying that we will help test Alice.
`UDPPacket` `buildPeerTestToCharlie(java.net.InetAddress aliceIP, int alicePort, SessionKey aliceIntroKey, long nonce, java.net.InetAddress charlieIP, int charliePort, SessionKey charlieCipherKey, SessionKey charlieMACKey)` Build a packet as if we are Bob sending Charlie a packet to help test Alice.
`UDPPacket` `buildRelayIntro(RemoteHostId alice, PeerState charlie, UDPPacketReader.RelayRequestReader request)`
`UDPPacket` `buildRelayRequest(java.net.InetAddress introHost, int introPort, byte[] introKey, long introTag, SessionKey ourIntroKey, long introNonce, boolean encrypt)`
`UDPPacket[]` `buildRelayRequest(UDPTransport transport, OutboundEstablishState state, SessionKey ourIntroKey)` build intro packets for each of the published introducers
`UDPPacket` `buildRelayResponse(RemoteHostId alice, PeerState charlie, long nonce, SessionKey aliceIntroKey)`
`UDPPacket` `buildSessionConfirmedPacket(OutboundEstablishState state, int fragmentNum, int numFragments, byte[] identity)` Build a new SessionConfirmed packet for the given peer
`UDPPacket[]` `buildSessionConfirmedPackets(OutboundEstablishState state, RouterIdentity ourIdentity)` Build a new series of SessionConfirmed packets for the given peer, encrypting it as necessary.
`UDPPacket` `buildSessionCreatedPacket(InboundEstablishState state, int externalPort, SessionKey ourIntroKey)` Build a new SessionCreated packet for the given peer, encrypting it as necessary.
`UDPPacket` `buildSessionRequestPacket(OutboundEstablishState state)` Build a new SessionRequest packet for the given peer, encrypting it as necessary.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PROTOCOL_VERSION

    static final int PROTOCOL_VERSION

  we only talk to people of the right version

  See Also:
    Constant Field Values

Constructor Detail

### PacketBuilder

    public PacketBuilder(I2PAppContext ctx,
                         UDPTransport transport)

Method Detail

### buildPacket

    public UDPPacket buildPacket(OutboundMessageState state,
                                 int fragment,
                                 PeerState peer)

### buildPacket

    public UDPPacket buildPacket(OutboundMessageState state,
                                 int fragment,
                                 PeerState peer,
                                 java.util.List ackIdsRemaining,
                                 java.util.List partialACKsRemaining)

  Parameters:
    `ackIdsRemaining` - list of messageIds (Long) that should be acked by this packet. The list itself is passed by reference, and if a messageId is transmitted and the sender does not want the ID to be included in subsequent acks, it should be removed from the list. NOTE: right now this does NOT remove the IDs, which means it assumes that the IDs will be transmitted potentially multiple times, and should otherwise be removed from the list.
    `partialACKsRemaining` - list of messageIds (ACKBitfield) that should be acked by this packet. The list itself is passed by reference, and if a messageId is included, it should be removed from the list.

### buildACK

    public UDPPacket buildACK(PeerState peer,
                              java.util.List ackBitfields)

  Parameters:
    `ackBitfields` - list of ACKBitfield instances to either fully or partially ACK

### buildSessionCreatedPacket

    public UDPPacket buildSessionCreatedPacket(InboundEstablishState state,
                                               int externalPort,
                                               SessionKey ourIntroKey)

  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

### buildSessionRequestPacket

    public UDPPacket buildSessionRequestPacket(OutboundEstablishState state)

  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

### buildSessionConfirmedPackets

    public UDPPacket[] buildSessionConfirmedPackets(OutboundEstablishState state,
                                                    RouterIdentity ourIdentity)

  Build a new series of SessionConfirmed packets for the given peer, encrypting it as necessary.

  Returns:
    ready to send packets, or null if there was a problem

### buildSessionConfirmedPacket

    public UDPPacket buildSessionConfirmedPacket(OutboundEstablishState state,
                                                 int fragmentNum,
                                                 int numFragments,
                                                 byte[] identity)

  Build a new SessionConfirmed packet for the given peer

  Returns:
    ready to send packets, or null if there was a problem

### buildPeerTestFromAlice

    public UDPPacket buildPeerTestFromAlice(java.net.InetAddress toIP,
                                            int toPort,
                                            SessionKey toIntroKey,
                                            long nonce,
                                            SessionKey aliceIntroKey)

  Build a packet as if we are Alice and we either want Bob to begin a peer test or Charlie to finish a peer test.

  Returns:
    ready to send packet, or null if there was a problem

### buildPeerTestFromAlice

    public UDPPacket buildPeerTestFromAlice(java.net.InetAddress toIP,
                                            int toPort,
                                            SessionKey toCipherKey,
                                            SessionKey toMACKey,
                                            long nonce,
                                            SessionKey aliceIntroKey)

### buildPeerTestToAlice

    public UDPPacket buildPeerTestToAlice(java.net.InetAddress aliceIP,
                                          int alicePort,
                                          SessionKey aliceIntroKey,
                                          SessionKey charlieIntroKey,
                                          long nonce)

  Build a packet as if we are either Bob or Charlie and we are helping test Alice.

  Returns:
    ready to send packet, or null if there was a problem

### buildPeerTestToCharlie

    public UDPPacket buildPeerTestToCharlie(java.net.InetAddress aliceIP,
                                            int alicePort,
                                            SessionKey aliceIntroKey,
                                            long nonce,
                                            java.net.InetAddress charlieIP,
                                            int charliePort,
                                            SessionKey charlieCipherKey,
                                            SessionKey charlieMACKey)

  Build a packet as if we are Bob sending Charlie a packet to help test Alice.

  Returns:
    ready to send packet, or null if there was a problem

### buildPeerTestToBob

    public UDPPacket buildPeerTestToBob(java.net.InetAddress bobIP,
                                        int bobPort,
                                        java.net.InetAddress aliceIP,
                                        int alicePort,
                                        SessionKey aliceIntroKey,
                                        long nonce,
                                        SessionKey bobCipherKey,
                                        SessionKey bobMACKey)

  Build a packet as if we are Charlie sending Bob a packet verifying that we will help test Alice.

  Returns:
    ready to send packet, or null if there was a problem

### buildRelayRequest

    public UDPPacket[] buildRelayRequest(UDPTransport transport,
                                         OutboundEstablishState state,
                                         SessionKey ourIntroKey)

  build intro packets for each of the published introducers

### buildRelayRequest

    public UDPPacket buildRelayRequest(java.net.InetAddress introHost,
                                       int introPort,
                                       byte[] introKey,
                                       long introTag,
                                       SessionKey ourIntroKey,
                                       long introNonce,
                                       boolean encrypt)

### buildRelayIntro

    public UDPPacket buildRelayIntro(RemoteHostId alice,
                                     PeerState charlie,
                                     UDPPacketReader.RelayRequestReader request)

### buildRelayResponse

    public UDPPacket buildRelayResponse(RemoteHostId alice,
                                        PeerState charlie,
                                        long nonce,
                                        SessionKey aliceIntroKey)

### buildHolePunch

    public UDPPacket buildHolePunch(UDPPacketReader reader)