- All Implemented Interfaces:
I2PSession, I2CPMessageReader.I2CPMessageEventListener
- Direct Known Subclasses:
SubSession
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(I2PAppContext); ... 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.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classKeep this simple.protected classMuxedAvailabilityNotifier Extends AvailabilityNotifier.Nested classes/interfaces inherited from class I2PSessionImpl
I2PSessionImpl.AvailabilityNotifier, I2PSessionImpl.StateModifier and TypeClassDescriptionprotected classThis notifies the client of payload messages.protected static enumSession state enumeration.Nested classes/interfaces inherited from interface I2PSession
I2PSession.TunnelPairModifier and TypeInterfaceDescriptionstatic classSimple holder for tunnel pair information.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PSessionDemultiplexerThe demultiplexer delivering the messages.private static final intUpper two bytes of MTIME in gzip header.private static final intOS byte in gzip header.private static final intLower two bytes of MTIME in gzip header.Fields inherited from class I2PSessionImpl2
_noEffort, _sendingStates, _sendMessageNonceModifier and TypeFieldDescriptionprotected booleanDon't expect any MSMs from the router for outbound traffic.protected final Map<Long, MessageState> One MessageState object per message in the process of being sent.protected final AtomicLongSource of the per-message replay nonces sent to the router.Fields inherited from class I2PSessionImpl
_availabilityNotifier, _availableMessages, _bwLimits, _bwReceivedLock, _context, _handlerMap, _hostname, _leaseSet, _leaseSetWait, _log, _pendingLookups, _portNum, _producer, _queue, _reader, _sessionListener, _socket, _state, _stateLock, _transientSigningPublicKey, _tunnelStatusListeners, _writer, CACHE_MAX_SIZE, DUMMY_SESSION, LISTEN_PORT, PROP_DOMAIN_SOCKETModifier and TypeFieldDescriptionprotected I2PSessionImpl.AvailabilityNotifierThread that we tell when new messages are available, who then tells us to fetch them.protected Map<Long, MessagePayloadMessage> Map of Long--> MessagePayloadMessage.protected int[]Current bandwidth limits.protected final ObjectLock for bandwidth limit updates.protected final I2PAppContextApp context, kept separate so we can get rid of singletons.protected final I2PClientMessageHandlerMapHandler map for I2CP message types.protected final StringHostname of router - will be null if in RouterContext.protected LeaseSetCurrently granted lease set, or null.protected final ObjectMonitor for waiting until a lease set has been granted.protected final LogLogger for this session.protected final LinkedBlockingQueue<I2PSessionImpl.LookupWaiter> Hashes of lookups we are waiting for.protected final intPort number of router - will be 0 if in RouterContext.protected final I2CPMessageProducerClass that generates new messages.protected I2CPMessageQueueUsed for internal connections to the router.protected I2CPMessageReaderReader that always searches for messages.protected I2PSessionListenerWhere session events are sent.protected SocketSocket for communication.protected I2PSessionImpl.StateCurrent session state.protected final ObjectLock for state transitions.protected SigningPublicKeyTransient signing public key for offline signatures.protected final Set<TunnelStatusListener> Listeners for tunnel status changes (tunnel failures and removals).protected ClientWriterRunnerWriter message queue.protected static final intMaximum size of the lookup cache.(package private) static final SessionIdDummy session ID for messages before a real session is established.static final intDefault I2CP listen port.protected static final StringUse Unix domain socket (or similar) to connect to a router.Fields inherited from interface I2PSession
PORT_ANY, PORT_UNSPECIFIED, PROTO_ANY, PROTO_DATAGRAM, PROTO_DATAGRAM_RAW, PROTO_DATAGRAM2, PROTO_DATAGRAM3, PROTO_STREAMING, PROTO_UNSPECIFIEDModifier and TypeFieldDescriptionstatic final intAny port.static final intUnspecified port.static final intAny protocol.static final intA repliable and signed datagram.static final intA raw (unsigned, unrepliable) datagram.static final intA repliable and signed datagram.static final intA repliable but unsigned datagram.static final intStreaming protocol.static final intUnspecified protocol.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedI2PSessionMuxedImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) For extension bySubSession.I2PSessionMuxedImpl(I2PAppContext ctx, InputStream destKeyStream, Properties options) Create a new muxed session.Method Summary
Modifier and TypeMethodDescriptionvoidaddMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port) Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.voidStore a received payload message and notify the client that it is available, including the protocol and ports it arrived on.voidaddSessionListener(I2PSessionListener lsnr, int proto, int port) Listen on specified protocol and port.private static intgetByte(MessagePayloadMessage msg, int i) Reads one payload byte of the message.private static intNon-muxed sets the MTIME bytes to 0.private static intNon-muxed sets the OS byte to 0xff.private static intNon-muxed sets the MTIME bytes to 0.private byte[]prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions.GzipOption gzo) Prepare the payload for sending.voidremoveListener(int proto, int port) Remove the specified listener (only).booleansendMessage(Destination dest, byte[] payload) Send an I2CP message, with the protocol and ports unset.booleansendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options) See SendMessageOptions for option details.longsendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options, SendMessageStatusListener listener) Send a message and request an asynchronous notification of delivery status.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort) Send a message with protocol and port information.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort, int flags) Send a message with protocol, port, and flags.private voidsendNoEffort(Destination dest, byte[] payload, SendMessageOptions options) Send a message without expecting a response.private static voidsetFromPort(byte[] payload, int p) Sets the from port of the payload.private static voidsetProto(byte[] payload, int p) Sets the protocol byte of the payload.voidListen on all protocols and ports.private static voidsetToPort(byte[] payload, int p) Sets the to port of the payload.Methods inherited from class I2PSessionImpl2
addTunnelStatusListener, destroySession, getCurrentTunnelPair, getTimeout, notifyPoolShuttingDown, notifyTunnelFailed, notifyTunnelRemoved, rebuildTunnels, receiveMessage, receiveStatus, reconnect, removeTunnelStatusListener, sendBestEffort, sendBestEffort, sendMessage, sendMessage, sendMessage, sendNoEffort, setCurrentTunnelPair, shouldCompress, startVerifyUsage, switchToNewTunnelModifier and TypeMethodDescriptionvoidRegister a tunnel status listener.voiddestroySession(boolean sendDisconnect) Destroy the I2P session, after clearing the message send states.Return the current tunnel pair.protected longWait this long for the router to accept a sent message, in ms.protected voidnotifyPoolShuttingDown(String poolName, boolean isInbound) Notify all tunnel status listeners of pool shutdown.protected voidnotifyTunnelFailed(String poolName, boolean isInbound) Notify all tunnel status listeners of a tunnel failure.protected voidNotify all tunnel status listeners of a tunnel removal.voidRebuild the tunnel set.byte[]receiveMessage(int msgId) Receive a message from the router, decompressing it unless it was sent uncompressed.voidreceiveStatus(int msgId, long nonce, int status) Only call this with nonzero status, i.e.protected booleanReconnect the I2CP session.voidRemove a tunnel status listener.protected booleansendBestEffort(Destination dest, byte[] payload, long expires, int flags) Send a best-effort message with the given flags.protected booleansendBestEffort(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) Send a message with best effort delivery.booleansendMessage(Destination dest, byte[] payload, int offset, int size) Send an I2CP message.booleansendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent) Send a message with session key and tags.booleansendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent) Send a message with session key and tags.protected booleansendNoEffort(Destination dest, byte[] payload, long expires, int flags) Same asI2PSessionImpl2.sendBestEffort(Destination, byte[], SessionKey, Set, long), except we do not expect any MessageStatusMessage responses - not for accepted, or success, or failure.voidCurrent tunnel pair in use.protected booleanshouldCompress(int size) Return whether compression should be used.protected voidFire up a periodic task to check for unclaimed messages.booleanSwitch to the new tunnel set.Methods inherited from class I2PSessionImpl
addSubsession, bandwidthLimits, bwReceived, changeState, clearCache, connect, dateUpdated, destLookupFailed, destLookupFailed, destReceived, destReceived, destroySession, discardMessage, disconnect, disconnected, getContext, getFastReceive, getHandlerMap, getLastLS2SignTime, getLeaseSet, getMyDestination, getName, getOfflineExpiration, getOfflineSignature, getOptions, getPrefix, getPrivateKey, getProducer, getRouterVersion, getSessionId, getSubsessions, getTransientSigningPublicKey, getTunnelBuildTimeout, isClosed, isOffline, lastActivity, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest, lookupDest2, messageReceived, propagateError, readError, removeSubsession, reportAbuse, sendBlindingInfo, sendMessage, sendMessage_unchecked, setLastLS2SignTime, setLeaseSet, setReduced, setSessionId, shouldReconnect, supportsLS2, toString, updateActivity, updateOptions, verifyOpen, waitForDateModifier and TypeMethodDescriptionaddSubsession(InputStream privateKeyStream, Properties opts) Router must be connected or was connected...int[]Blocking.(package private) voidbwReceived(int[] limits) Called by the message handler.protected voidchangeState(I2PSessionImpl.State state) Change the session state.static voidClear the lookup cache.voidconnect()Connect to the router and establish a session.(package private) voiddateUpdated(String routerVersion) Update the router version and related feature support flags.(package private) voiddestLookupFailed(long nonce, int code) Called by the message handler on reception of HostReplyMessage.(package private) voidCalled by the message handler on reception of DestReplyMessage.(package private) voiddestReceived(long nonce, Destination d) Called by the message handler on reception of HostReplyMessage.(package private) voidCalled by the message handler on reception of DestReplyMessage.voidTear down the session, and do NOT reconnect.voiddiscardMessage(int msgId) Throw away the received message, we don't want it.protected voidWill interrupt a connect in progress.voiddisconnected(I2CPMessageReader reader) The I2CPMessageEventListener callback.(package private) I2PAppContextFor Subsessions.booleanDoes this session support fast receive?(package private) I2PClientMessageHandlerMapFor Subsessions.(package private) longThe published timestamp of the last LS2 we signed.Current lease set published by this session.Retrieve the destination of the session.protected StringgetName()Session name for logging.longJava time (ms) or 0 if not initialized or does not have offline keys.Null on error or if not initialized or does not have offline keys.Retrieve the configuration options, filtered.protected final StringTry hard to make a decent identifier as this will appear in error logs.Retrieve the signing SigningPrivateKey.(package private) I2CPMessageProducerRetrieve the helper that generates I2CP messages.Always valid in RouterContext.(package private) SessionIdRetrieve the session's ID.List of subsessions, non-null, does not include the primary session.Null on error or if not initialized or does not have offline keys.(package private) static intgetTunnelBuildTimeout(String sessionValue, String contextValue) Parse the tunnel build timeout, shared with the instance method and tests.booleanisClosed()Has the session been closed (or not yet connected)? False when open and during transitions.booleanDoes this session have offline and transient keys?longTime of last session activity in milliseconds.lookupDest(String name) Ask the router to lookup a Destination by host name.lookupDest(String name, long maxWait) Ask the router to lookup a Destination by host name.lookupDest(String name, long maxWait, LookupCallback callback) Lookup a Destination by hash.lookupDest(Hash h) Blocking.lookupDest(Hash h, long maxWait) Blocking.lookupDest(Hash h, long maxWait, LookupCallback callback) Lookup a Destination by hostname.lookupDest2(String name, long maxWait) Ask the router to lookup a Destination by host name.voidmessageReceived(I2CPMessageReader reader, I2CPMessage message) The I2CPMessageEventListener callback.(package private) voidpropagateError(String msg, Throwable error) Pass off the error to the listener Misspelled, oh well.voidreadError(I2CPMessageReader reader, Exception error) The I2CPMessageEventListener callback.voidremoveSubsession(I2PSession session) No-op, this session has no subsessions.voidreportAbuse(int msgId, int severity) Report abuse with regards to the given messageId.voidSend blinding info to a peer.(package private) voidsendMessage(I2CPMessage message) Deliver an I2CP message to the router As of 0.9.3, may block for several seconds if the write queue to the router is full.(package private) voidsendMessage_unchecked(I2CPMessage message) Deliver an I2CP message to the router.(package private) voidsetLastLS2SignTime(long now) The published timestamp of the last LS2 we signed.(package private) voidsetLeaseSet(LeaseSet ls) Lease set published by this session.voidMark the session as reduced.(package private) voidSession ID assigned by the router.protected booleanWhether the session should attempt reconnection on disconnect.booleanDoes this session support LS2?toString()protected voidUpdate the last activity timestamp.voidupdateOptions(Properties options) Update the tunnel and bandwidth settings.protected voidThrows I2PSessionException if uninitialized, closed or closing.protected voidWait for a SetDate response from the router.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface I2PSession
getDecryptionKeyModifier and TypeMethodDescriptionRetrieve the decryption PrivateKey associated with the Destination.
Field Details
_demultiplexer
The demultiplexer delivering the messages.PROTO_BYTE
FROMPORT_BYTES
private static final int FROMPORT_BYTESUpper two bytes of MTIME in gzip header.- See Also:
TOPORT_BYTES
private static final int TOPORT_BYTESLower two bytes of MTIME in gzip header.- See Also:
Constructor Details
I2PSessionMuxedImpl
public I2PSessionMuxedImpl(I2PAppContext ctx, InputStream destKeyStream, Properties options) throws I2PSessionException Create a new muxed session.- Parameters:
ctx- the application context whose router is to be useddestKeyStream- stream containing the private key data, format is specified inPrivateKeyFileoptions- set of options to configure the router with, if null will use System properties- Throws:
I2PSessionException- if there is a problem loading the private keys
I2PSessionMuxedImpl
protected I2PSessionMuxedImpl(I2PSessionImpl primary, InputStream destKeyStream, Properties options) throws I2PSessionException For extension bySubSession.- Parameters:
primary- the SubSession this one multiplexes alongside, or nulldestKeyStream- stream containing the private key data, format is specified inPrivateKeyFileoptions- set of options to configure the router with, if null will use System properties- Throws:
I2PSessionException- if there is a problem loading the private keys
Method Details
setSessionListener
Listen on all protocols and ports.- Specified by:
setSessionListenerin interfaceI2PSession- Overrides:
setSessionListenerin classI2PSessionImpl- Parameters:
lsnr- listener to retrieve events
addSessionListener
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:
addSessionListenerin interfaceI2PSession- Overrides:
addSessionListenerin classI2PSessionImpl2- Parameters:
lsnr- the listener to addproto- 1-254 or PROTO_ANY (0) for all; recommended: I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedport- 1-65535 or PORT_ANY (0) for all
addMuxedSessionListener
Listen on specified protocol and port, and receive notification of proto, fromPort, and toPort for every message.- Specified by:
addMuxedSessionListenerin interfaceI2PSession- Overrides:
addMuxedSessionListenerin classI2PSessionImpl2- Parameters:
l- the listener to addproto- 1-254 or PROTO_ANY (0) for all; 255 disallowedport- 1-65535 or PORT_ANY (0) for all
removeListener
public void removeListener(int proto, int port) Remove the specified listener (only).- Specified by:
removeListenerin interfaceI2PSession- Overrides:
removeListenerin classI2PSessionImpl2- Parameters:
proto- the protocol the listener was added forport- the port the listener was added for
sendMessage
Send an I2CP message, with the protocol and ports unset.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)- Returns:
- true if the router accepted the message, false if it was refused
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException Send an I2CP message.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)proto- 1-254, or 0 for unset; 255 disallowedfromport- source port, 1-65535 or 0 for unsettoport- destination port, 1-65535 or 0 for unset- Returns:
- true if the router accepted the message, false if it was refused
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires) throws I2PSessionException Send a message with session key and tags.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoexpires- absolute expiration timestamp, NOT interval from now- Returns:
- true unless the router reported a failed send status
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromport, int toport) throws I2PSessionException Send a message with session key and tags.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromport- 1-65535 or 0 for unsettoport- 1-65535 or 0 for unset- Returns:
- true unless the router reported a failed send status
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort) throws I2PSessionException Send a message with protocol and port information.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoexpires- absolute expiration timestamp, NOT interval from nowproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromPort- 1-65535 or 0 for unsettoPort- 1-65535 or 0 for unset- Returns:
- true unless the router reported a failed send status
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expires, int proto, int fromPort, int toPort, int flags) throws I2PSessionException Send a message with protocol, port, and flags.- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendkeyUsed- unused - no end-to-end cryptotagsSent- unused - no end-to-end cryptoexpires- absolute expiration timestamp, NOT interval from nowproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromPort- 1-65535 or 0 for unsettoPort- 1-65535 or 0 for unsetflags- to be passed to the router- Returns:
- true unless the router reported a failed send status
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options) throws I2PSessionException See SendMessageOptions for option details.Always uses sendNoEffort for now.
- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromPort- 1-65535 or 0 for unsettoPort- 1-65535 or 0 for unsetoptions- to be passed to the router- Returns:
- true always
- Throws:
I2PSessionException- if the session is not open or closed, or the write queue stays full
sendMessage
public long sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException Send a message and request an asynchronous notification of delivery status.See I2PSessionMuxedImpl for proto/port details. See SendMessageOptions for option details.
- Specified by:
sendMessagein interfaceI2PSession- Overrides:
sendMessagein classI2PSessionImpl2- Parameters:
dest- location to send the messagepayload- body of the message to be sent (unencrypted)offset- offset into the payloadsize- number of bytes to sendproto- 1-254 or 0 for unset; recommended: I2PSession.PROTO_UNSPECIFIED I2PSession.PROTO_STREAMING I2PSession.PROTO_DATAGRAM 255 disallowedfromPort- 1-65535 or 0 for unsettoPort- 1-65535 or 0 for unsetoptions- to be passed to the routerlistener- for delivery status notification- Returns:
- the message ID to be used for later notification to the listener
- Throws:
I2PSessionException- on all errors
prepPayload
private byte[] prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions.GzipOption gzo) throws I2PSessionException Prepare the payload for sending.- Parameters:
payload- the message data to wrapoffset- start of the message data within payloadsize- number of message bytes to take from offsetproto- protocol written to the gzip OS byte, 1-254 or 0 for unsetfromPort- source port written to the MTIME field, 1-65535 or 0 for unsettoPort- destination port written to the MTIME field, 1-65535 or 0 for unsetgzo- gzip selection; DEFAULT compresses by size heuristic, GZIP_ON forces compression- Returns:
- gzip compressed payload, ready to send
- Throws:
I2PSessionException- if the session is not open
sendNoEffort
private void sendNoEffort(Destination dest, byte[] payload, SendMessageOptions options) throws I2PSessionException Send a message without expecting a response.- Parameters:
dest- the destination to deliver the message topayload- the already-prepared message dataoptions- delivery options, expiration and flags applied to the message- Throws:
I2PSessionException- if the message cannot be queued to the router, e.g. the write queue is full or the session closed
addNewMessage
Store a received payload message and notify the client that it is available, including the protocol and ports it arrived on.- Overrides:
addNewMessagein classI2PSessionImpl- Parameters:
msg- the received payload, whose data must be at least 10 bytes for the gzip header
getProto
Non-muxed sets the OS byte to 0xff.- Parameters:
msg- the received payload message to read the header from- Returns:
- the protocol 0-254, or PROTO_UNSPECIFIED when the OS byte is 0xff
getFromPort
Non-muxed sets the MTIME bytes to 0.- Parameters:
msg- the received payload message to read the header from- Returns:
- the source port 0-65535 from the upper two MTIME bytes, 0 if unset
getToPort
Non-muxed sets the MTIME bytes to 0.- Parameters:
msg- the received payload message to read the header from- Returns:
- the destination port 0-65535 from the lower two MTIME bytes, 0 if unset
getByte
Reads one payload byte of the message.- Parameters:
msg- the message to readi- the index of the byte- Returns:
- the payload byte
setProto
private static void setProto(byte[] payload, int p) Sets the protocol byte of the payload.- Parameters:
payload- the payload to changep- the protocol to set
setFromPort
private static void setFromPort(byte[] payload, int p) Sets the from port of the payload.- Parameters:
payload- the payload to changep- the port to set
setToPort
private static void setToPort(byte[] payload, int p) Sets the to port of the payload.- Parameters:
payload- the payload to changep- the port to set