Skip to content

Commit

Permalink
Make the transport plugins use the twisted IPlugin interface
Browse files Browse the repository at this point in the history
here we also make the setup.py install the twisted plugins
  • Loading branch information
david415 committed Jun 1, 2016
1 parent 45a5ec4 commit ba6ed17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -50,7 +50,7 @@ def run(self):
"platforms": ["any"],

"package_dir": {"": "src"},
"packages": ["foolscap", "foolscap.slicers", "foolscap.logging",
"packages": ["twisted.plugins", "foolscap", "foolscap.slicers", "foolscap.logging",
"foolscap.appserver", "foolscap.test"],
"entry_points": {"console_scripts": [
"flogtool = foolscap.logging.cli:run_flogtool",
Expand Down
10 changes: 6 additions & 4 deletions src/foolscap/connection_plugins.py
Expand Up @@ -2,9 +2,11 @@
import re
from zope.interface import implementer
from twisted.internet import endpoints
from twisted.plugin import IPlugin

from foolscap.ipb import IConnectionHintHandler, InvalidHintError


try:
import txsocksx
except ImportError:
Expand Down Expand Up @@ -57,8 +59,8 @@ def convert_legacy_hint(location):
return "tcp:%s:%d" % (host, port)
return location

@implementer(IConnectionHintHandler)
class DefaultTCP:
@implementer(IConnectionHintHandler, IPlugin)
class DefaultTCP(object):
def hint_to_endpoint(self, hint, reactor):
# Return (endpoint, hostname), where "hostname" is what we pass to the
# HTTP "Host:" header so a dumb HTTP server can be used to redirect us.
Expand All @@ -68,8 +70,8 @@ def hint_to_endpoint(self, hint, reactor):
host, port = mo.group(1), int(mo.group(2))
return endpoints.HostnameEndpoint(reactor, host, port), host

@implementer(IConnectionHintHandler)
class SOCKS5:
@implementer(IConnectionHintHandler, IPlugin)
class SOCKS5(object):
def __init__(self, endpoint=None, proxy_endpoint_factory=None):
if txsocksx is None:
raise PluginDependencyNotLoaded("""SOCKS5 foolscap client transport plugin requires txsocksx.\n
Expand Down
3 changes: 3 additions & 0 deletions src/twisted/plugins/load_transport_plugins.py
@@ -0,0 +1,3 @@
import foolscap
tcpTransportPlugin = foolscap.DefaultTCP()
socksTransportPlugin = foolscap.SOCKS5()

0 comments on commit ba6ed17

Please sign in to comment.