]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Merge branch '2510-new-foolscap'
authorBrian Warner <warner@lothar.com>
Wed, 23 Sep 2015 04:30:03 +0000 (21:30 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 23 Sep 2015 04:30:03 +0000 (21:30 -0700)
src/allmydata/introducer/common.py
src/allmydata/introducer/old.py
src/allmydata/introducer/server.py
src/allmydata/test/test_introducer.py
src/allmydata/test/test_system.py
src/allmydata/util/rrefutil.py
src/allmydata/web/introducer.xhtml
src/allmydata/web/introweb.py

index 9337d4bbcb10be98f8f96d3f35d36d3f0e0b439c..699408ece8d6cc996103fb5dce720ee26dd94e21 100644 (file)
@@ -100,20 +100,18 @@ class SubscriberDescriptor:
     .nickname: their self-provided nickname, or "?" (unicode)
     .version: their self-provided version (string)
     .app_versions: versions of each library they use (dict str->str)
-    .advertised_addresses: what hosts they listen on (list of strings)
     .remote_address: the external address from which they connected (string)
     .tubid: for subscribers connecting with Foolscap, their tubid (string)
     """
 
     def __init__(self, service_name, when,
                  nickname, version, app_versions,
-                 advertised_addresses, remote_address, tubid):
+                 remote_address, tubid):
         self.service_name = service_name
         self.when = when
         self.nickname = nickname
         self.version = version
         self.app_versions = app_versions
-        self.advertised_addresses = advertised_addresses
         self.remote_address = remote_address
         self.tubid = tubid
 
@@ -133,9 +131,9 @@ class AnnouncementDescriptor:
      .nickname: their self-provided nickname, or "" (unicode)
      .serverid: the server identifier. This is a pubkey (for V2 clients),
                 or a tubid (for V1 clients).
-     .advertised_addresses: which hosts they listen on (list of strings)
-                            if the announcement included a key for
-                            'anonymous-storage-FURL', else an empty list.
+     .connection_hints: where they listen (list of strings) if the
+                        announcement included a key for
+                        'anonymous-storage-FURL', else an empty list.
     """
 
     def __init__(self, when, index, canary, ann_d):
@@ -150,6 +148,6 @@ class AnnouncementDescriptor:
         self.serverid = key_s or tubid_s
         furl = ann_d.get("anonymous-storage-FURL")
         if furl:
-            self.advertised_addresses = rrefutil.hosts_for_furl(furl)
+            self.connection_hints = rrefutil.connection_hints_for_furl(furl)
         else:
-            self.advertised_addresses = []
+            self.connection_hints = []
index 702969f0f2578e3c068b086a5a351416dea953fb..3c2fcb7122510e69bc0cc8d0f4c8ab1e2d89bbdf 100644 (file)
@@ -405,13 +405,11 @@ class IntroducerService_v1(service.MultiService, Referenceable):
         for service_name, subscribers in self._subscribers.items():
             for rref, when in subscribers.items():
                 tubid = rref.getRemoteTubID() or "?"
-                advertised_addresses = rrefutil.hosts_for_rref(rref)
                 remote_address = rrefutil.stringify_remote_address(rref)
                 nickname, version, app_versions = u"?", u"?", {}
                 sd = SubscriberDescriptor(service_name, when,
                                           nickname, version, app_versions,
-                                          advertised_addresses, remote_address,
-                                          tubid)
+                                          remote_address, tubid)
                 s.append(sd)
         return s
 
index 7031c3af68b792e45651476342b736f14c782757..92c2497e43ebaadcf6fada52cce4a4e48459a118 100644 (file)
@@ -175,7 +175,6 @@ class IntroducerService(service.MultiService, Referenceable):
                 # tubid will be None. Also, subscribers do not tell us which
                 # pubkey they use; only publishers do that.
                 tubid = rref.getRemoteTubID() or "?"
-                advertised_addresses = rrefutil.hosts_for_rref(rref)
                 remote_address = rrefutil.stringify_remote_address(rref)
                 # these three assume subscriber_info["version"]==0, but
                 # should tolerate other versions
@@ -188,8 +187,7 @@ class IntroducerService(service.MultiService, Referenceable):
                 # 'when' is the time they subscribed
                 sd = SubscriberDescriptor(service_name, when,
                                           nickname, version, app_versions,
-                                          advertised_addresses, remote_address,
-                                          tubid)
+                                          remote_address, tubid)
                 s.append(sd)
         return s
 
index 475b04dba6ac13b485d962210ecdc466513c9960..be7d05ddc37b638f7f1652a9a9d7485de8f79c4e 100644 (file)
@@ -877,8 +877,8 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
 class FakeRemoteReference:
     def notifyOnDisconnect(self, *args, **kwargs): pass
     def getRemoteTubID(self): return "62ubehyunnyhzs7r6vdonnm2hpi52w6y"
-    def getLocationHints(self): return [("ipv4", "here.example.com", "1234"),
-                                        ("ipv4", "there.example.com", "2345")]
+    def getLocationHints(self): return ["tcp:here.example.com:1234",
+                                        "tcp:there.example.com2345"]
     def getPeer(self): return address.IPv4Address("TCP", "remote.example.com",
                                                   3456)
 
index 4ffbb29cea50f95bbb63ca293962f826171c03b2..1887c7e28b2e4fa4652a9c64c50e8e10c2a0494f 100644 (file)
@@ -812,8 +812,6 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
                                      {"storage": 5})
                 self.failUnlessEqual(data["announcement_summary"],
                                      {"storage": 5})
-                self.failUnlessEqual(data["announcement_distinct_hosts"],
-                                     {"storage": 1})
             except unittest.FailTest:
                 print
                 print "GET %s?t=json output was:" % self.introweb_url
index a14d15f13fcb835f3afd09fd46030668c77eb871..6481cabc9e3a82f9d8cde7df0b494a7a8c3ca2ee 100644 (file)
@@ -27,30 +27,18 @@ def trap_deadref(f):
     return trap_and_discard(f, DeadReferenceError)
 
 
-def hosts_for_rref(rref, ignore_localhost=True):
-    # actually, this only returns hostnames
-    advertised = []
-    for hint in rref.getLocationHints():
-        # Foolscap-0.2.5 and earlier used strings in .locationHints, but we
-        # require a newer version that uses tuples of ("ipv4", host, port)
-        assert not isinstance(hint, str), hint
-        if hint[0] == "ipv4":
-            host = hint[1]
-            if ignore_localhost and host == "127.0.0.1":
-                continue
-            advertised.append(host)
-    return advertised
-
-def hosts_for_furl(furl, ignore_localhost=True):
-    advertised = []
-    for hint in SturdyRef(furl).locationHints:
-        assert not isinstance(hint, str), hint
-        if hint[0] == "ipv4":
-            host = hint[1]
-            if ignore_localhost and host == "127.0.0.1":
-                continue
-            advertised.append(host)
-    return advertised
+def connection_hints_for_furl(furl):
+    hints = []
+    for h in SturdyRef(furl).locationHints:
+        # Foolscap-0.2.5 and earlier used strings in .locationHints, 0.2.6
+        # through 0.6.4 used tuples of ("ipv4",host,port), 0.6.5 through
+        # 0.8.0 used tuples of ("tcp",host,port), and >=0.9.0 uses strings
+        # again. Tolerate them all.
+        if isinstance(h, tuple):
+            hints.append(":".join([str(s) for s in h]))
+        else:
+            hints.append(h)
+    return hints
 
 def stringify_remote_address(rref):
     remote = rref.getPeer()
index e89e88c3be2f00969619108b6a44dffbdaab71be..f64f7e09236089d9150fb9b0ecaf2d019f693979 100644 (file)
@@ -30,7 +30,6 @@
     <th class="nickname-and-peerid">
       <div class="service-nickname">Nickname</div>
       <div class="nodeid data-chars">ServerID</div></th>
-    <th>Advertised IPs</th>
     <th>Announced</th>
     <th>Version</th>
     <th>Service Name</th>
@@ -39,8 +38,7 @@
     <td class="nickname-and-peerid">
       <div class="nickname"><n:slot name="nickname"/></div>
       <div class="nodeid data-chars"><n:slot name="serverid"/></div></td>
-    <td><n:slot name="advertised"/></td>
-    <td class="service-announced"><n:slot name="announced"/></td>
+    <td class="service-announced"><n:attr name="title"><n:slot name="connection-hints"/></n:attr><n:slot name="announced"/></td>
     <td class="service-version"><n:slot name="version"/></td>
     <td class="service-service-name"><n:slot name="service_name"/></td>
   </tr>
@@ -56,7 +54,6 @@
     <th class="nickname-and-peerid">
       <div class="service-nickname">Nickname</div>
       <div class="nodeid data-chars">Tub ID</div></th>
-    <th>Advertised IPs</th>
     <th>Connected From</th>
     <th>Since</th>
     <th>Version</th>
@@ -66,7 +63,6 @@
     <td class="nickname-and-peerid">
       <div class="nickname"><n:slot name="nickname"/></div>
       <div class="nodeid data-chars"><n:slot name="tubid"/></div></td>
-    <td><n:slot name="advertised"/></td>
     <td><n:slot name="connected"/></td>
     <td class="service-since"><n:slot name="since"/></td>
     <td class="service-version"><n:slot name="version"/></td>
index cc8b2ce15ebf32e107dd835fdb80f97a83addbf5..6287af63131351a15bcbf3ee1fd118c9b18aafd8 100644 (file)
@@ -42,28 +42,12 @@ class IntroducerRoot(rend.Page):
         res["subscription_summary"] = counts
 
         announcement_summary = {}
-        service_hosts = {}
         for ad in self.introducer_service.get_announcements():
             service_name = ad.service_name
             if service_name not in announcement_summary:
                 announcement_summary[service_name] = 0
             announcement_summary[service_name] += 1
-            if service_name not in service_hosts:
-                service_hosts[service_name] = set()
-            # it's nice to know how many distinct hosts are available for
-            # each service. We define a "host" by a set of addresses
-            # (hostnames or ipv4 addresses), which we extract from the
-            # connection hints. In practice, this is usually close
-            # enough: when multiple services are run on a single host,
-            # they're usually either configured with the same addresses,
-            # or setLocationAutomatically picks up the same interfaces.
-            host = frozenset(ad.advertised_addresses)
-            service_hosts[service_name].add(host)
         res["announcement_summary"] = announcement_summary
-        distinct_hosts = dict([(name, len(hosts))
-                               for (name, hosts)
-                               in service_hosts.iteritems()])
-        res["announcement_distinct_hosts"] = distinct_hosts
 
         return simplejson.dumps(res, indent=1) + "\n"
 
@@ -105,7 +89,8 @@ class IntroducerRoot(rend.Page):
     def render_service_row(self, ctx, ad):
         ctx.fillSlots("serverid", ad.serverid)
         ctx.fillSlots("nickname", ad.nickname)
-        ctx.fillSlots("advertised", " ".join(ad.advertised_addresses))
+        ctx.fillSlots("connection-hints",
+                      "connection hints: " + " ".join(ad.connection_hints))
         ctx.fillSlots("connected", "?")
         when_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(ad.when))
         ctx.fillSlots("announced", when_s)
@@ -119,7 +104,6 @@ class IntroducerRoot(rend.Page):
     def render_subscriber_row(self, ctx, s):
         ctx.fillSlots("nickname", s.nickname)
         ctx.fillSlots("tubid", s.tubid)
-        ctx.fillSlots("advertised", " ".join(s.advertised_addresses))
         ctx.fillSlots("connected", s.remote_address)
         since_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(s.when))
         ctx.fillSlots("since", since_s)