Ticket #151: 151_i2p_destinations.txt

File 151_i2p_destinations.txt, 1.1 KB (added by duck, 14 years ago)

Recognize base32 I2P destinations.

Line 
1diff --git foolscap/referenceable.py foolscap/referenceable.py
2index 7efbcb5..c15d706 100644
3--- foolscap/referenceable.py
4+++ foolscap/referenceable.py
5@@ -763,6 +763,8 @@ AUTH_STURDYREF_RE = re.compile(r"pb://([^@]+)@([^/]+)/(.+)$")
6 NONAUTH_STURDYREF_RE = re.compile(r"pbu://([^/]+)/(.+)$")
7 
8 IPV4_HINT_RE = re.compile(r"^([^:]+):(\d+)$")
9+# I2P: Recognize I2P destinations
10+I2P_HINT_RE = re.compile(r"^([a-z2-7]{52}\.b32\.i2p)$")
11 def encode_location_hint(hint):
12     assert hint[0] == "ipv4"
13     host, port = hint[1:]
14@@ -775,8 +777,14 @@ def decode_location_hints(hints_s):
15             hint = ( "ipv4", mo.group(1), int(mo.group(2)) )
16             hints.append(hint)
17         else:
18-            # some extension from the future that we will ignore
19-            pass
20+            mo = I2P_HINT_RE.search(hint_s)
21+            if mo:
22+                # I2P: destinations have no port
23+                hint = ( "ipv4", mo.group(1), 0)
24+                hints.append(hint)
25+            else:
26+                # some extension from the future that we will ignore
27+                pass
28     return hints
29 
30 class BadFURLError(Exception):