Explorar o código

2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added uploadLength and numSeeders to the response of tellStatus
	xml-rpc method. Assert that PeerStorage instance is not null
	instead of checking if statement. It should be non-null in this
	context.
	* src/XmlRpcMethodImpl.cc
Tatsuhiro Tsujikawa %!s(int64=16) %!d(string=hai) anos
pai
achega
9d910c47c2
Modificáronse 2 ficheiros con 27 adicións e 7 borrados
  1. 8 0
      ChangeLog
  2. 19 7
      src/XmlRpcMethodImpl.cc

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2009-06-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added uploadLength and numSeeders to the response of tellStatus
+	xml-rpc method. Assert that PeerStorage instance is not null
+	instead of checking if statement. It should be non-null in this
+	context.
+	* src/XmlRpcMethodImpl.cc
+	
 2009-06-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use htmlEscape instead of xmlEscape. Removed static function xmlEscape.

+ 19 - 7
src/XmlRpcMethodImpl.cc

@@ -265,6 +265,7 @@ static void gatherProgressCommon
   TransferStat stat = group->calculateStat();
   entryDict["downloadSpeed"] = Util::uitos(stat.getDownloadSpeed());
   entryDict["uploadSpeed"] = Util::uitos(stat.getUploadSpeed());
+  entryDict["uploadLength"] = Util::uitos(stat.getAllTimeUploadLength());
   entryDict["connections"] = Util::uitos(group->getNumConnection());
   SharedHandle<PieceStorage> ps = group->getPieceStorage();
   if(!ps.isNull()) {
@@ -281,9 +282,20 @@ static void gatherProgressCommon
 
 #ifdef ENABLE_BITTORRENT
 static void gatherProgressBitTorrent
-(BDE& entryDict, const SharedHandle<BtContext>& btctx)
+(BDE& entryDict, const SharedHandle<BtContext>& btctx,
+ const SharedHandle<BtRegistry>& btreg)
 {
   entryDict["infoHash"] = btctx->getInfoHashAsString();
+
+  SharedHandle<PeerStorage> peerStorage =
+    btreg->getPeerStorage(btctx->getInfoHashAsString());
+  assert(!peerStorage.isNull());
+
+  std::deque<SharedHandle<Peer> > peers;
+  peerStorage->getActivePeers(peers);
+  entryDict["numSeeders"] =
+    Util::uitos(std::count_if(peers.begin(), peers.end(),
+			      mem_fun_sh(&Peer::isSeeder)));
 }
 
 static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
@@ -318,7 +330,8 @@ static void gatherProgress
   SharedHandle<BtContext> btctx =
     dynamic_pointer_cast<BtContext>(group->getDownloadContext());
   if(!btctx.isNull()) {
-    gatherProgressBitTorrent(entryDict, btctx);
+    SharedHandle<BtRegistry> btreg = e->getBtRegistry();
+    gatherProgressBitTorrent(entryDict, btctx, btreg);
   }
 #endif // ENABLE_BITTORRENT
 }
@@ -444,12 +457,11 @@ BDE GetPeersXmlRpcMethod::process
     dynamic_pointer_cast<BtContext>(group->getDownloadContext());
   if(!btctx.isNull()) {
     SharedHandle<BtRegistry> btreg = e->getBtRegistry();
-    SharedHandle<PeerStorage> ps =
+    SharedHandle<PeerStorage> peerStorage =
       btreg->getPeerStorage(btctx->getInfoHashAsString());
-    if(!ps.isNull()) {
-      BDE entry = BDE::dict();
-      gatherPeer(peers, ps);
-    }
+    assert(!peerStorage.isNull());
+    BDE entry = BDE::dict();
+    gatherPeer(peers, peerStorage);
   }
   return peers;
 }