net.i2p.router.transport.udp
Class OutboundMessageState

java.lang.Object
  extended by net.i2p.router.transport.udp.OutboundMessageState
All Implemented Interfaces:
CDPQEntry, CDQEntry, PQEntry

 class OutboundMessageState
extends Object
implements CDPQEntry

Maintain the outbound fragmentation for resending, for a single message.


Field Summary
static int MAX_MSG_SIZE
           
 
Constructor Summary
OutboundMessageState(I2PAppContext context)
           
 
Method Summary
 boolean acked(ACKBitfield bitfield)
          Ack all the fragments in the ack list.
 void drop()
          For CDQ
 void fragment(int fragmentSize)
          Prepare the message for fragmented delivery, using no more than fragmentSize bytes per fragment.
 int fragmentSize(int fragmentNum)
           
 long getEnqueueTime()
          For CDQ
 int getFragmentCount()
          how many fragments in the message
 int getFragmentSize()
           
 long getLifetime()
           
 int getMaxSends()
           
 OutNetMessage getMessage()
           
 long getMessageId()
           
 long getNextSendTime()
           
 PeerState getPeer()
           
 int getPriority()
          For CDPQ
 int getPushCount()
           
 long getSeqNum()
          For CDPQ
 int getUnackedSize()
           
 boolean initialize(I2NPMessage msg, PeerState peer)
          Called from UDPTransport TODO make two constructors, remove this, and make more things final
 boolean initialize(OutNetMessage m, I2NPMessage msg)
          Called from OutboundMessageFragments TODO make two constructors, remove this, and make more things final
 boolean isComplete()
           
 boolean isExpired()
           
 boolean isFragmented()
           
 boolean needsSending(int fragment)
           
 void push()
          note that we have pushed the message fragments
 void releaseResources()
          This is synchronized with writeFragment(), so we do not release (probably due to an ack) while we are retransmitting.
 void setEnqueueTime(long now)
          For CDQ
 void setNextSendTime(long when)
           
 void setPeer(PeerState peer)
           
 void setSeqNum(long num)
          For CDPQ
 boolean shouldSend(int fragmentNum)
          should we continue sending this fragment?
 String toString()
           
 int writeFragment(byte[] out, int outOffset, int fragmentNum)
          Write a part of the the message onto the specified buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_MSG_SIZE

public static final int MAX_MSG_SIZE
See Also:
Constant Field Values
Constructor Detail

OutboundMessageState

public OutboundMessageState(I2PAppContext context)
Method Detail

initialize

public boolean initialize(I2NPMessage msg,
                          PeerState peer)
Called from UDPTransport TODO make two constructors, remove this, and make more things final

Returns:
success
Throws:
IAE - if too big

initialize

public boolean initialize(OutNetMessage m,
                          I2NPMessage msg)
Called from OutboundMessageFragments TODO make two constructors, remove this, and make more things final

Returns:
success
Throws:
IAE - if too big

releaseResources

public void releaseResources()
This is synchronized with writeFragment(), so we do not release (probably due to an ack) while we are retransmitting. Also prevent double-free


getMessage

public OutNetMessage getMessage()

getMessageId

public long getMessageId()

getPeer

public PeerState getPeer()

setPeer

public void setPeer(PeerState peer)

isExpired

public boolean isExpired()

isComplete

public boolean isComplete()

getUnackedSize

public int getUnackedSize()

needsSending

public boolean needsSending(int fragment)

getLifetime

public long getLifetime()

acked

public boolean acked(ACKBitfield bitfield)
Ack all the fragments in the ack list. As a side effect, if there are still unacked fragments, the 'next send' time will be updated under the assumption that that all of the packets within a volley would reach the peer within that ack frequency (2-400ms).

Returns:
true if the message was completely ACKed

getNextSendTime

public long getNextSendTime()

setNextSendTime

public void setNextSendTime(long when)

getMaxSends

public int getMaxSends()

getPushCount

public int getPushCount()

push

public void push()
note that we have pushed the message fragments


isFragmented

public boolean isFragmented()

fragment

public void fragment(int fragmentSize)
Prepare the message for fragmented delivery, using no more than fragmentSize bytes per fragment.


getFragmentCount

public int getFragmentCount()
how many fragments in the message


getFragmentSize

public int getFragmentSize()

shouldSend

public boolean shouldSend(int fragmentNum)
should we continue sending this fragment?


fragmentSize

public int fragmentSize(int fragmentNum)

writeFragment

public int writeFragment(byte[] out,
                         int outOffset,
                         int fragmentNum)
Write a part of the the message onto the specified buffer. See releaseResources() above for synchhronization information.

Parameters:
out - target to write
outOffset - into outOffset to begin writing
fragmentNum - fragment to write (0 indexed)
Returns:
bytesWritten

setEnqueueTime

public void setEnqueueTime(long now)
For CDQ

Specified by:
setEnqueueTime in interface CDQEntry
Since:
0.9.3

getEnqueueTime

public long getEnqueueTime()
For CDQ

Specified by:
getEnqueueTime in interface CDQEntry
Since:
0.9.3

drop

public void drop()
For CDQ

Specified by:
drop in interface CDQEntry
Since:
0.9.3

setSeqNum

public void setSeqNum(long num)
For CDPQ

Specified by:
setSeqNum in interface PQEntry
Since:
0.9.3

getSeqNum

public long getSeqNum()
For CDPQ

Specified by:
getSeqNum in interface PQEntry
Since:
0.9.3

getPriority

public int getPriority()
For CDPQ

Specified by:
getPriority in interface PQEntry
Returns:
OutNetMessage priority or 1000 for injected
Since:
0.9.3

toString

public String toString()
Overrides:
toString in class Object