Package net.i2p.router.transport.udp
Class InboundMessageState
java.lang.Object
net.i2p.router.transport.udp.InboundMessageState
- All Implemented Interfaces:
CDQEntry
Hold the raw data fragments of an inbound message.
Warning - there is no synchronization in this class, take care in
InboundMessageFragments to avoid use-after-release, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int10 -
Constructor Summary
ConstructorsConstructorDescriptionInboundMessageState(RouterContext ctx, long messageId, Hash from) Only for Poison right now.InboundMessageState(RouterContext ctx, long messageId, Hash from, byte[] data, int off, int len, int fragmentNum, boolean isLast) Create a new IMS and read in the data from the fragment.InboundMessageState(RouterContext ctx, long messageId, Hash from, UDPPacketReader.DataReader data, int dataFragment) Create a new IMS and read in the data from the fragment. -
Method Summary
Modifier and TypeMethodDescriptionOnly call this if not complete.voiddrop()For CDQintlongFor CDQintgetFrom()longlongbooleanhasFragment(int fragmentNum) Do we have this fragment? SSU 2 only.booleanMay not be valid after released.booleanbooleanreceiveFragment(byte[] data, int off, int len, int fragmentNum, boolean isLast) Read in the data from the fragment.booleanreceiveFragment(UDPPacketReader.DataReader data, int dataFragment) Read in the data from the fragment.voidvoidsetEnqueueTime(long now) For CDQtoString()May not be valid if released, or may NPE on race with release, use with care in exception text
-
Field Details
-
MAX_FRAGMENTS
public static final int MAX_FRAGMENTS- See Also:
-
MAX_PARTIAL_BITFIELD_BYTES
public static final int MAX_PARTIAL_BITFIELD_BYTES10- See Also:
-
-
Constructor Details
-
InboundMessageState
Only for Poison right now. -
InboundMessageState
public InboundMessageState(RouterContext ctx, long messageId, Hash from, UDPPacketReader.DataReader data, int dataFragment) throws DataFormatException Create a new IMS and read in the data from the fragment. Do NOT call receiveFragment for the same fragment afterwards. This is more efficient if the fragment is the last (and probably only) fragment. The main savings is not allocating ByteArray[64]. SSU 1 only.- Parameters:
dataFragment- the fragment index in the DataReader, NOT the fragment number- Throws:
DataFormatException- if the fragment was corrupt- Since:
- 0.9.9
-
InboundMessageState
public InboundMessageState(RouterContext ctx, long messageId, Hash from, byte[] data, int off, int len, int fragmentNum, boolean isLast) throws DataFormatException Create a new IMS and read in the data from the fragment. Do NOT call receiveFragment for the same fragment afterwards. This is more efficient if the fragment is the last (and probably only) fragment. The main savings is not allocating ByteArray[64]. SSU 2 only.- Parameters:
fragmentNum- the fragment number- Throws:
DataFormatException- if the fragment was corrupt- Since:
- 0.9.54
-
-
Method Details
-
receiveFragment
public boolean receiveFragment(UDPPacketReader.DataReader data, int dataFragment) throws DataFormatException Read in the data from the fragment. Caller should synchronize. SSU 1 only.- Parameters:
dataFragment- the fragment index in the DataReader, NOT the fragment number- Returns:
- true if the data was ok, false if it was corrupt
- Throws:
DataFormatException
-
receiveFragment
public boolean receiveFragment(byte[] data, int off, int len, int fragmentNum, boolean isLast) throws DataFormatException Read in the data from the fragment. Caller should synchronize. SSU 2 only.- Parameters:
fragmentNum- the fragment number- Returns:
- true if the data was ok, false if it was corrupt
- Throws:
DataFormatException- Since:
- 0.9.54
-
hasFragment
public boolean hasFragment(int fragmentNum) Do we have this fragment? SSU 2 only.- Parameters:
fragmentNum- the fragment number- Returns:
- true if we have the fragment
- Since:
- 0.9.54
-
isComplete
public boolean isComplete()May not be valid after released. Probably doesn't need to be synced by caller, given the order of events in receiveFragment() above, but you might want to anyway to be safe. -
isExpired
public boolean isExpired() -
getLifetime
public long getLifetime() -
setEnqueueTime
public void setEnqueueTime(long now) For CDQ- Specified by:
setEnqueueTimein interfaceCDQEntry- Since:
- 0.9.3
-
getEnqueueTime
public long getEnqueueTime()For CDQ- Specified by:
getEnqueueTimein interfaceCDQEntry- Since:
- 0.9.3
-
drop
public void drop()For CDQ -
getFrom
-
getMessageId
public long getMessageId() -
getCompleteSize
public int getCompleteSize()- Throws:
IllegalStateException- if released or not isComplete()
-
createACKBitfield
Only call this if not complete. TODO remove this, have InboundMessageState implement ACKBitfield. FIXME synch here or PeerState.fetchPartialACKs() -
releaseResources
public void releaseResources() -
getFragments
- Throws:
IllegalStateException- if released
-
getFragmentCount
public int getFragmentCount() -
toString
May not be valid if released, or may NPE on race with release, use with care in exception text
-