Starting with Tor version 0.2.7.1 it is possible, through Tor’s control socket API, to create and destroy ’ephemeral’ hidden services programmatically. https://stem.torproject.org/api/control.html#stem.control.Controller.create_ephemeral_hidden_service
This means that if Tor is running (and proper authorization is available), bitcoin could automatically create a hidden service to listen on, without user manual configuration. That would positively affect the number of available .onion nodes.
This would involve the following, if enabled:
- When the node is started, connect to Tor through control socket
- Send
create_ephemeral_hidden_service
command - First time:
- Make it create a hidden service key
- Save the key in the data directory for later usage (optional: Could also use a new key every time. Better for privacy, less so for having stable identifiers, so this should be configurable)
- Make it redirect port 8333 to the local port 8333 (or whatever port we’re listening on). E.g.
0response = controller.create_ephemeral_hidden_service({8333: 8333}, key_type='NEW', key_content='BEST', await_publication = True)
1# Advertize <response.service_id>.onion
2# Optionally save response.private_key, response.private_key_type
- Keep control socket connection open for as long node is running. The hidden service will (by default) automatically go away when the connection is closed.
Challenges:
- Except for experimentation we probably don’t want to rely on a Python script. This means the
create_ephemeral_hidden_service
STEM interface has to be implemented in C++. Internal command isADD_ONION
, see https://gitweb.torproject.org/torspec.git/commit/?id=f5ff369 for the appropriate addition to torspec.
Edit: the controller.create_ephemeral_hidden_service will take a while (I suppose the reason is that it needs to generate a key) - maybe execute it in a thread and not in the main initialization.
Edit.2: FYI the part that takes significant time is not the key generation, but waiting for publication await_publication = True
.