Search in sources :

Example 1 with PeerManagerRegistration

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

the class PEPeerControlImpl method start.

@Override
public void start() {
    // This torrent Hash
    try {
        _hash = PeerIdentityManager.createDataID(disk_mgr.getTorrent().getHash());
    } catch (TOTorrentException e) {
        // this should never happen
        Debug.printStackTrace(e);
        _hash = PeerIdentityManager.createDataID(new byte[20]);
    }
    // the recovered active pieces
    for (int i = 0; i < _nbPieces; i++) {
        final DiskManagerPiece dmPiece = dm_pieces[i];
        if (!dmPiece.isDone() && dmPiece.getNbWritten() > 0) {
            addPiece(new PEPieceImpl(piecePicker, dmPiece, 0), i, true, null);
        }
    }
    // The peer connections
    peer_transports_cow = new ArrayList();
    // BtManager is threaded, this variable represents the
    // current loop iteration. It's used by some components only called
    // at some specific times.
    mainloop_loop_count = 0;
    // The current tracker state
    // this could be start or update
    _averageReceptionSpeed = Average.getInstance(1000, 30);
    // the stats
    _stats = new PEPeerManagerStatsImpl(this);
    superSeedMode = (COConfigurationManager.getBooleanParameter("Use Super Seeding") && this.getRemaining() == 0);
    superSeedModeCurrentPiece = 0;
    if (superSeedMode) {
        initialiseSuperSeedMode();
    }
    // initial check on finished state - future checks are driven by piece check results
    // Moved out of mainLoop() so that it runs immediately, possibly changing
    // the state to seeding.
    checkFinished(true);
    UploadSlotManager.getSingleton().registerHelper(upload_helper);
    lastNeededUndonePieceChange = Long.MIN_VALUE;
    _timeStarted = SystemTime.getCurrentTime();
    _timeStarted_mono = SystemTime.getMonotonousTime();
    is_running = true;
    // activate after marked as running as we may synchronously add connections here due to pending activations
    PeerManagerRegistration reg = adapter.getPeerManagerRegistration();
    if (reg != null) {
        reg.activate(this);
    }
    PeerNATTraverser.getSingleton().register(this);
    PeerControlSchedulerFactory.getSingleton(partition_id).register(this);
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) PeerManagerRegistration(com.biglybt.core.peermanager.PeerManagerRegistration)

Example 2 with PeerManagerRegistration

use of com.biglybt.core.peermanager.PeerManagerRegistration 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)

Example 3 with PeerManagerRegistration

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

the class PEPeerControlImpl method stopAll.

@Override
public void stopAll() {
    is_running = false;
    UploadSlotManager.getSingleton().deregisterHelper(upload_helper);
    PeerControlSchedulerFactory.getSingleton(partition_id).unregister(this);
    PeerNATTraverser.getSingleton().unregister(this);
    // remove legacy controller activation
    PeerManagerRegistration reg = adapter.getPeerManagerRegistration();
    if (reg != null) {
        reg.deactivate();
    }
    closeAndRemoveAllPeers("download stopped", false);
    // clear pieces
    for (int i = 0; i < _nbPieces; i++) {
        if (pePieces[i] != null)
            removePiece(pePieces[i], i);
    }
    // 5. Remove listeners
    ip_filter.removeListener(this);
    piecePicker.destroy();
    final ArrayList<PEPeerManagerListener> peer_manager_listeners = peer_manager_listeners_cow;
    for (int i = 0; i < peer_manager_listeners.size(); i++) {
        ((PEPeerManagerListener) peer_manager_listeners.get(i)).destroyed();
    }
    sweepList = Collections.emptyList();
    pending_nat_traversals.clear();
    udp_reconnects.clear();
    is_destroyed = true;
}
Also used : PeerManagerRegistration(com.biglybt.core.peermanager.PeerManagerRegistration)

Aggregations

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