java.lang.Object
net.i2p.router.transport.udp.PeerStateDestroyed
All Implemented Interfaces:
SSU2Payload.PayloadCallback, SSU2Sender

class PeerStateDestroyedextends Object implements SSU2Payload.PayloadCallback, SSU2Sender
Small, stub version of PeerState2, for handling destroy acks with possible tokens in them.

This is the "closing state" as defined in QUIC RFC-9000 section 10.2.1. Unlike in QUIC, we do increment the packet number for every sent destroy packet. Also, we retain the header and body decryption keys, and we do process any tokens received. We only respond when receiving data or a termination with a non-ack reason.

Does not extend PeerState2 or PeerState.

  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • _log

      private final Log _log
      Logger for the destroyed peer state.
    • _transport

      private final UDPTransport _transport
      The SSU transport we serve.
    • _remoteHostId

      private final RemoteHostId _remoteHostId
      The peer's host id.
    • _mtu

      private final int _mtu
      The MTU for sending to the peer.
    • _sendConnID

      private final long _sendConnID
      Connection id we send with.
    • _rcvConnID

      private final long _rcvConnID
      Connection id we receive with.
    • _packetNumber

      private final AtomicInteger _packetNumber
      Next packet number to send.
    • _sendCha

      private final CipherState _sendCha
      ChaCha20 state for encrypting sent packets.
    • _rcvCha

      private final CipherState _rcvCha
      ChaCha20 state for decrypting received packets.
    • _sendHeaderEncryptKey1

      private final byte[] _sendHeaderEncryptKey1
      First header encryption key for sending.
    • _rcvHeaderEncryptKey1

      private final byte[] _rcvHeaderEncryptKey1
      First header encryption key for receiving.
    • _sendHeaderEncryptKey2

      private final byte[] _sendHeaderEncryptKey2
      Second header encryption key for sending.
    • _rcvHeaderEncryptKey2

      private final byte[] _rcvHeaderEncryptKey2
      Second header encryption key for receiving.
    • _receivedMessages

      private final SSU2Bitfield _receivedMessages
      Bitfield of received message numbers.
    • _ackTimer

      private final PeerStateDestroyed.ACKTimer _ackTimer
      Timer scheduling acks and retransmits.
    • _killTimer

      private final PeerStateDestroyed.KillTimer _killTimer
      Timer killing this state when it expires.
    • _destroyedOn

      private final long _destroyedOn
      When the state was destroyed.
    • _wantACKSendSince

      protected volatile long _wantACKSendSince
      Redeclares the base class field: zero means no termination ACK is owed, nonzero is when one first became due.
    • _destroyReason

      private volatile int _destroyReason
      Reason code for the destroy.
    • MAX_LIFETIME

      private static final long MAX_LIFETIME
      Maximum lifetime of a destroyed state.
      See Also:
    • TERMINATION_RETX_TIME

      private static final long TERMINATION_RETX_TIME
      Interval between Destroyed packet retransmits.
      See Also:
  • Constructor Details

    • PeerStateDestroyed

      public PeerStateDestroyed(RouterContext ctx, UDPTransport transport, PeerState2 peer)
      This must be called after the first termination or termination ack was sent from PeerState2, so the next packet number is correct.
      Parameters:
      ctx - the router context
      transport - the UDP transport
      peer - that just sent (or received and sent) a termination
    • PeerStateDestroyed

      public PeerStateDestroyed(RouterContext ctx, UDPTransport transport, RemoteHostId id, long sendID, long rcvID, CipherState sendCha, CipherState rcvCha, byte[] sendKey1, byte[] sendKey2, byte[] rcvKey2, int reason)
      Direct from IES2, there was never a PS2. Caller must send termination after creating.
      Parameters:
      ctx - the router context
      transport - the UDP transport
      id - the remote host identifier
      sendID - the next outbound session ID
      rcvID - the next inbound session ID
      sendCha - outbound cipher state
      rcvCha - inbound cipher state
      sendKey1 - first half of the outbound key
      sendKey2 - second half of the outbound key
      rcvKey2 - second half of the inbound key
      reason - the termination reason code
  • Method Details

    • kill

      public void kill()
      Call at transport shutdown or cache eviction.
    • getRemoteHostId

      public RemoteHostId getRemoteHostId()
      The remote host ID.
      Specified by:
      getRemoteHostId in interface SSU2Sender
      Returns:
      the peer's IP and port as a RemoteHostId
    • isIPv6

      public boolean isIPv6()
      Whether the peer is IPv6.
      Specified by:
      isIPv6 in interface SSU2Sender
      Returns:
      whether IPv6
    • getRemoteIPAddress

      public InetAddress getRemoteIPAddress()
      The peer's IP address, built from its host id.
      Specified by:
      getRemoteIPAddress in interface SSU2Sender
      Returns:
      the peer's address
    • getRemotePort

      public int getRemotePort()
      The remote port.
      Specified by:
      getRemotePort in interface SSU2Sender
      Returns:
      the peer's UDP port
    • getMTU

      public int getMTU()
      The MTU.
      Specified by:
      getMTU in interface SSU2Sender
      Returns:
      the maximum UDP payload size in bytes for this peer
    • getNextPacketNumber

      public long getNextPacketNumber()
      The next packet number.
      Specified by:
      getNextPacketNumber in interface SSU2Sender
      Returns:
      the number for the next outbound packet, then increments
    • getSendConnID

      public long getSendConnID()
      The send connection ID.
      Specified by:
      getSendConnID in interface SSU2Sender
      Returns:
      the send conn i d
    • getSendCipher

      public CipherState getSendCipher()
      The send cipher.
      Specified by:
      getSendCipher in interface SSU2Sender
      Returns:
      the Noise cipher state for outbound packets
    • getSendHeaderEncryptKey1

      public byte[] getSendHeaderEncryptKey1()
      The first send header encryption key.
      Specified by:
      getSendHeaderEncryptKey1 in interface SSU2Sender
      Returns:
      the send header encrypt key1
    • getSendHeaderEncryptKey2

      public byte[] getSendHeaderEncryptKey2()
      The second send header encryption key.
      Specified by:
      getSendHeaderEncryptKey2 in interface SSU2Sender
      Returns:
      the send header encrypt key2
    • setDestroyReason

      public void setDestroyReason(int reason)
      The destroy reason.
      Specified by:
      setDestroyReason in interface SSU2Sender
      Parameters:
      reason - the SSU2Util termination code, echoed to the peer in a SessionDestroy and ignored once destroyed
    • getReceivedMessages

      public SSU2Bitfield getReceivedMessages()
      The received messages bitfield.
      Specified by:
      getReceivedMessages in interface SSU2Sender
      Returns:
      the received messages
    • getAckedMessages

      public SSU2Bitfield getAckedMessages()
      No-op, we don't care what was acked.
      Specified by:
      getAckedMessages in interface SSU2Sender
      Returns:
      null always, we don't care what was acked
    • fragmentsSent

      public void fragmentsSent(long pktNum, int length, List<PacketBuilder2.Fragment> fragments)
      Track sent fragments; no-op after destruction.
      Specified by:
      fragmentsSent in interface SSU2Sender
      Parameters:
      pktNum - the packet number the fragments were sent under
      length - the total payload length those fragments add up to
      fragments - fragment list
    • getFlags

      public byte getFlags()
      The flags byte.
      Specified by:
      getFlags in interface SSU2Sender
      Returns:
      zero, as a destroyed session sends no packets
    • getRcvConnID

      long getRcvConnID()
      The inbound connection ID for this session.
      Returns:
      the connection ID
    • messagePartiallyReceived

      private void messagePartiallyReceived()
      Keeps the state alive while a message is partially received.
    • receivePacket

      void receivePacket(UDPPacket packet)
      Handle one packet received from the peer.
      Parameters:
      packet - fully encrypted, header and body decryption will be done here
    • receivePacket

      void receivePacket(RemoteHostId from, UDPPacket packet)
      Handle one packet received from the given source address.
      Parameters:
      from - the address the packet was received from
      packet - fully encrypted, header and body decryption will be done here
    • gotDateTime

      public void gotDateTime(long time)
      Process a received DateTime block; no-op after destruction.
      Specified by:
      gotDateTime in interface SSU2Payload.PayloadCallback
      Parameters:
      time - time in milliseconds since epoch
    • gotOptions

      public void gotOptions(byte[] options, boolean isHandshake)
      Process a received Options block; no-op after destruction.
      Specified by:
      gotOptions in interface SSU2Payload.PayloadCallback
      Parameters:
      options - the option data
      isHandshake - true only for message 3 part 2
    • gotRI

      public void gotRI(RouterInfo ri, boolean isHandshake, boolean flood)
      Process a received RouterInfo block.
      Specified by:
      gotRI in interface SSU2Payload.PayloadCallback
      Parameters:
      ri - will already be validated
      isHandshake - true only for message 3 part 2
      flood - true if this is a floodfill router
    • gotRIFragment

      public void gotRIFragment(byte[] data, boolean isHandshake, boolean flood, boolean isGzipped, int frag, int totalFrags)
      Process a received RouterInfo fragment block.
      Specified by:
      gotRIFragment in interface SSU2Payload.PayloadCallback
      Parameters:
      data - is first gzipped and then fragmented
      isHandshake - true only for message 3 part 2
      flood - true if this is a floodfill router
      isGzipped - true if the data is gzipped
      frag - fragment number (0-based)
      totalFrags - total number of fragments
    • gotAddress

      public void gotAddress(byte[] ip, int port)
      Process a received Address block; no-op after destruction.
      Specified by:
      gotAddress in interface SSU2Payload.PayloadCallback
      Parameters:
      ip - IP address bytes
      port - the port number to send
    • gotRelayTagRequest

      public void gotRelayTagRequest()
      Process a received RelayTagRequest block; no-op after destruction.
      Specified by:
      gotRelayTagRequest in interface SSU2Payload.PayloadCallback
    • gotRelayTag

      public void gotRelayTag(long tag)
      Process a received RelayTag block; no-op after destruction.
      Specified by:
      gotRelayTag in interface SSU2Payload.PayloadCallback
      Parameters:
      tag - the relay tag
    • gotRelayRequest

      public void gotRelayRequest(byte[] data)
      Process a received RelayRequest block.
      Specified by:
      gotRelayRequest in interface SSU2Payload.PayloadCallback
      Parameters:
      data - excludes flag, includes signature
    • gotRelayResponse

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

      public void gotRelayIntro(Hash aliceHash, byte[] data)
      Process a received RelayIntro block.
      Specified by:
      gotRelayIntro in interface SSU2Payload.PayloadCallback
      Parameters:
      aliceHash - hash of the introducer
      data - excludes flag, includes signature
    • gotPeerTest

      public void gotPeerTest(int msg, int status, Hash h, byte[] data)
      Process a received PeerTest block.
      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
    • gotToken

      public void gotToken(long token, long expires)
      Process a received Token block.
      Specified by:
      gotToken in interface SSU2Payload.PayloadCallback
      Parameters:
      token - the session token to attach to the next peer test
      expires - token expiration time in milliseconds
    • gotI2NP

      public void gotI2NP(I2NPMessage msg)
      Process a received I2NP block.
      Specified by:
      gotI2NP in interface SSU2Payload.PayloadCallback
      Parameters:
      msg - the parsed I2NP message
    • gotFragment

      public void gotFragment(byte[] data, int off, int len, long messageId, int frag, boolean isLast)
      Process a received Fragment block.
      Specified by:
      gotFragment in interface SSU2Payload.PayloadCallback
      Parameters:
      data - buffer containing fragment data
      off - offset in data
      len - length of data to copy
      messageId - unique message identifier
      frag - fragment number (0-based)
      isLast - whether this is the last fragment
    • gotACK

      public void gotACK(long ackThru, int acks, byte[] ranges)
      Process a received ACK block; no-op after destruction.
      Specified by:
      gotACK in interface SSU2Payload.PayloadCallback
      Parameters:
      ackThru - highest contiguous sequence number acknowledged
      acks - number of additional acknowledgments beyond ackThru
      ranges - null if none
    • gotTermination

      public void gotTermination(int reason, long count)
      Process a received Termination block.
      Specified by:
      gotTermination in interface SSU2Payload.PayloadCallback
      Parameters:
      reason - termination reason code
      count - in theory could wrap around to negative, but very unlikely
    • gotPathChallenge

      public void gotPathChallenge(RemoteHostId from, byte[] data)
      Process a received PathChallenge block; no-op after destruction.
      Specified by:
      gotPathChallenge in interface SSU2Payload.PayloadCallback
      Parameters:
      from - null if unknown
      data - the challenge bytes, which must be copied out
    • gotPathResponse

      public void gotPathResponse(RemoteHostId from, byte[] data)
      Process a received PathResponse block; no-op after destruction.
      Specified by:
      gotPathResponse in interface SSU2Payload.PayloadCallback
      Parameters:
      from - null if unknown
      data - the response bytes, which must be copied out
    • toString

      public String toString()
      String representation of this destroyed peer.
      Overrides:
      toString in class Object