net.i2p.client
Class I2PSessionMuxedImpl

java.lang.Object
  extended by net.i2p.client.I2PSessionImpl
      extended by net.i2p.client.I2PSessionImpl2
          extended by net.i2p.client.I2PSessionMuxedImpl
All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener

 class I2PSessionMuxedImpl
extends I2PSessionImpl2
implements I2PSession

I2PSession with protocol and ports Streaming lib has been modified to send I2PSession.PROTO_STREAMING but still receives all. It sends with fromPort and toPort = 0, and receives on all ports. No datagram apps have been modified yet. Therefore the compatibility situation is as follows: Compatibility: old streaming -> new streaming: sends proto anything, rcvs proto anything new streaming -> old streaming: sends PROTO_STREAMING, ignores rcvd proto old datagram -> new datagram: sends proto anything, rcvs proto anything new datagram -> old datagram: sends PROTO_DATAGRAM, ignores rcvd proto In all the above cases, streaming and datagram receive traffic for the other protocol, same as before. old datagram -> new muxed: doesn't work because the old sends proto 0 but the udp side of the mux registers with PROTO_DATAGRAM, so the datagrams go to the streaming side, same as before. old streaming -> new muxed: works Typical Usage: Streaming + datagrams: I2PSocketManager sockMgr = getSocketManager(); I2PSession session = sockMgr.getSession(); session.addMuxedSessionListener(myI2PSessionMuxedListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); * or * session.addSessionListener(myI2PSessionListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); session.sendMessage(dest, payload, I2PSession.PROTO_DATAGRAM, fromPort, toPort); Datagrams only, with multiple ports: I2PClient client = I2PClientFactory.createClient(); ... I2PSession session = client.createSession(...); session.addMuxedSessionListener(myI2PSessionMuxedListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); * or * session.addSessionListener(myI2PSessionListener, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY); session.sendMessage(dest, payload, I2PSession.PROTO_DATAGRAM, fromPort, toPort); Multiple streaming ports: Needs some streaming lib hacking

Author:
zzz

Nested Class Summary
protected  class I2PSessionMuxedImpl.MuxedAvailabilityNotifier
           
 
Nested classes/interfaces inherited from class net.i2p.client.I2PSessionImpl
I2PSessionImpl.AvailabilityNotifier, I2PSessionImpl.VerifyUsage
 
Field Summary
 
Fields inherited from class net.i2p.client.I2PSessionImpl
_availabilityNotifier, _availableMessages, _closed, _closing, _context, _handlerMap, _hostname, _log, _opening, _out, _portNum, _producer, _reader, _sessionListener, _socket, _writer, LISTEN_PORT
 
Fields inherited from interface net.i2p.client.I2PSession
PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_STREAMING, PROTO_UNSPECIFIED
 
Constructor Summary
I2PSessionMuxedImpl(I2PAppContext ctx, java.io.InputStream destKeyStream, java.util.Properties options)
           
 
Method Summary
 void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port)
          Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.
 void addNewMessage(MessagePayloadMessage msg)
          Receive a payload message and let the app know its available
 void addSessionListener(I2PSessionListener lsnr, int proto, int port)
          Listen on specified protocol and port.
 void removeListener(int proto, int port)
          removes the specified listener (only)
 boolean sendMessage(Destination dest, byte[] payload)
          Send the data to the destination.
 boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport)
          See I2PSessionMuxedImpl for details
 boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, java.util.Set tagsSent, int proto, int fromport, int toport)
          See I2PSessionMuxedImpl for details
 boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, java.util.Set tagsSent, long expires)
           
 boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, java.util.Set tagsSent, long expires, int proto, int fromPort, int toPort)
          See I2PSessionMuxedImpl for details
 void setSessionListener(I2PSessionListener lsnr)
          listen on all protocols and ports
 
Methods inherited from class net.i2p.client.I2PSessionImpl2
destroySession, getTimeout, receiveMessage, receiveStatus, reconnect, sendBestEffort, sendMessage, sendMessage, sendMessage, shouldCompress
 
Methods inherited from class net.i2p.client.I2PSessionImpl
bandwidthLimits, connect, dateUpdated, destroySession, disconnect, disconnected, getDecryptionKey, getLeaseSet, getMyDestination, getOpening, getOptions, getPrefix, getPrivateKey, getProducer, getSessionId, isClosed, lastActivity, loadConfig, lookupDest, messageReceived, propogateError, readError, reportAbuse, sendMessage, setLeaseSet, setOpening, setReduced, setSessionId, shouldReconnect, toString, updateActivity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.i2p.client.I2PSession
bandwidthLimits, connect, destroySession, getDecryptionKey, getMyDestination, getPrivateKey, isClosed, lookupDest, receiveMessage, reportAbuse, sendMessage, sendMessage, sendMessage
 

Constructor Detail

I2PSessionMuxedImpl

public I2PSessionMuxedImpl(I2PAppContext ctx,
                           java.io.InputStream destKeyStream,
                           java.util.Properties options)
                    throws I2PSessionException
Throws:
I2PSessionException
Method Detail

setSessionListener

public void setSessionListener(I2PSessionListener lsnr)
listen on all protocols and ports

Specified by:
setSessionListener in interface I2PSession
Overrides:
setSessionListener in class I2PSessionImpl
Parameters:
lsnr - listener to retrieve events

addSessionListener

public void addSessionListener(I2PSessionListener lsnr,
                               int proto,
                               int port)
Listen on specified protocol and port. An existing listener with the same proto and port is replaced. Only the listener with the best match is called back for each message.

Specified by:
addSessionListener in interface I2PSession
Overrides:
addSessionListener in class I2PSessionImpl2
Parameters:
proto - 1-254 or PROTO_ANY for all; recommended: I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
port - 1-65535 or PORT_ANY for all

addMuxedSessionListener

public void addMuxedSessionListener(I2PSessionMuxedListener l,
                                    int proto,
                                    int port)
Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.

Specified by:
addMuxedSessionListener in interface I2PSession
Overrides:
addMuxedSessionListener in class I2PSessionImpl2
Parameters:
proto - 1-254 or 0 for all; 255 disallowed
port - 1-65535 or 0 for all

removeListener

public void removeListener(int proto,
                           int port)
removes the specified listener (only)

Specified by:
removeListener in interface I2PSession
Overrides:
removeListener in class I2PSessionImpl2

sendMessage

public boolean sendMessage(Destination dest,
                           byte[] payload)
                    throws I2PSessionException
Description copied from class: I2PSessionImpl
Send the data to the destination. TODO: this currently always returns true, regardless of whether the message was delivered successfully. make this wait for at least ACCEPTED

Specified by:
sendMessage in interface I2PSession
Overrides:
sendMessage in class I2PSessionImpl2
Parameters:
dest - location to send the message
payload - body of the message to be sent (unencrypted)
Returns:
whether it was accepted by the router for delivery or not
Throws:
I2PSessionException

sendMessage

public boolean sendMessage(Destination dest,
                           byte[] payload,
                           int proto,
                           int fromport,
                           int toport)
                    throws I2PSessionException
Description copied from interface: I2PSession
See I2PSessionMuxedImpl for details

Specified by:
sendMessage in interface I2PSession
Overrides:
sendMessage in class I2PSessionImpl2
Throws:
I2PSessionException

sendMessage

public boolean sendMessage(Destination dest,
                           byte[] payload,
                           int offset,
                           int size,
                           SessionKey keyUsed,
                           java.util.Set tagsSent,
                           long expires)
                    throws I2PSessionException
Specified by:
sendMessage in interface I2PSession
Overrides:
sendMessage in class I2PSessionImpl2
Parameters:
keyUsed - unused - no end-to-end crypto
tagsSent - unused - no end-to-end crypto
Throws:
I2PSessionException

sendMessage

public boolean sendMessage(Destination dest,
                           byte[] payload,
                           int offset,
                           int size,
                           SessionKey keyUsed,
                           java.util.Set tagsSent,
                           int proto,
                           int fromport,
                           int toport)
                    throws I2PSessionException
Description copied from interface: I2PSession
See I2PSessionMuxedImpl for details

Specified by:
sendMessage in interface I2PSession
Overrides:
sendMessage in class I2PSessionImpl2
Parameters:
keyUsed - unused - no end-to-end crypto
tagsSent - unused - no end-to-end crypto
Throws:
I2PSessionException

sendMessage

public boolean sendMessage(Destination dest,
                           byte[] payload,
                           int offset,
                           int size,
                           SessionKey keyUsed,
                           java.util.Set tagsSent,
                           long expires,
                           int proto,
                           int fromPort,
                           int toPort)
                    throws I2PSessionException
Description copied from interface: I2PSession
See I2PSessionMuxedImpl for details

Specified by:
sendMessage in interface I2PSession
Overrides:
sendMessage in class I2PSessionImpl2
Parameters:
keyUsed - unused - no end-to-end crypto
tagsSent - unused - no end-to-end crypto
proto - 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowed
fromPort - 1-65535 or 0 for unset
toPort - 1-65535 or 0 for unset
Throws:
I2PSessionException

addNewMessage

public void addNewMessage(MessagePayloadMessage msg)
Receive a payload message and let the app know its available

Overrides:
addNewMessage in class I2PSessionImpl