Search in sources :

Example 31 with DirectByteBuffer

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 };
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) DirectByteBuffer(com.biglybt.core.util.DirectByteBuffer)

Example 32 with DirectByteBuffer

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");
        }
    });
}
Also used : PooledByteBuffer(com.biglybt.pif.utils.PooledByteBuffer) ByteBuffer(java.nio.ByteBuffer) DirectByteBuffer(com.biglybt.core.util.DirectByteBuffer) GenericMessageEndpoint(com.biglybt.pif.messaging.generic.GenericMessageEndpoint) DirectByteBuffer(com.biglybt.core.util.DirectByteBuffer)

Example 33 with DirectByteBuffer

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;
}
Also used : DirectByteBuffer(com.biglybt.core.util.DirectByteBuffer) ByteBuffer(java.nio.ByteBuffer) DirectByteBuffer(com.biglybt.core.util.DirectByteBuffer)

Aggregations

DirectByteBuffer (com.biglybt.core.util.DirectByteBuffer)33 ByteBuffer (java.nio.ByteBuffer)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 RawMessage (com.biglybt.core.networkmanager.RawMessage)6 IOException (java.io.IOException)6 Message (com.biglybt.core.peermanager.messaging.Message)5 RawMessageImpl (com.biglybt.core.networkmanager.impl.RawMessageImpl)3 CacheFileManagerException (com.biglybt.core.diskmanager.cache.CacheFileManagerException)2 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)1 DiskManagerFileInfoImpl (com.biglybt.core.disk.impl.DiskManagerFileInfoImpl)1 DiskManagerRecheckInstance (com.biglybt.core.disk.impl.DiskManagerRecheckInstance)1 DMPieceList (com.biglybt.core.disk.impl.piecemapper.DMPieceList)1 DMPieceMapEntry (com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry)1 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 LogEvent (com.biglybt.core.logging.LogEvent)1 MessageException (com.biglybt.core.peermanager.messaging.MessageException)1 AESemaphore (com.biglybt.core.util.AESemaphore)1 ByteArrayHashMap (com.biglybt.core.util.ByteArrayHashMap)1