remove make_index()

index is now always (service_name, key_id)
This commit is contained in:
Brian Warner 2016-05-10 20:19:55 -07:00
parent b2e5507e09
commit 6f1e01453e
4 changed files with 7 additions and 22 deletions

View File

@ -7,7 +7,7 @@ from allmydata.interfaces import InsufficientVersionError
from allmydata.introducer.interfaces import IIntroducerClient, \
RIIntroducerSubscriberClient_v2
from allmydata.introducer.common import sign_to_foolscap, unsign_from_foolscap,\
make_index, get_tubid_string_from_ann
get_tubid_string_from_ann
from allmydata.util import log
from allmydata.util.rrefutil import add_version_to_remote_reference
from allmydata.util.keyutil import BadSignatureError
@ -271,7 +271,7 @@ class IntroducerClient(service.Service, Referenceable):
description = "/".join(desc_bits)
# the index is used to track duplicates
index = make_index(ann, key_s)
index = (service_name, key_s)
# is this announcement a duplicate?
if (index in self._inbound_announcements

View File

@ -2,20 +2,6 @@
import re, simplejson
from allmydata.util import keyutil, base32, rrefutil
def make_index(ann, key_s):
"""Return something that can be used as an index (e.g. a tuple of
strings), such that two messages that refer to the same 'thing' will have
the same index. This is a tuple of (service-name, signing-key, None) for
signed announcements, or (service-name, None, tubid_s) for unsigned
announcements."""
service_name = str(ann["service-name"])
if key_s:
return (service_name, key_s, None)
else:
tubid_s = get_tubid_string_from_ann(ann)
return (service_name, None, tubid_s)
def get_tubid_string_from_ann(ann):
return get_tubid_string(str(ann.get("anonymous-storage-FURL")
or ann.get("FURL")))
@ -107,8 +93,8 @@ class AnnouncementDescriptor:
self.service_name = ann_d["service-name"]
self.version = ann_d.get("my-version", "")
self.nickname = ann_d.get("nickname", u"")
(service_name, key_s, tubid_s) = index
self.serverid = key_s or tubid_s
(service_name, key_s) = index
self.serverid = key_s
furl = ann_d.get("anonymous-storage-FURL")
if furl:
self.connection_hints = rrefutil.connection_hints_for_furl(furl)

View File

@ -9,7 +9,7 @@ from allmydata.util import log, rrefutil
from allmydata.util.fileutil import abspath_expanduser_unicode
from allmydata.introducer.interfaces import \
RIIntroducerPublisherAndSubscriberService_v2
from allmydata.introducer.common import unsign_from_foolscap, make_index, \
from allmydata.introducer.common import unsign_from_foolscap, \
SubscriberDescriptor, AnnouncementDescriptor
class FurlFileConflictError(Exception):
@ -162,10 +162,9 @@ class IntroducerService(service.MultiService, Referenceable):
self.log("introducer: announcement published: %s" % (ann_t,),
umid="wKHgCw")
ann, key = unsign_from_foolscap(ann_t) # might raise BadSignatureError
index = make_index(ann, key)
service_name = str(ann["service-name"])
index = (service_name, key)
old = self._announcements.get(index)
if old:
(old_ann_t, canary, old_ann, timestamp) = old

View File

@ -711,7 +711,7 @@ class Announcements(unittest.TestCase):
a = introducer.get_announcements()
self.failUnlessEqual(len(a), 1)
self.failUnlessIdentical(a[0].canary, canary0)
self.failUnlessEqual(a[0].index, ("storage", pks, None))
self.failUnlessEqual(a[0].index, ("storage", pks))
self.failUnlessEqual(a[0].announcement["app-versions"], app_versions)
self.failUnlessEqual(a[0].nickname, u"nick-v2")
self.failUnlessEqual(a[0].service_name, "storage")