Search in sources :

Example 1 with PeerExchangerItem

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

the class PEPeerTransportProtocol method doPostHandshakeProcessing.

/**
 * this method might be called repeatedly since LTEP allows headers to be sent more than once
 * make sure that multiple invokations do not have unintended consequences
 */
private void doPostHandshakeProcessing() {
    // peer exchange registration
    if (manager.isPeerExchangeEnabled()) {
        // try and register all connections for their peer exchange info
        PeerExchangerItem pex_item = peer_exchange_item;
        if (pex_item == null && canBePeerExchanged()) {
            pex_item = peer_exchange_item = manager.createPeerExchangeConnection(this);
        }
        if (pex_item != null) {
            if (ut_pex_enabled || peerSupportsMessageType(AZMessage.ID_AZ_PEER_EXCHANGE)) {
                peer_exchange_supported = true;
                pex_item.enableStateMaintenance();
            } else {
                MessageStreamEncoder encoder = connection.getOutgoingMessageQueue().getEncoder();
                if (encoder instanceof LTMessageEncoder && ((LTMessageEncoder) encoder).hasCustomExtensionHandler(LTMessageEncoder.CET_PEX)) {
                    peer_exchange_supported = true;
                    pex_item.enableStateMaintenance();
                } else {
                    // no need to maintain internal states as we wont be sending/receiving peer exchange messages
                    pex_item.disableStateMaintenance();
                }
            }
        }
    }
    request_hint_supported = peerSupportsMessageType(AZMessage.ID_AZ_REQUEST_HINT);
    bad_piece_supported = peerSupportsMessageType(AZMessage.ID_AZ_BAD_PIECE);
    stats_request_supported = peerSupportsMessageType(AZMessage.ID_AZ_STAT_REQUEST);
    stats_reply_supported = peerSupportsMessageType(AZMessage.ID_AZ_STAT_REPLY);
    az_metadata_supported = peerSupportsMessageType(AZMessage.ID_AZ_METADATA);
    if (is_metadata_download) {
        if (az_metadata_supported) {
            int mds = manager.getTorrentInfoDictSize();
            if (mds > 0) {
                spoofMDAvailability(mds);
            }
        }
    }
}
Also used : PeerExchangerItem(com.biglybt.core.peermanager.peerdb.PeerExchangerItem) MessageStreamEncoder(com.biglybt.core.peermanager.messaging.MessageStreamEncoder)

Example 2 with PeerExchangerItem

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

the class PEPeerTransportProtocol method updatePeerExchange.

@Override
public void updatePeerExchange() {
    if (current_peer_state != TRANSFERING)
        return;
    if (!peer_exchange_supported)
        return;
    PeerExchangerItem pex_item = peer_exchange_item;
    if (pex_item != null && manager.isPeerExchangeEnabled()) {
        if (peer_item_identity.getNetwork() == AENetworkClassifier.AT_PUBLIC) {
            final PeerItem[] adds = pex_item.getNewlyAddedPeerConnections(AENetworkClassifier.AT_PUBLIC);
            final PeerItem[] drops = pex_item.getNewlyDroppedPeerConnections(AENetworkClassifier.AT_PUBLIC);
            if ((adds != null && adds.length > 0) || (drops != null && drops.length > 0)) {
                if (ut_pex_enabled) {
                    connection.getOutgoingMessageQueue().addMessage(new UTPeerExchange(adds, drops, null, (byte) 0), false);
                } else {
                    connection.getOutgoingMessageQueue().addMessage(new AZPeerExchange(manager.getHash(), adds, drops, other_peer_pex_version), false);
                }
            }
        } else {
            MessageStreamEncoder encoder = connection.getOutgoingMessageQueue().getEncoder();
            if (encoder instanceof LTMessageEncoder) {
                ((LTMessageEncoder) encoder).handleCustomExtension(LTMessageEncoder.CET_PEX, new Object[] { pex_item });
            }
        }
    }
}
Also used : PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem) PeerExchangerItem(com.biglybt.core.peermanager.peerdb.PeerExchangerItem) MessageStreamEncoder(com.biglybt.core.peermanager.messaging.MessageStreamEncoder)

Example 3 with PeerExchangerItem

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

the class PEPeerTransportProtocol method decodePeerExchange.

protected void decodePeerExchange(AZStylePeerExchange exchange) {
    // if we're seeding ignore µT-PEXed seeds, Az won't send them in the first place
    PeerItem[] added = exchange instanceof UTPeerExchange ? ((UTPeerExchange) exchange).getAddedPeers(!(manager.isSeeding() || Constants.DOWNLOAD_SOURCES_PRETEND_COMPLETE)) : exchange.getAddedPeers();
    PeerItem[] dropped = exchange.getDroppedPeers();
    int max_added = exchange.getMaxAllowedPeersPerVolley(!has_received_initial_pex, true);
    int max_dropped = exchange.getMaxAllowedPeersPerVolley(!has_received_initial_pex, false);
    exchange.destroy();
    if (!message_limiter.countIncomingMessage(exchange.getID(), 7, 120 * 1000)) {
        // allow max 7 PEX per 2min  //TODO reduce max after 2308 release?
        System.out.println(manager.getDisplayName() + ": Incoming PEX message flood detected, dropping spamming peer connection." + PEPeerTransportProtocol.this);
        closeConnectionInternally("Incoming PEX message flood detected, dropping spamming peer connection.");
        return;
    }
    if ((added != null && added.length > max_added) || (dropped != null && dropped.length > max_dropped)) {
        if (Logger.isEnabled()) {
            Logger.log(new LogEvent(this, LOGID, "Invalid PEX message received: too large, ignoring this exchange. (added=" + (added == null ? 0 : added.length) + ",dropped=" + (dropped == null ? 0 : dropped.length) + ")"));
        }
        added = null;
        dropped = null;
    }
    has_received_initial_pex = true;
    PeerExchangerItem pex_item = peer_exchange_item;
    if (peer_exchange_supported && pex_item != null && manager.isPeerExchangeEnabled()) {
        if (added != null) {
            for (int i = 0; i < added.length; i++) {
                PeerItem pi = added[i];
                manager.peerDiscovered(this, pi);
                pex_item.addConnectedPeer(pi);
            }
        }
        if (dropped != null) {
            for (int i = 0; i < dropped.length; i++) {
                pex_item.dropConnectedPeer(dropped[i]);
            }
        }
    } else {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(this, LOGID, "Peer Exchange disabled for this download, " + "dropping received exchange message"));
    }
}
Also used : PeerItem(com.biglybt.core.peermanager.peerdb.PeerItem) PeerExchangerItem(com.biglybt.core.peermanager.peerdb.PeerExchangerItem)

Example 4 with PeerExchangerItem

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

the class PEPeerTransportProtocol method setSeed.

private void setSeed(boolean s) {
    if (seeding != s) {
        seeding = s;
        PeerExchangerItem pex_item = peer_exchange_item;
        if (pex_item != null && s) {
            pex_item.seedStatusChanged();
        }
    }
}
Also used : PeerExchangerItem(com.biglybt.core.peermanager.peerdb.PeerExchangerItem)

Aggregations

PeerExchangerItem (com.biglybt.core.peermanager.peerdb.PeerExchangerItem)4 MessageStreamEncoder (com.biglybt.core.peermanager.messaging.MessageStreamEncoder)2 PeerItem (com.biglybt.core.peermanager.peerdb.PeerItem)2