- Rework traffic counters

- Record the metadata bandwidth
- More null announce handling
- Callbacks for got MetaInfo event
- Cleanups
This commit is contained in:
zzz
2010-12-21 23:43:13 +00:00
parent f15b329874
commit 690aea255b
7 changed files with 129 additions and 52 deletions

View File

@ -53,6 +53,10 @@ public class Peer implements Comparable
private DataInputStream din;
private DataOutputStream dout;
/** running counters */
private long downloaded;
private long uploaded;
// Keeps state for in/out connections. Non-null when the handshake
// was successful, the connection setup and runs
PeerState state;
@ -410,10 +414,10 @@ public class Peer implements Comparable
* Switch from magnet mode to normal mode
* @since 0.8.4
*/
public void gotMetaInfo(MetaInfo meta) {
public void setMetaInfo(MetaInfo meta) {
PeerState s = state;
if (s != null)
s.gotMetaInfo(meta);
s.setMetaInfo(meta);
}
public boolean isConnected()
@ -577,14 +581,29 @@ public class Peer implements Comparable
return (s == null) || s.choked;
}
/**
* Increment the counter.
* @since 0.8.4
*/
public void downloaded(int size) {
downloaded += size;
}
/**
* Increment the counter.
* @since 0.8.4
*/
public void uploaded(int size) {
uploaded += size;
}
/**
* Returns the number of bytes that have been downloaded.
* Can be reset to zero with <code>resetCounters()</code>/
*/
public long getDownloaded()
{
PeerState s = state;
return (s != null) ? s.downloaded : 0;
return downloaded;
}
/**
@ -593,8 +612,7 @@ public class Peer implements Comparable
*/
public long getUploaded()
{
PeerState s = state;
return (s != null) ? s.uploaded : 0;
return uploaded;
}
/**
@ -602,12 +620,8 @@ public class Peer implements Comparable
*/
public void resetCounters()
{
PeerState s = state;
if (s != null)
{
s.downloaded = 0;
s.uploaded = 0;
}
downloaded = 0;
uploaded = 0;
}
public long getInactiveTime() {