Search in sources :

Example 1 with BitFlags

use of com.biglybt.core.peermanager.piecepicker.util.BitFlags in project BiglyBT by BiglySoftware.

the class PeerImpl method addListener.

@Override
public void addListener(final PeerListener2 l) {
    PEPeerListener core_listener = new PEPeerListener() {

        @Override
        public void stateChanged(// seems don't need this here
        final PEPeer peer, int new_state) {
            fireEvent(PeerEvent.ET_STATE_CHANGED, new Integer(new_state));
        }

        @Override
        public void sentBadChunk(// seems don't need this here
        final PEPeer peer, int piece_num, int total_bad_chunks) {
            fireEvent(PeerEvent.ET_BAD_CHUNK, new Integer[] { new Integer(piece_num), new Integer(total_bad_chunks) });
        }

        @Override
        public void addAvailability(final PEPeer peer, BitFlags peerHavePieces) {
            fireEvent(PeerEvent.ET_ADD_AVAILABILITY, peerHavePieces.flags);
        }

        @Override
        public void removeAvailability(final PEPeer peer, BitFlags peerHavePieces) {
            fireEvent(PeerEvent.ET_REMOVE_AVAILABILITY, peerHavePieces.flags);
        }

        protected void fireEvent(final int type, final Object data) {
            try {
                l.eventOccurred(new PeerEvent() {

                    @Override
                    public int getType() {
                        return (type);
                    }

                    @Override
                    public Object getData() {
                        return (data);
                    }
                });
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    };
    delegate.addListener(core_listener);
    synchronized (this) {
        if (peer_listeners == null) {
            peer_listeners = new HashMap<>();
        }
        peer_listeners.put(l, core_listener);
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags) PEPeer(com.biglybt.core.peer.PEPeer) PEPeerListener(com.biglybt.core.peer.PEPeerListener)

Example 2 with BitFlags

use of com.biglybt.core.peermanager.piecepicker.util.BitFlags in project BiglyBT by BiglySoftware.

the class PEPeerTransportProtocol method decodeHaveAll.

protected void decodeHaveAll(BTHaveAll have_all) {
    have_all.destroy();
    received_bitfield = true;
    if (is_metadata_download) {
        return;
    }
    try {
        closing_mon.enter();
        if (!closing) {
            final BitFlags tempHavePieces;
            if (peerHavePieces == null) {
                tempHavePieces = new BitFlags(nbPieces);
            } else {
                tempHavePieces = peerHavePieces;
                removeAvailability();
            }
            tempHavePieces.setAll();
            for (int i = 0; i < nbPieces; i++) {
                manager.updateSuperSeedPiece(this, i);
            }
            peerHavePieces = tempHavePieces;
            addAvailability();
            checkSeed();
            checkInterested();
        }
    } finally {
        closing_mon.exit();
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags)

Example 3 with BitFlags

use of com.biglybt.core.peermanager.piecepicker.util.BitFlags in project BiglyBT by BiglySoftware.

the class PEPeerTransportProtocol method checkAllowedFast.

private void checkAllowedFast() {
    try {
        general_mon.enter();
        if (piecePicker.getNbPiecesDone() > ALLOWED_FAST_OTHER_PEER_PIECE_MAX) {
            List<Integer> pieces = (List<Integer>) getUserData(KEY_ALLOWED_FAST_RECEIVED);
            if (pieces != null) {
                if (DEBUG_FAST) {
                    System.out.println("Clearing down fast received for " + getIp());
                }
                setUserData(KEY_ALLOWED_FAST_RECEIVED, null);
                calculatePiecePriorities();
            }
        }
        BitFlags flags = peerHavePieces;
        if (flags != null && flags.nbSet >= ALLOWED_FAST_OTHER_PEER_PIECE_MAX) {
            int[][] pieces = (int[][]) getUserData(KEY_ALLOWED_FAST_SENT);
            if (pieces != null) {
                if (DEBUG_FAST) {
                    System.out.println("Clearing down fast sent for " + getIp());
                }
                setUserData(KEY_ALLOWED_FAST_SENT, null);
            }
        }
    } finally {
        general_mon.exit();
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags)

Example 4 with BitFlags

use of com.biglybt.core.peermanager.piecepicker.util.BitFlags in project BiglyBT by BiglySoftware.

the class PEPeerTransportProtocol method decodeHaveNone.

protected void decodeHaveNone(BTHaveNone have_none) {
    have_none.destroy();
    if ((relativeSeeding & RELATIVE_SEEDING_UPLOAD_ONLY_INDICATED) != 0) {
        relativeSeeding &= ~RELATIVE_SEEDING_UPLOAD_ONLY_INDICATED;
    }
    received_bitfield = true;
    if (is_metadata_download) {
        return;
    }
    try {
        closing_mon.enter();
        if (!closing) {
            final BitFlags tempHavePieces;
            if (peerHavePieces == null) {
                tempHavePieces = new BitFlags(nbPieces);
            } else {
                tempHavePieces = peerHavePieces;
                removeAvailability();
            }
            tempHavePieces.clear();
            peerHavePieces = tempHavePieces;
            // some of these kinda pointless but whatever
            addAvailability();
            checkSeed();
            checkInterested();
            checkFast(tempHavePieces);
        }
    } finally {
        closing_mon.exit();
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags)

Example 5 with BitFlags

use of com.biglybt.core.peermanager.piecepicker.util.BitFlags in project BiglyBT by BiglySoftware.

the class PEPeerTransportProtocol method decodeAZHave.

protected void decodeAZHave(AZHave have) {
    final int[] pieceNumbers = have.getPieceNumbers();
    have.destroy();
    if (closing) {
        return;
    }
    if (peerHavePieces == null) {
        peerHavePieces = new BitFlags(nbPieces);
    }
    boolean send_interested = false;
    boolean new_have = false;
    for (int i = 0; i < pieceNumbers.length; i++) {
        int pieceNumber = pieceNumbers[i];
        if ((pieceNumber >= nbPieces) || (pieceNumber < 0)) {
            closeConnectionInternally("invalid pieceNumber: " + pieceNumber);
            return;
        }
        if (!peerHavePieces.flags[pieceNumber]) {
            new_have = true;
            if (!(send_interested || interested_in_other_peer || is_download_disabled) && diskManager.isInteresting(pieceNumber)) {
                send_interested = true;
            }
            peerHavePieces.set(pieceNumber);
            final int pieceLength = manager.getPieceLength(pieceNumber);
            manager.havePiece(pieceNumber, pieceLength, this);
            peer_stats.hasNewPiece(pieceLength);
        }
    }
    if (new_have) {
        // maybe a seed using lazy bitfield, or suddenly became a seed;
        checkSeed();
        if (other_peer_interested_in_me) {
            if (isSeed() || isRelativeSeed()) {
                // never consider seeds interested
                other_peer_interested_in_me = false;
            }
        }
    }
    if (send_interested) {
        connection.getOutgoingMessageQueue().addMessage(new BTInterested(other_peer_interested_version), false);
        interested_in_other_peer = true;
    }
}
Also used : BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags)

Aggregations

BitFlags (com.biglybt.core.peermanager.piecepicker.util.BitFlags)16 PEPeer (com.biglybt.core.peer.PEPeer)4 LogEvent (com.biglybt.core.logging.LogEvent)3 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)3 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)2 DMPieceList (com.biglybt.core.disk.impl.piecemapper.DMPieceList)2 PEPeerManager (com.biglybt.core.peer.PEPeerManager)2 DiskManager (com.biglybt.core.disk.DiskManager)1 NetworkAdminASN (com.biglybt.core.networkmanager.admin.NetworkAdminASN)1 NetworkAdminASNListener (com.biglybt.core.networkmanager.admin.NetworkAdminASNListener)1 NetworkAdminException (com.biglybt.core.networkmanager.admin.NetworkAdminException)1 PEPeerListener (com.biglybt.core.peer.PEPeerListener)1 PEPieceImpl (com.biglybt.core.peer.impl.PEPieceImpl)1 PEPeerTransportProtocol (com.biglybt.core.peer.impl.transport.PEPeerTransportProtocol)1 AERunnable (com.biglybt.core.util.AERunnable)1 BloomFilter (com.biglybt.core.util.bloom.BloomFilter)1 Graphic (com.biglybt.pif.ui.Graphic)1 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)1 UISWTGraphicImpl (com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl)1 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)1