def test_id_collision(self): # test replacement case where tubid equals a keyid (one should # not replace the other) ic = IntroducerClient(None, "introducer.furl", u"my_nickname", "my_version", "oldest_version", {}) announcements = [] ic.subscribe_to("storage", lambda key_s, ann: announcements.append(ann)) sk_s, vk_s = keyutil.make_keypair() sk, _ignored = keyutil.parse_privkey(sk_s) keyid = keyutil.remove_prefix(vk_s, "pub-v0-") furl1 = "pb://[email protected]:123/short" # base32("short") furl2 = "pb://%[email protected]:36106/swissnum" % keyid ann_t = ic.create_announcement("storage", make_ann(furl1), sk) ic.remote_announce_v2([ann_t]) d = fireEventually() def _then(ign): # first announcement has been processed self.failUnlessEqual(len(announcements), 1) self.failUnlessEqual(announcements[0]["anonymous-storage-FURL"], furl1) # now submit a second one, with a tubid that happens to look just # like the pubkey-based serverid we just processed. They should # not overlap. ann2 = (furl2, "storage", "RIStorage", "nick1", "ver23", "ver0") ca = WrapV2ClientInV1Interface(ic) ca.remote_announce([ann2]) return fireEventually() d.addCallback(_then) def _then2(ign): # if they overlapped, the second announcement would be ignored self.failUnlessEqual(len(announcements), 2) self.failUnlessEqual(announcements[1]["anonymous-storage-FURL"], furl2) d.addCallback(_then2) return d
def test_id_collision(self): # test replacement case where tubid equals a keyid (one should # not replace the other) ic = IntroducerClient(None, "introducer.furl", u"my_nickname", "my_version", "oldest_version", {}) announcements = [] ic.subscribe_to("storage", lambda key_s,ann: announcements.append(ann)) sk_s, vk_s = keyutil.make_keypair() sk, _ignored = keyutil.parse_privkey(sk_s) keyid = keyutil.remove_prefix(vk_s, "pub-v0-") furl1 = "pb://[email protected]:123/short" # base32("short") furl2 = "pb://%[email protected]:36106/swissnum" % keyid ann_t = ic.create_announcement("storage", make_ann(furl1), sk) ic.remote_announce_v2([ann_t]) d = fireEventually() def _then(ign): # first announcement has been processed self.failUnlessEqual(len(announcements), 1) self.failUnlessEqual(announcements[0]["anonymous-storage-FURL"], furl1) # now submit a second one, with a tubid that happens to look just # like the pubkey-based serverid we just processed. They should # not overlap. ann2 = (furl2, "storage", "RIStorage", "nick1", "ver23", "ver0") ca = WrapV2ClientInV1Interface(ic) ca.remote_announce([ann2]) return fireEventually() d.addCallback(_then) def _then2(ign): # if they overlapped, the second announcement would be ignored self.failUnlessEqual(len(announcements), 2) self.failUnlessEqual(announcements[1]["anonymous-storage-FURL"], furl2) d.addCallback(_then2) return d
def test_duplicate_receive_v2(self): ic1 = IntroducerClient(None, "introducer.furl", u"my_nickname", "ver23", "oldest_version", {}, fakeseq, FilePath(self.mktemp())) # we use a second client just to create a different-looking # announcement ic2 = IntroducerClient(None, "introducer.furl", u"my_nickname", "ver24","oldest_version",{}, fakeseq, FilePath(self.mktemp())) announcements = [] def _received(key_s, ann): announcements.append( (key_s, ann) ) ic1.subscribe_to("storage", _received) furl1 = "pb://[email protected]:36106/gydnp" furl1a = "pb://[email protected]:7777/gydnp" furl2 = "pb://[email protected]:36106/ttwwoo" privkey_s, pubkey_vs = keyutil.make_keypair() privkey, _ignored = keyutil.parse_privkey(privkey_s) pubkey_s = keyutil.remove_prefix(pubkey_vs, "pub-") # ann1: ic1, furl1 # ann1a: ic1, furl1a (same SturdyRef, different connection hints) # ann1b: ic2, furl1 # ann2: ic2, furl2 self.ann1 = make_ann_t(ic1, furl1, privkey, seqnum=10) self.ann1old = make_ann_t(ic1, furl1, privkey, seqnum=9) self.ann1noseqnum = make_ann_t(ic1, furl1, privkey, seqnum=None) self.ann1b = make_ann_t(ic2, furl1, privkey, seqnum=11) self.ann1a = make_ann_t(ic1, furl1a, privkey, seqnum=12) self.ann2 = make_ann_t(ic2, furl2, privkey, seqnum=13) ic1.remote_announce_v2([self.ann1]) # queues eventual-send d = fireEventually() def _then1(ign): self.failUnlessEqual(len(announcements), 1) key_s,ann = announcements[0] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then1) # now send a duplicate announcement. This should not fire the # subscriber d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1])) d.addCallback(fireEventually) def _then2(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2) # an older announcement shouldn't fire the subscriber either d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1old])) d.addCallback(fireEventually) def _then2a(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2a) # announcement with no seqnum cannot replace one with-seqnum d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1noseqnum])) d.addCallback(fireEventually) def _then2b(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2b) # and a replacement announcement: same FURL, new other stuff. The # subscriber *should* be fired. d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1b])) d.addCallback(fireEventually) def _then3(ign): self.failUnlessEqual(len(announcements), 2) key_s,ann = announcements[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1) self.failUnlessEqual(ann["my-version"], "ver24") d.addCallback(_then3) # and a replacement announcement with a different FURL (it uses # different connection hints) d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1a])) d.addCallback(fireEventually) def _then4(ign): self.failUnlessEqual(len(announcements), 3) key_s,ann = announcements[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1a) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then4) # now add a new subscription, which should be called with the # backlog. The introducer only records one announcement per index, so # the backlog will only have the latest message. announcements2 = [] def _received2(key_s, ann): announcements2.append( (key_s, ann) ) d.addCallback(lambda ign: ic1.subscribe_to("storage", _received2)) d.addCallback(fireEventually) def _then5(ign): self.failUnlessEqual(len(announcements2), 1) key_s,ann = announcements2[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1a) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then5) return d
def test_duplicate_receive_v2(self): ic1 = IntroducerClient(None, "introducer.furl", u"my_nickname", "ver23", "oldest_version", {}, fakeseq, FilePath(self.mktemp())) # we use a second client just to create a different-looking # announcement ic2 = IntroducerClient(None, "introducer.furl", u"my_nickname", "ver24", "oldest_version", {}, fakeseq, FilePath(self.mktemp())) announcements = [] def _received(key_s, ann): announcements.append((key_s, ann)) ic1.subscribe_to("storage", _received) furl1 = "pb://[email protected]:36106/gydnp" furl1a = "pb://[email protected]:7777/gydnp" furl2 = "pb://[email protected]:36106/ttwwoo" privkey_s, pubkey_vs = keyutil.make_keypair() privkey, _ignored = keyutil.parse_privkey(privkey_s) pubkey_s = keyutil.remove_prefix(pubkey_vs, "pub-") # ann1: ic1, furl1 # ann1a: ic1, furl1a (same SturdyRef, different connection hints) # ann1b: ic2, furl1 # ann2: ic2, furl2 self.ann1 = make_ann_t(ic1, furl1, privkey, seqnum=10) self.ann1old = make_ann_t(ic1, furl1, privkey, seqnum=9) self.ann1noseqnum = make_ann_t(ic1, furl1, privkey, seqnum=None) self.ann1b = make_ann_t(ic2, furl1, privkey, seqnum=11) self.ann1a = make_ann_t(ic1, furl1a, privkey, seqnum=12) self.ann2 = make_ann_t(ic2, furl2, privkey, seqnum=13) ic1.remote_announce_v2([self.ann1]) # queues eventual-send d = fireEventually() def _then1(ign): self.failUnlessEqual(len(announcements), 1) key_s, ann = announcements[0] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then1) # now send a duplicate announcement. This should not fire the # subscriber d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1])) d.addCallback(fireEventually) def _then2(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2) # an older announcement shouldn't fire the subscriber either d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1old])) d.addCallback(fireEventually) def _then2a(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2a) # announcement with no seqnum cannot replace one with-seqnum d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1noseqnum])) d.addCallback(fireEventually) def _then2b(ign): self.failUnlessEqual(len(announcements), 1) d.addCallback(_then2b) # and a replacement announcement: same FURL, new other stuff. The # subscriber *should* be fired. d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1b])) d.addCallback(fireEventually) def _then3(ign): self.failUnlessEqual(len(announcements), 2) key_s, ann = announcements[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1) self.failUnlessEqual(ann["my-version"], "ver24") d.addCallback(_then3) # and a replacement announcement with a different FURL (it uses # different connection hints) d.addCallback(lambda ign: ic1.remote_announce_v2([self.ann1a])) d.addCallback(fireEventually) def _then4(ign): self.failUnlessEqual(len(announcements), 3) key_s, ann = announcements[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1a) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then4) # now add a new subscription, which should be called with the # backlog. The introducer only records one announcement per index, so # the backlog will only have the latest message. announcements2 = [] def _received2(key_s, ann): announcements2.append((key_s, ann)) d.addCallback(lambda ign: ic1.subscribe_to("storage", _received2)) d.addCallback(fireEventually) def _then5(ign): self.failUnlessEqual(len(announcements2), 1) key_s, ann = announcements2[-1] self.failUnlessEqual(key_s, pubkey_s) self.failUnlessEqual(ann["anonymous-storage-FURL"], furl1a) self.failUnlessEqual(ann["my-version"], "ver23") d.addCallback(_then5) return d