Search in sources :

Example 1 with ConnectionEndpoint

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

the class UDPConnectionManager method accept.

protected void accept(final int local_port, final InetSocketAddress remote_address, final UDPConnection connection) {
    final UDPTransportHelper helper = new UDPTransportHelper(this, remote_address, connection);
    try {
        connection.setTransport(helper);
        TransportCryptoManager.getSingleton().manageCrypto(helper, null, true, null, new TransportCryptoManager.HandshakeListener() {

            @Override
            public void handshakeSuccess(ProtocolDecoder decoder, ByteBuffer remaining_initial_data) {
                TransportHelperFilter filter = decoder.getFilter();
                ConnectionEndpoint co_ep = new ConnectionEndpoint(remote_address);
                ProtocolEndpointUDP pe_udp = (ProtocolEndpointUDP) ProtocolEndpointFactory.createEndpoint(ProtocolEndpoint.PROTOCOL_UDP, co_ep, remote_address);
                UDPTransport transport = new UDPTransport(pe_udp, filter);
                helper.setTransport(transport);
                incoming_manager.addConnection(local_port, filter, transport);
            }

            @Override
            public void handshakeFailure(Throwable failure_msg) {
                if (Logger.isEnabled()) {
                    Logger.log(new LogEvent(LOGID, "incoming crypto handshake failure: " + Debug.getNestedExceptionMessage(failure_msg)));
                }
                connection.close("handshake failure: " + Debug.getNestedExceptionMessage(failure_msg));
            }

            @Override
            public void gotSecret(byte[] session_secret) {
                helper.getConnection().setSecret(session_secret);
            }

            @Override
            public int getMaximumPlainHeaderLength() {
                return (incoming_manager.getMaxMinMatchBufferSize());
            }

            @Override
            public int matchPlainHeader(ByteBuffer buffer) {
                Object[] match_data = incoming_manager.checkForMatch(helper, local_port, buffer, true);
                if (match_data == null) {
                    return (TransportCryptoManager.HandshakeListener.MATCH_NONE);
                } else {
                    return (TransportCryptoManager.HandshakeListener.MATCH_CRYPTO_NO_AUTO_FALLBACK);
                }
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        helper.close(Debug.getNestedExceptionMessage(e));
    }
}
Also used : TransportHelperFilter(com.biglybt.core.networkmanager.impl.TransportHelperFilter) LogEvent(com.biglybt.core.logging.LogEvent) ProtocolDecoder(com.biglybt.core.networkmanager.impl.ProtocolDecoder) ByteBuffer(java.nio.ByteBuffer) ConnectionEndpoint(com.biglybt.core.networkmanager.ConnectionEndpoint) TransportCryptoManager(com.biglybt.core.networkmanager.impl.TransportCryptoManager)

Example 2 with ConnectionEndpoint

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

the class ConnectionManagerImpl method createConnection.

@Override
public Connection createConnection(InetSocketAddress remote_address, MessageStreamEncoder encoder, MessageStreamDecoder decoder) {
    ConnectionEndpoint connection_endpoint = new ConnectionEndpoint(remote_address);
    connection_endpoint.addProtocol(ProtocolEndpointFactory.createEndpoint(ProtocolEndpoint.PROTOCOL_TCP, remote_address));
    com.biglybt.core.networkmanager.NetworkConnection core_conn = NetworkManager.getSingleton().createConnection(connection_endpoint, new MessageStreamEncoderAdapter(encoder), new MessageStreamDecoderAdapter(decoder), false, false, null);
    return new ConnectionImpl(core_conn, false);
}
Also used : ConnectionEndpoint(com.biglybt.core.networkmanager.ConnectionEndpoint) MessageStreamDecoderAdapter(com.biglybt.pifimpl.local.messaging.MessageStreamDecoderAdapter) MessageStreamEncoderAdapter(com.biglybt.pifimpl.local.messaging.MessageStreamEncoderAdapter)

Aggregations

ConnectionEndpoint (com.biglybt.core.networkmanager.ConnectionEndpoint)2 LogEvent (com.biglybt.core.logging.LogEvent)1 ProtocolDecoder (com.biglybt.core.networkmanager.impl.ProtocolDecoder)1 TransportCryptoManager (com.biglybt.core.networkmanager.impl.TransportCryptoManager)1 TransportHelperFilter (com.biglybt.core.networkmanager.impl.TransportHelperFilter)1 MessageStreamDecoderAdapter (com.biglybt.pifimpl.local.messaging.MessageStreamDecoderAdapter)1 MessageStreamEncoderAdapter (com.biglybt.pifimpl.local.messaging.MessageStreamEncoderAdapter)1 ByteBuffer (java.nio.ByteBuffer)1