use ephemeral_hidden_service if available
This commit is contained in:
parent
8d919e63db
commit
9fa06bbde7
1 changed files with 24 additions and 18 deletions
28
oml/tor.py
28
oml/tor.py
|
@ -8,6 +8,7 @@ import distutils
|
||||||
import ox
|
import ox
|
||||||
import stem
|
import stem
|
||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
|
from Crypto.PublicKey import RSA
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
import state
|
import state
|
||||||
|
@ -164,7 +165,22 @@ class Tor(object):
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
return False
|
return False
|
||||||
controller = self.controller
|
controller = self.controller
|
||||||
logger.debug("FIXME: dont remove/add service if already defined")
|
if controller.get_version() >= stem.version.Requirement.ADD_ONION:
|
||||||
|
with open(settings.ssl_key_path, 'rb') as fd:
|
||||||
|
private_key = fd.read()
|
||||||
|
key_content = RSA.importKey(private_key).exportKey().decode()
|
||||||
|
key_content = ''.join(key_content.strip().split('\n')[1:-1])
|
||||||
|
ports = {9851: settings.server['node_port']}
|
||||||
|
controller.remove_ephemeral_hidden_service(settings.USER_ID)
|
||||||
|
response = controller.create_ephemeral_hidden_service(ports,
|
||||||
|
key_type='RSA1024', key_content=key_content,
|
||||||
|
detached=True)
|
||||||
|
if response.is_ok():
|
||||||
|
logger.debug('published node as https://%s.onion:%s',
|
||||||
|
settings.USER_ID, settings.server_defaults['node_port'])
|
||||||
|
else:
|
||||||
|
logger.debug('failed to publish node to tor')
|
||||||
|
else:
|
||||||
controller.remove_hidden_service(self.dir)
|
controller.remove_hidden_service(self.dir)
|
||||||
result = controller.create_hidden_service(
|
result = controller.create_hidden_service(
|
||||||
self.dir,
|
self.dir,
|
||||||
|
@ -172,16 +188,6 @@ class Tor(object):
|
||||||
target_port=settings.server['node_port']
|
target_port=settings.server['node_port']
|
||||||
)
|
)
|
||||||
logger.debug('published node as https://%s:%s', result.hostname, settings.server_defaults['node_port'])
|
logger.debug('published node as https://%s:%s', result.hostname, settings.server_defaults['node_port'])
|
||||||
'''
|
|
||||||
with open(settings.ssl_key_path) as fd:
|
|
||||||
key_content = fd.read()
|
|
||||||
ports = {9851: settings.server['node_port']}
|
|
||||||
response = controller.create_ephemeral_hidden_service(ports,
|
|
||||||
key_type='RSA1024', key_content=key_content,
|
|
||||||
detached=True, await_publication = True)
|
|
||||||
logger.debug('published node as https://%s.onion:%s',
|
|
||||||
settings.USER_ID, settings.server_defaults['node_port'])
|
|
||||||
'''
|
|
||||||
|
|
||||||
def depublish(self):
|
def depublish(self):
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
|
|
Loading…
Reference in a new issue