Search in sources :

Example 1 with PeerManagerRoutingListener

use of com.biglybt.core.peermanager.PeerManagerRoutingListener in project BiglyBT by BiglySoftware.

the class HTTPNetworkManager method reRoute.

protected void reRoute(final HTTPNetworkConnection old_http_connection, final byte[] old_hash, final byte[] new_hash, final String header) {
    final NetworkConnection old_connection = old_http_connection.getConnection();
    PeerManagerRegistration reg_data = PeerManager.getSingleton().manualMatchHash(old_connection.getEndpoint().getNotionalAddress(), new_hash);
    if (reg_data == null) {
        old_http_connection.close("Re-routing failed - registration not found");
        return;
    }
    final Transport transport = old_connection.detachTransport();
    old_http_connection.close("Switching torrents");
    final NetworkConnection new_connection = NetworkManager.getSingleton().bindTransport(transport, new HTTPMessageEncoder(), new HTTPMessageDecoder(header));
    PeerManager.getSingleton().manualRoute(reg_data, new_connection, new PeerManagerRoutingListener() {

        @Override
        public boolean routed(PEPeerTransport peer) {
            HTTPNetworkConnection new_http_connection;
            if (header.contains("/webseed")) {
                new_http_connection = new HTTPNetworkConnectionWebSeed(HTTPNetworkManager.this, new_connection, peer);
            } else if (header.contains("/files/")) {
                new_http_connection = new HTTPNetworkConnectionFile(HTTPNetworkManager.this, new_connection, peer);
            } else {
                return (false);
            }
            // fake a wakeup so pre-read header is processed
            new_http_connection.readWakeup();
            return (true);
        }
    });
}
Also used : PeerManagerRegistration(com.biglybt.core.peermanager.PeerManagerRegistration) PeerManagerRoutingListener(com.biglybt.core.peermanager.PeerManagerRoutingListener) PEPeerTransport(com.biglybt.core.peer.impl.PEPeerTransport) NetworkConnection(com.biglybt.core.networkmanager.NetworkConnection) Transport(com.biglybt.core.networkmanager.Transport) PEPeerTransport(com.biglybt.core.peer.impl.PEPeerTransport)

Aggregations

NetworkConnection (com.biglybt.core.networkmanager.NetworkConnection)1 Transport (com.biglybt.core.networkmanager.Transport)1 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)1 PeerManagerRegistration (com.biglybt.core.peermanager.PeerManagerRegistration)1 PeerManagerRoutingListener (com.biglybt.core.peermanager.PeerManagerRoutingListener)1