- 
                Notifications
    
You must be signed in to change notification settings  - Fork 76
 
Description
Hi,
I have previously used this codebase to start up ephemeral onion services with no issues, however I encountered an issue when using it to start a persistent onion service. In my torrc I have configured HiddenServicePort in the usual way; 80 for the public port, and a specific chosen port is entered (say 8080) for the local port.
When I ran a test using the example code, but setting my endpoint string like this:
"onion:80:controlPort=9051:localPort=8080:hiddenServiceDir=/my/hidserv/dir"
... I found that the local port is generated randomly, rather than being 8080. In the code for TCPHiddenServiceEndpoint.listen() it's clear why:
txtorcon/txtorcon/endpoints.py
Lines 562 to 569 in 0c416cc
| # XXX - perhaps allow the user to pass in an endpoint | |
| # descriptor and make this one the default? Then would | |
| # probably want to check for "is a local interface or not" and | |
| # at *least* warn if it's not local... | |
| self.tcp_endpoint = serverFromString( | |
| self._reactor, | |
| 'tcp:0:interface=127.0.0.1', | |
| ) | 
The variable self.local_port was set in the constructor as intended (here, to 8080) but the string used in the serverFromString call just puts 0 so we get a fresh port. I verified that this could be fixed with something like:
        if self.local_port is None:
            serverstring = 'tcp:0:interface=127.0.0.1'
        else:
            serverstring = 'tcp:{}:interface=127.0.0.1'.format(self.local_port)
        self.tcp_endpoint = serverFromString(
            self._reactor,
            serverstring,
        )
... not that that is more than a testing patch, but just to concretize the point. It works fine after that (i.e. the hidden service is accessible).