Ticket #151: 151-accept-i2p-destinations.patch
File 151-accept-i2p-destinations.patch, 3.5 KB (added by , 11 years ago) |
---|
-
foolscap/referenceable.py
From cd437e60418e43a6dc4fad32da68c536d1469d5b Mon Sep 17 00:00:00 2001 From: Kill Your TV <killyourtv@i2pmail.org> Date: Wed, 7 Aug 2013 16:37:08 +0000 Subject: [PATCH] accept i2p destinations --- foolscap/referenceable.py | 12 +++++++++++- foolscap/test/test_reference.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/foolscap/referenceable.py b/foolscap/referenceable.py index c1cc63b..dd7574c 100644
a b def decode_location_hints(hints_s): 782 782 hints = [] 783 783 if hints_s: 784 784 for hint_s in hints_s.split(","): 785 if ":" not in hint_s: 785 if ( 786 ":" not in hint_s and not hint_s.endswith(".i2p") 787 and not hint_s.startswith("i2p:") 788 ): 786 789 raise BadFURLError("bad connection hint '%s' " 787 790 "(hostname, but no port)" % hint_s) 788 791 mo = IPV4_HINT_RE.search(hint_s) 789 792 if mo: 790 793 hint = ( "ipv4", mo.group(1), int(mo.group(2)) ) 791 794 hints.append(hint) 795 elif hint_s.startswith("i2p:"): 796 (protocol, destination) = hints_s.split(":", 2) 797 hint = ( "ipv4", destination, 0) # I2P destinations have no port 798 hints.append(hint) 799 elif hint_s.endswith(".i2p"): # For compatibility, to be removed in a future version 800 hint = ( "ipv4", hint_s, 0) 801 hints.append(hint) 792 802 else: 793 803 # This is some extension from the future that we will ignore. 794 804 # All extensions are required to start with "TYPE:" (where -
foolscap/test/test_reference.py
diff --git a/foolscap/test/test_reference.py b/foolscap/test/test_reference.py index db57e33..7f2b9cf 100644
a b class LocalReference(unittest.TestCase, ShouldFailMixin): 52 52 "you asked me to fail", 53 53 rref.callRemote, "fail") 54 54 55 class LocationTest(unittest.TestCase): 56 def test_encode_ipv4(self): 57 hint = ("ipv4", "127.0.0.1", 1234) 58 location = referenceable.encode_location_hint(hint) 59 self.failUnlessEqual(location, "127.0.0.1:1234") 60 61 def test_decode_ipv4(self): 62 hints_s1 = "127.0.0.1:1234" 63 hints1 = referenceable.decode_location_hints(hints_s1) 64 self.failUnlessEqual(hints1, [("ipv4", "127.0.0.1", 1234)]) 65 66 hints_s2 = "127.0.0.1:1234,192.168.0.1:0" 67 hints2 = referenceable.decode_location_hints(hints_s2) 68 self.failUnless(("ipv4", "127.0.0.1", 1234) in hints2, hints2) 69 self.failUnless(("ipv4", "192.168.0.1", 0) in hints2, hints2) 70 71 def test_decode_i2p(self): 72 hints_s = "i2p:ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p" 73 hints = referenceable.decode_location_hints(hints_s) 74 self.failUnlessEqual(hints, [("ipv4", 75 "ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p", 0)]) 76 77 def test_decode_i2p_deprecated(self): 78 hints_s = "ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p" 79 hints = referenceable.decode_location_hints(hints_s) 80 self.failUnlessEqual(hints, [("ipv4", 81 "ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p", 0)]) 82 55 83 class TubID(unittest.TestCase): 56 84 def test_tubid_must_match(self): 57 85 good_tubid = "fu2bixsrymp34hwrnukv7hzxc2vrhqqa"