Esempio n. 1
0
 def setUp(self):
     self.node = None
     self.port_assigner = SameProcessStreamEndpointAssigner()
     self.port_assigner.setUp()
     self.addCleanup(self.port_assigner.tearDown)
     # Anything using Foolscap leaves some timer trash in the reactor that
     # we have to arrange to have cleaned up.
     self.addCleanup(lambda: flushEventualQueue(None))
Esempio n. 2
0
def flush_but_dont_ignore(res):
    d = flushEventualQueue()

    def _done(ignored):
        return res

    d.addCallback(_done)
    return d
Esempio n. 3
0
def flush_but_dont_ignore(res):
    d = flushEventualQueue()

    def _done(ignored):
        return res

    d.addCallback(_done)
    return d
Esempio n. 4
0
 def tearDown(self, passthrough):
     # the client node will shut down in a few seconds
     #os.remove(os.path.join(self.clientdir, "suicide_prevention_hotline"))
     log.msg("shutting down SystemTest services")
     if self.keepalive_file and os.path.exists(self.keepalive_file):
         age = time.time() - os.stat(self.keepalive_file)[stat.ST_MTIME]
         log.msg("keepalive file at shutdown was %ds old" % age)
     d = defer.succeed(None)
     if self.proc:
         d.addCallback(lambda res: self.kill_client())
     d.addCallback(lambda res: self.sparent.stopService())
     d.addCallback(lambda res: flushEventualQueue())
     def _close_statsfile(res):
         self.statsfile.close()
     d.addCallback(_close_statsfile)
     d.addCallback(lambda res: passthrough)
     return d
Esempio n. 5
0
 def tearDown(self, passthrough):
     # the client node will shut down in a few seconds
     #os.remove(os.path.join(self.clientdir, client.Client.EXIT_TRIGGER_FILE))
     log.msg("shutting down SystemTest services")
     if self.keepalive_file and os.path.exists(self.keepalive_file):
         age = time.time() - os.stat(self.keepalive_file)[stat.ST_MTIME]
         log.msg("keepalive file at shutdown was %ds old" % age)
     d = defer.succeed(None)
     if self.proc:
         d.addCallback(lambda res: self.kill_client())
     d.addCallback(lambda res: self.sparent.stopService())
     d.addCallback(lambda res: flushEventualQueue())
     def _close_statsfile(res):
         self.statsfile.close()
     d.addCallback(_close_statsfile)
     d.addCallback(lambda res: passthrough)
     return d
    def test_client_cache(self):
        basedir = "introducer/ClientSeqnums/test_client_cache_1"
        fileutil.make_dirs(basedir)
        cache_filepath = FilePath(os.path.join(basedir, "private",
                                               "introducer_default_cache.yaml"))

        # if storage is enabled, the Client will publish its storage server
        # during startup (although the announcement will wait in a queue
        # until the introducer connection is established). To avoid getting
        # confused by this, disable storage.
        f = open(os.path.join(basedir, "tahoe.cfg"), "w")
        f.write("[client]\n")
        f.write("introducer.furl = nope\n")
        f.write("[storage]\n")
        f.write("enabled = false\n")
        f.close()

        c = TahoeClient(basedir)
        ic = c.introducer_clients[0]
        sk_s, vk_s = keyutil.make_keypair()
        sk, _ignored = keyutil.parse_privkey(sk_s)
        pub1 = keyutil.remove_prefix(vk_s, "pub-")
        furl1 = "pb://[email protected]:123/short" # base32("short")
        ann_t = make_ann_t(ic, furl1, sk, 1)

        ic.got_announcements([ann_t])
        yield flushEventualQueue()

        # check the cache for the announcement
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(announcements[0]['key_s'], pub1)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1)
        self.failUnlessEqual(ann["seqnum"], 1)

        # a new announcement that replaces the first should replace the
        # cached entry, not duplicate it
        furl2 = furl1 + "er"
        ann_t2 = make_ann_t(ic, furl2, sk, 2)
        ic.got_announcements([ann_t2])
        yield flushEventualQueue()
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(announcements[0]['key_s'], pub1)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ann["anonymous-storage-FURL"], furl2)
        self.failUnlessEqual(ann["seqnum"], 2)

        # but a third announcement with a different key should add to the
        # cache
        sk_s2, vk_s2 = keyutil.make_keypair()
        sk2, _ignored = keyutil.parse_privkey(sk_s2)
        pub2 = keyutil.remove_prefix(vk_s2, "pub-")
        furl3 = "pb://[email protected]:456/short"
        ann_t3 = make_ann_t(ic, furl3, sk2, 1)
        ic.got_announcements([ann_t3])
        yield flushEventualQueue()

        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 2)
        self.failUnlessEqual(set([pub1, pub2]),
                             set([a["key_s"] for a in announcements]))
        self.failUnlessEqual(set([furl2, furl3]),
                             set([a["ann"]["anonymous-storage-FURL"]
                                  for a in announcements]))

        # test loading
        yield flushEventualQueue()
        ic2 = IntroducerClient(None, "introducer.furl", u"my_nickname",
                               "my_version", "oldest_version", {}, fakeseq,
                               ic._cache_filepath)
        announcements = {}
        def got(key_s, ann):
            announcements[key_s] = ann
        ic2.subscribe_to("storage", got)
        ic2._load_announcements() # normally happens when connection fails
        yield flushEventualQueue()

        self.failUnless(pub1 in announcements)
        self.failUnlessEqual(announcements[pub1]["anonymous-storage-FURL"],
                             furl2)
        self.failUnlessEqual(announcements[pub2]["anonymous-storage-FURL"],
                             furl3)

        c2 = TahoeClient(basedir)
        c2.introducer_clients[0]._load_announcements()
        yield flushEventualQueue()
        self.assertEqual(c2.storage_broker.get_all_serverids(),
                         frozenset([pub1, pub2]))
Esempio n. 7
0
    def test_client_cache(self):
        basedir = "introducer/ClientSeqnums/test_client_cache_1"
        fileutil.make_dirs(basedir)
        cache_filepath = FilePath(
            os.path.join(basedir, "private", "introducer_default_cache.yaml"))

        # if storage is enabled, the Client will publish its storage server
        # during startup (although the announcement will wait in a queue
        # until the introducer connection is established). To avoid getting
        # confused by this, disable storage.
        f = open(os.path.join(basedir, "tahoe.cfg"), "w")
        f.write("[client]\n")
        f.write("introducer.furl = nope\n")
        f.write("[storage]\n")
        f.write("enabled = false\n")
        f.close()

        c = create_client(basedir)
        ic = c.introducer_clients[0]
        sk_s, vk_s = keyutil.make_keypair()
        sk, _ignored = keyutil.parse_privkey(sk_s)
        pub1 = keyutil.remove_prefix(vk_s, "pub-")
        furl1 = "pb://[email protected]:123/short"  # base32("short")
        ann_t = make_ann_t(ic, furl1, sk, 1)

        ic.got_announcements([ann_t])
        yield flushEventualQueue()

        # check the cache for the announcement
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(announcements[0]['key_s'], pub1)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1)
        self.failUnlessEqual(ann["seqnum"], 1)

        # a new announcement that replaces the first should replace the
        # cached entry, not duplicate it
        furl2 = furl1 + "er"
        ann_t2 = make_ann_t(ic, furl2, sk, 2)
        ic.got_announcements([ann_t2])
        yield flushEventualQueue()
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(announcements[0]['key_s'], pub1)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ann["anonymous-storage-FURL"], furl2)
        self.failUnlessEqual(ann["seqnum"], 2)

        # but a third announcement with a different key should add to the
        # cache
        sk_s2, vk_s2 = keyutil.make_keypair()
        sk2, _ignored = keyutil.parse_privkey(sk_s2)
        pub2 = keyutil.remove_prefix(vk_s2, "pub-")
        furl3 = "pb://[email protected]:456/short"
        ann_t3 = make_ann_t(ic, furl3, sk2, 1)
        ic.got_announcements([ann_t3])
        yield flushEventualQueue()

        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 2)
        self.failUnlessEqual(set([pub1, pub2]),
                             set([a["key_s"] for a in announcements]))
        self.failUnlessEqual(
            set([furl2, furl3]),
            set([a["ann"]["anonymous-storage-FURL"] for a in announcements]))

        # test loading
        yield flushEventualQueue()
        ic2 = IntroducerClient(None, "introducer.furl", u"my_nickname",
                               "my_version", "oldest_version", {}, fakeseq,
                               ic._cache_filepath)
        announcements = {}

        def got(key_s, ann):
            announcements[key_s] = ann

        ic2.subscribe_to("storage", got)
        ic2._load_announcements()  # normally happens when connection fails
        yield flushEventualQueue()

        self.failUnless(pub1 in announcements)
        self.failUnlessEqual(announcements[pub1]["anonymous-storage-FURL"],
                             furl2)
        self.failUnlessEqual(announcements[pub2]["anonymous-storage-FURL"],
                             furl3)

        c2 = create_client(basedir)
        c2.introducer_clients[0]._load_announcements()
        yield flushEventualQueue()
        self.assertEqual(c2.storage_broker.get_all_serverids(),
                         frozenset([pub1, pub2]))
Esempio n. 8
0
 def _tearDown_1(self, res):
     return flushEventualQueue()
Esempio n. 9
0
    def test_client_cache(self):
        """
        Announcements received by an introducer client are written to that
        introducer client's cache file.
        """
        basedir = FilePath("introducer/ClientSeqnums/test_client_cache_1")
        private = basedir.child("private")
        private.makedirs()
        write_introducer(basedir, "default", "nope")
        cache_filepath = basedir.descendant([
            "private",
            "introducer_default_cache.yaml",
        ])

        # if storage is enabled, the Client will publish its storage server
        # during startup (although the announcement will wait in a queue
        # until the introducer connection is established). To avoid getting
        # confused by this, disable storage.
        with basedir.child("tahoe.cfg").open("w") as f:
            f.write(b"[storage]\n")
            f.write(b"enabled = false\n")

        c = yield create_client(basedir.path)
        ic = c.introducer_clients[0]
        private_key, public_key = ed25519.create_signing_keypair()
        public_key_str = remove_prefix(
            ed25519.string_from_verifying_key(public_key), b"pub-")
        furl1 = b"pb://[email protected]:123/short"  # base32("short")
        ann_t = make_ann_t(ic, furl1, private_key, 1)

        ic.got_announcements([ann_t])
        yield flushEventualQueue()

        # check the cache for the announcement
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(ensure_binary(announcements[0]['key_s']),
                             public_key_str)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ensure_binary(ann["anonymous-storage-FURL"]),
                             furl1)
        self.failUnlessEqual(ann["seqnum"], 1)

        # a new announcement that replaces the first should replace the
        # cached entry, not duplicate it
        furl2 = furl1 + b"er"
        ann_t2 = make_ann_t(ic, furl2, private_key, 2)
        ic.got_announcements([ann_t2])
        yield flushEventualQueue()
        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 1)
        self.failUnlessEqual(ensure_binary(announcements[0]['key_s']),
                             public_key_str)
        ann = announcements[0]["ann"]
        self.failUnlessEqual(ensure_binary(ann["anonymous-storage-FURL"]),
                             furl2)
        self.failUnlessEqual(ann["seqnum"], 2)

        # but a third announcement with a different key should add to the
        # cache
        private_key2, public_key2 = ed25519.create_signing_keypair()
        public_key_str2 = remove_prefix(
            ed25519.string_from_verifying_key(public_key2), b"pub-")
        furl3 = b"pb://[email protected]:456/short"
        ann_t3 = make_ann_t(ic, furl3, private_key2, 1)
        ic.got_announcements([ann_t3])
        yield flushEventualQueue()

        announcements = self._load_cache(cache_filepath)
        self.failUnlessEqual(len(announcements), 2)
        self.failUnlessEqual(
            set([public_key_str, public_key_str2]),
            set([ensure_binary(a["key_s"]) for a in announcements]))
        self.failUnlessEqual(
            set([furl2, furl3]),
            set([
                ensure_binary(a["ann"]["anonymous-storage-FURL"])
                for a in announcements
            ]))

        # test loading
        yield flushEventualQueue()
        ic2 = IntroducerClient(None, "introducer.furl", u"my_nickname",
                               "my_version", "oldest_version", fakeseq,
                               ic._cache_filepath)
        announcements = {}

        def got(key_s, ann):
            announcements[key_s] = ann

        ic2.subscribe_to("storage", got)
        ic2._load_announcements()  # normally happens when connection fails
        yield flushEventualQueue()

        self.failUnless(public_key_str in announcements)
        self.failUnlessEqual(
            ensure_binary(
                announcements[public_key_str]["anonymous-storage-FURL"]),
            furl2)
        self.failUnlessEqual(
            ensure_binary(
                announcements[public_key_str2]["anonymous-storage-FURL"]),
            furl3)

        c2 = yield create_client(basedir.path)
        c2.introducer_clients[0]._load_announcements()
        yield flushEventualQueue()
        self.assertEqual(c2.storage_broker.get_all_serverids(),
                         frozenset([public_key_str, public_key_str2]))
Esempio n. 10
0
 def _tearDown_1(self, res):
     self.failIf(pb.Listeners)
     return flushEventualQueue()
Esempio n. 11
0
 def _tearDown_1(self, res):
     return flushEventualQueue()
Esempio n. 12
0
 def _tearDown_1(self, res):
     self.failIf(pb.Listeners)
     return flushEventualQueue()