Skip to content

Commit

Permalink
Allow listening mode with all interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 10, 2022
1 parent 1e1b773 commit 37b26b5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
5 changes: 3 additions & 2 deletions shell/_lnpd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ _lnpd() {
'--electrum-port=[Customize Electrum server port number. By default the wallet will use port matching the selected network]:ELECTRUM_PORT: ' \
'*-L+[Start daemon in listening mode binding the provided local address(es)]:LISTEN: ' \
'*--listen=[Start daemon in listening mode binding the provided local address(es)]:LISTEN: ' \
'(-L --listen)--bolt=[Use BOLT protocol for listening for the incoming connections. Can optionally specify a custom port number]:BOLT: ' \
'(-L --listen)--bifrost=[Use Bifrost protocol for listening for the incoming connections. Can optionally specify a custom port number]:BIFROST: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
Expand All @@ -43,8 +45,7 @@ _lnpd() {
'*--verbose[Set verbosity level]' \
'-t[Spawn daemons as threads and not processes]' \
'--threaded[Spawn daemons as threads and not processes]' \
'--bolt[Use BOLT protocol for listening for the incoming connections]' \
'--bifrost[Use Bifrost protocol for listening for the incoming connections]' \
'(-L --listen)--listen-all[If the argument is provided, the node binds to all network addresses and requires `--bifrost` and/or `--bolt` arguments]' \
":: :_lnpd_commands" \
"*::: :->lnpd" \
&& ret=0
Expand Down
5 changes: 3 additions & 2 deletions shell/_lnpd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Register-ArgumentCompleter -Native -CommandName 'lnpd' -ScriptBlock {
[CompletionResult]::new('--electrum-port', 'electrum-port', [CompletionResultType]::ParameterName, 'Customize Electrum server port number. By default the wallet will use port matching the selected network')
[CompletionResult]::new('-L', 'L', [CompletionResultType]::ParameterName, 'Start daemon in listening mode binding the provided local address(es)')
[CompletionResult]::new('--listen', 'listen', [CompletionResultType]::ParameterName, 'Start daemon in listening mode binding the provided local address(es)')
[CompletionResult]::new('--bolt', 'bolt', [CompletionResultType]::ParameterName, 'Use BOLT protocol for listening for the incoming connections. Can optionally specify a custom port number')
[CompletionResult]::new('--bifrost', 'bifrost', [CompletionResultType]::ParameterName, 'Use Bifrost protocol for listening for the incoming connections. Can optionally specify a custom port number')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
Expand All @@ -49,8 +51,7 @@ Register-ArgumentCompleter -Native -CommandName 'lnpd' -ScriptBlock {
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Set verbosity level')
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Spawn daemons as threads and not processes')
[CompletionResult]::new('--threaded', 'threaded', [CompletionResultType]::ParameterName, 'Spawn daemons as threads and not processes')
[CompletionResult]::new('--bolt', 'bolt', [CompletionResultType]::ParameterName, 'Use BOLT protocol for listening for the incoming connections')
[CompletionResult]::new('--bifrost', 'bifrost', [CompletionResultType]::ParameterName, 'Use Bifrost protocol for listening for the incoming connections')
[CompletionResult]::new('--listen-all', 'listen-all', [CompletionResultType]::ParameterName, 'If the argument is provided, the node binds to all network addresses and requires `--bifrost` and/or `--bolt` arguments')
[CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initialize data directory')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
break
Expand Down
10 changes: 9 additions & 1 deletion shell/lnpd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _lnpd() {

case "${cmd}" in
lnpd)
opts="-h -V -k -v -d -c -T -M -X -R -n -t -L --help --version --key-file --verbose --data-dir --config --tor-proxy --msg --ctl --rpc --chain --electrum-server --electrum-port --threaded --listen --bolt --bifrost init help"
opts="-h -V -k -v -d -c -T -M -X -R -n -t -L --help --version --key-file --verbose --data-dir --config --tor-proxy --msg --ctl --rpc --chain --electrum-server --electrum-port --threaded --listen --listen-all --bolt --bifrost init help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -111,6 +111,14 @@ _lnpd() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--bolt)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--bifrost)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
Expand Down
14 changes: 9 additions & 5 deletions src/bin/lnpd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::io::Write;
use std::net::{IpAddr, Ipv4Addr};
use std::path::{Path, PathBuf};

use amplify::empty;
use bitcoin::XpubIdentifier;
use clap::Parser;
use internet2::addr::LocalNode;
Expand Down Expand Up @@ -67,16 +68,19 @@ fn main() -> Result<(), Error> {

let key_file = PathBuf::from(opts.key_opts.key_file);
let listen = opts.listen.unwrap_or_else(|| {
if !opts.listen_all {
return empty!();
}
let ip = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
let mut list = Vec::with_capacity(2);
if opts.bifrost {
list.push(ListenAddr::bifrost(ip, None));
if let Some(port) = opts.bifrost {
list.push(ListenAddr::bifrost(ip, port));
}
if opts.bolt {
list.push(ListenAddr::bolt(ip, None));
if let Some(port) = opts.bolt {
list.push(ListenAddr::bolt(ip, port));
}
if list.is_empty() {
panic!("either --bolt or --bifrost option must be given with the empty --listen flag")
panic!("either --bolt or --bifrost option must be given with the empty --listen flag");
}
list
});
Expand Down
26 changes: 15 additions & 11 deletions src/lnpd/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ pub struct Opts {
/// Binds to the specified interface and listens for incoming connections, spawning
/// a new thread / forking child process for each new incoming client connecting the
/// opened socket. Whether the child is spawned as a thread or forked as a child
/// process determined by the presence of `--threaded-daemons` flag.
///
/// If the argument is provided in form of flag, without value, uses `0.0.0.0` as
/// the bind address and requires `--bifrost` and/or `--bolt` arguments.
#[clap(short = 'L', long, group = "action")]
/// process determined by the presence of `--threaded` flag.
#[clap(short = 'L', long)]
pub listen: Option<Vec<ListenAddr>>,

/// Use BOLT protocol for listening for the incoming connections.
#[clap(long, requires = "listen")]
pub bolt: bool,
/// If the argument is provided, the node binds to all network addresses and requires
/// `--bifrost` and/or `--bolt` arguments.
#[clap(long, conflicts_with = "listen")]
pub listen_all: bool,

/// Use BOLT protocol for listening for the incoming connections. Can optionally specify a
/// custom port number.
#[clap(long, conflicts_with = "listen", requires = "listen-all")]
pub bolt: Option<Option<u16>>,

/// Use Bifrost protocol for listening for the incoming connections.
#[clap(long, requires = "listen")]
pub bifrost: bool,
/// Use Bifrost protocol for listening for the incoming connections. Can optionally specify a
/// custom port number.
#[clap(long, conflicts_with = "listen", requires = "listen-all")]
pub bifrost: Option<Option<u16>>,

/// Optional command to execute and exit
#[clap(subcommand)]
Expand Down

0 comments on commit 37b26b5

Please sign in to comment.