Skip to content

Commit d254979

Browse files
committed
add client allowlist and close virtual channel
1 parent d711f69 commit d254979

7 files changed

Lines changed: 916 additions & 54 deletions

File tree

src/args.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use bitcoin::secp256k1::PublicKey;
12
use clap::{value_parser, Parser};
23
use rgb_lib::BitcoinNetwork;
34
use std::path::PathBuf;
45

56
use crate::auth::check_auth_args;
67
use crate::error::AppError;
7-
use crate::utils::check_port_is_available;
8+
use crate::utils::{check_port_is_available, hex_str_to_compressed_pubkey};
89

910
#[derive(Parser)]
1011
#[command(author, version, about, long_about = None)]
@@ -38,6 +39,9 @@ struct Args {
3839

3940
#[arg(long, default_value_t = false)]
4041
enable_virtual_channels_v0: bool,
42+
43+
#[arg(long, value_delimiter = ',')]
44+
virtual_peer_pubkeys: Vec<String>,
4145
}
4246

4347
pub(crate) struct UserArgs {
@@ -48,6 +52,7 @@ pub(crate) struct UserArgs {
4852
pub(crate) max_media_upload_size_mb: u16,
4953
pub(crate) root_public_key: Option<biscuit_auth::PublicKey>,
5054
pub(crate) enable_virtual_channels_v0: bool,
55+
pub(crate) virtual_peer_pubkeys: Vec<PublicKey>,
5156
}
5257

5358
pub(crate) fn parse_startup_args() -> Result<UserArgs, AppError> {
@@ -62,6 +67,14 @@ pub(crate) fn parse_startup_args() -> Result<UserArgs, AppError> {
6267

6368
let root_public_key = check_auth_args(args.disable_authentication, args.root_public_key)?;
6469

70+
let mut virtual_peer_pubkeys = Vec::new();
71+
for pubkey in args.virtual_peer_pubkeys {
72+
let Some(parsed_pubkey) = hex_str_to_compressed_pubkey(&pubkey) else {
73+
return Err(AppError::InvalidVirtualPeerPubkey(pubkey));
74+
};
75+
virtual_peer_pubkeys.push(parsed_pubkey);
76+
}
77+
6578
Ok(UserArgs {
6679
storage_dir_path: args.storage_directory_path,
6780
daemon_listening_port,
@@ -70,5 +83,6 @@ pub(crate) fn parse_startup_args() -> Result<UserArgs, AppError> {
7083
max_media_upload_size_mb: args.max_media_upload_size_mb,
7184
root_public_key,
7285
enable_virtual_channels_v0: args.enable_virtual_channels_v0,
86+
virtual_peer_pubkeys,
7387
})
7488
}

src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub enum APIError {
3535
#[error("Batch transfer not found")]
3636
BatchTransferNotFound,
3737

38-
#[error("Cannot close channel")]
38+
#[error("Cannot close channel: {0}")]
3939
CannotCloseChannel(String),
4040

4141
#[error("Cannot estimate fees")]
@@ -546,6 +546,9 @@ pub enum AppError {
546546
#[error("The provided root public key is invalid")]
547547
InvalidRootKey,
548548

549+
#[error("Invalid virtual peer pubkey: {0}")]
550+
InvalidVirtualPeerPubkey(String),
551+
549552
#[error("IO error: {0}")]
550553
IO(#[from] std::io::Error),
551554

0 commit comments

Comments
 (0)