use of com.biglybt.pif.messaging.generic.GenericMessageConnectionListener in project BiglyBT by BiglySoftware.
the class SESTSConnectionImpl method receiveContent.
protected void receiveContent(PooledByteBuffer message) throws MessageException {
boolean buffer_handled = false;
try {
if (incoming_cipher != null) {
try {
byte[] enc = message.toByteArray();
byte[] plain = incoming_cipher.doFinal(enc);
PooledByteBuffer temp = new PooledByteBufferImpl(plain);
message.returnToPool();
buffer_handled = true;
message = temp;
} catch (Throwable e) {
throw (new MessageException("Failed to decrypt data", e));
}
} else if (block_crypto != SESecurityManager.BLOCK_ENCRYPTION_NONE) {
throw (new MessageException("Crypto isn't setup"));
}
List<GenericMessageConnectionListener> listeners_ref = listeners.getList();
MessageException last_error = null;
for (int i = 0; i < listeners_ref.size(); i++) {
PooledByteBuffer message_to_deliver;
if (i == 0) {
message_to_deliver = message;
} else {
// unlikely we'll ever have > 1 receiver....
message_to_deliver = new PooledByteBufferImpl(message.toByteArray());
}
try {
listeners_ref.get(i).receive(this, message_to_deliver);
if (message_to_deliver == message) {
buffer_handled = true;
}
} catch (Throwable e) {
message_to_deliver.returnToPool();
if (message_to_deliver == message) {
buffer_handled = true;
}
if (e instanceof MessageException) {
last_error = (MessageException) e;
} else {
last_error = new MessageException("Failed to process message", e);
}
}
}
if (last_error != null) {
throw (last_error);
}
} finally {
if (!buffer_handled) {
message.returnToPool();
}
}
}
use of com.biglybt.pif.messaging.generic.GenericMessageConnectionListener in project BiglyBT by BiglySoftware.
the class GenericMessageConnectionImpl method receive.
protected void receive(GenericMessage message) {
boolean handled = false;
for (int i = 0; i < listeners.size(); i++) {
PooledByteBuffer buffer = new PooledByteBufferImpl(message.getPayload());
try {
((GenericMessageConnectionListener) listeners.get(i)).receive(this, buffer);
handled = true;
} catch (Throwable f) {
buffer.returnToPool();
if (!(f instanceof MessageException)) {
Debug.printStackTrace(f);
}
}
}
if (!handled && !(closed || closing)) {
// get this on some processing paths
// Debug.out( "GenericMessage: incoming message not handled" );
}
}
Aggregations