Search in sources :

Example 16 with I2PSessionException

use of net.i2p.client.I2PSessionException in project i2p.i2p by i2p.

the class MessagePayloadMessageHandler method handleMessage.

public void handleMessage(I2CPMessage message, I2PSessionImpl session) {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handle message " + message + " for session " + session);
    try {
        MessagePayloadMessage msg = (MessagePayloadMessage) message;
        long id = msg.getMessageId();
        decryptPayload(msg, session);
        session.addNewMessage(msg);
        // (needs router version saving support in SetDateMessageHandler)
        if (!session.getFastReceive()) {
            ReceiveMessageEndMessage m = new ReceiveMessageEndMessage();
            m.setMessageId(id);
            m.setSessionId(msg.getSessionId());
            session.sendMessage(m);
        }
    } catch (DataFormatException dfe) {
        session.propogateError("Error handling a new payload message", dfe);
    } catch (I2PSessionException ise) {
        session.propogateError("Error handling a new payload message", ise);
    }
}
Also used : MessagePayloadMessage(net.i2p.data.i2cp.MessagePayloadMessage) DataFormatException(net.i2p.data.DataFormatException) ReceiveMessageEndMessage(net.i2p.data.i2cp.ReceiveMessageEndMessage) I2PSessionException(net.i2p.client.I2PSessionException)

Example 17 with I2PSessionException

use of net.i2p.client.I2PSessionException in project i2p.i2p by i2p.

the class UDPIOthread method run.

/**
 */
public void run() {
    byte[] data = new byte[1024];
    up = true;
    try {
        in = new DataInputStream(socket.getInputStream());
        out = new DataOutputStream(socket.getOutputStream());
        while (up) {
            int c = in.read(data);
            // Note: could do a loopback test here with a wrapper.
            boolean ok = _session.sendMessage(_peerDestination, data, 0, c);
            if (!ok) {
                // Is this the right thing to do??
                up = false;
            }
        }
    } catch (IOException ioe) {
        _log.error("Error running", ioe);
    } catch (I2PSessionException ise) {
        _log.error("Error communicating", ise);
    // } catch(DataFormatException dfe) {
    // _log.error("Peer destination file is not valid", dfe);
    } finally {
        if (_session != null) {
            try {
                _session.destroySession();
            } catch (I2PSessionException ise) {
            // ignored
            }
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) I2PSessionException(net.i2p.client.I2PSessionException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 18 with I2PSessionException

use of net.i2p.client.I2PSessionException in project i2p.i2p by i2p.

the class I2PSessionIT method testSendClosedMessage.

public void testSendClosedMessage() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Destination d = I2PClientFactory.createClient().createDestination(out);
    I2PSession session = new I2PSessionImpl2(I2PAppContext.getGlobalContext(), new ByteArrayInputStream(out.toByteArray()), null);
    boolean error = false;
    try {
        session.sendMessage(d, out.toByteArray());
    } catch (I2PSessionException i2pse) {
        error = true;
    }
    assertTrue(error);
}
Also used : Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PSessionException(net.i2p.client.I2PSessionException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 19 with I2PSessionException

use of net.i2p.client.I2PSessionException in project i2p.i2p by i2p.

the class ClientManager method internalConnect.

/**
 *  The InternalClientManager interface.
 *  Connects to the router, receiving a message queue to talk to the router with.
 *  @throws I2PSessionException if the router isn't ready
 *  @since 0.8.3
 */
public I2CPMessageQueue internalConnect() throws I2PSessionException {
    if (!_isStarted)
        throw new I2PSessionException("Router client manager is shut down");
    LinkedBlockingQueue<I2CPMessage> in = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE);
    LinkedBlockingQueue<I2CPMessage> out = new LinkedBlockingQueue<I2CPMessage>(INTERNAL_QUEUE_SIZE);
    I2CPMessageQueue myQueue = new I2CPMessageQueueImpl(in, out);
    I2CPMessageQueue hisQueue = new I2CPMessageQueueImpl(out, in);
    ClientConnectionRunner runner = new QueuedClientConnectionRunner(_ctx, this, myQueue);
    registerConnection(runner);
    return hisQueue;
}
Also used : I2CPMessage(net.i2p.data.i2cp.I2CPMessage) I2PSessionException(net.i2p.client.I2PSessionException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) I2CPMessageQueue(net.i2p.internal.I2CPMessageQueue)

Example 20 with I2PSessionException

use of net.i2p.client.I2PSessionException in project i2p.i2p-bote by i2p.

the class I2PPacketDispatcher method messageAvailable.

@Override
public void messageAvailable(I2PSession session, int msgId, long size) {
    byte[] msg = new byte[0];
    try {
        msg = session.receiveMessage(msgId);
    } catch (I2PSessionException e) {
        log.error("Can't get new message from I2PSession.", e);
    }
    if (msg == null) {
        log.error("I2PSession returned a null message: msgId=" + msgId + ", size=" + size + ", " + session);
        return;
    }
    I2PDatagramDissector datagramDissector = new I2PDatagramDissector();
    try {
        datagramDissector.loadI2PDatagram(msg);
        // TODO keep this line or remove it?
        datagramDissector.verifySignature();
        byte[] payload = datagramDissector.extractPayload();
        Destination sender = datagramDissector.getSender();
        dispatchPacket(payload, sender);
    } catch (DataFormatException e) {
        log.error("Invalid datagram received.", e);
    } catch (I2PInvalidDatagramException e) {
        log.error("Datagram failed verification.", e);
    } catch (Exception e) {
        log.error("Error processing datagram.", e);
    }
}
Also used : Destination(net.i2p.data.Destination) I2PDatagramDissector(net.i2p.client.datagram.I2PDatagramDissector) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException) MalformedPacketException(i2p.bote.packet.MalformedPacketException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException)

Aggregations

I2PSessionException (net.i2p.client.I2PSessionException)44 IOException (java.io.IOException)18 DataFormatException (net.i2p.data.DataFormatException)15 Properties (java.util.Properties)13 I2PSession (net.i2p.client.I2PSession)11 Destination (net.i2p.data.Destination)11 SessionId (net.i2p.data.i2cp.SessionId)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InterruptedIOException (java.io.InterruptedIOException)5 I2PException (net.i2p.I2PException)5 File (java.io.File)4 GeneralSecurityException (java.security.GeneralSecurityException)4 I2PClient (net.i2p.client.I2PClient)4 FileInputStream (java.io.FileInputStream)3 UnknownHostException (java.net.UnknownHostException)3 Payload (net.i2p.data.Payload)3 Log (net.i2p.util.Log)3 BufferedInputStream (java.io.BufferedInputStream)2 DataInputStream (java.io.DataInputStream)2