Class PeerState2

    • Constructor Detail

      • PeerState2

        public PeerState2​(RouterContext ctx,
                          UDPTransport transport,
                          InetSocketAddress remoteAddress,
                          Hash remotePeer,
                          boolean isInbound,
                          int rtt,
                          CipherState sendCha,
                          CipherState rcvCha,
                          long sendID,
                          long rcvID,
                          byte[] sendHdrKey1,
                          byte[] sendHdrKey2,
                          byte[] rcvHdrKey2)
        Parameters:
        rtt - from the EstablishState, or 0 if not available
    • Method Detail

      • fragmentSize

        int fragmentSize()
        how much payload data can we shove in there? This is 5 bytes too low for first or only fragment, because the 9 byte I2NP header is included in that fragment. Does NOT leave any room for acks with a full-size fragment.
        Overrides:
        fragmentSize in class PeerState
        Returns:
        MTU - 68 (IPv4), MTU - 88 (IPv6)
      • fragmentOverhead

        int fragmentOverhead()
        Packet overhead This is 5 bytes too high for first or only fragment, because the 9 byte I2NP header is included in that fragment. Does NOT leave any room for acks with a full-size fragment.
        Overrides:
        fragmentOverhead in class PeerState
        Returns:
        68 (IPv4), 88 (IPv6)
      • messagePartiallyReceived

        protected void messagePartiallyReceived​(long now)
        Overridden to use our version of ACKTimer
        Overrides:
        messagePartiallyReceived in class PeerState
      • finishMessages

        int finishMessages​(long now)
        Overridden to expire unacked packets in _sentMessages. These will remain unacked if lost; fragments will be retransmitted in a new packet.
        Overrides:
        finishMessages in class PeerState
        Returns:
        number of active outbound messages remaining
      • allocateSend

        List<OutboundMessageState> allocateSend​(long now)
        Overridden to retransmit SessionConfirmed also
        Overrides:
        allocateSend in class PeerState
        Returns:
        allocated messages to send (never empty), or null if no messages or no resources
      • setCurrentMACKey

        void setCurrentMACKey​(SessionKey key)
        Description copied from class: PeerState
        The AES key used to verify packets, set only after the connection is established.
        Overrides:
        setCurrentMACKey in class PeerState
      • setCurrentCipherKey

        void setCurrentCipherKey​(SessionKey key)
        Description copied from class: PeerState
        The AES key used to encrypt/decrypt packets, set only after the connection is established.
        Overrides:
        setCurrentCipherKey in class PeerState
      • getCurrentFullACKs

        List<Long> getCurrentFullACKs()
        Description copied from class: PeerState
        Grab a list of message ids (Long) that we want to send to the remote peer, regardless of the packet size, but don't remove it from our "want to send" list. If the message id is transmitted to the peer, removeACKMessage(Long) should be called. The returned list contains acks not yet sent only. The caller should NOT transmit all of them all the time, even if there is room, or the packets will have way too much overhead. SSU 1 only.
        Overrides:
        getCurrentFullACKs in class PeerState
        Returns:
        a new list, do as you like with it
      • getCurrentResendACKs

        List<Long> getCurrentResendACKs()
        Description copied from class: PeerState
        Grab a list of message ids (Long) that we want to send to the remote peer, regardless of the packet size, but don't remove it from our "want to send" list. The returned list contains a random assortment of acks already sent. The caller should NOT transmit all of them all the time, even if there is room, or the packets will have way too much overhead. SSU 1 only.
        Overrides:
        getCurrentResendACKs in class PeerState
        Returns:
        a new list, do as you like with it
      • removeACKMessage

        void removeACKMessage​(Long messageId)
        Description copied from class: PeerState
        The ack was sent. Side effect - sets _lastACKSend SSU 1 only.
        Overrides:
        removeACKMessage in class PeerState
      • fetchPartialACKs

        void fetchPartialACKs​(List<ACKBitfield> rv)
        Description copied from class: PeerState
        SSU 1 only.
        Overrides:
        fetchPartialACKs in class PeerState
        Parameters:
        rv - out parameter, populated with true partial ACKBitfields. no full bitfields are included.
      • getNextPacketNumber

        long getNextPacketNumber()
        Next outbound packet number, starts at 1 for Alice (0 is Session Confirmed) and 0 for Bob
      • getSendConnID

        long getSendConnID()
      • getRcvConnID

        long getRcvConnID()
      • getSendCipher

        CipherState getSendCipher()
        caller must sync on returned object when encrypting
      • getSendHeaderEncryptKey1

        byte[] getSendHeaderEncryptKey1()
      • getRcvHeaderEncryptKey1

        byte[] getRcvHeaderEncryptKey1()
      • getSendHeaderEncryptKey2

        byte[] getSendHeaderEncryptKey2()
      • getRcvHeaderEncryptKey2

        byte[] getRcvHeaderEncryptKey2()
      • setOurAddress

        void setOurAddress​(byte[] ip,
                           int port)
      • getOurIP

        byte[] getOurIP()
      • getOurPort

        int getOurPort()
      • receivePacket

        void receivePacket​(UDPPacket packet)
        Parameters:
        packet - fully encrypted, header and body decryption will be done here
      • gotOptions

        public void gotOptions​(byte[] options,
                               boolean isHandshake)
        Specified by:
        gotOptions in interface SSU2Payload.PayloadCallback
        isHandshake - true only for message 3 part 2
      • gotRIFragment

        public void gotRIFragment​(byte[] data,
                                  boolean isHandshake,
                                  boolean flood,
                                  boolean isGzipped,
                                  int frag,
                                  int totalFrags)
        Specified by:
        gotRIFragment in interface SSU2Payload.PayloadCallback
        Parameters:
        data - is first gzipped and then fragmented
        isHandshake - true only for message 3 part 2
      • gotRelayResponse

        public void gotRelayResponse​(int status,
                                     byte[] data)
        Specified by:
        gotRelayResponse in interface SSU2Payload.PayloadCallback
        Parameters:
        status - 0 = accept, 1-255 = reject
        data - excludes flag, includes signature
      • gotPeerTest

        public void gotPeerTest​(int msg,
                                int status,
                                Hash h,
                                byte[] data)
        Specified by:
        gotPeerTest in interface SSU2Payload.PayloadCallback
        Parameters:
        msg - 1-7
        status - 0 = accept, 1-255 = reject
        h - Alice or Charlie hash for msg 2 and 4, null for msg 1, 3, 5-7
        data - excludes flag, includes signature
      • gotTermination

        public void gotTermination​(int reason,
                                   long count)
        Specified by:
        gotTermination in interface SSU2Payload.PayloadCallback
        count - in theory could wrap around to negative, but very unlikely
      • fragmentsSent

        void fragmentsSent​(long pktNum,
                           List<PacketBuilder.Fragment> fragments)
        Record the mapping of packet number to what fragments were in it, so we can process acks.
      • bitSet

        public void bitSet​(long pktNum)
        Callback from SSU2Bitfield.forEachAndNot(). A new ack was received.
        Specified by:
        bitSet in interface SSU2Bitfield.Callback
      • confirmedPacketsSent

        void confirmedPacketsSent​(byte[][] data)
        Note that we just sent the SessionConfirmed packets and save them for retransmission.