upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/git_remote_nostr/main.rs4
-rw-r--r--src/lib/git/utils.rs23
2 files changed, 26 insertions, 1 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index 29731e2..cf47a30 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -16,7 +16,7 @@ use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache};
16use git::{RepoActions, nostr_url::NostrUrlDecoded}; 16use git::{RepoActions, nostr_url::NostrUrlDecoded};
17use ngit::{ 17use ngit::{
18 client::{self, Params}, 18 client::{self, Params},
19 git, 19 git::{self, utils::set_git_timeout},
20 login::existing::load_existing_login, 20 login::existing::load_existing_login,
21}; 21};
22use nostr::nips::nip19::Nip19Coordinate; 22use nostr::nips::nip19::Nip19Coordinate;
@@ -62,6 +62,8 @@ async fn main() -> Result<()> {
62 62
63 repo_ref.set_nostr_git_url(decoded_nostr_url.clone()); 63 repo_ref.set_nostr_git_url(decoded_nostr_url.clone());
64 64
65 let _ = set_git_timeout();
66
65 let stdin = io::stdin(); 67 let stdin = io::stdin();
66 let mut line = String::new(); 68 let mut line = String::new();
67 69
diff --git a/src/lib/git/utils.rs b/src/lib/git/utils.rs
index 4e8f153..c5f8850 100644
--- a/src/lib/git/utils.rs
+++ b/src/lib/git/utils.rs
@@ -1,6 +1,8 @@
1use std::path::Path; 1use std::path::Path;
2 2
3use anyhow::{Context, Result};
3use directories::UserDirs; 4use directories::UserDirs;
5use git2::opts::{set_server_connect_timeout_in_milliseconds, set_server_timeout_in_milliseconds};
4 6
5pub fn check_ssh_keys() -> bool { 7pub fn check_ssh_keys() -> bool {
6 // Get the user's home directory using the directories crate 8 // Get the user's home directory using the directories crate
@@ -23,3 +25,24 @@ pub fn check_ssh_keys() -> bool {
23 } 25 }
24 false // No keys found 26 false // No keys found
25} 27}
28
29pub fn set_git_timeout() -> Result<()> {
30 unsafe {
31 // Set a 3 000 ms timeout for establishing the TCP connection (default: 60 000
32 // ms).
33 set_server_connect_timeout_in_milliseconds(3_000)
34 .context("failed to set libgit2 connect timeout")?;
35
36 // The server timeout applies per socket send()/recv() call rather than
37 // to the entire fetch or push. libgit2 transfers data in ~16 KiB chunks,
38 // so each chunk’s transfer is subject to this timeout instead of the
39 // overall command.
40 //
41 // We set it to 15 000 ms (instead of the 300 000 ms default) to quickly
42 // abort any stalled ~16 KiB chunk transfer—enabling fast failover across
43 // redundant Git servers—while still accommodating transient hiccups.
44 set_server_timeout_in_milliseconds(15_000).context("failed to set libgit2 I/O timeout")?;
45
46 Ok(())
47 }
48}