-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2889 tub port listen #437
2889 tub port listen #437
Conversation
0185cec
to
a68024c
Compare
Codecov Report
@@ Coverage Diff @@
## master #437 +/- ##
==========================================
- Coverage 89.85% 89.85% -0.01%
==========================================
Files 144 144
Lines 27090 27105 +15
Branches 3893 3895 +2
==========================================
+ Hits 24343 24355 +12
- Misses 2017 2019 +2
- Partials 730 731 +1
Continue to review full report at Codecov.
|
src/allmydata/node.py
Outdated
@@ -400,7 +400,13 @@ def create_main_tub(self): | |||
for port in tubport.split(","): | |||
if port in ("0", "tcp:0"): | |||
raise ValueError("tub.port cannot be 0: you must choose") | |||
self.tub.listenOn(port) | |||
if port == "listen:i2p": | |||
port_or_endpoint = self._i2p_provider.get_listener() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_listener
could do with some docs
@@ -294,6 +294,28 @@ def test_handler_default(self): | |||
self.assertIs(h, handler) | |||
i2p.default.assert_called_with(reactor, keyfile=None) | |||
|
|||
class Provider_Listener(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny name. ProviderListener
matches the naming convention better, no?
@@ -294,6 +294,28 @@ def test_handler_default(self): | |||
self.assertIs(h, handler) | |||
i2p.default.assert_called_with(reactor, keyfile=None) | |||
|
|||
class Provider_Listener(unittest.TestCase): | |||
def test_listener(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a docstring for this test method?
reactor) | ||
endpoint_or_description = p.get_listener() | ||
self.assertEqual(endpoint_or_description, | ||
"i2p:%s:3457:api=SAM:apiEndpoint=goodport" % privkeyfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be another similar test that exercises the necessary escaping logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naw, the whole point of this exercise is to avoid the need for escaping anything. In this early state, the get_listener()
method doesn't return anything complicated enough to require escaping. In the later state (which I hope @str4d will write), it will return an Endpoint object instead of a (string) endpoint descriptor, so it won't need escaping either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some escaping in the implementation, though. Maybe you want to remove that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, you're absolutely right. I just pushed a patch to exercise that escaping.
When @str4d rewrites this to build an endpoint directly, he can remove that.
@@ -393,6 +393,20 @@ def test_handler_default(self): | |||
self.assertIs(h, handler) | |||
tor.default_socks.assert_called_with() | |||
|
|||
class Provider_Listener(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That funny name again
src/allmydata/util/tor_provider.py
Outdated
def get_listener(self): | ||
local_port = self._get_tor_config("onion.local_port") | ||
tor_port = "tcp:%s:interface=127.0.0.1" % local_port | ||
return tor_port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty easy to make the endpoint object instead here:
from twisted.internet.endpoints import TCP4ServerEndpoint
return TCP4ServerEndpoint(self._reactor, tor_port, interface="127.0.0.1")
I think that addresses everything. I changed tor_provider to return an Endpoint (even though it's pretty simple, and a string descriptor would be sufficient) to serve as an example, and to exercise the property that it's supposed to be allowed to return either. Thanks for the suggestion! |
726af4f
to
286c33a
Compare
8f2b322
to
d09849f
Compare
This delegates the construction of the server Endpoint object to the i2p/tor Provider, which can use the i2p/tor section of the config file to add options which would be awkward to express as text in an endpoint descriptor string. refs ticket:2889 (but note this merely makes room for a function to be written that can process I2CP options, it does not actually handle such options, so it does not close this ticket yet)
…criptor get_listener() is allowed to return either, and the Tor provider is currently simple enough to not really need more than a basic descriptor, but have it return a full Endpoint for use as an example of what I2P can do later.
d09849f
to
a171108
Compare
tahoe.cfg: add tub.port=listen:i2p (and/or listen:tor)
This delegates the construction of the server Endpoint object to the i2p/tor
Provider, which can use the i2p/tor section of the config file to add options
which would be awkward to express as text in an endpoint descriptor string.
refs ticket:2889 (but note this merely makes room for a function to be
written that can process I2CP options, it does not actually handle such
options, so it does not close this ticket yet)