浏览代码

2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added getServers XML-RPC method.
	* doc/aria2c.1.txt
	* src/FileEntry.h
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
Tatsuhiro Tsujikawa 15 年之前
父节点
当前提交
6ce44b001d
共有 8 个文件被更改,包括 180 次插入1 次删除
  1. 9 0
      ChangeLog
  2. 29 0
      doc/aria2c.1
  3. 51 1
      doc/aria2c.1.html
  4. 28 0
      doc/aria2c.1.txt
  5. 5 0
      src/FileEntry.h
  6. 2 0
      src/XmlRpcMethodFactory.cc
  7. 45 0
      src/XmlRpcMethodImpl.cc
  8. 11 0
      src/XmlRpcMethodImpl.h

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2010-03-07  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added getServers XML-RPC method.
+	* doc/aria2c.1.txt
+	* src/FileEntry.h
+	* src/XmlRpcMethodFactory.cc
+	* src/XmlRpcMethodImpl.cc
+	* src/XmlRpcMethodImpl.h
+
 2010-03-07  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Pool request when download finished.

+ 29 - 0
doc/aria2c.1

@@ -2450,6 +2450,35 @@ seeder
 "true" is this client is a seeder\&. Otherwise "false"\&.
 .RE
 .sp
+\fBaria2\&.getServers\fR \fIgid\fR
+.sp
+This method returns currently connected HTTP(S)/FTP servers of the download denoted by \fIgid\fR\&. \fIgid\fR is of type string\&. The response is of type array and its element is of type struct and it contains following keys\&. The value type is string\&.
+.PP
+index
+.RS 4
+Index of file\&. Starting with 1\&. This is the same order with the files in multi\-file torrent\&.
+.RE
+.PP
+servers
+.RS 4
+The list of struct which contains following keys\&.
+.PP
+uri
+.RS 4
+URI originally added\&.
+.RE
+.PP
+currentUri
+.RS 4
+This is the URI currently used for downloading\&. If redirection is involved, currentUri and uri may differ\&.
+.RE
+.PP
+downloadSpeed
+.RS 4
+Download speed (byte/sec)
+.RE
+.RE
+.sp
 \fBaria2\&.tellActive\fR
 .sp
 This method returns the list of active downloads\&. The response is of type array and its element is the same struct returned by \fBaria2\&.tellStatus\fR method\&.

+ 51 - 1
doc/aria2c.1.html

@@ -3146,6 +3146,56 @@ seeder
 </p>
 </dd>
 </dl></div>
+<div class="paragraph"><p><strong>aria2.getServers</strong> <em>gid</em></p></div>
+<div class="paragraph"><p>This method returns currently connected HTTP(S)/FTP servers of the download denoted by <em>gid</em>. <em>gid</em> is of type string. The response
+is of type array and its element is of type struct and it contains
+following keys. The value type is string.</p></div>
+<div class="dlist"><dl>
+<dt class="hdlist1">
+index
+</dt>
+<dd>
+<p>
+  Index of file. Starting with 1. This is the same order with the
+  files in multi-file torrent.
+</p>
+</dd>
+<dt class="hdlist1">
+servers
+</dt>
+<dd>
+<p>
+  The list of struct which contains following keys.
+</p>
+<div class="dlist"><dl>
+<dt class="hdlist1">
+uri
+</dt>
+<dd>
+<p>
+    URI originally added.
+</p>
+</dd>
+<dt class="hdlist1">
+currentUri
+</dt>
+<dd>
+<p>
+    This is the URI currently used for downloading. If redirection is
+    involved, currentUri and uri may differ.
+</p>
+</dd>
+<dt class="hdlist1">
+downloadSpeed
+</dt>
+<dd>
+<p>
+    Download speed (byte/sec)
+</p>
+</dd>
+</dl></div>
+</dd>
+</dl></div>
 <div class="paragraph"><p><strong>aria2.tellActive</strong></p></div>
 <div class="paragraph"><p>This method returns the list of active downloads.  The response is of
 type array and its element is the same struct returned by
@@ -3754,7 +3804,7 @@ files in the program, then also delete it here.</p></div>
 <div id="footnotes"><hr /></div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2010-03-07 16:16:27 JST
+Last updated 2010-03-07 17:15:38 JST
 </div>
 </div>
 </body>

+ 28 - 0
doc/aria2c.1.txt

@@ -1418,6 +1418,34 @@ seeder::
 
   "true" is this client is a seeder. Otherwise "false".
 
+*aria2.getServers* 'gid'
+
+This method returns currently connected HTTP(S)/FTP servers of the download denoted by 'gid'. 'gid' is of type string. The response
+is of type array and its element is of type struct and it contains
+following keys. The value type is string.
+
+index::
+
+  Index of file. Starting with 1. This is the same order with the
+  files in multi-file torrent.
+
+servers::
+
+  The list of struct which contains following keys.
+
+  uri;;
+
+    URI originally added.
+
+  currentUri;;
+
+    This is the URI currently used for downloading. If redirection is
+    involved, currentUri and uri may differ.
+
+  downloadSpeed;;
+
+    Download speed (byte/sec)
+
 *aria2.tellActive*
 
 This method returns the list of active downloads.  The response is of

+ 5 - 0
src/FileEntry.h

@@ -212,6 +212,11 @@ public:
     return _requestPool.size();
   }
 
+  const std::deque<SharedHandle<Request> >& getInFlightRequests() const
+  {
+    return _inFlightRequests;
+  }
+
   bool operator<(const FileEntry& fileEntry) const;
 
   bool exists() const;

+ 2 - 0
src/XmlRpcMethodFactory.cc

@@ -73,6 +73,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
   else if(methodName == GetPeersXmlRpcMethod::getMethodName()) {
     return SharedHandle<XmlRpcMethod>(new GetPeersXmlRpcMethod());
 #endif // ENABLE_BITTORRENT
+  } else if(methodName == GetServersXmlRpcMethod::getMethodName()) {
+    return SharedHandle<XmlRpcMethod>(new GetServersXmlRpcMethod());
   } else if(methodName == TellActiveXmlRpcMethod::getMethodName()) {
     return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
   } else if(methodName == TellWaitingXmlRpcMethod::getMethodName()) {

+ 45 - 0
src/XmlRpcMethodImpl.cc

@@ -112,6 +112,7 @@ const std::string KEY_PATH = "path";
 const std::string KEY_SELECTED = "selected";
 const std::string KEY_LENGTH = "length";
 const std::string KEY_URI = "uri";
+const std::string KEY_CURRENT_URI = "currentUri";
 const std::string KEY_VERSION = "version";
 const std::string KEY_ENABLED_FEATURES = "enabledFeatures";
 const std::string KEY_METHOD_NAME = "methodName";
@@ -127,6 +128,7 @@ const std::string KEY_ANNOUNCE_LIST = "announceList";
 const std::string KEY_COMMENT = "comment";
 const std::string KEY_CREATION_DATE = "creationDate";
 const std::string KEY_MODE = "mode";
+const std::string KEY_SERVERS = "servers";
 }
 
 static BDE createGIDResponse(int32_t gid)
@@ -880,6 +882,49 @@ BDE GetSessionInfoXmlRpcMethod::process
   return result;
 }
 
+BDE GetServersXmlRpcMethod::process
+(const XmlRpcRequest& req, DownloadEngine* e)
+{
+  const BDE& params = req._params;
+  assert(params.isList());
+
+  if(params.empty() || !params[0].isString()) {
+    throw DL_ABORT_EX("Bad request");
+  }
+  int32_t gid = util::parseInt(params[0].s());
+  SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
+  if(group.isNull()) {
+    throw DL_ABORT_EX(StringFormat("No active download for GID#%d", gid).str());
+  }
+  SharedHandle<DownloadContext> dctx = group->getDownloadContext();
+  const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
+  BDE result = BDE::list();
+  size_t index = 1;
+  for(std::vector<SharedHandle<FileEntry> >::const_iterator fi = files.begin(),
+        eoi = files.end(); fi != eoi; ++fi, ++index) {
+    BDE fileEntry = BDE::dict();
+    fileEntry[KEY_INDEX] = util::uitos(index);
+    BDE servers = BDE::list();
+    const std::deque<SharedHandle<Request> >& requests =
+      (*fi)->getInFlightRequests();
+    for(std::deque<SharedHandle<Request> >::const_iterator ri =requests.begin(),
+          eoi = requests.end(); ri != eoi; ++ri) {
+      SharedHandle<PeerStat> ps = (*ri)->getPeerStat();
+      if(!ps.isNull()) {
+        BDE serverEntry = BDE::dict();
+        serverEntry[KEY_URI] = (*ri)->getUrl();
+        serverEntry[KEY_CURRENT_URI] = (*ri)->getCurrentUrl();
+        serverEntry[KEY_DOWNLOAD_SPEED] =
+          util::uitos(ps->calculateDownloadSpeed());
+        servers << serverEntry;
+      }
+    }
+    fileEntry[KEY_SERVERS] = servers;
+    result << fileEntry;
+  }
+  return result;
+}
+
 BDE ChangeUriXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {

+ 11 - 0
src/XmlRpcMethodImpl.h

@@ -156,6 +156,17 @@ public:
 };
 #endif // ENABLE_BITTORRENT
 
+class GetServersXmlRpcMethod:public XmlRpcMethod {
+protected:
+  virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
+public:
+  static const std::string& getMethodName()
+  {
+    static std::string methodName = "aria2.getServers";
+    return methodName;
+  }
+};
+
 class TellStatusXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);