From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 65C797D50E for ; Tue, 9 Nov 2021 07:53:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A9DCB2E158 for ; Tue, 9 Nov 2021 07:53:08 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id AD25A2DF74 for ; Tue, 9 Nov 2021 07:53:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 267B345DA6; Tue, 9 Nov 2021 07:52:57 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 07:52:53 +0100 Message-Id: <20211109065253.980304-17-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109065253.980304-1-dietmar@proxmox.com> References: <20211109065253.980304-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.507 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-backup-proxy.rs] Subject: [pbs-devel] [PATCH proxmox-backup 9/9] proxmox-backup-proxy: implement traffic control X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 06:53:10 -0000 Signed-off-by: Dietmar Maurer --- src/bin/proxmox-backup-proxy.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 1589a57d..01308463 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -21,6 +21,7 @@ use proxmox::sys::linux::socket::set_tcp_keepalive; use proxmox::tools::fs::CreateOptions; use proxmox_lang::try_block; use proxmox_router::{RpcEnvironment, RpcEnvironmentType, UserInformation}; +use proxmox_http::client::{RateLimiter, RateLimitedStream}; use pbs_tools::{task_log, task_warn}; use pbs_datastore::DataStore; @@ -70,6 +71,7 @@ use proxmox_backup::api2::pull::do_sync_job; use proxmox_backup::api2::tape::backup::do_tape_backup_job; use proxmox_backup::server::do_verification_job; use proxmox_backup::server::do_prune_job; +use proxmox_backup::TrafficControlCache; fn main() -> Result<(), Error> { proxmox_backup::tools::setup_safe_path_env(); @@ -351,7 +353,7 @@ fn make_tls_acceptor() -> Result { } type ClientStreamResult = - Result>>, Error>; + Result>>>, Error>; const MAX_PENDING_ACCEPTS: usize = 1024; fn accept_connections( @@ -387,6 +389,9 @@ async fn accept_connection( sock.set_nodelay(true).unwrap(); let _ = set_tcp_keepalive(sock.as_raw_fd(), PROXMOX_BACKUP_TCP_KEEPALIVE_TIME); + let peer = sock.peer_addr().ok(); + let sock = RateLimitedStream::with_limiter_update_cb(sock, move || lookup_rate_limiter(peer)); + let ssl = { // limit acceptor_guard scope // Acceptor can be reloaded using the command socket "reload-certificate" command let acceptor_guard = acceptor.lock().unwrap(); @@ -1075,3 +1080,21 @@ fn gather_disk_stats(disk_manager: Arc, path: &Path, rrd_prefix: &st } } } + +// Rate Limiter lookup + +// Test WITH +// proxmox-backup-client restore vm/201/2021-10-22T09:55:56Z drive-scsi0.img img1.img --repository localhost:store2 + +lazy_static::lazy_static!{ + static ref TRAFFIC_CONTROL_CACHE: Arc> = + Arc::new(Mutex::new(TrafficControlCache::new())); +} + +fn lookup_rate_limiter( + peer: Option, +) -> (Option>>, Option>>) { + let mut cache = TRAFFIC_CONTROL_CACHE.lock().unwrap(); + cache.reload(); + cache.lookup_rate_limiter(peer) +} -- 2.30.2