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);
}
}
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();
}
}
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();
}
}
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();
}
}
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;
}
}
Aggregations