net.i2p.router.transport
Class TransportImpl

java.lang.Object
  extended by net.i2p.router.transport.TransportImpl
All Implemented Interfaces:
Transport
Direct Known Subclasses:
NTCPTransport, 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?
 int countActiveSendPeers()
          How many peers are we actively sending messages to (this minute)
 java.util.Vector getClockSkews()
          Return our peer clock skews on a transport.
 RouterContext getContext()
           
 RouterAddress getCurrentAddress()
          What addresses are we currently listening to?
 java.util.List getMostRecentErrorMessages()
           
 OutNetMessage getNextMessage()
          Nonblocking call to pull the next outbound message off the queue.
 short getReachabilityStatus()
           
 boolean isBacklogged(Hash dest)
           
static boolean isPubliclyRoutable(byte[] addr)
           
 boolean isUnreachable(Hash peer)
           
 void markReachable(Hash peer)
          called when we establish a peer connection (outbound or inbound)
 void markUnreachable(Hash peer)
          called when we can't reach a peer
 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 recheckReachability()
           
 void renderStatusHTML(java.io.Writer out)
          Make this stuff pretty (only used in the old console)
 void renderStatusHTML(java.io.Writer out, java.lang.String urlBase, int sortFlags)
           
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

countActiveSendPeers

public int countActiveSendPeers()
How many peers are we actively sending messages to (this minute)

Specified by:
countActiveSendPeers in interface Transport

getClockSkews

public java.util.Vector getClockSkews()
Return our peer clock skews on a transport. Vector composed of Long, each element representing a peer skew in seconds. Dummy version. Transports override it.

Specified by:
getClockSkews 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


getCurrentAddress

public RouterAddress getCurrentAddress()
What addresses are we currently listening to?

Specified by:
getCurrentAddress 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)

Throws:
java.io.IOException

renderStatusHTML

public void renderStatusHTML(java.io.Writer out,
                             java.lang.String urlBase,
                             int sortFlags)
                      throws java.io.IOException
Specified by:
renderStatusHTML in interface Transport
Throws:
java.io.IOException

getContext

public RouterContext getContext()

getReachabilityStatus

public short getReachabilityStatus()
Specified by:
getReachabilityStatus in interface Transport

recheckReachability

public void recheckReachability()
Specified by:
recheckReachability in interface Transport

isBacklogged

public boolean isBacklogged(Hash dest)
Specified by:
isBacklogged in interface Transport

isUnreachable

public boolean isUnreachable(Hash peer)
Specified by:
isUnreachable in interface Transport

markUnreachable

public void markUnreachable(Hash peer)
called when we can't reach a peer


markReachable

public void markReachable(Hash peer)
called when we establish a peer connection (outbound or inbound)


isPubliclyRoutable

public static boolean isPubliclyRoutable(byte[] addr)