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);
}
}
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
}
}
}
}
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);
}
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;
}
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);
}
}
Aggregations