net.i2p.router.transport
Class TransportImpl

java.lang.Object
  extended bynet.i2p.router.transport.TransportImpl
All Implemented Interfaces:
Transport
Direct Known Subclasses:
TCPTransport, UDPTransport

public abstract class TransportImpl
extends java.lang.Object
implements Transport

Defines a way to send a message to another peer and start listening for messages


Field Summary
protected  RouterContext _context
           
 
Constructor Summary
TransportImpl(RouterContext context)
          Initialize the new transport
 
Method Summary
protected  void afterSend(OutNetMessage msg, boolean sendSuccessful)
          The transport is done sending this message
protected  void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue)
          The transport is done sending this message
protected  void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend)
          The transport is done sending this message.
protected  void afterSend(OutNetMessage msg, boolean sendSuccessful, long msToSend)
          The transport is done sending this message
 int countActivePeers()
          How many peers can we talk to right now?
 RouterContext getContext()
           
 java.util.Set getCurrentAddresses()
          What addresses are we currently listening to?
 java.util.List getMostRecentErrorMessages()
           
 OutNetMessage getNextMessage()
          Nonblocking call to pull the next outbound message off the queue.
 void messageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived)
          Message received from the I2NPMessageReader - send it to the listener
protected abstract  void outboundMessageReady()
          This message is called whenever a new message is added to the send pool, and it should not block
 void renderStatusHTML(java.io.Writer out)
          Make this stuff pretty (only used in the old console)
protected  void replaceAddress(RouterAddress address)
          Replace any existing addresses for the current transport with the given one.
 void send(OutNetMessage msg)
          Asynchronously send the message as requested in the message and, if the send is successful, queue up any msg.getOnSendJob job, and register it with the OutboundMessageRegistry (if it has a reply selector).
 void setListener(TransportEventListener listener)
          Who to notify on message availability
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.i2p.router.transport.Transport
bid, getStyle, startListening, stopListening
 

Field Detail

_context

protected RouterContext _context
Constructor Detail

TransportImpl

public TransportImpl(RouterContext context)
Initialize the new transport

Method Detail

countActivePeers

public int countActivePeers()
How many peers can we talk to right now?

Specified by:
countActivePeers in interface Transport

getMostRecentErrorMessages

public java.util.List getMostRecentErrorMessages()
Specified by:
getMostRecentErrorMessages in interface Transport

getNextMessage

public OutNetMessage getNextMessage()
Nonblocking call to pull the next outbound message off the queue.

Returns:
the next message or null if none are available

afterSend

protected void afterSend(OutNetMessage msg,
                         boolean sendSuccessful)
The transport is done sending this message

Parameters:
msg - message in question
sendSuccessful - true if the peer received it

afterSend

protected void afterSend(OutNetMessage msg,
                         boolean sendSuccessful,
                         boolean allowRequeue)
The transport is done sending this message

Parameters:
msg - message in question
sendSuccessful - true if the peer received it
allowRequeue - true if we should try other transports if available

afterSend

protected void afterSend(OutNetMessage msg,
                         boolean sendSuccessful,
                         long msToSend)
The transport is done sending this message

Parameters:
msg - message in question
sendSuccessful - true if the peer received it
msToSend - how long it took to transfer the data to the peer

afterSend

protected void afterSend(OutNetMessage msg,
                         boolean sendSuccessful,
                         boolean allowRequeue,
                         long msToSend)
The transport is done sending this message. This is the method that actually does all of the cleanup - firing off jobs, requeueing, updating stats, etc.

Parameters:
msg - message in question
sendSuccessful - true if the peer received it
msToSend - how long it took to transfer the data to the peer
allowRequeue - true if we should try other transports if available

send

public void send(OutNetMessage msg)
Asynchronously send the message as requested in the message and, if the send is successful, queue up any msg.getOnSendJob job, and register it with the OutboundMessageRegistry (if it has a reply selector). If the send fails, queue up any msg.getOnFailedSendJob

Specified by:
send in interface Transport

outboundMessageReady

protected abstract void outboundMessageReady()
This message is called whenever a new message is added to the send pool, and it should not block


messageReceived

public void messageReceived(I2NPMessage inMsg,
                            RouterIdentity remoteIdent,
                            Hash remoteIdentHash,
                            long msToReceive,
                            int bytesReceived)
Message received from the I2NPMessageReader - send it to the listener


getCurrentAddresses

public java.util.Set getCurrentAddresses()
What addresses are we currently listening to?

Specified by:
getCurrentAddresses in interface Transport

replaceAddress

protected void replaceAddress(RouterAddress address)
Replace any existing addresses for the current transport with the given one.


setListener

public void setListener(TransportEventListener listener)
Who to notify on message availability

Specified by:
setListener in interface Transport

renderStatusHTML

public void renderStatusHTML(java.io.Writer out)
                      throws java.io.IOException
Make this stuff pretty (only used in the old console)

Specified by:
renderStatusHTML in interface Transport
Throws:
java.io.IOException

getContext

public RouterContext getContext()