diff --git a/doc/listings/i2p.py b/doc/listings/i2p.py
new file mode 100644
index 0000000..62520ef
-
|
+
|
|
| 1 | from foolscap.ipb import IConnectionHintHandler |
| 2 | from foolscap.logging import log |
| 3 | import re |
| 4 | from twisted.internet import endpoints |
| 5 | from zope.interface import implementer |
| 6 | |
| 7 | HINT_RE=re.compile(r"^i2p:([A-Za-z.0-9\-]+)(:(\d+){1,5})?$") |
| 8 | |
| 9 | @implementer(IConnectionHintHandler) |
| 10 | class I2PPlugin: |
| 11 | def hint_to_endpoint(self, hint, reactor): |
| 12 | mo = HINT_RE.search(hint) |
| 13 | if not mo: |
| 14 | raise InvalidHintError("unrecognized I2P hint") |
| 15 | host, port = mo.group(1), mo.group(2) |
| 16 | desc = 'i2p:%s:%s' % (host, port) if port else 'i2p:%s' % host |
| 17 | try: |
| 18 | return endpoints.clientFromString(reactor, desc), host |
| 19 | except ValueError: |
| 20 | raise InvalidHintError("txi2p is not installed") |
diff --git a/doc/listings/pb3calculator.py b/doc/listings/pb3calculator.py
index df41931..0418a9a 100644
a
|
b
|
class Calculator(Referenceable): |
33 | 33 | |
34 | 34 | tub = Tub() |
35 | 35 | tub.listenOn("tcp:12345") |
36 | | tub.setLocation("localhost:12345") |
| 36 | tub.setLocation("i2p:6wata5vdjeo4ma5v2id2nka6jqaig2xfqrfzrlcgrekpcqwklnza.b32.i2p") |
37 | 37 | url = tub.registerReference(Calculator(), "calculator") |
38 | 38 | print "the object is available at:", url |
39 | 39 | |
diff --git a/doc/listings/pb3user.py b/doc/listings/pb3user.py
index 2b05323..915eed7 100644
a
|
b
|
|
3 | 3 | import sys |
4 | 4 | from twisted.internet import reactor |
5 | 5 | from foolscap.api import Referenceable, Tub |
| 6 | from i2p import I2PPlugin |
6 | 7 | |
7 | 8 | class Observer(Referenceable): |
8 | 9 | def remote_event(self, msg): |
… |
… |
def gotRemote(remote): |
27 | 28 | |
28 | 29 | url = sys.argv[1] |
29 | 30 | tub = Tub() |
| 31 | tub.addConnectionHintHandler('i2p', I2PPlugin()) |
30 | 32 | tub.startService() |
31 | 33 | d = tub.getReference(url) |
32 | 34 | d.addCallback(gotRemote) |