Skip to content
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

Merged
merged 5 commits into from
Nov 3, 2017
Merged

Conversation

warner
Copy link
Member

@warner warner commented Aug 10, 2017

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)

@codecov-io
Copy link

codecov-io commented Aug 10, 2017

Codecov Report

Merging #437 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/allmydata/scripts/create_node.py 98.98% <ø> (ø) ⬆️
src/allmydata/node.py 94.6% <100%> (+0.07%) ⬆️
src/allmydata/util/i2p_provider.py 95.76% <100%> (+0.22%) ⬆️
src/allmydata/util/tor_provider.py 98.3% <100%> (+0.03%) ⬆️
src/allmydata/mutable/servermap.py 93.7% <0%> (-0.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 856425f...a171108. Read the comment docs.

@@ -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()
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That funny name again

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
Copy link
Member

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")

@warner
Copy link
Member Author

warner commented Aug 16, 2017

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!

@warner warner force-pushed the 2889-tub-port-listen branch 2 times, most recently from 8f2b322 to d09849f Compare September 21, 2017 07:31
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.
@warner warner merged commit a171108 into tahoe-lafs:master Nov 3, 2017
@warner warner deleted the 2889-tub-port-listen branch November 3, 2017 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants