コード例 #1
0
ファイル: server.py プロジェクト: joepie91/tahoe-lafs
    def _attach_stub_client(self, ann, lp):
        # There might be a v1 subscriber for whom this is a stub_client.
        # We might have received the subscription before the stub_client
        # announcement, in which case we now need to fix up the record in
        # self._subscriptions .

        # record it for later, in case the stub_client arrived before the
        # subscription
        subscriber_info = self._get_subscriber_info_from_ann(ann)
        ann_tubid = get_tubid_string_from_ann(ann)
        self._stub_client_announcements[ann_tubid] = subscriber_info

        lp2 = self.log("stub_client announcement, "
                       "looking for matching subscriber",
                       parent=lp, level=log.NOISY, umid="BTywDg")

        for sn in self._subscribers:
            s = self._subscribers[sn]
            for (subscriber, info) in s.items():
                # we correlate these by looking for a subscriber whose tubid
                # matches this announcement
                sub_tubid = subscriber.getRemoteTubID()
                if sub_tubid == ann_tubid:
                    self.log(format="found a match, nodeid=%(nodeid)s",
                             nodeid=sub_tubid,
                             level=log.NOISY, parent=lp2, umid="xsWs1A")
                    # found a match. Does it need info?
                    if not info[0]:
                        self.log(format="replacing info",
                                 level=log.NOISY, parent=lp2, umid="m5kxwA")
                        # yup
                        s[subscriber] = (subscriber_info, info[1])
コード例 #2
0
ファイル: client.py プロジェクト: joepie91/tahoe-lafs
    def _process_announcement(self, ann, key_s):
        self._debug_counts["inbound_announcement"] += 1
        service_name = str(ann["service-name"])
        if service_name not in self._subscribed_service_names:
            self.log("announcement for a service we don't care about [%s]"
                     % (service_name,), level=log.UNUSUAL, umid="dIpGNA")
            self._debug_counts["wrong_service"] += 1
            return
        # for ASCII values, simplejson might give us unicode *or* bytes
        if "nickname" in ann and isinstance(ann["nickname"], str):
            ann["nickname"] = unicode(ann["nickname"])
        nick_s = ann.get("nickname",u"").encode("utf-8")
        lp2 = self.log(format="announcement for nickname '%(nick)s', service=%(svc)s: %(ann)s",
                       nick=nick_s, svc=service_name, ann=ann, umid="BoKEag")

        # how do we describe this node in the logs?
        desc_bits = []
        if key_s:
            desc_bits.append("serverid=" + key_s[:20])
        if "anonymous-storage-FURL" in ann:
            tubid_s = get_tubid_string_from_ann(ann)
            desc_bits.append("tubid=" + tubid_s[:8])
        description = "/".join(desc_bits)

        # the index is used to track duplicates
        index = make_index(ann, key_s)

        # is this announcement a duplicate?
        if (index in self._current_announcements
            and self._current_announcements[index][0] == ann):
            self.log(format="reannouncement for [%(service)s]:%(description)s, ignoring",
                     service=service_name, description=description,
                     parent=lp2, level=log.UNUSUAL, umid="B1MIdA")
            self._debug_counts["duplicate_announcement"] += 1
            return
        # does it update an existing one?
        if index in self._current_announcements:
            self._debug_counts["update"] += 1
            self.log("replacing old announcement: %s" % (ann,),
                     parent=lp2, level=log.NOISY, umid="wxwgIQ")
        else:
            self._debug_counts["new_announcement"] += 1
            self.log("new announcement[%s]" % service_name,
                     parent=lp2, level=log.NOISY)

        self._current_announcements[index] = (ann, key_s, time.time())
        # note: we never forget an index, but we might update its value

        for (service_name2,cb,args,kwargs) in self._local_subscribers:
            if service_name2 == service_name:
                eventually(cb, key_s, ann, *args, **kwargs)
コード例 #3
0
ファイル: server.py プロジェクト: antagonismorg/tahoe-lafs
    def _attach_stub_client(self, ann, lp):
        # There might be a v1 subscriber for whom this is a stub_client.
        # We might have received the subscription before the stub_client
        # announcement, in which case we now need to fix up the record in
        # self._subscriptions .

        # record it for later, in case the stub_client arrived before the
        # subscription
        subscriber_info = self._get_subscriber_info_from_ann(ann)
        ann_tubid = get_tubid_string_from_ann(ann)
        self._stub_client_announcements[ann_tubid] = subscriber_info

        lp2 = self.log(
            "stub_client announcement, "
            "looking for matching subscriber",
            parent=lp,
            level=log.NOISY,
            umid="BTywDg")

        for sn in self._subscribers:
            s = self._subscribers[sn]
            for (subscriber, info) in s.items():
                # we correlate these by looking for a subscriber whose tubid
                # matches this announcement
                sub_tubid = subscriber.getRemoteTubID()
                if sub_tubid == ann_tubid:
                    self.log(format="found a match, nodeid=%(nodeid)s",
                             nodeid=sub_tubid,
                             level=log.NOISY,
                             parent=lp2,
                             umid="xsWs1A")
                    # found a match. Does it need info?
                    if not info[0]:
                        self.log(format="replacing info",
                                 level=log.NOISY,
                                 parent=lp2,
                                 umid="m5kxwA")
                        # yup
                        s[subscriber] = (subscriber_info, info[1])
コード例 #4
0
ファイル: client.py プロジェクト: gvsurenderreddy/tahoe-lafs
    def _process_announcement(self, ann, key_s):
        self._debug_counts["inbound_announcement"] += 1
        service_name = str(ann["service-name"])
        if service_name not in self._subscribed_service_names:
            self.log("announcement for a service we don't care about [%s]"
                     % (service_name,), level=log.UNUSUAL, umid="dIpGNA")
            self._debug_counts["wrong_service"] += 1
            return
        # for ASCII values, simplejson might give us unicode *or* bytes
        if "nickname" in ann and isinstance(ann["nickname"], str):
            ann["nickname"] = unicode(ann["nickname"])
        nick_s = ann.get("nickname",u"").encode("utf-8")
        lp2 = self.log(format="announcement for nickname '%(nick)s', service=%(svc)s: %(ann)s",
                       nick=nick_s, svc=service_name, ann=ann, umid="BoKEag")

        # how do we describe this node in the logs?
        desc_bits = []
        assert key_s
        desc_bits.append("serverid=" + key_s[:20])
        if "anonymous-storage-FURL" in ann:
            tubid_s = get_tubid_string_from_ann(ann)
            desc_bits.append("tubid=" + tubid_s[:8])
        description = "/".join(desc_bits)

        # the index is used to track duplicates
        index = (service_name, key_s)

        # is this announcement a duplicate?
        if (index in self._inbound_announcements
            and self._inbound_announcements[index][0] == ann):
            self.log(format="reannouncement for [%(service)s]:%(description)s, ignoring",
                     service=service_name, description=description,
                     parent=lp2, level=log.UNUSUAL, umid="B1MIdA")
            self._debug_counts["duplicate_announcement"] += 1
            return

        # does it update an existing one?
        if index in self._inbound_announcements:
            old,_,_ = self._inbound_announcements[index]
            if "seqnum" in old:
                # must beat previous sequence number to replace
                if ("seqnum" not in ann
                    or not isinstance(ann["seqnum"], (int,long))):
                    self.log("not replacing old announcement, no valid seqnum: %s"
                             % (ann,),
                             parent=lp2, level=log.NOISY, umid="zFGH3Q")
                    return
                if ann["seqnum"] <= old["seqnum"]:
                    # note that exact replays are caught earlier, by
                    # comparing the entire signed announcement.
                    self.log("not replacing old announcement, "
                             "new seqnum is too old (%s <= %s) "
                             "(replay attack?): %s"
                             % (ann["seqnum"], old["seqnum"], ann),
                             parent=lp2, level=log.UNUSUAL, umid="JAAAoQ")
                    return
                # ok, seqnum is newer, allow replacement
            self._debug_counts["update"] += 1
            self.log("replacing old announcement: %s" % (ann,),
                     parent=lp2, level=log.NOISY, umid="wxwgIQ")
        else:
            self._debug_counts["new_announcement"] += 1
            self.log("new announcement[%s]" % service_name,
                     parent=lp2, level=log.NOISY)

        self._inbound_announcements[index] = (ann, key_s, time.time())
        self._save_announcements()
        # note: we never forget an index, but we might update its value

        self._deliver_announcements(key_s, ann)
コード例 #5
0
 def got(key_s_or_tubid, ann, announcements):
     index = key_s_or_tubid or get_tubid_string_from_ann(ann)
     announcements[index] = ann
コード例 #6
0
ファイル: test_introducer.py プロジェクト: stlee42/tahoe-lafs
 def got(key_s_or_tubid, ann, announcements):
     index = key_s_or_tubid or get_tubid_string_from_ann(ann)
     announcements[index] = ann
コード例 #7
0
 def got(key_s_or_tubid, ann, announcements, i):
     if i == 0:
         index = get_tubid_string_from_ann(ann)
     else:
         index = key_s_or_tubid or get_tubid_string_from_ann(ann)
     announcements[index] = ann
コード例 #8
0
    def _process_announcement(self, ann, key_s):
        precondition(isinstance(key_s, bytes), key_s)
        self._debug_counts["inbound_announcement"] += 1
        service_name = str(ann["service-name"])
        if service_name not in self._subscribed_service_names:
            self.log("announcement for a service we don't care about [%s]" %
                     (service_name, ),
                     level=log.UNUSUAL,
                     umid="dIpGNA")
            self._debug_counts["wrong_service"] += 1
            return
        # for ASCII values, simplejson might give us unicode *or* bytes
        if "nickname" in ann and isinstance(ann["nickname"], bytes):
            ann["nickname"] = unicode(ann["nickname"])
        nick_s = ann.get("nickname", u"").encode("utf-8")
        lp2 = self.log(
            format=
            "announcement for nickname '%(nick)s', service=%(svc)s: %(ann)s",
            nick=nick_s,
            svc=service_name,
            ann=ann,
            umid="BoKEag")

        # how do we describe this node in the logs?
        desc_bits = []
        assert key_s
        desc_bits.append(b"serverid=" + key_s[:20])
        if "anonymous-storage-FURL" in ann:
            tubid_s = get_tubid_string_from_ann(ann)
            desc_bits.append(b"tubid=" + tubid_s[:8])
        description = b"/".join(desc_bits)

        # the index is used to track duplicates
        index = (service_name, key_s)

        # is this announcement a duplicate?
        if (index in self._inbound_announcements
                and self._inbound_announcements[index][0] == ann):
            self.log(
                format=
                "reannouncement for [%(service)s]:%(description)s, ignoring",
                service=service_name,
                description=description,
                parent=lp2,
                level=log.UNUSUAL,
                umid="B1MIdA")
            self._debug_counts["duplicate_announcement"] += 1
            return

        # does it update an existing one?
        if index in self._inbound_announcements:
            old, _, _ = self._inbound_announcements[index]
            if "seqnum" in old:
                # must beat previous sequence number to replace
                if ("seqnum" not in ann
                        or not isinstance(ann["seqnum"], (int, long))):
                    self.log(
                        "not replacing old announcement, no valid seqnum: %s" %
                        (ann, ),
                        parent=lp2,
                        level=log.NOISY,
                        umid="zFGH3Q")
                    return
                if ann["seqnum"] <= old["seqnum"]:
                    # note that exact replays are caught earlier, by
                    # comparing the entire signed announcement.
                    self.log("not replacing old announcement, "
                             "new seqnum is too old (%s <= %s) "
                             "(replay attack?): %s" %
                             (ann["seqnum"], old["seqnum"], ann),
                             parent=lp2,
                             level=log.UNUSUAL,
                             umid="JAAAoQ")
                    return
                # ok, seqnum is newer, allow replacement
            self._debug_counts["update"] += 1
            self.log("replacing old announcement: %s" % (ann, ),
                     parent=lp2,
                     level=log.NOISY,
                     umid="wxwgIQ")
        else:
            self._debug_counts["new_announcement"] += 1
            self.log("new announcement[%s]" % service_name,
                     parent=lp2,
                     level=log.NOISY)

        self._inbound_announcements[index] = (ann, key_s, time.time())
        self._save_announcements()
        # note: we never forget an index, but we might update its value

        self._deliver_announcements(key_s, ann)
コード例 #9
0
ファイル: client.py プロジェクト: antagonismorg/tahoe-lafs
    def _process_announcement(self, ann, key_s):
        self._debug_counts["inbound_announcement"] += 1
        service_name = str(ann["service-name"])
        if service_name not in self._subscribed_service_names:
            self.log("announcement for a service we don't care about [%s]" %
                     (service_name, ),
                     level=log.UNUSUAL,
                     umid="dIpGNA")
            self._debug_counts["wrong_service"] += 1
            return
        # for ASCII values, simplejson might give us unicode *or* bytes
        if "nickname" in ann and isinstance(ann["nickname"], str):
            ann["nickname"] = unicode(ann["nickname"])
        nick_s = ann.get("nickname", u"").encode("utf-8")
        lp2 = self.log(
            format=
            "announcement for nickname '%(nick)s', service=%(svc)s: %(ann)s",
            nick=nick_s,
            svc=service_name,
            ann=ann,
            umid="BoKEag")

        # how do we describe this node in the logs?
        desc_bits = []
        if key_s:
            desc_bits.append("serverid=" + key_s[:20])
        if "anonymous-storage-FURL" in ann:
            tubid_s = get_tubid_string_from_ann(ann)
            desc_bits.append("tubid=" + tubid_s[:8])
        description = "/".join(desc_bits)

        # the index is used to track duplicates
        index = make_index(ann, key_s)

        # is this announcement a duplicate?
        if (index in self._current_announcements
                and self._current_announcements[index][0] == ann):
            self.log(
                format=
                "reannouncement for [%(service)s]:%(description)s, ignoring",
                service=service_name,
                description=description,
                parent=lp2,
                level=log.UNUSUAL,
                umid="B1MIdA")
            self._debug_counts["duplicate_announcement"] += 1
            return
        # does it update an existing one?
        if index in self._current_announcements:
            self._debug_counts["update"] += 1
            self.log("replacing old announcement: %s" % (ann, ),
                     parent=lp2,
                     level=log.NOISY,
                     umid="wxwgIQ")
        else:
            self._debug_counts["new_announcement"] += 1
            self.log("new announcement[%s]" % service_name,
                     parent=lp2,
                     level=log.NOISY)

        self._current_announcements[index] = (ann, key_s, time.time())
        # note: we never forget an index, but we might update its value

        for (service_name2, cb, args, kwargs) in self._local_subscribers:
            if service_name2 == service_name:
                eventually(cb, key_s, ann, *args, **kwargs)
コード例 #10
0
 def got(key_s_or_tubid, ann, announcements, i):
     if i == 0:
         index = get_tubid_string_from_ann(ann)
     else:
         index = key_s_or_tubid or get_tubid_string_from_ann(ann)
     announcements[index] = ann