Search in sources :

Example 1 with TransportHelperFilterStreamCipher

use of com.biglybt.core.networkmanager.impl.TransportHelperFilterStreamCipher in project BiglyBT by BiglySoftware.

the class ConnectionManagerImpl method createTransportFilter.

@Override
public TransportFilter createTransportFilter(Connection connection, TransportCipher read_cipher, TransportCipher write_cipher) throws TransportException {
    Transport transport = connection.getTransport();
    if (transport == null) {
        throw (new TransportException("no transport available"));
    }
    com.biglybt.core.networkmanager.Transport core_transport;
    try {
        core_transport = ((TransportImpl) transport).coreTransport();
    } catch (IOException e) {
        throw new TransportException(e);
    }
    TransportHelper helper;
    if (core_transport instanceof TCPTransportImpl) {
        TransportHelperFilter hfilter = ((TCPTransportImpl) core_transport).getFilter();
        if (hfilter != null) {
            helper = hfilter.getHelper();
        } else {
            helper = new TCPTransportHelper(((TCPTransportImpl) (core_transport)).getSocketChannel());
        }
    } else if (core_transport instanceof UDPTransport) {
        TransportHelperFilter hfilter = ((UDPTransport) core_transport).getFilter();
        if (hfilter != null) {
            helper = hfilter.getHelper();
        } else {
            helper = ((UDPTransport) core_transport).getFilter().getHelper();
            InetSocketAddress addr = core_transport.getTransportEndpoint().getProtocolEndpoint().getConnectionEndpoint().getNotionalAddress();
            if (!connection.isIncoming()) {
                try {
                    helper = new UDPTransportHelper(UDPNetworkManager.getSingleton().getConnectionManager(), addr, (UDPTransport) core_transport);
                } catch (IOException ioe) {
                    throw new TransportException(ioe);
                }
            } else {
                // helper = new UDPTransportHelper(UDPNetworkManager.getSingleton().getConnectionManager(), addr, (UDPTransport)core_transport);
                throw new TransportException("udp incoming transport type not supported - " + core_transport);
            }
        }
    } else {
        throw new TransportException("transport type not supported - " + core_transport);
    }
    TransportHelperFilterStreamCipher core_filter = new TransportHelperFilterStreamCipher(helper, ((TransportCipherImpl) read_cipher).cipher, ((TransportCipherImpl) write_cipher).cipher);
    return new TransportFilterImpl(core_filter);
}
Also used : TransportHelperFilterStreamCipher(com.biglybt.core.networkmanager.impl.TransportHelperFilterStreamCipher) TransportHelperFilter(com.biglybt.core.networkmanager.impl.TransportHelperFilter) TCPTransportImpl(com.biglybt.core.networkmanager.impl.tcp.TCPTransportImpl) InetSocketAddress(java.net.InetSocketAddress) TransportHelper(com.biglybt.core.networkmanager.impl.TransportHelper) TCPTransportHelper(com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper) UDPTransportHelper(com.biglybt.core.networkmanager.impl.udp.UDPTransportHelper) IOException(java.io.IOException) UDPTransport(com.biglybt.core.networkmanager.impl.udp.UDPTransport) TCPTransportHelper(com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper) UDPTransportHelper(com.biglybt.core.networkmanager.impl.udp.UDPTransportHelper) UDPTransport(com.biglybt.core.networkmanager.impl.udp.UDPTransport)

Aggregations

TransportHelper (com.biglybt.core.networkmanager.impl.TransportHelper)1 TransportHelperFilter (com.biglybt.core.networkmanager.impl.TransportHelperFilter)1 TransportHelperFilterStreamCipher (com.biglybt.core.networkmanager.impl.TransportHelperFilterStreamCipher)1 TCPTransportHelper (com.biglybt.core.networkmanager.impl.tcp.TCPTransportHelper)1 TCPTransportImpl (com.biglybt.core.networkmanager.impl.tcp.TCPTransportImpl)1 UDPTransport (com.biglybt.core.networkmanager.impl.udp.UDPTransport)1 UDPTransportHelper (com.biglybt.core.networkmanager.impl.udp.UDPTransportHelper)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1