Ticket #151: 151-accept-i2p-destinations.patch

File 151-accept-i2p-destinations.patch, 3.5 KB (added by killyourtv, 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): 
    782782    hints = []
    783783    if hints_s:
    784784        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                ):
    786789                raise BadFURLError("bad connection hint '%s' "
    787790                                   "(hostname, but no port)" % hint_s)
    788791            mo = IPV4_HINT_RE.search(hint_s)
    789792            if mo:
    790793                hint = ( "ipv4", mo.group(1), int(mo.group(2)) )
    791794                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)
    792802            else:
    793803                # This is some extension from the future that we will ignore.
    794804                # 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): 
    5252                               "you asked me to fail",
    5353                               rref.callRemote, "fail")
    5454
     55class 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
    5583class TubID(unittest.TestCase):
    5684    def test_tubid_must_match(self):
    5785        good_tubid = "fu2bixsrymp34hwrnukv7hzxc2vrhqqa"