use of com.biglybt.core.util.DirectByteBuffer in project BiglyBT by BiglySoftware.
the class AZBadPiece method getData.
@Override
public DirectByteBuffer[] getData() {
if (buffer == null) {
Map map = new HashMap();
map.put("piece", new Long(piece_number));
buffer = MessagingUtil.convertPayloadToBencodedByteStream(map, DirectByteBuffer.AL_MSG);
}
return new DirectByteBuffer[] { buffer };
}
use of com.biglybt.core.util.DirectByteBuffer in project BiglyBT by BiglySoftware.
the class GenericMessageConnectionDirect method connect.
@Override
public void connect(ByteBuffer upper_initial_data, final GenericMessageConnectionAdapter.ConnectionListener listener) {
if (connected) {
return;
}
ConnectionEndpoint cep = endpoint.getConnectionEndpoint();
cep = cep.getLANAdjustedEndpoint();
connection = NetworkManager.getSingleton().createConnection(cep, new GenericMessageEncoder(), new GenericMessageDecoder(msg_id, msg_desc), // use crypto
stream_crypto != MessageManager.STREAM_ENCRYPTION_NONE, // allow fallback
stream_crypto != MessageManager.STREAM_ENCRYPTION_RC4_REQUIRED, shared_secrets);
ByteBuffer initial_data = ByteBuffer.wrap(msg_id.getBytes());
if (upper_initial_data != null) {
GenericMessage gm = new GenericMessage(msg_id, msg_desc, new DirectByteBuffer(upper_initial_data), false);
DirectByteBuffer[] payload = new GenericMessageEncoder().encodeMessage(gm)[0].getRawData();
int size = initial_data.remaining();
for (int i = 0; i < payload.length; i++) {
size += payload[i].remaining(DirectByteBuffer.SS_MSG);
}
ByteBuffer temp = ByteBuffer.allocate(size);
temp.put(initial_data);
for (int i = 0; i < payload.length; i++) {
temp.put(payload[i].getBuffer(DirectByteBuffer.SS_MSG));
}
temp.rewind();
initial_data = temp;
}
connection.connect(initial_data, ProtocolEndpoint.CONNECT_PRIORITY_MEDIUM, new NetworkConnection.ConnectionListener() {
@Override
public int connectStarted(int default_connect_timeout) {
return (default_connect_timeout);
}
@Override
public void connectSuccess(ByteBuffer remaining_initial_data) {
connected = true;
try {
if (remaining_initial_data != null && remaining_initial_data.remaining() > 0) {
// queue as a *raw* message as already encoded
connection.getOutgoingMessageQueue().addMessage(new GenericMessage(msg_id, msg_desc, new DirectByteBuffer(remaining_initial_data), true), false);
}
listener.connectSuccess();
startProcessing();
} catch (Throwable e) {
connectFailure(e);
}
}
@Override
public void connectFailure(Throwable failure_msg) {
listener.connectFailure(failure_msg);
connection.close(failure_msg == null ? null : Debug.getNestedExceptionMessage(failure_msg));
}
@Override
public void exceptionThrown(Throwable error) {
listener.connectFailure(error);
connection.close(error == null ? null : Debug.getNestedExceptionMessage(error));
}
@Override
public Object getConnectionProperty(String property_name) {
return (null);
}
@Override
public String getDescription() {
return ("generic connection");
}
});
}
use of com.biglybt.core.util.DirectByteBuffer in project BiglyBT by BiglySoftware.
the class MessageAdapter method getData.
@Override
public DirectByteBuffer[] getData() {
if (plug_msg == null) {
return core_msg.getData();
}
ByteBuffer[] bbs = plug_msg.getPayload();
// TODO cache it???
DirectByteBuffer[] dbbs = new DirectByteBuffer[bbs.length];
for (int i = 0; i < bbs.length; i++) {
dbbs[i] = new DirectByteBuffer(bbs[i]);
}
return dbbs;
}
Aggregations