use of com.biglybt.core.peermanager.messaging.MessageException in project BiglyBT by BiglySoftware.
the class AZMetaData method deserialize.
@Override
public Message deserialize(DirectByteBuffer data, byte version) throws MessageException {
int pos = data.position(DirectByteBuffer.SS_MSG);
byte[] dict_bytes = new byte[Math.min(128, data.remaining(DirectByteBuffer.SS_MSG))];
data.get(DirectByteBuffer.SS_MSG, dict_bytes);
try {
Map root = BDecoder.decode(dict_bytes);
data.position(DirectByteBuffer.SS_MSG, pos + BEncoder.encode(root).length);
return (new AZMetaData(root, data, version));
} catch (Throwable e) {
e.printStackTrace();
throw (new MessageException("decode failed", e));
}
}
use of com.biglybt.core.peermanager.messaging.MessageException in project BiglyBT by BiglySoftware.
the class AZPeerExchange method deserialize.
@Override
public Message deserialize(DirectByteBuffer data, byte version) throws MessageException {
if (data.remaining(bss) > 2000)
System.out.println("Received PEX msg byte size = " + data.remaining(bss));
Map root = MessagingUtil.convertBencodedByteStreamToPayload(data, 10, getID());
byte[] hash = (byte[]) root.get("infohash");
if (hash == null)
throw new MessageException("hash == null");
if (hash.length != 20)
throw new MessageException("hash.length != 20: " + hash.length);
PeerItem[] added = extractPeers("added", root);
PeerItem[] dropped = extractPeers("dropped", root);
if (added == null && dropped == null)
throw new MessageException("[" + getID() + "] received exchange message without any adds or drops");
return new AZPeerExchange(hash, added, dropped, version);
}
use of com.biglybt.core.peermanager.messaging.MessageException in project BiglyBT by BiglySoftware.
the class LTMessageDecoder method createMessage.
@Override
protected Message createMessage(DirectByteBuffer ref_buff) throws MessageException {
// Check to see if it is a LT-extension message. If not, delegate to BTMessageDecoder.
int old_position = ref_buff.position(DirectByteBuffer.SS_MSG);
byte id = ref_buff.get(DirectByteBuffer.SS_MSG);
if (id != 20) {
ref_buff.position(DirectByteBuffer.SS_MSG, old_position);
return super.createMessage(ref_buff);
}
// Here is where we decode the message.
id = ref_buff.get(DirectByteBuffer.SS_MSG);
switch(id) {
case 0:
return MessageManager.getSingleton().createMessage(LTMessage.ID_LT_HANDSHAKE_BYTES, ref_buff, (byte) 1);
case 1:
return MessageManager.getSingleton().createMessage(LTMessage.ID_UT_PEX_BYTES, ref_buff, (byte) 1);
case 3:
return MessageManager.getSingleton().createMessage(LTMessage.ID_UT_METADATA_BYTES, ref_buff, (byte) 1);
case 4:
return MessageManager.getSingleton().createMessage(LTMessage.ID_UT_UPLOAD_ONLY_BYTES, ref_buff, (byte) 1);
default:
{
byte[] message_id;
message_id = extension_handlers.get(id);
if (message_id != null) {
return MessageManager.getSingleton().createMessage(message_id, ref_buff, (byte) 1);
}
System.out.println("Unknown LTEP message id [" + id + "]");
throw new MessageException("Unknown LTEP message id [" + id + "]");
}
}
}
use of com.biglybt.core.peermanager.messaging.MessageException in project BiglyBT by BiglySoftware.
the class UTMetaData method deserialize.
@Override
public Message deserialize(DirectByteBuffer data, byte version) throws MessageException {
int pos = data.position(DirectByteBuffer.SS_MSG);
byte[] dict_bytes = new byte[Math.min(128, data.remaining(DirectByteBuffer.SS_MSG))];
data.get(DirectByteBuffer.SS_MSG, dict_bytes);
try {
Map root = BDecoder.decode(dict_bytes);
data.position(DirectByteBuffer.SS_MSG, pos + BEncoder.encode(root).length);
return (new UTMetaData(root, data, version));
} catch (Throwable e) {
e.printStackTrace();
throw (new MessageException("decode failed", e));
}
}
use of com.biglybt.core.peermanager.messaging.MessageException in project BiglyBT by BiglySoftware.
the class UTUploadOnly method deserialize.
@Override
public Message deserialize(DirectByteBuffer data, byte version) throws MessageException {
byte[] dict_bytes = new byte[Math.min(128, data.remaining(DirectByteBuffer.SS_MSG))];
data.get(DirectByteBuffer.SS_MSG, dict_bytes);
if (dict_bytes.length != 1) {
throw (new MessageException("decode failed: incorrect length"));
}
boolean ulo = dict_bytes[0] != 0;
return (new UTUploadOnly(ulo, version));
}
Aggregations