bitcoind: add separate p2p socket for tor connections

This re-enables onion tagging while still supporting untagged connections.

Onion sockets are not yet supported in the latest liquidd/elements
version 0.18.1.12 available on nixpkgs.
This commit is contained in:
Erik Arvstedt 2021-10-15 15:56:13 +02:00
parent 06a971dfa9
commit df2070b44a
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
2 changed files with 18 additions and 4 deletions

View File

@ -15,6 +15,14 @@ let
default = 8333; default = 8333;
description = "Port to listen for peer connections."; description = "Port to listen for peer connections.";
}; };
onionPort = mkOption {
type = types.nullOr types.port;
default = null;
description = ''
Port to listen for Tor peer connections.
If set, inbound connections to this port are tagged as onion peers.
'';
};
getPublicAddressCmd = mkOption { getPublicAddressCmd = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
@ -253,8 +261,10 @@ let
${optionalString (cfg.assumevalid != null) "assumevalid=${cfg.assumevalid}"} ${optionalString (cfg.assumevalid != null) "assumevalid=${cfg.assumevalid}"}
# Connection options # Connection options
${optionalString cfg.listen "bind=${cfg.address}"} ${optionalString cfg.listen
port=${toString cfg.port} "bind=${cfg.address}:${toString cfg.port}"}
${optionalString (cfg.listen && cfg.onionPort != null)
"bind=${cfg.address}:${toString cfg.onionPort}=onion"}
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
listen=${if cfg.listen then "1" else "0"} listen=${if cfg.listen then "1" else "0"}
${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"} ${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"}

View File

@ -18,7 +18,7 @@ let
default = config.public; default = config.public;
description = '' description = ''
Create an onion service for the given service. Create an onion service for the given service.
The service must define options 'address' and 'port'. The service must define options 'address' and 'onionPort' (or `port`).
''; '';
}; };
public = mkOption { public = mkOption {
@ -64,7 +64,7 @@ in {
inherit (cfg.${name}) externalPort; inherit (cfg.${name}) externalPort;
in nbLib.mkOnionService { in nbLib.mkOnionService {
port = if externalPort != null then externalPort else service.port; port = if externalPort != null then externalPort else service.port;
target.port = service.port; target.port = service.onionPort or service.port;
target.addr = nbLib.address service.address; target.addr = nbLib.address service.address;
} }
); );
@ -118,6 +118,10 @@ in {
externalPort = 80; externalPort = 80;
}; };
}; };
# When the bitcoind onion service is enabled, add an onion-tagged socket
# to distinguish local connections from Tor connections
services.bitcoind.onionPort = mkIf (cfg.bitcoind.enable or false) 8334;
} }
]; ];
} }