Ticket #517: calculator-test.patch

File calculator-test.patch, 1.9 KB (added by str4d, at 2015-09-22T01:42:48Z)

Example I2P client plugin, and patches to use it for foolscap calculator example

  • new file doc/listings/i2p.py

    diff --git a/doc/listings/i2p.py b/doc/listings/i2p.py
    new file mode 100644
    index 0000000..62520ef
    - +  
     1from foolscap.ipb import IConnectionHintHandler
     2from foolscap.logging import log
     3import re
     4from twisted.internet import endpoints
     5from zope.interface import implementer
     6
     7HINT_RE=re.compile(r"^i2p:([A-Za-z.0-9\-]+)(:(\d+){1,5})?$")
     8
     9@implementer(IConnectionHintHandler)
     10class 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")
  • doc/listings/pb3calculator.py

    diff --git a/doc/listings/pb3calculator.py b/doc/listings/pb3calculator.py
    index df41931..0418a9a 100644
    a b class Calculator(Referenceable): 
    3333
    3434tub = Tub()
    3535tub.listenOn("tcp:12345")
    36 tub.setLocation("localhost:12345")
     36tub.setLocation("i2p:6wata5vdjeo4ma5v2id2nka6jqaig2xfqrfzrlcgrekpcqwklnza.b32.i2p")
    3737url = tub.registerReference(Calculator(), "calculator")
    3838print "the object is available at:", url
    3939
  • doc/listings/pb3user.py

    diff --git a/doc/listings/pb3user.py b/doc/listings/pb3user.py
    index 2b05323..915eed7 100644
    a b  
    33import sys
    44from twisted.internet import reactor
    55from foolscap.api import Referenceable, Tub
     6from i2p import I2PPlugin
    67
    78class Observer(Referenceable):
    89    def remote_event(self, msg):
    def gotRemote(remote): 
    2728
    2829url = sys.argv[1]
    2930tub = Tub()
     31tub.addConnectionHintHandler('i2p', I2PPlugin())
    3032tub.startService()
    3133d = tub.getReference(url)
    3234d.addCallback(gotRemote)