[mirrorbrain-commits] r8031 - /trunk/mod_mirrorbrain/mod_mirrorbrain.c

From: <poeml_at_mirrorbrain.org>
Date: Mon, 29 Mar 2010 02:58:18 -0000
Author: poeml
Date: Mon Mar 29 04:58:17 2010
New Revision: 8031

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8031&view=rev
Log:
mod_mirrorbrain:
- Now also the original BitTorrent client groks our torrents. It complained
  about invalid bencoding, which really meant "I don't know the url-list key",
  and we discovered that it doesn't complain if we put the key after the SHA1
  pieces. (Oh well.)

Modified:
    trunk/mod_mirrorbrain/mod_mirrorbrain.c

Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mod_mirrorbrain/mod_mirrorbrain.c?rev=8031&r1=8030&r2=8031&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Mon Mar 29 04:58:17 2010
_at_@ -2607,69 +2607,6 @@
         ap_rprintf(r,     "13:creation date"
                               "i%se", apr_itoa(r->pool, apr_time_sec(r->finfo.mtime)));
 
-        /* Web seeds */
-        ap_rputs(         "8:url-listl", r);
-        int found_urls = 0;
-        mirrorp = (mirror_entry_t **)mirrors_same_prefix->elts;
-        for (i = 0; i < mirrors_same_prefix->nelts; i++, found_urls++) {
-            mirror = mirrorp[i];
-            ap_rprintf(r,     "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
-                                           mirror->baseurl, filename);
-        }
-        if (!found_urls) {
-            mirrorp = (mirror_entry_t **)mirrors_same_as->elts;
-            for (i = 0; i < mirrors_same_as->nelts; i++, found_urls++) {
-                mirror = mirrorp[i];
-                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
-                                               mirror->baseurl, filename);
-            }
-        }
-        if (!found_urls) {
-            mirrorp = (mirror_entry_t **)mirrors_same_country->elts;
-            for (i = 0; i < mirrors_same_country->nelts; i++, found_urls++) {
-                mirror = mirrorp[i];
-                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
-                                               mirror->baseurl, filename);
-            }
-        }
-        if (!found_urls) {
-            mirrorp = (mirror_entry_t **)mirrors_same_region->elts;
-            for (i = 0; i < mirrors_same_region->nelts; i++, found_urls++) {
-                mirror = mirrorp[i];
-                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
-                                               mirror->baseurl, filename);
-            }
-        }
-        if (!found_urls) {
-            mirrorp = (mirror_entry_t **)mirrors_elsewhere->elts;
-            for (i = 0; i < mirrors_elsewhere->nelts; i++, found_urls++) {
-                mirror = mirrorp[i];
-                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
-                                               mirror->baseurl, filename);
-            }
-        }
-        /* add the redirector, in case there wasn't any mirror */
-        if (!found_urls) {
-            ap_rprintf(r,     "%d:http://%s%s", (7 + strlen(r->hostname) + strlen(r->uri)), 
-                                                r->hostname, r->uri);
-        }
-        ap_rputs(         "e", r);
-
-#if 0
-        /* it would be simple to just list the URL of the redirector itself, but aria2c
-         * retrieves a Metalink then and doesn't expect it in that situation. Maybe later */
-        ap_rprintf(r,     "8:url-list"
-                              "%d:http://%s%s", (7 + strlen(r->hostname) + strlen(r->uri)), 
-                                                r->hostname, r->uri);
-#endif
-
-#if 0
-        /* I can't find info about this element which could possibly also list mirrors */
-        ap_rprintf(r,     "7:sourcesl"
-                              "%d:http://%s%s" "e", (7 + strlen(r->hostname) + strlen(r->uri)), 
-                                                r->hostname, r->uri);
-#endif
-
         ap_rprintf(r,     "4:info"
                               "d"
                                   "6:length"
_at_@ -2689,8 +2626,79 @@
         for (i = 0; i < hashbag->sha1pieceshex->nelts; i++) {
             ap_rwrite(hex_decode(r, p[i], SHA1_DIGESTSIZE), SHA1_DIGESTSIZE, r);
         }
-        ap_rputs(             "e"
-                      "e", r);
+        ap_rputs(             "e", r);
+
+        /* Web seeds
+         *
+         * There's a trick: send this stuff _after_ the sha1 pieces. 
+         * The original BitTorrent client doesn't ignore unknown keys, but
+         * refuses to grok the torrent and says "is not a valid torrent file
+         * (not a valid bencoded string)". (Which is wrong.) However, it does
+         * _not_ seam to read past the pieces; at least it doesn't complain
+         * about stuff occurring afterwards. */
+        ap_rputs(         "8:url-listl", r);
+        int found_urls = 0;
+        mirrorp = (mirror_entry_t **)mirrors_same_prefix->elts;
+        for (i = 0; i < mirrors_same_prefix->nelts; i++, found_urls++) {
+            mirror = mirrorp[i];
+            ap_rprintf(r,     "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
+                                           mirror->baseurl, filename);
+        }
+        if (!found_urls) {
+            mirrorp = (mirror_entry_t **)mirrors_same_as->elts;
+            for (i = 0; i < mirrors_same_as->nelts; i++, found_urls++) {
+                mirror = mirrorp[i];
+                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
+                                               mirror->baseurl, filename);
+            }
+        }
+        if (!found_urls) {
+            mirrorp = (mirror_entry_t **)mirrors_same_country->elts;
+            for (i = 0; i < mirrors_same_country->nelts; i++, found_urls++) {
+                mirror = mirrorp[i];
+                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
+                                               mirror->baseurl, filename);
+            }
+        }
+        if (!found_urls) {
+            mirrorp = (mirror_entry_t **)mirrors_same_region->elts;
+            for (i = 0; i < mirrors_same_region->nelts; i++, found_urls++) {
+                mirror = mirrorp[i];
+                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
+                                               mirror->baseurl, filename);
+            }
+        }
+        if (!found_urls) {
+            mirrorp = (mirror_entry_t **)mirrors_elsewhere->elts;
+            for (i = 0; i < mirrors_elsewhere->nelts; i++, found_urls++) {
+                mirror = mirrorp[i];
+                ap_rprintf(r, "%d:%s%s", (strlen(mirror->baseurl) + strlen(filename)),
+                                               mirror->baseurl, filename);
+            }
+        }
+        /* add the redirector, in case there wasn't any mirror */
+        if (!found_urls) {
+            ap_rprintf(r,     "%d:http://%s%s", (7 + strlen(r->hostname) + strlen(r->uri)), 
+                                                r->hostname, r->uri);
+        }
+        ap_rputs(         "e", r);
+
+#if 0
+        /* it would be simple to just list the URL of the redirector itself, but aria2c
+         * retrieves a Metalink then and doesn't expect it in that situation. Maybe later */
+        ap_rprintf(r,     "8:url-list"
+                              "%d:http://%s%s", (7 + strlen(r->hostname) + strlen(r->uri)), 
+                                                r->hostname, r->uri);
+#endif
+
+#if 0
+        /* I can't find info about this element which could possibly also list mirrors */
+        ap_rprintf(r,     "7:sourcesl"
+                              "%d:http://%s%s" "e", (7 + strlen(r->hostname) + strlen(r->uri)), 
+                                                r->hostname, r->uri);
+#endif
+
+        ap_rputs(     "e", r);
 
         /* if there's no announce key (trackerless torrent), we should add a "nodes" key. 
          * TODO: find out what it should contain. See http://www.bittorrent.org/beps/bep_0005.html */




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Mon Mar 29 2010 - 02:58:21 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT