2005-12-30 jrandom

* Close streams more gracefully
This commit is contained in:
jrandom
2005-12-30 23:33:52 +00:00
committed by zzz
parent 8e87ae08fb
commit 0f8611e465
12 changed files with 52 additions and 25 deletions

View File

@ -117,7 +117,8 @@ public class BitField
public String toString()
{
// Not very efficient
StringBuffer sb = new StringBuffer("BitField[");
StringBuffer sb = new StringBuffer("BitField(");
sb.append(size).append(")[");
for (int i = 0; i < size; i++)
if (get(i))
{

View File

@ -116,7 +116,7 @@ class PeerConnectionIn implements Runnable
din.readFully(bitmap);
ps.bitfieldMessage(bitmap);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Received bitmap from " + peer + " on " + peer.metainfo.getName());
_log.debug("Received bitmap from " + peer + " on " + peer.metainfo.getName() + ": size=" + (i-1) + ": " + ps.bitfield);
break;
case 6:
piece = din.readInt();

View File

@ -365,8 +365,11 @@ public class PeerCoordinator implements PeerListener
*/
public int wantPiece(Peer peer, BitField havePieces)
{
if (halted)
if (halted) {
if (_log.shouldLog(Log.WARN))
_log.warn("We don't want anything from the peer, as we are halted! peer=" + peer);
return -1;
}
synchronized(wantedPieces)
{
@ -398,7 +401,12 @@ public class PeerCoordinator implements PeerListener
piece = p;
}
}
if (piece == null) return -1; //If we still can't find a piece we want, so be it.
if (piece == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("nothing to even rerequest from " + peer + ": requested = " + requested
+ " wanted = " + wantedPieces + " peerHas = " + havePieces);
return -1; //If we still can't find a piece we want, so be it.
}
}
piece.setRequested(true);
return piece.getId();

View File

@ -35,4 +35,8 @@ public class Piece implements Comparable {
public boolean removePeer(Peer peer) { return this.peers.remove(peer.getPeerID()); }
public boolean isRequested() { return this.requested; }
public void setRequested(boolean requested) { this.requested = requested; }
public String toString() {
return String.valueOf(id);
}
}

View File

@ -26,6 +26,7 @@ import java.util.*;
import org.klomp.snark.bencode.*;
import net.i2p.data.Destination;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.util.I2PThread;
@ -287,8 +288,10 @@ public class Snark
I2PServerSocket serversocket = I2PSnarkUtil.instance().getServerSocket();
if (serversocket == null)
fatal("Unable to listen for I2P connections");
else
debug("Listening on I2P destination " + serversocket.getManager().getSession().getMyDestination().toBase64(), NOTICE);
else {
Destination d = serversocket.getManager().getSession().getMyDestination();
debug("Listening on I2P destination " + d.toBase64() + " / " + d.calculateHash().toBase64(), NOTICE);
}
// Figure out what the torrent argument represents.
meta = null;