🔥 remove: auto update. Drops the yumush-update/1 ALPN, signed manifests, release signing/build tooling and the builder › Release tab, client self-replace/rollback, CPU-level builds, Hello.release / session release / overview versions, Close::Outdated and min-version kicks. session.release column dropped (old DBs must be recreated)
Browse files at this commitb36c61c2e96b87af7a11bacdbbcac0db70919419Parent: 1ed357054 changed files +25 -2507
- Cargo.lock +0 -1
- crates/client/Cargo.toml +1 -2
- crates/client/lang/en/builder.txt +0 -1
- crates/client/lang/en/builder_log.txt +0 -1
- crates/client/lang/en/builder_overview.txt +0 -2
- crates/client/lang/en/builder_release.txt +0 -28
- crates/client/lang/en/builder_users.txt +0 -1
- crates/client/lang/tr/builder.txt +0 -1
- crates/client/lang/tr/builder_log.txt +0 -1
- crates/client/lang/tr/builder_overview.txt +0 -2
- crates/client/lang/tr/builder_release.txt +0 -28
- crates/client/lang/tr/builder_users.txt +0 -1
- crates/client/src/cpu.rs +0 -25
- crates/client/src/gui.rs +0 -20
- crates/client/src/gui/builder.rs +1 -8
- crates/client/src/gui/builder/log.rs +1 -3
- crates/client/src/gui/builder/overview.rs +0 -27
- crates/client/src/gui/builder/release.rs +0 -498
- crates/client/src/gui/builder/users.rs +0 -10
- crates/client/src/gui/chat.rs +1 -1
- crates/client/src/gui/parts.rs +0 -3
- crates/client/src/lib.rs +0 -3
- crates/client/src/main.rs +0 -6
- crates/client/src/net/events.rs +0 -3
- crates/client/src/net/fail.rs +0 -1
- crates/client/src/net/link.rs +4 -66
- crates/client/src/net/mod.rs +0 -11
- crates/client/src/release.rs +0 -371
- crates/client/src/settings.rs +1 -12
- crates/client/src/update.rs +0 -669
- crates/client/src/update/keys.rs +0 -1
- crates/common/src/call.rs +2 -13
- crates/common/src/error.rs +0 -2
- crates/common/src/event.rs +0 -1
- crates/common/src/lib.rs +0 -1
- crates/common/src/model.rs +0 -18
- crates/common/src/open.rs +0 -8
- crates/common/src/session.rs +0 -1
- crates/common/src/transport.rs +1 -4
- crates/common/src/update.rs +0 -187
- crates/server/src/authentication.rs +0 -1
- crates/server/src/call/admin.rs +7 -41
- crates/server/src/call/mod.rs +0 -2
- crates/server/src/certificate.rs +1 -4
- crates/server/src/db/schema.sql +0 -1
- crates/server/src/db/session.rs +4 -10
- crates/server/src/error.rs +0 -1
- crates/server/src/hub.rs +0 -26
- crates/server/src/lib.rs +0 -3
- crates/server/src/network.rs +1 -26
- crates/server/src/request.rs +0 -1
- crates/server/src/update.rs +0 -274
- packaging/release-windows.ps1 +0 -22
- packaging/release.sh +0 -53
Cargo.lockmodified+0 -1
| @@ -1295,7 +1295,6 @@ dependencies = [ | |||
| 1295 | "quinn", | 1295 | "quinn", |
| 1296 | "reed-solomon-simd", | 1296 | "reed-solomon-simd", |
| 1297 | "resvg 0.50.0", | 1297 | "resvg 0.50.0", |
| 1298 | - "ring", | ||
| 1299 | "rtrb", | 1298 | "rtrb", |
| 1300 | "rustls-platform-verifier", | 1299 | "rustls-platform-verifier", |
| 1301 | "spectrum", | 1300 | "spectrum", |
crates/client/Cargo.tomlmodified+1 -2
| @@ -33,10 +33,8 @@ dirs = "7.0.0" | |||
| 33 | sys-locale = "0.3.2" | 33 | sys-locale = "0.3.2" |
| 34 | image = { version = "0.25.10", default-features = false, features = ["jpeg", "png", "webp", "gif"] } | 34 | image = { version = "0.25.10", default-features = false, features = ["jpeg", "png", "webp", "gif"] } |
| 35 | rtrb = "0.4.1" | 35 | rtrb = "0.4.1" |
| 36 | -ring = "0.17.14" | ||
| 37 | gethostname = "1.1.0" | 36 | gethostname = "1.1.0" |
| 38 | rustls-platform-verifier = "0.7.1" | 37 | rustls-platform-verifier = "0.7.1" |
| 39 | -sysinfo = { version = "0.40.4", default-features = false, features = ["system"] } | ||
| 40 | flate2 = "1.1.11" | 38 | flate2 = "1.1.11" |
| 41 | emojis = "0.9.1" | 39 | emojis = "0.9.1" |
| 42 | resvg = "0.50.0" | 40 | resvg = "0.50.0" |
| @@ -56,6 +54,7 @@ wasapi = "0.27.0" | |||
| 56 | windows-capture = "2.0.1" | 54 | windows-capture = "2.0.1" |
| 57 | tray-icon = { version = "0.27.0", default-features = false } | 55 | tray-icon = { version = "0.27.0", default-features = false } |
| 58 | winreg = "0.56.0" | 56 | winreg = "0.56.0" |
| 57 | +sysinfo = { version = "0.40.4", default-features = false, features = ["system"] } | ||
| 59 | 58 | ||
| 60 | [target.'cfg(target_os = "macos")'.dependencies] | 59 | [target.'cfg(target_os = "macos")'.dependencies] |
| 61 | coreaudio-rs = "0.14.2" | 60 | coreaudio-rs = "0.14.2" |
crates/client/lang/en/builder.txtmodified+0 -1
| @@ -6,7 +6,6 @@ storage = Storage | |||
| 6 | access = Access | 6 | access = Access |
| 7 | reports = Reports | 7 | reports = Reports |
| 8 | server = Server | 8 | server = Server |
| 9 | -release = Release | ||
| 10 | log = Log | 9 | log = Log |
| 11 | ghost = Ghost | 10 | ghost = Ghost |
| 12 | refresh = Refresh | 11 | refresh = Refresh |
crates/client/lang/en/builder_log.txtmodified+0 -1
| @@ -32,7 +32,6 @@ ghost_voice = {actor} listened in {community} as ghost for {seconds}s | |||
| 32 | backup_created = {actor} created backup {name} | 32 | backup_created = {actor} created backup {name} |
| 33 | backup_deleted = {actor} deleted backup {name} | 33 | backup_deleted = {actor} deleted backup {name} |
| 34 | backup_downloaded = {actor} exported backup {name} | 34 | backup_downloaded = {actor} exported backup {name} |
| 35 | -release_pushed = {actor} pushed release #{seq} (min {minimum}) | ||
| 36 | unknown_user = Unknown user | 35 | unknown_user = Unknown user |
| 37 | apply = Apply | 36 | apply = Apply |
| 38 | no_entries = No entries | 37 | no_entries = No entries |
crates/client/lang/en/builder_overview.txtmodified+0 -2
| @@ -5,5 +5,3 @@ in_voice = In voice | |||
| 5 | storage = Storage | 5 | storage = Storage |
| 6 | active_users = Active users | 6 | active_users = Active users |
| 7 | server = Server | 7 | server = Server |
| 8 | -versions = Versions | ||
| 9 | -dev = dev | ||
crates/client/lang/en/builder_release.txtdeleted+0 -28
| @@ -1,28 +0,0 @@ | |||
| 1 | -release = Release | ||
| 2 | -live = Live | ||
| 3 | -no_release = No release | ||
| 4 | -pipeline = Pipeline | ||
| 5 | -source = Source | ||
| 6 | -pick = Pick | ||
| 7 | -seq = Seq | ||
| 8 | -minimum = Min | ||
| 9 | -passphrase = Passphrase | ||
| 10 | -keys = Keys | ||
| 11 | -linux = Linux | ||
| 12 | -windows = Windows | ||
| 13 | -sign = Sign | ||
| 14 | -push = Push | ||
| 15 | -binaries = Binaries | ||
| 16 | -signed = Signed | ||
| 17 | -unsigned = Unsigned | ||
| 18 | -none = Nothing built | ||
| 19 | -log = Log | ||
| 20 | -not_source = Not a source folder | ||
| 21 | -live_line = #{seq} · min {minimum} · {version} | ||
| 22 | -keys_made = keys in {dir}; commit keys.rs, move backup.key offline | ||
| 23 | -built = {platform} built #{seq} | ||
| 24 | -signed_done = signed #{seq} | ||
| 25 | -uploaded = uploaded {name} | ||
| 26 | -pushed = live #{seq} | ||
| 27 | -again = Type the passphrase again, then Keys | ||
| 28 | -mismatch = Passphrases differ | ||
crates/client/lang/en/builder_users.txtmodified+0 -1
| @@ -7,7 +7,6 @@ confirm = Confirm | |||
| 7 | revoke = Revoke | 7 | revoke = Revoke |
| 8 | end_session = End this session | 8 | end_session = End this session |
| 9 | unknown_device = unknown device | 9 | unknown_device = unknown device |
| 10 | -dev = dev | ||
| 11 | ip_on = IP: on | 10 | ip_on = IP: on |
| 12 | ip_off = IP: off | 11 | ip_off = IP: off |
| 13 | manage = Manage | 12 | manage = Manage |
crates/client/lang/tr/builder.txtmodified+0 -1
| @@ -6,7 +6,6 @@ storage = Depolama | |||
| 6 | access = Erişim | 6 | access = Erişim |
| 7 | reports = Raporlar | 7 | reports = Raporlar |
| 8 | server = Sunucu | 8 | server = Sunucu |
| 9 | -release = Sürüm | ||
| 10 | log = Günlük | 9 | log = Günlük |
| 11 | ghost = Hayalet | 10 | ghost = Hayalet |
| 12 | refresh = Yenile | 11 | refresh = Yenile |
crates/client/lang/tr/builder_log.txtmodified+0 -1
| @@ -32,7 +32,6 @@ ghost_voice = {actor} hayalet olarak dinledi: {community} ({seconds} sn) | |||
| 32 | backup_created = {actor} yedek oluşturdu: {name} | 32 | backup_created = {actor} yedek oluşturdu: {name} |
| 33 | backup_deleted = {actor} yedeği sildi: {name} | 33 | backup_deleted = {actor} yedeği sildi: {name} |
| 34 | backup_downloaded = {actor} yedeği dışa aktardı: {name} | 34 | backup_downloaded = {actor} yedeği dışa aktardı: {name} |
| 35 | -release_pushed = {actor} #{seq} sürümünü yayınladı (en az {minimum}) | ||
| 36 | unknown_user = Bilinmeyen kullanıcı | 35 | unknown_user = Bilinmeyen kullanıcı |
| 37 | apply = Uygula | 36 | apply = Uygula |
| 38 | no_entries = Kayıt yok | 37 | no_entries = Kayıt yok |
crates/client/lang/tr/builder_overview.txtmodified+0 -2
| @@ -5,5 +5,3 @@ in_voice = Seste | |||
| 5 | storage = Depolama | 5 | storage = Depolama |
| 6 | active_users = Aktif kullanıcılar | 6 | active_users = Aktif kullanıcılar |
| 7 | server = Sunucu | 7 | server = Sunucu |
| 8 | -versions = Sürümler | ||
| 9 | -dev = geliştirme | ||
crates/client/lang/tr/builder_release.txtdeleted+0 -28
| @@ -1,28 +0,0 @@ | |||
| 1 | -release = Sürüm | ||
| 2 | -live = Canlı | ||
| 3 | -no_release = Sürüm yok | ||
| 4 | -pipeline = Hat | ||
| 5 | -source = Kaynak | ||
| 6 | -pick = Seç | ||
| 7 | -seq = Sıra | ||
| 8 | -minimum = Min | ||
| 9 | -passphrase = Parola | ||
| 10 | -keys = Anahtar | ||
| 11 | -linux = Linux | ||
| 12 | -windows = Windows | ||
| 13 | -sign = İmzala | ||
| 14 | -push = Gönder | ||
| 15 | -binaries = İkililer | ||
| 16 | -signed = İmzalı | ||
| 17 | -unsigned = İmzasız | ||
| 18 | -none = Derlenmedi | ||
| 19 | -log = Günlük | ||
| 20 | -not_source = Kaynak klasörü değil | ||
| 21 | -live_line = #{seq} · min {minimum} · {version} | ||
| 22 | -keys_made = {dir} içinde anahtarlar; keys.rs'i commit et, backup.key'i çevrimdışına taşı | ||
| 23 | -built = {platform} derlendi #{seq} | ||
| 24 | -signed_done = #{seq} imzalandı | ||
| 25 | -uploaded = {name} yüklendi | ||
| 26 | -pushed = canlı #{seq} | ||
| 27 | -again = Parolayı tekrar yazıp Anahtar'a bas | ||
| 28 | -mismatch = Parolalar farklı | ||
crates/client/lang/tr/builder_users.txtmodified+0 -1
| @@ -7,7 +7,6 @@ confirm = Onayla | |||
| 7 | revoke = İptal et | 7 | revoke = İptal et |
| 8 | end_session = Bu oturumu sonlandır | 8 | end_session = Bu oturumu sonlandır |
| 9 | unknown_device = bilinmeyen cihaz | 9 | unknown_device = bilinmeyen cihaz |
| 10 | -dev = geliştirme | ||
| 11 | ip_on = IP: açık | 10 | ip_on = IP: açık |
| 12 | ip_off = IP: kapalı | 11 | ip_off = IP: kapalı |
| 13 | manage = Yönet | 12 | manage = Yönet |
crates/client/src/cpu.rsdeleted+0 -25
| @@ -1,25 +0,0 @@ | |||
| 1 | -#[cfg(target_arch = "x86_64")] | ||
| 2 | -pub fn levels() -> impl Iterator<Item = &'static str> { | ||
| 3 | - let v3 = std::arch::is_x86_feature_detected!("avx2") | ||
| 4 | - && std::arch::is_x86_feature_detected!("bmi1") | ||
| 5 | - && std::arch::is_x86_feature_detected!("bmi2") | ||
| 6 | - && std::arch::is_x86_feature_detected!("fma") | ||
| 7 | - && std::arch::is_x86_feature_detected!("lzcnt") | ||
| 8 | - && std::arch::is_x86_feature_detected!("movbe") | ||
| 9 | - && std::arch::is_x86_feature_detected!("f16c"); | ||
| 10 | - let v4 = v3 | ||
| 11 | - && std::arch::is_x86_feature_detected!("avx512f") | ||
| 12 | - && std::arch::is_x86_feature_detected!("avx512bw") | ||
| 13 | - && std::arch::is_x86_feature_detected!("avx512cd") | ||
| 14 | - && std::arch::is_x86_feature_detected!("avx512dq") | ||
| 15 | - && std::arch::is_x86_feature_detected!("avx512vl"); | ||
| 16 | - [("v4", v4), ("v3", v3), ("v1", true)] | ||
| 17 | - .into_iter() | ||
| 18 | - .filter(|(_, supported)| *supported) | ||
| 19 | - .map(|(level, _)| level) | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -#[cfg(not(target_arch = "x86_64"))] | ||
| 23 | -pub fn levels() -> impl Iterator<Item = &'static str> { | ||
| 24 | - std::iter::empty() | ||
| 25 | -} | ||
crates/client/src/gui.rsmodified+0 -20
| @@ -603,14 +603,6 @@ pub struct Yumush { | |||
| 603 | deferred: Vec<NetworkEvent>, | 603 | deferred: Vec<NetworkEvent>, |
| 604 | backups: Vec<BackupInfo>, | 604 | backups: Vec<BackupInfo>, |
| 605 | pending_backup_delete: Option<String>, | 605 | pending_backup_delete: Option<String>, |
| 606 | - release: Option<common::model::Release>, | ||
| 607 | - release_seq: Entity<InputState>, | ||
| 608 | - release_minimum: Entity<InputState>, | ||
| 609 | - release_passphrase: Entity<InputState>, | ||
| 610 | - release_log: Vec<String>, | ||
| 611 | - release_busy: bool, | ||
| 612 | - pending_release_push: Option<()>, | ||
| 613 | - release_first_passphrase: Option<String>, | ||
| 614 | share_apps: Vec<crate::share::audio::AudioApp>, | 606 | share_apps: Vec<crate::share::audio::AudioApp>, |
| 615 | share_apps_seen: std::cell::Cell<Instant>, | 607 | share_apps_seen: std::cell::Cell<Instant>, |
| 616 | share_apps_task: Option<gpui_kit::Task<()>>, | 608 | share_apps_task: Option<gpui_kit::Task<()>>, |
| @@ -669,10 +661,6 @@ impl Yumush { | |||
| 669 | 661 | ||
| 670 | let server = network.server(); | 662 | let server = network.server(); |
| 671 | let account_filter = new_input(w().auth.find_account, window, cx); | 663 | let account_filter = new_input(w().auth.find_account, window, cx); |
| 672 | - let release_seq = new_input(w().builder_release.seq, window, cx); | ||
| 673 | - let release_minimum = new_input(w().builder_release.minimum, window, cx); | ||
| 674 | - let release_passphrase = new_input(w().builder_release.passphrase, window, cx); | ||
| 675 | - release_passphrase.update(cx, |input, cx| input.set_masked(true, window, cx)); | ||
| 676 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { | 664 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { |
| 677 | if matches!(event, InputEvent::Change) { | 665 | if matches!(event, InputEvent::Change) { |
| 678 | cx.notify(); | 666 | cx.notify(); |
| @@ -697,14 +685,6 @@ impl Yumush { | |||
| 697 | deferred: Vec::new(), | 685 | deferred: Vec::new(), |
| 698 | backups: Vec::new(), | 686 | backups: Vec::new(), |
| 699 | pending_backup_delete: None, | 687 | pending_backup_delete: None, |
| 700 | - release: None, | ||
| 701 | - release_seq, | ||
| 702 | - release_minimum, | ||
| 703 | - release_passphrase, | ||
| 704 | - release_log: Vec::new(), | ||
| 705 | - release_busy: false, | ||
| 706 | - pending_release_push: None, | ||
| 707 | - release_first_passphrase: None, | ||
| 708 | share_apps: Vec::new(), | 688 | share_apps: Vec::new(), |
| 709 | share_apps_seen: std::cell::Cell::new(Instant::now()), | 689 | share_apps_seen: std::cell::Cell::new(Instant::now()), |
| 710 | share_apps_task: None, | 690 | share_apps_task: None, |
crates/client/src/gui/builder.rsmodified+1 -8
| @@ -4,7 +4,6 @@ mod communities; | |||
| 4 | mod log; | 4 | mod log; |
| 5 | mod messages; | 5 | mod messages; |
| 6 | mod overview; | 6 | mod overview; |
| 7 | -mod release; | ||
| 8 | mod reports; | 7 | mod reports; |
| 9 | mod server; | 8 | mod server; |
| 10 | mod storage; | 9 | mod storage; |
| @@ -54,12 +53,11 @@ pub(super) enum BuilderTab { | |||
| 54 | Access, | 53 | Access, |
| 55 | Reports, | 54 | Reports, |
| 56 | Server, | 55 | Server, |
| 57 | - Release, | ||
| 58 | Log, | 56 | Log, |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | impl BuilderTab { | 59 | impl BuilderTab { |
| 62 | - pub(super) const ALL: [Self; 11] = [ | 60 | + pub(super) const ALL: [Self; 10] = [ |
| 63 | Self::Overview, | 61 | Self::Overview, |
| 64 | Self::Users, | 62 | Self::Users, |
| 65 | Self::Communities, | 63 | Self::Communities, |
| @@ -69,7 +67,6 @@ impl BuilderTab { | |||
| 69 | Self::Access, | 67 | Self::Access, |
| 70 | Self::Reports, | 68 | Self::Reports, |
| 71 | Self::Server, | 69 | Self::Server, |
| 72 | - Self::Release, | ||
| 73 | Self::Log, | 70 | Self::Log, |
| 74 | ]; | 71 | ]; |
| 75 | 72 | ||
| @@ -84,7 +81,6 @@ impl BuilderTab { | |||
| 84 | Self::Access => "access", | 81 | Self::Access => "access", |
| 85 | Self::Reports => "reports", | 82 | Self::Reports => "reports", |
| 86 | Self::Server => "server", | 83 | Self::Server => "server", |
| 87 | - Self::Release => "release", | ||
| 88 | Self::Log => "log", | 84 | Self::Log => "log", |
| 89 | } | 85 | } |
| 90 | } | 86 | } |
| @@ -101,7 +97,6 @@ impl BuilderTab { | |||
| 101 | Self::Access => w.access, | 97 | Self::Access => w.access, |
| 102 | Self::Reports => w.reports, | 98 | Self::Reports => w.reports, |
| 103 | Self::Server => w.server, | 99 | Self::Server => w.server, |
| 104 | - Self::Release => w.release, | ||
| 105 | Self::Log => w.log, | 100 | Self::Log => w.log, |
| 106 | } | 101 | } |
| 107 | } | 102 | } |
| @@ -136,7 +131,6 @@ impl Yumush { | |||
| 136 | BuilderTab::Access => self.access_body(entity, palette), | 131 | BuilderTab::Access => self.access_body(entity, palette), |
| 137 | BuilderTab::Reports => self.reports_body(entity, palette), | 132 | BuilderTab::Reports => self.reports_body(entity, palette), |
| 138 | BuilderTab::Server => self.server_body(entity, palette), | 133 | BuilderTab::Server => self.server_body(entity, palette), |
| 139 | - BuilderTab::Release => self.release_body(entity, palette, cx), | ||
| 140 | BuilderTab::Log => self.log_body(entity, palette), | 134 | BuilderTab::Log => self.log_body(entity, palette), |
| 141 | }; | 135 | }; |
| 142 | let mut sections = vec![ | 136 | let mut sections = vec![ |
| @@ -288,7 +282,6 @@ impl Yumush { | |||
| 288 | BuilderTab::Access => self.load_access(window, cx), | 282 | BuilderTab::Access => self.load_access(window, cx), |
| 289 | BuilderTab::Reports => self.load_reports(window, cx), | 283 | BuilderTab::Reports => self.load_reports(window, cx), |
| 290 | BuilderTab::Server => {} | 284 | BuilderTab::Server => {} |
| 291 | - BuilderTab::Release => self.load_release(window, cx), | ||
| 292 | BuilderTab::Log => { | 285 | BuilderTab::Log => { |
| 293 | self.load_users(window, cx); | 286 | self.load_users(window, cx); |
| 294 | self.load_builder_logs(window, cx); | 287 | self.load_builder_logs(window, cx); |
crates/client/src/gui/builder/log.rsmodified+1 -3
| @@ -75,7 +75,6 @@ fn builder_log_text(entry: &AdminLogEntry) -> String { | |||
| 75 | AdminAction::BackupCreated { name } => words.backup_created(actor, name), | 75 | AdminAction::BackupCreated { name } => words.backup_created(actor, name), |
| 76 | AdminAction::BackupDeleted { name } => words.backup_deleted(actor, name), | 76 | AdminAction::BackupDeleted { name } => words.backup_deleted(actor, name), |
| 77 | AdminAction::BackupDownloaded { name } => words.backup_downloaded(actor, name), | 77 | AdminAction::BackupDownloaded { name } => words.backup_downloaded(actor, name), |
| 78 | - AdminAction::ReleasePushed { seq, minimum } => words.release_pushed(actor, minimum, seq), | ||
| 79 | } | 78 | } |
| 80 | } | 79 | } |
| 81 | 80 | ||
| @@ -167,8 +166,7 @@ fn action_icon(action: &AdminAction) -> IconName { | |||
| 167 | | AdminAction::GhostVoice { .. } => IconName::Eye, | 166 | | AdminAction::GhostVoice { .. } => IconName::Eye, |
| 168 | AdminAction::BackupCreated { .. } | 167 | AdminAction::BackupCreated { .. } |
| 169 | | AdminAction::BackupDeleted { .. } | 168 | | AdminAction::BackupDeleted { .. } |
| 170 | - | AdminAction::BackupDownloaded { .. } | 169 | + | AdminAction::BackupDownloaded { .. } => IconName::HardDrive, |
| 171 | - | AdminAction::ReleasePushed { .. } => IconName::HardDrive, | ||
| 172 | } | 170 | } |
| 173 | } | 171 | } |
| 174 | 172 | ||
crates/client/src/gui/builder/overview.rsmodified+0 -27
| @@ -223,33 +223,6 @@ impl Yumush { | |||
| 223 | palette, | 223 | palette, |
| 224 | )), | 224 | )), |
| 225 | ); | 225 | ); |
| 226 | - if !overview.releases.is_empty() { | ||
| 227 | - rows.push( | ||
| 228 | - card(palette) | ||
| 229 | - .child(card_header( | ||
| 230 | - w().builder_overview.versions, | ||
| 231 | - Vec::new(), | ||
| 232 | - palette, | ||
| 233 | - )) | ||
| 234 | - .child( | ||
| 235 | - div() | ||
| 236 | - .pt(px(space::SM)) | ||
| 237 | - .flex() | ||
| 238 | - .flex_wrap() | ||
| 239 | - .gap(px(space::MD)) | ||
| 240 | - .children(overview.releases.iter().map(|count| { | ||
| 241 | - let label = count.release.map_or_else( | ||
| 242 | - || w().builder_overview.dev.to_string(), | ||
| 243 | - |release| format!("#{release}"), | ||
| 244 | - ); | ||
| 245 | - div() | ||
| 246 | - .text_size(text(text::LABEL)) | ||
| 247 | - .text_color(palette.text) | ||
| 248 | - .child(format!("{label} · {}", count.clients)) | ||
| 249 | - })), | ||
| 250 | - ), | ||
| 251 | - ); | ||
| 252 | - } | ||
| 253 | if let Some(stats) = &self.chat.server_stats { | 226 | if let Some(stats) = &self.chat.server_stats { |
| 254 | rows.push( | 227 | rows.push( |
| 255 | card(palette) | 228 | card(palette) |
crates/client/src/gui/builder/release.rsdeleted+0 -498
| @@ -1,498 +0,0 @@ | |||
| 1 | -use std::{fmt::Display, fs, path::PathBuf}; | ||
| 2 | - | ||
| 3 | -use common::{ | ||
| 4 | - call::{GetRelease, PushRelease}, | ||
| 5 | - model::Release, | ||
| 6 | -}; | ||
| 7 | -use gpui_kit::{ | ||
| 8 | - AnyElement, App, AsyncWindowContext, Context, Div, Entity, IntoElement, ParentElement, | ||
| 9 | - PathPromptOptions, Styled, WeakEntity, Window, | ||
| 10 | - component::{WindowExt, notification::Notification}, | ||
| 11 | - div, | ||
| 12 | -}; | ||
| 13 | - | ||
| 14 | -use crate::gui::glyph::Fill as _; | ||
| 15 | - | ||
| 16 | -use super::ui::{confirmed, field_row, list_card, list_row, toolbar}; | ||
| 17 | -use crate::{ | ||
| 18 | - gui::{ | ||
| 19 | - MONO_FONT, Palette, Yumush, entity_action, notify_error, | ||
| 20 | - parts::{self, Press}, | ||
| 21 | - storage, | ||
| 22 | - style::text, | ||
| 23 | - text, | ||
| 24 | - widget::field, | ||
| 25 | - }, | ||
| 26 | - lang::w, | ||
| 27 | - net::NetworkHandle, | ||
| 28 | - release::{self, Platform, ReleaseError}, | ||
| 29 | - settings, | ||
| 30 | -}; | ||
| 31 | - | ||
| 32 | -const LOG_LINES: usize = 300; | ||
| 33 | -const LOG_VIEW: usize = 40; | ||
| 34 | - | ||
| 35 | -fn text_of(input: &Entity<gpui_kit::component::input::InputState>, cx: &App) -> String { | ||
| 36 | - input.read(cx).text().to_string() | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -fn set_text( | ||
| 40 | - input: &Entity<gpui_kit::component::input::InputState>, | ||
| 41 | - value: &str, | ||
| 42 | - window: &mut Window, | ||
| 43 | - cx: &mut App, | ||
| 44 | -) { | ||
| 45 | - input.update(cx, |input, cx| input.fill(value, window, cx)); | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | -fn platform_label(platform: Platform) -> &'static str { | ||
| 49 | - let words = &w().builder_release; | ||
| 50 | - match platform { | ||
| 51 | - Platform::Linux => words.linux, | ||
| 52 | - Platform::Windows => words.windows, | ||
| 53 | - } | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -fn text_row(label: String, value: Option<String>, palette: Palette) -> Div { | ||
| 57 | - list_row() | ||
| 58 | - .child( | ||
| 59 | - div() | ||
| 60 | - .flex_1() | ||
| 61 | - .min_w_0() | ||
| 62 | - .truncate() | ||
| 63 | - .text_size(text(text::LABEL)) | ||
| 64 | - .text_color(palette.text) | ||
| 65 | - .child(label), | ||
| 66 | - ) | ||
| 67 | - .children(value.map(|value| { | ||
| 68 | - div() | ||
| 69 | - .flex_shrink_0() | ||
| 70 | - .text_size(text(text::CAPTION)) | ||
| 71 | - .text_color(palette.muted) | ||
| 72 | - .child(value) | ||
| 73 | - })) | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -fn release_button( | ||
| 77 | - id: String, | ||
| 78 | - label: &'static str, | ||
| 79 | - enabled: bool, | ||
| 80 | - palette: Palette, | ||
| 81 | - entity: &Entity<Yumush>, | ||
| 82 | - run: impl Fn(&mut Yumush, &mut Window, &mut Context<Yumush>) + 'static, | ||
| 83 | -) -> AnyElement { | ||
| 84 | - parts::button( | ||
| 85 | - id, | ||
| 86 | - label, | ||
| 87 | - if enabled { Press::Plain } else { Press::Off }, | ||
| 88 | - palette.tokens, | ||
| 89 | - entity_action(entity, move |yumush, window, cx| { | ||
| 90 | - if enabled { | ||
| 91 | - run(yumush, window, cx) | ||
| 92 | - } | ||
| 93 | - }), | ||
| 94 | - ) | ||
| 95 | - .into_any_element() | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -async fn push_release( | ||
| 99 | - network: &NetworkHandle, | ||
| 100 | - this: &WeakEntity<Yumush>, | ||
| 101 | - cx: &mut AsyncWindowContext, | ||
| 102 | - files: Vec<(String, PathBuf)>, | ||
| 103 | - signed: Vec<u8>, | ||
| 104 | -) -> Result<Release, String> { | ||
| 105 | - for (name, path) in files { | ||
| 106 | - let line = w().builder_release.uploaded(&name); | ||
| 107 | - let _ = this.update(cx, |yumush, cx| yumush.release_line(line, cx)); | ||
| 108 | - network | ||
| 109 | - .publish(name, path) | ||
| 110 | - .await | ||
| 111 | - .map_err(|error| error.to_string())?; | ||
| 112 | - } | ||
| 113 | - network | ||
| 114 | - .call(PushRelease { manifest: signed }) | ||
| 115 | - .await | ||
| 116 | - .map_err(|error| error.to_string()) | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | -impl Yumush { | ||
| 120 | - fn release_source(&self) -> Option<PathBuf> { | ||
| 121 | - self.settings | ||
| 122 | - .release_source | ||
| 123 | - .clone() | ||
| 124 | - .filter(|path| release::is_source(path)) | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - fn release_seq_value(&self, cx: &App) -> Option<u64> { | ||
| 128 | - text_of(&self.release_seq, cx) | ||
| 129 | - .trim() | ||
| 130 | - .parse() | ||
| 131 | - .ok() | ||
| 132 | - .filter(|seq| *seq > 0) | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - fn release_minimum_value(&self, cx: &App) -> Option<u64> { | ||
| 136 | - text_of(&self.release_minimum, cx) | ||
| 137 | - .trim() | ||
| 138 | - .parse() | ||
| 139 | - .ok() | ||
| 140 | - .filter(|minimum| *minimum > 0) | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - fn release_line(&mut self, line: String, cx: &mut Context<Self>) { | ||
| 144 | - self.release_log.push(line); | ||
| 145 | - let extra = self.release_log.len().saturating_sub(LOG_LINES); | ||
| 146 | - self.release_log.drain(..extra); | ||
| 147 | - cx.notify(); | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - fn release_fail(&mut self, error: impl Display, window: &mut Window, cx: &mut Context<Self>) { | ||
| 151 | - let message = error.to_string(); | ||
| 152 | - self.release_line(message.clone(), cx); | ||
| 153 | - window.push_notification(Notification::error(message), cx); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - fn run_release<T: Send + 'static>( | ||
| 157 | - &mut self, | ||
| 158 | - window: &mut Window, | ||
| 159 | - cx: &mut Context<Self>, | ||
| 160 | - work: impl FnOnce(&dyn Fn(String)) -> Result<T, ReleaseError> + Send + 'static, | ||
| 161 | - done: impl FnOnce(&mut Self, &mut Window, &mut Context<Self>, Result<T, ReleaseError>) + 'static, | ||
| 162 | - ) { | ||
| 163 | - self.release_busy = true; | ||
| 164 | - let (lines, mut received) = tokio::sync::mpsc::unbounded_channel::<String>(); | ||
| 165 | - let (outcome, reply) = tokio::sync::oneshot::channel(); | ||
| 166 | - std::thread::spawn(move || { | ||
| 167 | - let emit = |line: String| { | ||
| 168 | - let _ = lines.send(line); | ||
| 169 | - }; | ||
| 170 | - let _ = outcome.send(work(&emit)); | ||
| 171 | - }); | ||
| 172 | - | ||
| 173 | - cx.spawn_in(window, async move |this, cx| { | ||
| 174 | - while let Some(line) = received.recv().await { | ||
| 175 | - let _ = this.update(cx, |yumush, cx| yumush.release_line(line, cx)); | ||
| 176 | - } | ||
| 177 | - let result = reply.await; | ||
| 178 | - let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 179 | - yumush.release_busy = false; | ||
| 180 | - match result { | ||
| 181 | - Ok(result) => done(yumush, window, cx, result), | ||
| 182 | - Err(_) => yumush.release_fail(ReleaseError::Build, window, cx), | ||
| 183 | - } | ||
| 184 | - cx.notify(); | ||
| 185 | - }); | ||
| 186 | - }) | ||
| 187 | - .detach(); | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - pub(super) fn load_release(&self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 191 | - if !self.is_builder() { | ||
| 192 | - return; | ||
| 193 | - } | ||
| 194 | - let network = self.network.clone(); | ||
| 195 | - | ||
| 196 | - cx.spawn_in(window, async move |this, cx| { | ||
| 197 | - let live = match network.call(GetRelease).await { | ||
| 198 | - Ok(live) => live, | ||
| 199 | - Err(error) => { | ||
| 200 | - notify_error(&this, cx, error); | ||
| 201 | - return; | ||
| 202 | - } | ||
| 203 | - }; | ||
| 204 | - let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 205 | - yumush.apply_release(live, window, cx) | ||
| 206 | - }); | ||
| 207 | - }) | ||
| 208 | - .detach(); | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - fn apply_release( | ||
| 212 | - &mut self, | ||
| 213 | - live: Option<Release>, | ||
| 214 | - window: &mut Window, | ||
| 215 | - cx: &mut Context<Self>, | ||
| 216 | - ) { | ||
| 217 | - let live_seq = live.as_ref().map(|release| release.seq); | ||
| 218 | - let minimum = live.as_ref().map_or(1, |release| release.minimum); | ||
| 219 | - self.release = live; | ||
| 220 | - if let Some(source) = self.release_source() { | ||
| 221 | - let seq = release::next_seq(&source, live_seq); | ||
| 222 | - set_text(&self.release_seq, &seq.to_string(), window, cx); | ||
| 223 | - set_text(&self.release_minimum, &minimum.to_string(), window, cx); | ||
| 224 | - } | ||
| 225 | - cx.notify(); | ||
| 226 | - } | ||
| 227 | - | ||
| 228 | - fn pick_release_source(&self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 229 | - let picked = cx.prompt_for_paths(PathPromptOptions { | ||
| 230 | - files: false, | ||
| 231 | - directories: true, | ||
| 232 | - multiple: false, | ||
| 233 | - prompt: None, | ||
| 234 | - }); | ||
| 235 | - | ||
| 236 | - cx.spawn_in(window, async move |this, cx| { | ||
| 237 | - let Ok(Ok(Some(paths))) = picked.await else { | ||
| 238 | - return; | ||
| 239 | - }; | ||
| 240 | - let Some(path) = paths.into_iter().next() else { | ||
| 241 | - return; | ||
| 242 | - }; | ||
| 243 | - let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 244 | - if !release::is_source(&path) { | ||
| 245 | - window | ||
| 246 | - .push_notification(Notification::error(w().builder_release.not_source), cx); | ||
| 247 | - return; | ||
| 248 | - } | ||
| 249 | - yumush.settings.release_source = Some(path); | ||
| 250 | - settings::save(&yumush.settings); | ||
| 251 | - yumush.load_release(window, cx); | ||
| 252 | - }); | ||
| 253 | - }) | ||
| 254 | - .detach(); | ||
| 255 | - } | ||
| 256 | - | ||
| 257 | - fn release_keys(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 258 | - let Some(source) = self.release_source() else { | ||
| 259 | - return; | ||
| 260 | - }; | ||
| 261 | - let passphrase = text_of(&self.release_passphrase, cx); | ||
| 262 | - set_text(&self.release_passphrase, "", window, cx); | ||
| 263 | - let Some(first) = self.release_first_passphrase.take() else { | ||
| 264 | - self.release_first_passphrase = Some(passphrase); | ||
| 265 | - self.release_line(w().builder_release.again.to_string(), cx); | ||
| 266 | - return; | ||
| 267 | - }; | ||
| 268 | - if first != passphrase { | ||
| 269 | - self.release_fail(w().builder_release.mismatch, window, cx); | ||
| 270 | - return; | ||
| 271 | - } | ||
| 272 | - self.run_release( | ||
| 273 | - window, | ||
| 274 | - cx, | ||
| 275 | - move |_| release::keygen(&source, &passphrase), | ||
| 276 | - |yumush, window, cx, result| match result { | ||
| 277 | - Ok(dir) => { | ||
| 278 | - let line = w().builder_release.keys_made(dir.display()); | ||
| 279 | - yumush.release_line(line, cx); | ||
| 280 | - } | ||
| 281 | - Err(error) => yumush.release_fail(error, window, cx), | ||
| 282 | - }, | ||
| 283 | - ); | ||
| 284 | - } | ||
| 285 | - | ||
| 286 | - fn release_build(&mut self, platform: Platform, window: &mut Window, cx: &mut Context<Self>) { | ||
| 287 | - let (Some(source), Some(seq)) = (self.release_source(), self.release_seq_value(cx)) else { | ||
| 288 | - return; | ||
| 289 | - }; | ||
| 290 | - self.run_release( | ||
| 291 | - window, | ||
| 292 | - cx, | ||
| 293 | - move |emit| release::build(&source, platform, seq, emit), | ||
| 294 | - move |yumush, window, cx, result| match result { | ||
| 295 | - Ok(()) => { | ||
| 296 | - let line = w().builder_release.built(platform_label(platform), seq); | ||
| 297 | - yumush.release_line(line, cx); | ||
| 298 | - } | ||
| 299 | - Err(error) => yumush.release_fail(error, window, cx), | ||
| 300 | - }, | ||
| 301 | - ); | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | - fn release_sign(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 305 | - let (Some(source), Some(seq), Some(minimum)) = ( | ||
| 306 | - self.release_source(), | ||
| 307 | - self.release_seq_value(cx), | ||
| 308 | - self.release_minimum_value(cx), | ||
| 309 | - ) else { | ||
| 310 | - return; | ||
| 311 | - }; | ||
| 312 | - let passphrase = text_of(&self.release_passphrase, cx); | ||
| 313 | - set_text(&self.release_passphrase, "", window, cx); | ||
| 314 | - self.run_release( | ||
| 315 | - window, | ||
| 316 | - cx, | ||
| 317 | - move |_| release::sign(&source, seq, minimum, &passphrase), | ||
| 318 | - move |yumush, window, cx, result| match result { | ||
| 319 | - Ok(_) => { | ||
| 320 | - let line = w().builder_release.signed_done(seq); | ||
| 321 | - yumush.release_line(line, cx); | ||
| 322 | - } | ||
| 323 | - Err(error) => yumush.release_fail(error, window, cx), | ||
| 324 | - }, | ||
| 325 | - ); | ||
| 326 | - } | ||
| 327 | - | ||
| 328 | - fn release_push(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 329 | - let (Some(source), Some(seq)) = (self.release_source(), self.release_seq_value(cx)) else { | ||
| 330 | - return; | ||
| 331 | - }; | ||
| 332 | - let Some(signed) = release::signed(&source, seq) else { | ||
| 333 | - return; | ||
| 334 | - }; | ||
| 335 | - let Some(files) = release::uploads(&signed, &source) else { | ||
| 336 | - return; | ||
| 337 | - }; | ||
| 338 | - if !confirmed(&mut self.pending_release_push, ()) { | ||
| 339 | - cx.notify(); | ||
| 340 | - return; | ||
| 341 | - } | ||
| 342 | - self.release_busy = true; | ||
| 343 | - let network = self.network.clone(); | ||
| 344 | - | ||
| 345 | - cx.spawn_in(window, async move |this, cx| { | ||
| 346 | - let outcome = push_release(&network, &this, cx, files, signed).await; | ||
| 347 | - let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 348 | - yumush.release_busy = false; | ||
| 349 | - match outcome { | ||
| 350 | - Ok(release) => { | ||
| 351 | - let line = w().builder_release.pushed(release.seq); | ||
| 352 | - yumush.release_line(line, cx); | ||
| 353 | - yumush.load_release(window, cx); | ||
| 354 | - } | ||
| 355 | - Err(error) => yumush.release_fail(error, window, cx), | ||
| 356 | - } | ||
| 357 | - }); | ||
| 358 | - }) | ||
| 359 | - .detach(); | ||
| 360 | - } | ||
| 361 | - | ||
| 362 | - pub(super) fn release_body( | ||
| 363 | - &self, | ||
| 364 | - entity: &Entity<Self>, | ||
| 365 | - palette: Palette, | ||
| 366 | - cx: &App, | ||
| 367 | - ) -> Vec<AnyElement> { | ||
| 368 | - let words = &w().builder_release; | ||
| 369 | - let source = self.release_source(); | ||
| 370 | - let seq = self.release_seq_value(cx); | ||
| 371 | - let minimum = self.release_minimum_value(cx); | ||
| 372 | - let ready = source.is_some() && !self.release_busy; | ||
| 373 | - let build_ready = ready && seq.is_some(); | ||
| 374 | - let sign_ready = build_ready && minimum.is_some(); | ||
| 375 | - let signed = match (&source, seq) { | ||
| 376 | - (Some(source), Some(seq)) => release::signed(source, seq), | ||
| 377 | - _ => None, | ||
| 378 | - }; | ||
| 379 | - let push_ready = ready && signed.is_some(); | ||
| 380 | - | ||
| 381 | - let live_rows: Vec<Div> = match &self.release { | ||
| 382 | - Some(live) => vec![text_row( | ||
| 383 | - words.live_line(live.minimum, live.seq, &live.version), | ||
| 384 | - None, | ||
| 385 | - palette, | ||
| 386 | - )], | ||
| 387 | - None => Vec::new(), | ||
| 388 | - }; | ||
| 389 | - | ||
| 390 | - let mut buttons = Vec::new(); | ||
| 391 | - if source | ||
| 392 | - .as_ref() | ||
| 393 | - .is_some_and(|source| release::trusted(source).is_empty()) | ||
| 394 | - { | ||
| 395 | - buttons.push(release_button( | ||
| 396 | - "release_keys".to_string(), | ||
| 397 | - words.keys, | ||
| 398 | - ready, | ||
| 399 | - palette, | ||
| 400 | - entity, | ||
| 401 | - |yumush, window, cx| yumush.release_keys(window, cx), | ||
| 402 | - )); | ||
| 403 | - } | ||
| 404 | - for platform in Platform::ALL { | ||
| 405 | - buttons.push(release_button( | ||
| 406 | - format!("release_build_{platform:?}"), | ||
| 407 | - platform_label(platform), | ||
| 408 | - build_ready, | ||
| 409 | - palette, | ||
| 410 | - entity, | ||
| 411 | - move |yumush, window, cx| yumush.release_build(platform, window, cx), | ||
| 412 | - )); | ||
| 413 | - } | ||
| 414 | - buttons.push(release_button( | ||
| 415 | - "release_sign".to_string(), | ||
| 416 | - words.sign, | ||
| 417 | - sign_ready, | ||
| 418 | - palette, | ||
| 419 | - entity, | ||
| 420 | - |yumush, window, cx| yumush.release_sign(window, cx), | ||
| 421 | - )); | ||
| 422 | - let push_label = if self.pending_release_push.is_some() { | ||
| 423 | - w().builder_ui.confirm | ||
| 424 | - } else { | ||
| 425 | - words.push | ||
| 426 | - }; | ||
| 427 | - buttons.push(release_button( | ||
| 428 | - "release_push".to_string(), | ||
| 429 | - push_label, | ||
| 430 | - push_ready, | ||
| 431 | - palette, | ||
| 432 | - entity, | ||
| 433 | - |yumush, window, cx| yumush.release_push(window, cx), | ||
| 434 | - )); | ||
| 435 | - | ||
| 436 | - let hint = source.as_ref().map(|path| path.display().to_string()); | ||
| 437 | - let pick = parts::button( | ||
| 438 | - "release_pick", | ||
| 439 | - words.pick, | ||
| 440 | - Press::Plain, | ||
| 441 | - palette.tokens, | ||
| 442 | - entity_action(entity, |yumush, window, cx| { | ||
| 443 | - yumush.pick_release_source(window, cx) | ||
| 444 | - }), | ||
| 445 | - ) | ||
| 446 | - .into_any_element(); | ||
| 447 | - let pipeline_rows: Vec<Div> = vec![ | ||
| 448 | - field_row(words.source, hint.as_deref(), pick, palette), | ||
| 449 | - field_row(words.seq, None, field(palette, &self.release_seq), palette), | ||
| 450 | - field_row( | ||
| 451 | - words.minimum, | ||
| 452 | - None, | ||
| 453 | - field(palette, &self.release_minimum), | ||
| 454 | - palette, | ||
| 455 | - ), | ||
| 456 | - field_row( | ||
| 457 | - words.passphrase, | ||
| 458 | - None, | ||
| 459 | - field(palette, &self.release_passphrase), | ||
| 460 | - palette, | ||
| 461 | - ), | ||
| 462 | - list_row().child(toolbar(buttons)), | ||
| 463 | - ]; | ||
| 464 | - | ||
| 465 | - let mut binary_rows = vec![text_row( | ||
| 466 | - if signed.is_some() { | ||
| 467 | - words.signed.to_string() | ||
| 468 | - } else { | ||
| 469 | - words.unsigned.to_string() | ||
| 470 | - }, | ||
| 471 | - None, | ||
| 472 | - palette, | ||
| 473 | - )]; | ||
| 474 | - if let (Some(source), Some(seq)) = (&source, seq) { | ||
| 475 | - binary_rows.extend( | ||
| 476 | - release::binaries(source, seq) | ||
| 477 | - .into_iter() | ||
| 478 | - .map(|(name, path)| { | ||
| 479 | - let size = fs::metadata(&path).map_or(0, |meta| meta.len()); | ||
| 480 | - text_row(name, Some(storage(size)), palette) | ||
| 481 | - }), | ||
| 482 | - ); | ||
| 483 | - } | ||
| 484 | - | ||
| 485 | - let start = self.release_log.len().saturating_sub(LOG_VIEW); | ||
| 486 | - let log_rows: Vec<Div> = self.release_log[start..] | ||
| 487 | - .iter() | ||
| 488 | - .map(|line| text_row(line.clone(), None, palette).font_family(MONO_FONT)) | ||
| 489 | - .collect(); | ||
| 490 | - | ||
| 491 | - vec![ | ||
| 492 | - list_card(Some(words.live), live_rows, words.no_release, palette).into_any_element(), | ||
| 493 | - list_card(Some(words.pipeline), pipeline_rows, "", palette).into_any_element(), | ||
| 494 | - list_card(Some(words.binaries), binary_rows, words.none, palette).into_any_element(), | ||
| 495 | - list_card(Some(words.log), log_rows, "", palette).into_any_element(), | ||
| 496 | - ] | ||
| 497 | - } | ||
| 498 | -} | ||
crates/client/src/gui/builder/users.rsmodified+0 -10
| @@ -657,16 +657,6 @@ impl Yumush { | |||
| 657 | .truncate() | 657 | .truncate() |
| 658 | .child(device.to_string()), | 658 | .child(device.to_string()), |
| 659 | ) | 659 | ) |
| 660 | - .child( | ||
| 661 | - div() | ||
| 662 | - .flex_shrink_0() | ||
| 663 | - .text_size(text(text::CAPTION)) | ||
| 664 | - .text_color(palette.muted) | ||
| 665 | - .child(session.release.map_or_else( | ||
| 666 | - || w().builder_users.dev.to_string(), | ||
| 667 | - |release| format!("#{release}"), | ||
| 668 | - )), | ||
| 669 | - ) | ||
| 670 | .child( | 660 | .child( |
| 671 | div() | 661 | div() |
| 672 | .flex_shrink_0() | 662 | .flex_shrink_0() |
crates/client/src/gui/chat.rsmodified+1 -1
| @@ -799,7 +799,7 @@ impl Chat { | |||
| 799 | followed.1 = stats; | 799 | followed.1 = stats; |
| 800 | } | 800 | } |
| 801 | } | 801 | } |
| 802 | - Event::ReportCreated | Event::SettingsUpdated(_) | Event::Release => {} | 802 | + Event::ReportCreated | Event::SettingsUpdated(_) => {} |
| 803 | } | 803 | } |
| 804 | } | 804 | } |
| 805 | 805 | ||
crates/client/src/gui/parts.rsmodified+0 -3
| @@ -250,7 +250,6 @@ pub enum Press { | |||
| 250 | Plain, | 250 | Plain, |
| 251 | Primary, | 251 | Primary, |
| 252 | Danger, | 252 | Danger, |
| 253 | - Off, | ||
| 254 | } | 253 | } |
| 255 | 254 | ||
| 256 | pub fn button( | 255 | pub fn button( |
| @@ -266,8 +265,6 @@ pub fn button( | |||
| 266 | .child(words(label, Text::Ui, Ink::Paper, t).font_weight(FontWeight::MEDIUM)), | 265 | .child(words(label, Text::Ui, Ink::Paper, t).font_weight(FontWeight::MEDIUM)), |
| 267 | Press::Danger => press(id, t, on_click) | 266 | Press::Danger => press(id, t, on_click) |
| 268 | .child(words(label, Text::Ui, Ink::Bad, t).font_weight(FontWeight::MEDIUM)), | 267 | .child(words(label, Text::Ui, Ink::Bad, t).font_weight(FontWeight::MEDIUM)), |
| 269 | - Press::Off => press(id, t, |_, _| {}) | ||
| 270 | - .child(words(label, Text::Ui, Ink::Faint, t).font_weight(FontWeight::MEDIUM)), | ||
| 271 | Press::Primary => pill(id, t, on_click).child( | 268 | Press::Primary => pill(id, t, on_click).child( |
| 272 | words(label, Text::Ui, Ink::Paper, t) | 269 | words(label, Text::Ui, Ink::Paper, t) |
| 273 | .font_weight(FontWeight::SEMIBOLD) | 270 | .font_weight(FontWeight::SEMIBOLD) |
crates/client/src/lib.rsmodified+0 -3
| @@ -6,7 +6,6 @@ use tracing::warn; | |||
| 6 | pub mod accounts; | 6 | pub mod accounts; |
| 7 | pub mod autostart; | 7 | pub mod autostart; |
| 8 | pub mod avatar; | 8 | pub mod avatar; |
| 9 | -pub mod cpu; | ||
| 10 | pub mod embed; | 9 | pub mod embed; |
| 11 | pub mod emoji; | 10 | pub mod emoji; |
| 12 | pub mod gui; | 11 | pub mod gui; |
| @@ -16,11 +15,9 @@ pub mod logo; | |||
| 16 | pub mod marks; | 15 | pub mod marks; |
| 17 | pub mod media; | 16 | pub mod media; |
| 18 | pub mod net; | 17 | pub mod net; |
| 19 | -pub mod release; | ||
| 20 | pub mod settings; | 18 | pub mod settings; |
| 21 | pub mod share; | 19 | pub mod share; |
| 22 | pub mod tray; | 20 | pub mod tray; |
| 23 | -pub mod update; | ||
| 24 | pub use usage; | 21 | pub use usage; |
| 25 | pub mod voice; | 22 | pub mod voice; |
| 26 | 23 | ||
crates/client/src/main.rsmodified+0 -6
| @@ -18,9 +18,6 @@ use tracing::Level; | |||
| 18 | use tracing_subscriber::{filter::Targets, layer::SubscriberExt, util::SubscriberInitExt}; | 18 | use tracing_subscriber::{filter::Targets, layer::SubscriberExt, util::SubscriberInitExt}; |
| 19 | 19 | ||
| 20 | fn main() { | 20 | fn main() { |
| 21 | - if client::update::selftest() || client::update::boot() { | ||
| 22 | - return; | ||
| 23 | - } | ||
| 24 | tracing_subscriber::registry() | 21 | tracing_subscriber::registry() |
| 25 | .with(tracing_subscriber::fmt::layer()) | 22 | .with(tracing_subscriber::fmt::layer()) |
| 26 | .with( | 23 | .with( |
| @@ -45,10 +42,8 @@ fn main() { | |||
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | let client::instance::Instance::First(mut wake) = client::instance::claim() else { | 44 | let client::instance::Instance::First(mut wake) = client::instance::claim() else { |
| 48 | - client::update::claimed(false); | ||
| 49 | return; | 45 | return; |
| 50 | }; | 46 | }; |
| 51 | - client::update::claimed(true); | ||
| 52 | 47 | ||
| 53 | #[cfg(target_os = "linux")] | 48 | #[cfg(target_os = "linux")] |
| 54 | if let Err(error) = client::logo::install() { | 49 | if let Err(error) = client::logo::install() { |
| @@ -80,7 +75,6 @@ fn main() { | |||
| 80 | if hidden { | 75 | if hidden { |
| 81 | hide(&view, cx); | 76 | hide(&view, cx); |
| 82 | } | 77 | } |
| 83 | - client::update::ready(); | ||
| 84 | 78 | ||
| 85 | let (mut tray_receiver, tray_handle) = tray::start(); | 79 | let (mut tray_receiver, tray_handle) = tray::start(); |
| 86 | let mut tray_state = TrayState::default(); | 80 | let mut tray_state = TrayState::default(); |
crates/client/src/net/events.rsmodified+0 -3
| @@ -17,9 +17,6 @@ pub(super) async fn event_receive_loop( | |||
| 17 | 17 | ||
| 18 | while let Ok(down) = frame::read::<Down>(&mut receive_stream, DOWN_MAX).await { | 18 | while let Ok(down) = frame::read::<Down>(&mut receive_stream, DOWN_MAX).await { |
| 19 | match down { | 19 | match down { |
| 20 | - Down::Event(event) if matches!(*event, common::event::Event::Release) => { | ||
| 21 | - crate::update::poke(); | ||
| 22 | - } | ||
| 23 | Down::Event(event) => { | 20 | Down::Event(event) => { |
| 24 | media.pushed(&event); | 21 | media.pushed(&event); |
| 25 | if event_sender | 22 | if event_sender |
crates/client/src/net/fail.rsmodified+0 -1
| @@ -49,7 +49,6 @@ impl From<quinn::ConnectionError> for LinkError { | |||
| 49 | } | 49 | } |
| 50 | quinn::ConnectionError::TransportError(error) => Self::by_code(u64::from(error.code)), | 50 | quinn::ConnectionError::TransportError(error) => Self::by_code(u64::from(error.code)), |
| 51 | quinn::ConnectionError::ApplicationClosed(close) => match Close::of(close.error_code) { | 51 | quinn::ConnectionError::ApplicationClosed(close) => match Close::of(close.error_code) { |
| 52 | - Some(Close::Outdated) => Self::Outdated, | ||
| 53 | Some(close) => Self::Closed(close), | 52 | Some(close) => Self::Closed(close), |
| 54 | None => Self::Reset, | 53 | None => Self::Reset, |
| 55 | }, | 54 | }, |
crates/client/src/net/link.rsmodified+4 -66
| @@ -110,25 +110,9 @@ async fn backoff(attempt: &mut u32) { | |||
| 110 | *attempt += 1; | 110 | *attempt += 1; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | -pub(crate) async fn dial<T>( | ||
| 114 | - server: &crate::Server, | ||
| 115 | - alpn: &[u8], | ||
| 116 | - work: impl AsyncFnOnce(&quinn::Connection) -> T, | ||
| 117 | -) -> Result<T, LinkError> { | ||
| 118 | - let mut endpoints = Endpoints::default(); | ||
| 119 | - let connection = connect(server, &mut endpoints, alpn).await?; | ||
| 120 | - let done = work(&connection).await; | ||
| 121 | - connection.close(0u32.into(), b""); | ||
| 122 | - for endpoint in [endpoints.v4, endpoints.v6].into_iter().flatten() { | ||
| 123 | - endpoint.wait_idle().await; | ||
| 124 | - } | ||
| 125 | - Ok(done) | ||
| 126 | -} | ||
| 127 | - | ||
| 128 | async fn connect( | 113 | async fn connect( |
| 129 | server: &crate::Server, | 114 | server: &crate::Server, |
| 130 | endpoints: &mut Endpoints, | 115 | endpoints: &mut Endpoints, |
| 131 | - alpn: &[u8], | ||
| 132 | ) -> Result<quinn::Connection, LinkError> { | 116 | ) -> Result<quinn::Connection, LinkError> { |
| 133 | let mut addresses: Vec<SocketAddr> = tokio::net::lookup_host(server.address.as_str()) | 117 | let mut addresses: Vec<SocketAddr> = tokio::net::lookup_host(server.address.as_str()) |
| 134 | .await | 118 | .await |
| @@ -146,7 +130,7 @@ async fn connect( | |||
| 146 | } | 130 | } |
| 147 | }; | 131 | }; |
| 148 | let connecting = | 132 | let connecting = |
| 149 | - match endpoint.connect_with(config(server.any_cert, alpn)?, address, server.host()) { | 133 | + match endpoint.connect_with(config(server.any_cert)?, address, server.host()) { |
| 150 | Ok(connecting) => connecting, | 134 | Ok(connecting) => connecting, |
| 151 | Err(_) => { | 135 | Err(_) => { |
| 152 | endpoints.forget(address); | 136 | endpoints.forget(address); |
| @@ -225,7 +209,7 @@ impl ServerCertVerifier for AcceptAnyCertificate { | |||
| 225 | } | 209 | } |
| 226 | } | 210 | } |
| 227 | 211 | ||
| 228 | -fn config(any_cert: bool, alpn: &[u8]) -> Result<quinn::ClientConfig, LinkError> { | 212 | +fn config(any_cert: bool) -> Result<quinn::ClientConfig, LinkError> { |
| 229 | let provider = Arc::new(rustls::crypto::ring::default_provider()); | 213 | let provider = Arc::new(rustls::crypto::ring::default_provider()); |
| 230 | let verifier: Arc<dyn ServerCertVerifier> = if any_cert { | 214 | let verifier: Arc<dyn ServerCertVerifier> = if any_cert { |
| 231 | Arc::new(AcceptAnyCertificate { | 215 | Arc::new(AcceptAnyCertificate { |
| @@ -241,7 +225,7 @@ fn config(any_cert: bool, alpn: &[u8]) -> Result<quinn::ClientConfig, LinkError> | |||
| 241 | .dangerous() | 225 | .dangerous() |
| 242 | .with_custom_certificate_verifier(verifier) | 226 | .with_custom_certificate_verifier(verifier) |
| 243 | .with_no_client_auth(); | 227 | .with_no_client_auth(); |
| 244 | - tls.alpn_protocols = vec![alpn.to_vec()]; | 228 | + tls.alpn_protocols = vec![ALPN.to_vec()]; |
| 245 | 229 | ||
| 246 | let crypto = QuicClientConfig::try_from(tls).map_err(tls_error)?; | 230 | let crypto = QuicClientConfig::try_from(tls).map_err(tls_error)?; |
| 247 | let mut client_config = quinn::ClientConfig::new(Arc::new(crypto)); | 231 | let mut client_config = quinn::ClientConfig::new(Arc::new(crypto)); |
| @@ -279,7 +263,6 @@ async fn hello(connection: &quinn::Connection, token: Option<String>) -> Result< | |||
| 279 | let hello = Hello { | 263 | let hello = Hello { |
| 280 | token, | 264 | token, |
| 281 | device: device_name(), | 265 | device: device_name(), |
| 282 | - release: crate::update::SEQ, | ||
| 283 | }; | 266 | }; |
| 284 | 267 | ||
| 285 | Ok(exchange(connection, &hello).await?.0) | 268 | Ok(exchange(connection, &hello).await?.0) |
| @@ -335,38 +318,6 @@ pub(super) async fn upload( | |||
| 335 | } | 318 | } |
| 336 | } | 319 | } |
| 337 | 320 | ||
| 338 | -pub(super) async fn publish( | ||
| 339 | - connection: &quinn::Connection, | ||
| 340 | - name: String, | ||
| 341 | - path: &Path, | ||
| 342 | -) -> Result<(), Fail> { | ||
| 343 | - let bytes = tokio::fs::read(path).await?; | ||
| 344 | - let sha256 = ring::digest::digest(&ring::digest::SHA256, &bytes) | ||
| 345 | - .as_ref() | ||
| 346 | - .try_into() | ||
| 347 | - .map_err(|_| Fail::Protocol)?; | ||
| 348 | - let header = common::open::Publish { | ||
| 349 | - name, | ||
| 350 | - size: bytes.len() as u64, | ||
| 351 | - sha256, | ||
| 352 | - }; | ||
| 353 | - let (send_stream, mut receive_stream) = connection.open_bi().await?; | ||
| 354 | - let mut send_stream = Sending::new(send_stream); | ||
| 355 | - frame::write(&mut send_stream, &Open::Publish(header), UP_MAX).await?; | ||
| 356 | - let write = async move { | ||
| 357 | - send_stream.get().write_all(&bytes).await?; | ||
| 358 | - Ok::<_, Fail>(send_stream.finish()?) | ||
| 359 | - }; | ||
| 360 | - let read = frame::read::<Result<(), Error>>(&mut receive_stream, DOWN_MAX); | ||
| 361 | - let (sent, reply) = tokio::join!(write, read); | ||
| 362 | - | ||
| 363 | - match (sent, reply) { | ||
| 364 | - (_, Ok(reply)) => Ok(reply?), | ||
| 365 | - (Err(error), _) => Err(error), | ||
| 366 | - (_, Err(error)) => Err(error.into()), | ||
| 367 | - } | ||
| 368 | -} | ||
| 369 | - | ||
| 370 | pub(super) async fn backup_download( | 321 | pub(super) async fn backup_download( |
| 371 | connection: &quinn::Connection, | 322 | connection: &quinn::Connection, |
| 372 | name: &str, | 323 | name: &str, |
| @@ -432,7 +383,7 @@ async fn actor( | |||
| 432 | let connection = loop { | 383 | let connection = loop { |
| 433 | let address = server.borrow_and_update().clone(); | 384 | let address = server.borrow_and_update().clone(); |
| 434 | let result = tokio::select! { | 385 | let result = tokio::select! { |
| 435 | - result = connect(&address, &mut endpoints, ALPN) => result, | 386 | + result = connect(&address, &mut endpoints) => result, |
| 436 | _ = server.changed() => { | 387 | _ = server.changed() => { |
| 437 | attempt = 0; | 388 | attempt = 0; |
| 438 | token = None; | 389 | token = None; |
| @@ -443,7 +394,6 @@ async fn actor( | |||
| 443 | Ok(connection) => break connection, | 394 | Ok(connection) => break connection, |
| 444 | Err(LinkError::Outdated) => { | 395 | Err(LinkError::Outdated) => { |
| 445 | warn!("server speaks another protocol version"); | 396 | warn!("server speaks another protocol version"); |
| 446 | - crate::update::outdated(); | ||
| 447 | let _ = event_sender | 397 | let _ = event_sender |
| 448 | .send(NetworkEvent::Disconnected(LinkError::Outdated)) | 398 | .send(NetworkEvent::Disconnected(LinkError::Outdated)) |
| 449 | .await; | 399 | .await; |
| @@ -502,9 +452,6 @@ async fn actor( | |||
| 502 | .map(LinkError::from) | 452 | .map(LinkError::from) |
| 503 | .filter(|reason| reason.terminal()) | 453 | .filter(|reason| reason.terminal()) |
| 504 | { | 454 | { |
| 505 | - if reason == LinkError::Outdated { | ||
| 506 | - crate::update::outdated(); | ||
| 507 | - } | ||
| 508 | let _ = event_sender.send(NetworkEvent::Disconnected(reason)).await; | 455 | let _ = event_sender.send(NetworkEvent::Disconnected(reason)).await; |
| 509 | while command_receiver.recv().await.is_some() {} | 456 | while command_receiver.recv().await.is_some() {} |
| 510 | return; | 457 | return; |
| @@ -516,7 +463,6 @@ async fn actor( | |||
| 516 | 463 | ||
| 517 | attempt = 0; | 464 | attempt = 0; |
| 518 | info!("connected"); | 465 | info!("connected"); |
| 519 | - crate::update::poke(); | ||
| 520 | shared.media.ready(connection.clone(), event_sender.clone()); | 466 | shared.media.ready(connection.clone(), event_sender.clone()); |
| 521 | if event_sender.send(NetworkEvent::Connected).await.is_err() { | 467 | if event_sender.send(NetworkEvent::Connected).await.is_err() { |
| 522 | return; | 468 | return; |
| @@ -557,11 +503,6 @@ async fn actor( | |||
| 557 | 503 | ||
| 558 | answer(reply, async move { fetches.memory(&connection, blob).await }); | 504 | answer(reply, async move { fetches.memory(&connection, blob).await }); |
| 559 | } | 505 | } |
| 560 | - Some(Command::Publish { name, path, reply }) => { | ||
| 561 | - let connection = connection.clone(); | ||
| 562 | - | ||
| 563 | - answer(reply, async move { publish(&connection, name, &path).await }); | ||
| 564 | - } | ||
| 565 | Some(Command::BackupDownload { name, path, reply }) => { | 506 | Some(Command::BackupDownload { name, path, reply }) => { |
| 566 | let connection = connection.clone(); | 507 | let connection = connection.clone(); |
| 567 | let fetches = shared.fetches.clone(); | 508 | let fetches = shared.fetches.clone(); |
| @@ -588,9 +529,6 @@ async fn actor( | |||
| 588 | 529 | ||
| 589 | let event = LinkError::from(error); | 530 | let event = LinkError::from(error); |
| 590 | let terminal = event.terminal(); | 531 | let terminal = event.terminal(); |
| 591 | - if event == LinkError::Outdated { | ||
| 592 | - crate::update::outdated(); | ||
| 593 | - } | ||
| 594 | 532 | ||
| 595 | if event_sender.send(NetworkEvent::Disconnected(event)).await.is_err() { | 533 | if event_sender.send(NetworkEvent::Disconnected(event)).await.is_err() { |
| 596 | return; | 534 | return; |
crates/client/src/net/mod.rsmodified+0 -11
| @@ -16,7 +16,6 @@ mod link; | |||
| 16 | mod media; | 16 | mod media; |
| 17 | 17 | ||
| 18 | pub use fail::{Fail, LinkError}; | 18 | pub use fail::{Fail, LinkError}; |
| 19 | -pub(crate) use link::dial; | ||
| 20 | pub use link::start; | 19 | pub use link::start; |
| 21 | use media::Media; | 20 | use media::Media; |
| 22 | 21 | ||
| @@ -80,11 +79,6 @@ enum Command { | |||
| 80 | path: PathBuf, | 79 | path: PathBuf, |
| 81 | reply: oneshot::Sender<Result<(), Fail>>, | 80 | reply: oneshot::Sender<Result<(), Fail>>, |
| 82 | }, | 81 | }, |
| 83 | - Publish { | ||
| 84 | - name: String, | ||
| 85 | - path: PathBuf, | ||
| 86 | - reply: oneshot::Sender<Result<(), Fail>>, | ||
| 87 | - }, | ||
| 88 | } | 82 | } |
| 89 | 83 | ||
| 90 | #[derive(Clone)] | 84 | #[derive(Clone)] |
| @@ -223,11 +217,6 @@ impl NetworkHandle { | |||
| 223 | self.ask(|reply| Command::Download { blob, reply }).await | 217 | self.ask(|reply| Command::Download { blob, reply }).await |
| 224 | } | 218 | } |
| 225 | 219 | ||
| 226 | - pub async fn publish(&self, name: String, path: PathBuf) -> Result<(), Fail> { | ||
| 227 | - self.ask(|reply| Command::Publish { name, path, reply }) | ||
| 228 | - .await | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | pub async fn download_backup(&self, name: &str, path: PathBuf) -> Result<(), Fail> { | 220 | pub async fn download_backup(&self, name: &str, path: PathBuf) -> Result<(), Fail> { |
| 232 | self.ask(|reply| Command::BackupDownload { | 221 | self.ask(|reply| Command::BackupDownload { |
| 233 | name: name.to_string(), | 222 | name: name.to_string(), |
crates/client/src/release.rsdeleted+0 -371
| @@ -1,371 +0,0 @@ | |||
| 1 | -use std::{ | ||
| 2 | - fs, | ||
| 3 | - io::{BufRead, BufReader}, | ||
| 4 | - num::NonZeroU32, | ||
| 5 | - path::{Path, PathBuf}, | ||
| 6 | - process::{Command, Stdio}, | ||
| 7 | -}; | ||
| 8 | - | ||
| 9 | -use common::update::{self as wire, MAGIC}; | ||
| 10 | -use ring::{ | ||
| 11 | - aead::{Aad, CHACHA20_POLY1305, LessSafeKey, Nonce, UnboundKey}, | ||
| 12 | - digest, pbkdf2, | ||
| 13 | - rand::{SecureRandom, SystemRandom}, | ||
| 14 | - signature::{self, Ed25519KeyPair, KeyPair}, | ||
| 15 | -}; | ||
| 16 | - | ||
| 17 | -const KEY_MAGIC: &[u8] = b"yumush-key 1\n"; | ||
| 18 | -const SALT: usize = 16; | ||
| 19 | -const NONCE: usize = 12; | ||
| 20 | -const SEED: usize = 32; | ||
| 21 | -const KEY_FILE: usize = KEY_MAGIC.len() + SALT + NONCE + SEED + 16; | ||
| 22 | -const ITERATIONS: NonZeroU32 = NonZeroU32::new(2_000_000).unwrap(); | ||
| 23 | -pub const KEY_NAMES: [&str; 2] = ["primary", "backup"]; | ||
| 24 | -const KEYS_RS: &str = "crates/client/src/update/keys.rs"; | ||
| 25 | - | ||
| 26 | -#[derive(Debug, thiserror::Error)] | ||
| 27 | -pub enum ReleaseError { | ||
| 28 | - #[error("not a yumush source folder")] | ||
| 29 | - Source, | ||
| 30 | - #[error("keys.rs already holds keys")] | ||
| 31 | - KeysExist, | ||
| 32 | - #[error("no signing keys")] | ||
| 33 | - NoKeys, | ||
| 34 | - #[error("wrong passphrase or damaged key")] | ||
| 35 | - Passphrase, | ||
| 36 | - #[error("passphrase is too short")] | ||
| 37 | - Short, | ||
| 38 | - #[error("key does not match keys.rs")] | ||
| 39 | - Untrusted, | ||
| 40 | - #[error("minimum must be 1..={0}")] | ||
| 41 | - Minimum(u64), | ||
| 42 | - #[error("{0} is not seq {1}")] | ||
| 43 | - Seq(String, u64), | ||
| 44 | - #[error("no binaries in dist/{0}")] | ||
| 45 | - Empty(u64), | ||
| 46 | - #[error("build failed")] | ||
| 47 | - Build, | ||
| 48 | - #[error("signing failed")] | ||
| 49 | - Sign, | ||
| 50 | - #[error(transparent)] | ||
| 51 | - Io(#[from] std::io::Error), | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | -pub fn is_source(source: &Path) -> bool { | ||
| 55 | - source.join("packaging/release.sh").is_file() && source.join(KEYS_RS).is_file() | ||
| 56 | -} | ||
| 57 | - | ||
| 58 | -fn checked(source: &Path) -> Result<(), ReleaseError> { | ||
| 59 | - if is_source(source) { | ||
| 60 | - Ok(()) | ||
| 61 | - } else { | ||
| 62 | - Err(ReleaseError::Source) | ||
| 63 | - } | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -pub fn signing_dir() -> PathBuf { | ||
| 67 | - std::env::var_os("YUMUSH_SIGNING_DIR") | ||
| 68 | - .map(PathBuf::from) | ||
| 69 | - .or_else(|| dirs::data_dir().map(|dir| dir.join("yumush-signing"))) | ||
| 70 | - .unwrap_or_else(|| PathBuf::from("yumush-signing")) | ||
| 71 | -} | ||
| 72 | - | ||
| 73 | -pub fn trusted(source: &Path) -> Vec<[u8; 32]> { | ||
| 74 | - let text = fs::read_to_string(source.join(KEYS_RS)).unwrap_or_default(); | ||
| 75 | - text.split('[') | ||
| 76 | - .filter_map(|chunk| { | ||
| 77 | - let bytes: Vec<u8> = chunk | ||
| 78 | - .split(|c: char| c == ',' || c == ']' || c.is_whitespace()) | ||
| 79 | - .filter_map(|part| part.strip_prefix("0x")) | ||
| 80 | - .filter_map(|hex| u8::from_str_radix(hex, 16).ok()) | ||
| 81 | - .collect(); | ||
| 82 | - bytes.try_into().ok() | ||
| 83 | - }) | ||
| 84 | - .collect() | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -fn derive(passphrase: &str, salt: &[u8]) -> Result<LessSafeKey, ReleaseError> { | ||
| 88 | - let mut key = [0u8; 32]; | ||
| 89 | - pbkdf2::derive( | ||
| 90 | - pbkdf2::PBKDF2_HMAC_SHA256, | ||
| 91 | - ITERATIONS, | ||
| 92 | - salt, | ||
| 93 | - passphrase.as_bytes(), | ||
| 94 | - &mut key, | ||
| 95 | - ); | ||
| 96 | - let unbound = UnboundKey::new(&CHACHA20_POLY1305, &key).map_err(|_| ReleaseError::Sign)?; | ||
| 97 | - Ok(LessSafeKey::new(unbound)) | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -fn seal(seed: &[u8; SEED], passphrase: &str) -> Result<Vec<u8>, ReleaseError> { | ||
| 101 | - let random = SystemRandom::new(); | ||
| 102 | - let mut salt = [0u8; SALT]; | ||
| 103 | - let mut nonce = [0u8; NONCE]; | ||
| 104 | - random.fill(&mut salt).map_err(|_| ReleaseError::Sign)?; | ||
| 105 | - random.fill(&mut nonce).map_err(|_| ReleaseError::Sign)?; | ||
| 106 | - let mut sealed = seed.to_vec(); | ||
| 107 | - derive(passphrase, &salt)? | ||
| 108 | - .seal_in_place_append_tag( | ||
| 109 | - Nonce::assume_unique_for_key(nonce), | ||
| 110 | - Aad::from(KEY_MAGIC), | ||
| 111 | - &mut sealed, | ||
| 112 | - ) | ||
| 113 | - .map_err(|_| ReleaseError::Sign)?; | ||
| 114 | - Ok([KEY_MAGIC, &salt, &nonce, &sealed].concat()) | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | -fn open(file: &[u8], passphrase: &str) -> Result<Ed25519KeyPair, ReleaseError> { | ||
| 118 | - if file.len() != KEY_FILE || !file.starts_with(KEY_MAGIC) { | ||
| 119 | - return Err(ReleaseError::Passphrase); | ||
| 120 | - } | ||
| 121 | - let (salt, rest) = file[KEY_MAGIC.len()..].split_at(SALT); | ||
| 122 | - let (nonce, sealed) = rest.split_at(NONCE); | ||
| 123 | - let nonce = Nonce::try_assume_unique_for_key(nonce).map_err(|_| ReleaseError::Passphrase)?; | ||
| 124 | - let mut sealed = sealed.to_vec(); | ||
| 125 | - let seed = derive(passphrase, salt)? | ||
| 126 | - .open_in_place(nonce, Aad::from(KEY_MAGIC), &mut sealed) | ||
| 127 | - .map_err(|_| ReleaseError::Passphrase)?; | ||
| 128 | - Ed25519KeyPair::from_seed_unchecked(seed).map_err(|_| ReleaseError::Passphrase) | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | -fn put_private(path: &Path, bytes: &[u8]) -> std::io::Result<()> { | ||
| 132 | - let mut options = fs::OpenOptions::new(); | ||
| 133 | - options.write(true).create_new(true); | ||
| 134 | - #[cfg(unix)] | ||
| 135 | - std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600); | ||
| 136 | - let mut file = options.open(path)?; | ||
| 137 | - std::io::Write::write_all(&mut file, bytes)?; | ||
| 138 | - file.sync_all() | ||
| 139 | -} | ||
| 140 | - | ||
| 141 | -pub fn keygen(source: &Path, passphrase: &str) -> Result<PathBuf, ReleaseError> { | ||
| 142 | - checked(source)?; | ||
| 143 | - if !trusted(source).is_empty() { | ||
| 144 | - return Err(ReleaseError::KeysExist); | ||
| 145 | - } | ||
| 146 | - if passphrase.chars().count() < 12 { | ||
| 147 | - return Err(ReleaseError::Short); | ||
| 148 | - } | ||
| 149 | - let directory = signing_dir(); | ||
| 150 | - fs::create_dir_all(&directory)?; | ||
| 151 | - let mut lines = String::from("pub const KEYS: &[[u8; 32]] = &[\n"); | ||
| 152 | - for name in KEY_NAMES { | ||
| 153 | - let mut seed = [0u8; SEED]; | ||
| 154 | - SystemRandom::new() | ||
| 155 | - .fill(&mut seed) | ||
| 156 | - .map_err(|_| ReleaseError::Sign)?; | ||
| 157 | - let pair = Ed25519KeyPair::from_seed_unchecked(&seed).map_err(|_| ReleaseError::Sign)?; | ||
| 158 | - let sealed = seal(&seed, passphrase)?; | ||
| 159 | - put_private(&directory.join(format!("{name}.key")), &sealed)?; | ||
| 160 | - let bytes: Vec<String> = pair | ||
| 161 | - .public_key() | ||
| 162 | - .as_ref() | ||
| 163 | - .iter() | ||
| 164 | - .map(|byte| format!("0x{byte:02x}")) | ||
| 165 | - .collect(); | ||
| 166 | - lines.push_str(&format!(" [{}],\n", bytes.join(", "))); | ||
| 167 | - } | ||
| 168 | - lines.push_str("];\n"); | ||
| 169 | - let out = source.join(KEYS_RS); | ||
| 170 | - let part = out.with_extension("rs.part"); | ||
| 171 | - fs::write(&part, lines)?; | ||
| 172 | - fs::rename(part, out)?; | ||
| 173 | - Ok(directory) | ||
| 174 | -} | ||
| 175 | - | ||
| 176 | -pub fn dist(source: &Path, seq: u64) -> PathBuf { | ||
| 177 | - source.join("dist").join(seq.to_string()) | ||
| 178 | -} | ||
| 179 | - | ||
| 180 | -pub fn next_seq(source: &Path, live: Option<u64>) -> u64 { | ||
| 181 | - let built = fs::read_dir(source.join("dist")) | ||
| 182 | - .into_iter() | ||
| 183 | - .flatten() | ||
| 184 | - .flatten() | ||
| 185 | - .filter_map(|entry| entry.file_name().to_str()?.parse::<u64>().ok()) | ||
| 186 | - .max(); | ||
| 187 | - built.max(live).unwrap_or(0) + 1 | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 191 | -pub enum Platform { | ||
| 192 | - Linux, | ||
| 193 | - Windows, | ||
| 194 | -} | ||
| 195 | - | ||
| 196 | -impl Platform { | ||
| 197 | - pub const ALL: [Self; 2] = [Self::Linux, Self::Windows]; | ||
| 198 | - | ||
| 199 | - fn arg(self) -> &'static str { | ||
| 200 | - match self { | ||
| 201 | - Self::Linux => "linux", | ||
| 202 | - Self::Windows => "windows", | ||
| 203 | - } | ||
| 204 | - } | ||
| 205 | -} | ||
| 206 | - | ||
| 207 | -pub fn build( | ||
| 208 | - source: &Path, | ||
| 209 | - platform: Platform, | ||
| 210 | - seq: u64, | ||
| 211 | - mut line: impl FnMut(String), | ||
| 212 | -) -> Result<(), ReleaseError> { | ||
| 213 | - checked(source)?; | ||
| 214 | - let mut child = Command::new("bash") | ||
| 215 | - .arg(source.join("packaging/release.sh")) | ||
| 216 | - .arg(platform.arg()) | ||
| 217 | - .arg(seq.to_string()) | ||
| 218 | - .current_dir(source) | ||
| 219 | - .stdin(Stdio::null()) | ||
| 220 | - .stdout(Stdio::piped()) | ||
| 221 | - .stderr(Stdio::piped()) | ||
| 222 | - .spawn()?; | ||
| 223 | - let stderr = child.stderr.take().ok_or(ReleaseError::Build)?; | ||
| 224 | - let (sender, receiver) = std::sync::mpsc::channel(); | ||
| 225 | - let errors = sender.clone(); | ||
| 226 | - let reader = std::thread::spawn(move || { | ||
| 227 | - for text in BufReader::new(stderr).lines().map_while(Result::ok) { | ||
| 228 | - let _ = errors.send(text); | ||
| 229 | - } | ||
| 230 | - }); | ||
| 231 | - let stdout = child.stdout.take().ok_or(ReleaseError::Build)?; | ||
| 232 | - std::thread::spawn(move || { | ||
| 233 | - for text in BufReader::new(stdout).lines().map_while(Result::ok) { | ||
| 234 | - let _ = sender.send(text); | ||
| 235 | - } | ||
| 236 | - }); | ||
| 237 | - for text in receiver { | ||
| 238 | - line(text); | ||
| 239 | - } | ||
| 240 | - let _ = reader.join(); | ||
| 241 | - if child.wait()?.success() { | ||
| 242 | - Ok(()) | ||
| 243 | - } else { | ||
| 244 | - Err(ReleaseError::Build) | ||
| 245 | - } | ||
| 246 | -} | ||
| 247 | - | ||
| 248 | -pub fn binaries(source: &Path, seq: u64) -> Vec<(String, PathBuf)> { | ||
| 249 | - let mut found: Vec<(String, PathBuf)> = fs::read_dir(dist(source, seq)) | ||
| 250 | - .into_iter() | ||
| 251 | - .flatten() | ||
| 252 | - .flatten() | ||
| 253 | - .filter_map(|entry| { | ||
| 254 | - let name = entry.file_name().to_str()?.to_string(); | ||
| 255 | - let target = name.split_once('-').is_some_and(|(arch, os)| { | ||
| 256 | - !arch.is_empty() && !os.is_empty() && !os.contains(['-', '.']) | ||
| 257 | - }); | ||
| 258 | - (target && wire::valid_name(&name)).then(|| (name, entry.path())) | ||
| 259 | - }) | ||
| 260 | - .collect(); | ||
| 261 | - found.sort(); | ||
| 262 | - found | ||
| 263 | -} | ||
| 264 | - | ||
| 265 | -fn version(source: &Path) -> Result<String, ReleaseError> { | ||
| 266 | - let manifest = fs::read_to_string(source.join("crates/client/Cargo.toml"))?; | ||
| 267 | - manifest | ||
| 268 | - .lines() | ||
| 269 | - .find_map(|line| { | ||
| 270 | - let value = line.strip_prefix("version")?.trim().strip_prefix('=')?; | ||
| 271 | - Some(value.trim().trim_matches('"').to_string()) | ||
| 272 | - }) | ||
| 273 | - .filter(|version| !version.is_empty()) | ||
| 274 | - .ok_or(ReleaseError::Source) | ||
| 275 | -} | ||
| 276 | - | ||
| 277 | -pub fn sign( | ||
| 278 | - source: &Path, | ||
| 279 | - seq: u64, | ||
| 280 | - minimum: u64, | ||
| 281 | - passphrase: &str, | ||
| 282 | -) -> Result<Vec<u8>, ReleaseError> { | ||
| 283 | - checked(source)?; | ||
| 284 | - if !(1..=seq).contains(&minimum) { | ||
| 285 | - return Err(ReleaseError::Minimum(seq)); | ||
| 286 | - } | ||
| 287 | - let files = binaries(source, seq); | ||
| 288 | - if files.is_empty() { | ||
| 289 | - return Err(ReleaseError::Empty(seq)); | ||
| 290 | - } | ||
| 291 | - let mut body = format!( | ||
| 292 | - "{MAGIC}\nseq {seq}\nminimum {minimum}\nversion {}\n", | ||
| 293 | - version(source)? | ||
| 294 | - ); | ||
| 295 | - for (name, path) in &files { | ||
| 296 | - let built = | ||
| 297 | - fs::read_to_string(path.with_file_name(format!("{name}.seq"))).unwrap_or_default(); | ||
| 298 | - if built.trim().parse::<u64>().ok() != Some(seq) { | ||
| 299 | - return Err(ReleaseError::Seq(name.clone(), seq)); | ||
| 300 | - } | ||
| 301 | - let bytes = fs::read(path)?; | ||
| 302 | - let hash: String = digest::digest(&digest::SHA256, &bytes) | ||
| 303 | - .as_ref() | ||
| 304 | - .iter() | ||
| 305 | - .map(|byte| format!("{byte:02x}")) | ||
| 306 | - .collect(); | ||
| 307 | - body.push_str(&format!("{name} {} {hash}\n", bytes.len())); | ||
| 308 | - } | ||
| 309 | - if wire::parse(body.as_bytes()).is_none() { | ||
| 310 | - return Err(ReleaseError::Sign); | ||
| 311 | - } | ||
| 312 | - let keys = trusted(source); | ||
| 313 | - if keys.is_empty() { | ||
| 314 | - return Err(ReleaseError::NoKeys); | ||
| 315 | - } | ||
| 316 | - let file = fs::read(signing_dir().join(format!("{}.key", KEY_NAMES[0]))) | ||
| 317 | - .map_err(|_| ReleaseError::NoKeys)?; | ||
| 318 | - let pair = open(&file, passphrase)?; | ||
| 319 | - if !keys.iter().any(|key| key == pair.public_key().as_ref()) { | ||
| 320 | - return Err(ReleaseError::Untrusted); | ||
| 321 | - } | ||
| 322 | - let sig = pair.sign(body.as_bytes()); | ||
| 323 | - let signed = [sig.as_ref(), body.as_bytes()].concat(); | ||
| 324 | - let (sig, checked_body) = wire::split(&signed).ok_or(ReleaseError::Sign)?; | ||
| 325 | - signature::UnparsedPublicKey::new(&signature::ED25519, pair.public_key().as_ref()) | ||
| 326 | - .verify(checked_body, sig) | ||
| 327 | - .map_err(|_| ReleaseError::Sign)?; | ||
| 328 | - let out = dist(source, seq).join(wire::MANIFEST); | ||
| 329 | - fs::write(&out, &signed)?; | ||
| 330 | - Ok(signed) | ||
| 331 | -} | ||
| 332 | - | ||
| 333 | -pub fn signed(source: &Path, seq: u64) -> Option<Vec<u8>> { | ||
| 334 | - fs::read(dist(source, seq).join(wire::MANIFEST)).ok() | ||
| 335 | -} | ||
| 336 | - | ||
| 337 | -pub fn uploads(signed: &[u8], source: &Path) -> Option<Vec<(String, PathBuf)>> { | ||
| 338 | - let (_, body) = wire::split(signed)?; | ||
| 339 | - let manifest = wire::parse(body)?; | ||
| 340 | - let directory = dist(source, manifest.seq); | ||
| 341 | - Some( | ||
| 342 | - manifest | ||
| 343 | - .files | ||
| 344 | - .iter() | ||
| 345 | - .map(|file| { | ||
| 346 | - ( | ||
| 347 | - wire::file_name(&file.name, manifest.seq), | ||
| 348 | - directory.join(&file.name), | ||
| 349 | - ) | ||
| 350 | - }) | ||
| 351 | - .collect(), | ||
| 352 | - ) | ||
| 353 | -} | ||
| 354 | - | ||
| 355 | -#[cfg(test)] | ||
| 356 | -mod tests { | ||
| 357 | - use super::*; | ||
| 358 | - | ||
| 359 | - #[test] | ||
| 360 | - fn key_round_trip() { | ||
| 361 | - let seed = [7u8; SEED]; | ||
| 362 | - let sealed = seal(&seed, "correct horse battery").unwrap(); | ||
| 363 | - let pair = open(&sealed, "correct horse battery").unwrap(); | ||
| 364 | - let expected = Ed25519KeyPair::from_seed_unchecked(&seed).unwrap(); | ||
| 365 | - assert_eq!(pair.public_key().as_ref(), expected.public_key().as_ref()); | ||
| 366 | - assert!(open(&sealed, "wrong horse battery").is_err()); | ||
| 367 | - let mut tampered = sealed.clone(); | ||
| 368 | - tampered[KEY_MAGIC.len()] ^= 1; | ||
| 369 | - assert!(open(&tampered, "correct horse battery").is_err()); | ||
| 370 | - } | ||
| 371 | -} | ||
crates/client/src/settings.rsmodified+1 -12
| @@ -1,4 +1,4 @@ | |||
| 1 | -use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive, path::PathBuf}; | 1 | +use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive}; |
| 2 | 2 | ||
| 3 | use common::{ | 3 | use common::{ |
| 4 | config::Config, | 4 | config::Config, |
| @@ -224,7 +224,6 @@ pub struct Settings { | |||
| 224 | pub clock_seconds: bool, | 224 | pub clock_seconds: bool, |
| 225 | pub jump_usage: BTreeMap<String, u32>, | 225 | pub jump_usage: BTreeMap<String, u32>, |
| 226 | pub last_chats: BTreeMap<Id, Id>, | 226 | pub last_chats: BTreeMap<Id, Id>, |
| 227 | - pub release_source: Option<PathBuf>, | ||
| 228 | } | 227 | } |
| 229 | 228 | ||
| 230 | impl Settings { | 229 | impl Settings { |
| @@ -254,7 +253,6 @@ impl Default for Settings { | |||
| 254 | clock_seconds: false, | 253 | clock_seconds: false, |
| 255 | jump_usage: BTreeMap::new(), | 254 | jump_usage: BTreeMap::new(), |
| 256 | last_chats: BTreeMap::new(), | 255 | last_chats: BTreeMap::new(), |
| 257 | - release_source: None, | ||
| 258 | } | 256 | } |
| 259 | } | 257 | } |
| 260 | } | 258 | } |
| @@ -390,7 +388,6 @@ pub fn load() -> Settings { | |||
| 390 | .collect() | 388 | .collect() |
| 391 | }) | 389 | }) |
| 392 | .unwrap_or_default(), | 390 | .unwrap_or_default(), |
| 393 | - release_source: text("release.source").map(PathBuf::from), | ||
| 394 | } | 391 | } |
| 395 | } | 392 | } |
| 396 | 393 | ||
| @@ -481,14 +478,6 @@ pub fn save(settings: &Settings) { | |||
| 481 | .collect::<Vec<_>>() | 478 | .collect::<Vec<_>>() |
| 482 | .join(","), | 479 | .join(","), |
| 483 | ), | 480 | ), |
| 484 | - line( | ||
| 485 | - "release.source", | ||
| 486 | - settings | ||
| 487 | - .release_source | ||
| 488 | - .as_ref() | ||
| 489 | - .map(|path| path.display().to_string()) | ||
| 490 | - .unwrap_or_default(), | ||
| 491 | - ), | ||
| 492 | ] | 481 | ] |
| 493 | .concat(); | 482 | .concat(); |
| 494 | 483 | ||
crates/client/src/update.rsdeleted+0 -669
| @@ -1,669 +0,0 @@ | |||
| 1 | -use std::{ | ||
| 2 | - fs, | ||
| 3 | - io::{Read, Write}, | ||
| 4 | - path::{Path, PathBuf}, | ||
| 5 | - process::{Command, Stdio}, | ||
| 6 | - sync::{ | ||
| 7 | - OnceLock, | ||
| 8 | - atomic::{AtomicBool, Ordering}, | ||
| 9 | - mpsc, | ||
| 10 | - }, | ||
| 11 | - time::{Duration, Instant}, | ||
| 12 | -}; | ||
| 13 | - | ||
| 14 | -use common::update::{self as wire, MANIFEST, MANIFEST_MAX}; | ||
| 15 | -use ring::{ | ||
| 16 | - digest, | ||
| 17 | - rand::{SecureRandom, SystemRandom}, | ||
| 18 | - signature, | ||
| 19 | -}; | ||
| 20 | -use tracing::{info, warn}; | ||
| 21 | - | ||
| 22 | -mod keys; | ||
| 23 | - | ||
| 24 | -pub const SELFTEST: &str = "--selftest"; | ||
| 25 | -const AFTER: &str = "--after"; | ||
| 26 | -const FIRST_CHECK: Duration = Duration::from_secs(5); | ||
| 27 | -const POKE_SPREAD: Duration = Duration::from_secs(20); | ||
| 28 | -const RETRY_FIRST: Duration = Duration::from_secs(30); | ||
| 29 | -const RETRY_LAST: Duration = Duration::from_secs(30 * 60); | ||
| 30 | -const PARENT_LIMIT: Duration = Duration::from_secs(30); | ||
| 31 | -const SELFTEST_LIMIT: Duration = Duration::from_secs(20); | ||
| 32 | -const PACKAGED_ENV: [&str; 3] = ["FLATPAK_ID", "SNAP", "APPIMAGE"]; | ||
| 33 | -const PACKAGED_ROOTS: [&str; 2] = ["/usr/", "/nix/"]; | ||
| 34 | - | ||
| 35 | -pub const SEQ: Option<u64> = match option_env!("YUMUSH_RELEASE_SEQ") { | ||
| 36 | - Some(text) => Some(parse_seq(text)), | ||
| 37 | - None => None, | ||
| 38 | -}; | ||
| 39 | - | ||
| 40 | -const _: () = assert!( | ||
| 41 | - SEQ.is_none() || !keys::KEYS.is_empty(), | ||
| 42 | - "release build needs update keys" | ||
| 43 | -); | ||
| 44 | - | ||
| 45 | -const fn parse_seq(text: &str) -> u64 { | ||
| 46 | - let bytes = text.as_bytes(); | ||
| 47 | - assert!(!bytes.is_empty() && bytes.len() <= 18, "YUMUSH_RELEASE_SEQ"); | ||
| 48 | - let mut value = 0u64; | ||
| 49 | - let mut index = 0; | ||
| 50 | - while index < bytes.len() { | ||
| 51 | - assert!(bytes[index].is_ascii_digit(), "YUMUSH_RELEASE_SEQ"); | ||
| 52 | - value = value * 10 + (bytes[index] - b'0') as u64; | ||
| 53 | - index += 1; | ||
| 54 | - } | ||
| 55 | - assert!(value > 0, "YUMUSH_RELEASE_SEQ"); | ||
| 56 | - value | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -#[derive(Debug)] | ||
| 60 | -enum Off { | ||
| 61 | - Unofficial, | ||
| 62 | - Multi, | ||
| 63 | - Packaged, | ||
| 64 | - NoExe, | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -#[allow(dead_code)] | ||
| 68 | -#[derive(Debug)] | ||
| 69 | -enum Fail { | ||
| 70 | - Link(crate::net::LinkError), | ||
| 71 | - Connection(quinn::ConnectionError), | ||
| 72 | - Wire(wire::UpdateError), | ||
| 73 | - Reject(Reject), | ||
| 74 | - Hash, | ||
| 75 | - Selftest, | ||
| 76 | - Io(std::io::Error), | ||
| 77 | -} | ||
| 78 | - | ||
| 79 | -#[derive(Debug)] | ||
| 80 | -enum Reject { | ||
| 81 | - Short, | ||
| 82 | - Signature, | ||
| 83 | - Format, | ||
| 84 | - Target, | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -enum Outcome { | ||
| 88 | - Current, | ||
| 89 | - Staged(u64), | ||
| 90 | - Restart, | ||
| 91 | -} | ||
| 92 | - | ||
| 93 | -#[derive(Debug, PartialEq)] | ||
| 94 | -struct Release { | ||
| 95 | - name: String, | ||
| 96 | - seq: u64, | ||
| 97 | - minimum: u64, | ||
| 98 | - version: String, | ||
| 99 | - size: u64, | ||
| 100 | - sha256: [u8; 32], | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -static POKE: OnceLock<mpsc::Sender<()>> = OnceLock::new(); | ||
| 104 | -static OUTDATED: AtomicBool = AtomicBool::new(false); | ||
| 105 | - | ||
| 106 | -pub fn poke() { | ||
| 107 | - if let Some(sender) = POKE.get() { | ||
| 108 | - let _ = sender.send(()); | ||
| 109 | - } | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | -pub fn outdated() { | ||
| 113 | - OUTDATED.store(true, Ordering::Relaxed); | ||
| 114 | - poke(); | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | -impl From<std::io::Error> for Fail { | ||
| 118 | - fn from(error: std::io::Error) -> Self { | ||
| 119 | - Self::Io(error) | ||
| 120 | - } | ||
| 121 | -} | ||
| 122 | - | ||
| 123 | -impl From<wire::UpdateError> for Fail { | ||
| 124 | - fn from(error: wire::UpdateError) -> Self { | ||
| 125 | - Self::Wire(error) | ||
| 126 | - } | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | -impl From<quinn::ConnectionError> for Fail { | ||
| 130 | - fn from(error: quinn::ConnectionError) -> Self { | ||
| 131 | - Self::Connection(error) | ||
| 132 | - } | ||
| 133 | -} | ||
| 134 | - | ||
| 135 | -fn mode() -> Result<(u64, &'static Path), Off> { | ||
| 136 | - let seq = SEQ.ok_or(Off::Unofficial)?; | ||
| 137 | - if std::env::args().any(|arg| arg == crate::instance::MULTI) { | ||
| 138 | - return Err(Off::Multi); | ||
| 139 | - } | ||
| 140 | - if PACKAGED_ENV | ||
| 141 | - .iter() | ||
| 142 | - .any(|name| std::env::var_os(name).is_some()) | ||
| 143 | - { | ||
| 144 | - return Err(Off::Packaged); | ||
| 145 | - } | ||
| 146 | - let exe = crate::exe().ok_or(Off::NoExe)?; | ||
| 147 | - let shown = exe.to_string_lossy(); | ||
| 148 | - if PACKAGED_ROOTS.iter().any(|root| shown.starts_with(root)) { | ||
| 149 | - return Err(Off::Packaged); | ||
| 150 | - } | ||
| 151 | - Ok((seq, exe)) | ||
| 152 | -} | ||
| 153 | - | ||
| 154 | -fn targets() -> Vec<String> { | ||
| 155 | - let os = std::env::consts::OS; | ||
| 156 | - let levels: Vec<&str> = crate::cpu::levels().collect(); | ||
| 157 | - if levels.is_empty() { | ||
| 158 | - return vec![format!("{}-{os}", std::env::consts::ARCH)]; | ||
| 159 | - } | ||
| 160 | - levels | ||
| 161 | - .into_iter() | ||
| 162 | - .map(|level| format!("{}_{level}-{os}", std::env::consts::ARCH)) | ||
| 163 | - .collect() | ||
| 164 | -} | ||
| 165 | - | ||
| 166 | -fn sibling(exe: &Path, tag: &str) -> PathBuf { | ||
| 167 | - let stem = exe.file_stem().unwrap_or_default().to_string_lossy(); | ||
| 168 | - let name = match exe.extension() { | ||
| 169 | - Some(extension) => format!("{stem}.{tag}.{}", extension.to_string_lossy()), | ||
| 170 | - None => format!("{stem}.{tag}"), | ||
| 171 | - }; | ||
| 172 | - exe.with_file_name(name) | ||
| 173 | -} | ||
| 174 | - | ||
| 175 | -fn state(exe: &Path, tag: &str) -> PathBuf { | ||
| 176 | - let name = exe.file_name().unwrap_or_default().to_string_lossy(); | ||
| 177 | - exe.with_file_name(format!("{name}.{tag}")) | ||
| 178 | -} | ||
| 179 | - | ||
| 180 | -fn read(path: &Path) -> Option<String> { | ||
| 181 | - fs::read_to_string(path) | ||
| 182 | - .ok() | ||
| 183 | - .map(|text| text.trim().to_string()) | ||
| 184 | -} | ||
| 185 | - | ||
| 186 | -fn number(path: &Path) -> Option<u64> { | ||
| 187 | - read(path)?.parse().ok() | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -fn sync_dir(path: &Path) { | ||
| 191 | - #[cfg(unix)] | ||
| 192 | - if let Some(dir) = path.parent() { | ||
| 193 | - let _ = fs::File::open(dir).and_then(|dir| dir.sync_all()); | ||
| 194 | - } | ||
| 195 | - #[cfg(not(unix))] | ||
| 196 | - let _ = path; | ||
| 197 | -} | ||
| 198 | - | ||
| 199 | -fn put(path: &Path, text: &str) -> std::io::Result<()> { | ||
| 200 | - let part = path.with_added_extension("part"); | ||
| 201 | - let mut file = fs::File::create(&part)?; | ||
| 202 | - file.write_all(text.as_bytes())?; | ||
| 203 | - file.sync_all()?; | ||
| 204 | - drop(file); | ||
| 205 | - fs::rename(&part, path)?; | ||
| 206 | - sync_dir(path); | ||
| 207 | - Ok(()) | ||
| 208 | -} | ||
| 209 | - | ||
| 210 | -fn trial(exe: &Path) -> Option<(u64, u32)> { | ||
| 211 | - let text = read(&state(exe, "trial"))?; | ||
| 212 | - let (seq, pid) = text.split_once(' ')?; | ||
| 213 | - Some((seq.parse().ok()?, pid.parse().ok()?)) | ||
| 214 | -} | ||
| 215 | - | ||
| 216 | -fn claim_trial(exe: &Path, seq: u64) -> std::io::Result<()> { | ||
| 217 | - put( | ||
| 218 | - &state(exe, "trial"), | ||
| 219 | - &format!("{seq} {}", std::process::id()), | ||
| 220 | - ) | ||
| 221 | -} | ||
| 222 | - | ||
| 223 | -fn alive(pid: u32) -> bool { | ||
| 224 | - let pid = sysinfo::Pid::from_u32(pid); | ||
| 225 | - let Ok(mut system) = sysinfo::System::new() else { | ||
| 226 | - return false; | ||
| 227 | - }; | ||
| 228 | - system.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[pid]), true); | ||
| 229 | - system.process(pid).is_some() | ||
| 230 | -} | ||
| 231 | - | ||
| 232 | -pub fn selftest() -> bool { | ||
| 233 | - if !std::env::args().any(|arg| arg == SELFTEST) { | ||
| 234 | - return false; | ||
| 235 | - } | ||
| 236 | - println!("{}", SEQ.unwrap_or(0)); | ||
| 237 | - true | ||
| 238 | -} | ||
| 239 | - | ||
| 240 | -fn wait_parent() { | ||
| 241 | - let mut args = std::env::args().skip_while(|arg| arg != AFTER).skip(1); | ||
| 242 | - let Some(pid) = args.next().and_then(|pid| pid.parse::<u32>().ok()) else { | ||
| 243 | - return; | ||
| 244 | - }; | ||
| 245 | - let started = Instant::now(); | ||
| 246 | - while alive(pid) && started.elapsed() < PARENT_LIMIT { | ||
| 247 | - std::thread::sleep(Duration::from_millis(100)); | ||
| 248 | - } | ||
| 249 | -} | ||
| 250 | - | ||
| 251 | -pub fn boot() -> bool { | ||
| 252 | - wait_parent(); | ||
| 253 | - let Ok((seq, exe)) = mode() else { | ||
| 254 | - return false; | ||
| 255 | - }; | ||
| 256 | - if let Some((trying, pid)) = trial(exe) | ||
| 257 | - && trying == seq | ||
| 258 | - && !alive(pid) | ||
| 259 | - { | ||
| 260 | - return rollback(seq, exe); | ||
| 261 | - } | ||
| 262 | - let pending = state(exe, "pending"); | ||
| 263 | - if number(&pending) == Some(seq) && claim_trial(exe, seq).is_ok() { | ||
| 264 | - let _ = fs::remove_file(&pending); | ||
| 265 | - sync_dir(exe); | ||
| 266 | - } | ||
| 267 | - false | ||
| 268 | -} | ||
| 269 | - | ||
| 270 | -pub fn claimed(first: bool) { | ||
| 271 | - let Ok((seq, exe)) = mode() else { | ||
| 272 | - return; | ||
| 273 | - }; | ||
| 274 | - let me = std::process::id(); | ||
| 275 | - match trial(exe) { | ||
| 276 | - Some((trying, pid)) if trying == seq => { | ||
| 277 | - if !first { | ||
| 278 | - if pid == me && put(&state(exe, "pending"), &seq.to_string()).is_ok() { | ||
| 279 | - let _ = fs::remove_file(state(exe, "trial")); | ||
| 280 | - } | ||
| 281 | - } else if pid != me { | ||
| 282 | - let _ = claim_trial(exe, seq); | ||
| 283 | - } | ||
| 284 | - if first { | ||
| 285 | - info!("update: trying {seq}"); | ||
| 286 | - } | ||
| 287 | - } | ||
| 288 | - _ if first => { | ||
| 289 | - for tag in ["trial", "pending"] { | ||
| 290 | - let _ = fs::remove_file(state(exe, tag)); | ||
| 291 | - } | ||
| 292 | - for tag in ["new", "bad", "old"] { | ||
| 293 | - let _ = fs::remove_file(sibling(exe, tag)); | ||
| 294 | - } | ||
| 295 | - } | ||
| 296 | - _ => {} | ||
| 297 | - } | ||
| 298 | -} | ||
| 299 | - | ||
| 300 | -fn rollback(seq: u64, exe: &Path) -> bool { | ||
| 301 | - let old = sibling(exe, "old"); | ||
| 302 | - if !old.exists() { | ||
| 303 | - let _ = fs::remove_file(state(exe, "trial")); | ||
| 304 | - return false; | ||
| 305 | - } | ||
| 306 | - let _ = put(&state(exe, "skip"), &seq.to_string()); | ||
| 307 | - if let Err(error) = restore(exe, &old) { | ||
| 308 | - warn!("update: rollback {error}"); | ||
| 309 | - return false; | ||
| 310 | - } | ||
| 311 | - sync_dir(exe); | ||
| 312 | - let _ = fs::remove_file(state(exe, "trial")); | ||
| 313 | - Command::new(exe) | ||
| 314 | - .args(std::env::args_os().skip(1)) | ||
| 315 | - .spawn() | ||
| 316 | - .is_ok() | ||
| 317 | -} | ||
| 318 | - | ||
| 319 | -#[cfg(unix)] | ||
| 320 | -fn restore(exe: &Path, old: &Path) -> std::io::Result<()> { | ||
| 321 | - fs::rename(old, exe) | ||
| 322 | -} | ||
| 323 | - | ||
| 324 | -#[cfg(not(unix))] | ||
| 325 | -fn restore(exe: &Path, old: &Path) -> std::io::Result<()> { | ||
| 326 | - let bad = sibling(exe, "bad"); | ||
| 327 | - let _ = fs::remove_file(&bad); | ||
| 328 | - fs::rename(exe, &bad)?; | ||
| 329 | - fs::rename(old, exe).inspect_err(|_| { | ||
| 330 | - let _ = fs::rename(&bad, exe); | ||
| 331 | - }) | ||
| 332 | -} | ||
| 333 | - | ||
| 334 | -pub fn ready() { | ||
| 335 | - let Ok((seq, exe)) = mode() else { | ||
| 336 | - return; | ||
| 337 | - }; | ||
| 338 | - if trial(exe) == Some((seq, std::process::id())) { | ||
| 339 | - let _ = fs::remove_file(sibling(exe, "old")); | ||
| 340 | - let _ = fs::remove_file(state(exe, "trial")); | ||
| 341 | - info!("update: {seq} is healthy"); | ||
| 342 | - } | ||
| 343 | - let (sender, receiver) = mpsc::channel(); | ||
| 344 | - if POKE.set(sender).is_err() { | ||
| 345 | - return; | ||
| 346 | - } | ||
| 347 | - let _ = std::thread::Builder::new() | ||
| 348 | - .name("update".to_string()) | ||
| 349 | - .spawn(move || watch(seq, exe, receiver)); | ||
| 350 | -} | ||
| 351 | - | ||
| 352 | -fn spread(limit: Duration) -> Duration { | ||
| 353 | - let mut bytes = [0u8; 4]; | ||
| 354 | - let _ = SystemRandom::new().fill(&mut bytes); | ||
| 355 | - limit.mul_f64(f64::from(u32::from_le_bytes(bytes)) / f64::from(u32::MAX)) | ||
| 356 | -} | ||
| 357 | - | ||
| 358 | -fn watch(running: u64, exe: &'static Path, pokes: mpsc::Receiver<()>) { | ||
| 359 | - let Ok(runtime) = tokio::runtime::Builder::new_current_thread() | ||
| 360 | - .enable_all() | ||
| 361 | - .build() | ||
| 362 | - else { | ||
| 363 | - return; | ||
| 364 | - }; | ||
| 365 | - let mut installed = running; | ||
| 366 | - let mut retry = RETRY_FIRST; | ||
| 367 | - let mut wait = Some(FIRST_CHECK); | ||
| 368 | - loop { | ||
| 369 | - let woke = match wait { | ||
| 370 | - Some(wait) => pokes | ||
| 371 | - .recv_timeout(wait) | ||
| 372 | - .map_err(|error| error == mpsc::RecvTimeoutError::Disconnected), | ||
| 373 | - None => pokes.recv().map_err(|_| true), | ||
| 374 | - }; | ||
| 375 | - if woke == Err(true) { | ||
| 376 | - return; | ||
| 377 | - } | ||
| 378 | - if woke.is_ok() && !OUTDATED.load(Ordering::Relaxed) { | ||
| 379 | - std::thread::sleep(spread(POKE_SPREAD)); | ||
| 380 | - } | ||
| 381 | - while pokes.try_recv().is_ok() {} | ||
| 382 | - match runtime.block_on(check(running, installed, exe)) { | ||
| 383 | - Ok(Outcome::Current) => { | ||
| 384 | - retry = RETRY_FIRST; | ||
| 385 | - wait = None; | ||
| 386 | - } | ||
| 387 | - Ok(Outcome::Staged(next)) => { | ||
| 388 | - info!("update: {next} staged, applies on restart"); | ||
| 389 | - installed = next; | ||
| 390 | - retry = RETRY_FIRST; | ||
| 391 | - wait = None; | ||
| 392 | - } | ||
| 393 | - Ok(Outcome::Restart) => restart(exe), | ||
| 394 | - Err(fail) => { | ||
| 395 | - warn!("update: {fail:?}"); | ||
| 396 | - wait = Some(retry / 2 + spread(retry / 2)); | ||
| 397 | - retry = (retry * 2).min(RETRY_LAST); | ||
| 398 | - } | ||
| 399 | - } | ||
| 400 | - } | ||
| 401 | -} | ||
| 402 | - | ||
| 403 | -fn restart(exe: &Path) { | ||
| 404 | - info!("update: required, restarting"); | ||
| 405 | - let mut args: Vec<std::ffi::OsString> = Vec::new(); | ||
| 406 | - let mut skip = false; | ||
| 407 | - for arg in std::env::args_os().skip(1) { | ||
| 408 | - if std::mem::take(&mut skip) { | ||
| 409 | - continue; | ||
| 410 | - } | ||
| 411 | - if arg == AFTER { | ||
| 412 | - skip = true; | ||
| 413 | - continue; | ||
| 414 | - } | ||
| 415 | - args.push(arg); | ||
| 416 | - } | ||
| 417 | - let spawned = Command::new(exe) | ||
| 418 | - .args(args) | ||
| 419 | - .arg(AFTER) | ||
| 420 | - .arg(std::process::id().to_string()) | ||
| 421 | - .spawn(); | ||
| 422 | - match spawned { | ||
| 423 | - Ok(_) => std::process::exit(0), | ||
| 424 | - Err(error) => warn!("update: restart {error}"), | ||
| 425 | - } | ||
| 426 | -} | ||
| 427 | - | ||
| 428 | -async fn fetch(connection: &quinn::Connection, name: &str, maximum: u64) -> Result<Vec<u8>, Fail> { | ||
| 429 | - let (mut send, mut receive) = connection.open_bi().await?; | ||
| 430 | - wire::ask(&mut send, name).await?; | ||
| 431 | - Ok(wire::receive(&mut receive, maximum).await?) | ||
| 432 | -} | ||
| 433 | - | ||
| 434 | -async fn check(running: u64, installed: u64, exe: &Path) -> Result<Outcome, Fail> { | ||
| 435 | - crate::net::dial(&crate::Server::load(), wire::ALPN, async |connection| { | ||
| 436 | - fetch_release(connection, running, installed, exe).await | ||
| 437 | - }) | ||
| 438 | - .await | ||
| 439 | - .map_err(Fail::Link)? | ||
| 440 | -} | ||
| 441 | - | ||
| 442 | -async fn fetch_release( | ||
| 443 | - connection: &quinn::Connection, | ||
| 444 | - running: u64, | ||
| 445 | - installed: u64, | ||
| 446 | - exe: &Path, | ||
| 447 | -) -> Result<Outcome, Fail> { | ||
| 448 | - let manifest = fetch(connection, MANIFEST, MANIFEST_MAX).await?; | ||
| 449 | - let release = verify(&manifest, &targets(), keys::KEYS).map_err(Fail::Reject)?; | ||
| 450 | - let required = running < release.minimum || OUTDATED.load(Ordering::Relaxed); | ||
| 451 | - if release.seq <= installed { | ||
| 452 | - return Ok(if required && installed > running { | ||
| 453 | - Outcome::Restart | ||
| 454 | - } else { | ||
| 455 | - Outcome::Current | ||
| 456 | - }); | ||
| 457 | - } | ||
| 458 | - if number(&state(exe, "skip")) == Some(release.seq) { | ||
| 459 | - return Ok(Outcome::Current); | ||
| 460 | - } | ||
| 461 | - let file = open_new(exe)?; | ||
| 462 | - info!("update: downloading {} ({})", release.version, release.seq); | ||
| 463 | - let bytes = fetch( | ||
| 464 | - connection, | ||
| 465 | - &wire::file_name(&release.name, release.seq), | ||
| 466 | - release.size, | ||
| 467 | - ) | ||
| 468 | - .await; | ||
| 469 | - let bytes = bytes.inspect_err(|_| { | ||
| 470 | - let _ = fs::remove_file(sibling(exe, "new")); | ||
| 471 | - })?; | ||
| 472 | - if bytes.len() as u64 != release.size | ||
| 473 | - || digest::digest(&digest::SHA256, &bytes).as_ref() != release.sha256 | ||
| 474 | - { | ||
| 475 | - let _ = fs::remove_file(sibling(exe, "new")); | ||
| 476 | - return Err(Fail::Hash); | ||
| 477 | - } | ||
| 478 | - stage(exe, file, &bytes, release.seq)?; | ||
| 479 | - Ok(if required { | ||
| 480 | - Outcome::Restart | ||
| 481 | - } else { | ||
| 482 | - Outcome::Staged(release.seq) | ||
| 483 | - }) | ||
| 484 | -} | ||
| 485 | - | ||
| 486 | -fn verify(signed: &[u8], targets: &[String], keys: &[[u8; 32]]) -> Result<Release, Reject> { | ||
| 487 | - let (sig, body) = wire::split(signed).ok_or(Reject::Short)?; | ||
| 488 | - let signed_by_us = keys.iter().any(|key| { | ||
| 489 | - signature::UnparsedPublicKey::new(&signature::ED25519, key) | ||
| 490 | - .verify(body, sig) | ||
| 491 | - .is_ok() | ||
| 492 | - }); | ||
| 493 | - if !signed_by_us { | ||
| 494 | - return Err(Reject::Signature); | ||
| 495 | - } | ||
| 496 | - let manifest = wire::parse(body).ok_or(Reject::Format)?; | ||
| 497 | - let file = targets | ||
| 498 | - .iter() | ||
| 499 | - .find_map(|target| manifest.file(target)) | ||
| 500 | - .ok_or(Reject::Target)?; | ||
| 501 | - Ok(Release { | ||
| 502 | - name: file.name.clone(), | ||
| 503 | - seq: manifest.seq, | ||
| 504 | - minimum: manifest.minimum, | ||
| 505 | - version: manifest.version.clone(), | ||
| 506 | - size: file.size, | ||
| 507 | - sha256: file.sha256, | ||
| 508 | - }) | ||
| 509 | -} | ||
| 510 | - | ||
| 511 | -fn open_new(exe: &Path) -> std::io::Result<fs::File> { | ||
| 512 | - let new = sibling(exe, "new"); | ||
| 513 | - let _ = fs::remove_file(&new); | ||
| 514 | - let mut options = fs::OpenOptions::new(); | ||
| 515 | - options.write(true).create_new(true); | ||
| 516 | - #[cfg(unix)] | ||
| 517 | - std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o755); | ||
| 518 | - options.open(&new) | ||
| 519 | -} | ||
| 520 | - | ||
| 521 | -fn stage(exe: &Path, mut file: fs::File, bytes: &[u8], seq: u64) -> Result<(), Fail> { | ||
| 522 | - let new = sibling(exe, "new"); | ||
| 523 | - let written = file.write_all(bytes).and_then(|()| file.sync_all()); | ||
| 524 | - drop(file); | ||
| 525 | - let staged = written.map_err(Fail::Io).and_then(|()| { | ||
| 526 | - run_selftest(&new, seq).inspect_err(|_| { | ||
| 527 | - let _ = put(&state(exe, "skip"), &seq.to_string()); | ||
| 528 | - }) | ||
| 529 | - }); | ||
| 530 | - let staged = staged.and_then(|()| swap(exe, &new, seq)); | ||
| 531 | - if staged.is_err() { | ||
| 532 | - let _ = fs::remove_file(&new); | ||
| 533 | - } | ||
| 534 | - staged | ||
| 535 | -} | ||
| 536 | - | ||
| 537 | -fn run_selftest(new: &Path, seq: u64) -> Result<(), Fail> { | ||
| 538 | - let mut child = Command::new(new) | ||
| 539 | - .arg(SELFTEST) | ||
| 540 | - .stdin(Stdio::null()) | ||
| 541 | - .stdout(Stdio::piped()) | ||
| 542 | - .stderr(Stdio::null()) | ||
| 543 | - .spawn()?; | ||
| 544 | - let started = Instant::now(); | ||
| 545 | - let status = loop { | ||
| 546 | - if let Some(status) = child.try_wait()? { | ||
| 547 | - break status; | ||
| 548 | - } | ||
| 549 | - if started.elapsed() > SELFTEST_LIMIT { | ||
| 550 | - let _ = child.kill(); | ||
| 551 | - let _ = child.wait(); | ||
| 552 | - return Err(Fail::Selftest); | ||
| 553 | - } | ||
| 554 | - std::thread::sleep(Duration::from_millis(100)); | ||
| 555 | - }; | ||
| 556 | - let mut out = String::new(); | ||
| 557 | - if let Some(mut stdout) = child.stdout.take() { | ||
| 558 | - let _ = stdout.read_to_string(&mut out); | ||
| 559 | - } | ||
| 560 | - if !status.success() || out.trim() != seq.to_string() { | ||
| 561 | - return Err(Fail::Selftest); | ||
| 562 | - } | ||
| 563 | - Ok(()) | ||
| 564 | -} | ||
| 565 | - | ||
| 566 | -fn swap(exe: &Path, new: &Path, seq: u64) -> Result<(), Fail> { | ||
| 567 | - let old = sibling(exe, "old"); | ||
| 568 | - let pending = state(exe, "pending"); | ||
| 569 | - let _ = fs::remove_file(&old); | ||
| 570 | - put(&pending, &seq.to_string())?; | ||
| 571 | - let swapped = replace(exe, new, &old); | ||
| 572 | - if swapped.is_err() { | ||
| 573 | - let _ = fs::remove_file(&pending); | ||
| 574 | - } | ||
| 575 | - sync_dir(exe); | ||
| 576 | - Ok(swapped?) | ||
| 577 | -} | ||
| 578 | - | ||
| 579 | -#[cfg(unix)] | ||
| 580 | -fn replace(exe: &Path, new: &Path, old: &Path) -> std::io::Result<()> { | ||
| 581 | - fs::hard_link(exe, old).or_else(|_| fs::copy(exe, old).map(drop))?; | ||
| 582 | - fs::rename(new, exe).inspect_err(|_| { | ||
| 583 | - let _ = fs::remove_file(old); | ||
| 584 | - }) | ||
| 585 | -} | ||
| 586 | - | ||
| 587 | -#[cfg(not(unix))] | ||
| 588 | -fn replace(exe: &Path, new: &Path, old: &Path) -> std::io::Result<()> { | ||
| 589 | - fs::rename(exe, old)?; | ||
| 590 | - fs::rename(new, exe).inspect_err(|_| { | ||
| 591 | - let _ = fs::rename(old, exe); | ||
| 592 | - }) | ||
| 593 | -} | ||
| 594 | - | ||
| 595 | -#[cfg(test)] | ||
| 596 | -mod tests { | ||
| 597 | - use ring::{ | ||
| 598 | - rand::SystemRandom, | ||
| 599 | - signature::{Ed25519KeyPair, KeyPair}, | ||
| 600 | - }; | ||
| 601 | - | ||
| 602 | - use common::update::MAGIC; | ||
| 603 | - | ||
| 604 | - use super::*; | ||
| 605 | - | ||
| 606 | - fn signed(key: &Ed25519KeyPair, body: &str) -> Vec<u8> { | ||
| 607 | - let mut out = key.sign(body.as_bytes()).as_ref().to_vec(); | ||
| 608 | - out.extend_from_slice(body.as_bytes()); | ||
| 609 | - out | ||
| 610 | - } | ||
| 611 | - | ||
| 612 | - fn pair() -> (Ed25519KeyPair, [u8; 32]) { | ||
| 613 | - let pkcs8 = Ed25519KeyPair::generate_pkcs8(&SystemRandom::new()).unwrap(); | ||
| 614 | - let key = Ed25519KeyPair::from_pkcs8(pkcs8.as_ref()).unwrap(); | ||
| 615 | - let public = key.public_key().as_ref().try_into().unwrap(); | ||
| 616 | - (key, public) | ||
| 617 | - } | ||
| 618 | - | ||
| 619 | - const HASH: &str = "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"; | ||
| 620 | - | ||
| 621 | - #[test] | ||
| 622 | - fn verifies() { | ||
| 623 | - let (key, public) = pair(); | ||
| 624 | - let body = format!( | ||
| 625 | - "{MAGIC}\nseq 7\nminimum 3\nversion 0.2.0\nx86_64_v3-linux 10 {HASH}\nx86_64_v4-linux 20 {HASH}\n" | ||
| 626 | - ); | ||
| 627 | - let wanted = ["x86_64_v4-linux".to_string(), "x86_64_v3-linux".to_string()]; | ||
| 628 | - let release = verify(&signed(&key, &body), &wanted, &[public]).unwrap(); | ||
| 629 | - assert_eq!(release.name, "x86_64_v4-linux"); | ||
| 630 | - let release = verify(&signed(&key, &body), &wanted[1..], &[public]).unwrap(); | ||
| 631 | - assert_eq!(release.name, "x86_64_v3-linux"); | ||
| 632 | - let release = verify(&signed(&key, &body), &wanted, &[public]).unwrap(); | ||
| 633 | - assert_eq!( | ||
| 634 | - ( | ||
| 635 | - release.seq, | ||
| 636 | - release.minimum, | ||
| 637 | - release.size, | ||
| 638 | - release.sha256[1] | ||
| 639 | - ), | ||
| 640 | - (7, 3, 20, 0x11) | ||
| 641 | - ); | ||
| 642 | - } | ||
| 643 | - | ||
| 644 | - #[test] | ||
| 645 | - fn rejects() { | ||
| 646 | - let (key, public) = pair(); | ||
| 647 | - let (other, _) = pair(); | ||
| 648 | - let good = format!("{MAGIC}\nseq 7\nminimum 7\nversion 1\nx86_64-linux 10 {HASH}\n"); | ||
| 649 | - let mut tampered = signed(&key, &good); | ||
| 650 | - *tampered.last_mut().unwrap() ^= 1; | ||
| 651 | - let cases = [ | ||
| 652 | - signed(&other, &good), | ||
| 653 | - tampered, | ||
| 654 | - signed(&key, &good)[..63].to_vec(), | ||
| 655 | - signed(&key, &good.replace("x86_64-linux", "aarch64-linux")), | ||
| 656 | - signed(&key, &format!("{good}x86_64-linux 10 {HASH}\n")), | ||
| 657 | - signed(&key, &good.replace(" 10 ", " 0 ")), | ||
| 658 | - signed(&key, &good.replace("seq 7", "seq x")), | ||
| 659 | - signed(&key, &good.replace(MAGIC, "yumush-update 2")), | ||
| 660 | - signed(&key, &format!("{good}manifest 10 {HASH}\n")), | ||
| 661 | - signed(&key, &good.replace("minimum 7", "minimum 8")), | ||
| 662 | - signed(&key, &good.replace("minimum 7", "minimum 0")), | ||
| 663 | - signed(&key, &good.replace("minimum 7\n", "")), | ||
| 664 | - ]; | ||
| 665 | - for case in cases { | ||
| 666 | - assert!(verify(&case, &["x86_64-linux".to_string()], &[public]).is_err()); | ||
| 667 | - } | ||
| 668 | - } | ||
| 669 | -} | ||
crates/client/src/update/keys.rsdeleted+0 -1
| @@ -1 +0,0 @@ | |||
| 1 | -pub const KEYS: &[[u8; 32]] = &[]; | ||
crates/common/src/call.rsmodified+2 -13
| @@ -7,9 +7,8 @@ use crate::{ | |||
| 7 | model::{ | 7 | model::{ |
| 8 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, | 8 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, |
| 9 | Community, CommunitySummary, CommunityUsage, DayStat, Edit, Friends, Id, Invitation, | 9 | Community, CommunitySummary, CommunityUsage, DayStat, Edit, Friends, Id, Invitation, |
| 10 | - InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Release, | 10 | + InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Report, |
| 11 | - Report, ReportStatus, ServerBan, ServerSettings, SessionInfo, Unread, Usage, User, | 11 | + ReportStatus, ServerBan, ServerSettings, SessionInfo, Unread, Usage, User, VoiceRoom, |
| 12 | - VoiceRoom, | ||
| 13 | }, | 12 | }, |
| 14 | share::{Codec, Kind, Quality, Share, Source}, | 13 | share::{Codec, Kind, Quality, Share, Source}, |
| 15 | stats::Stats, | 14 | stats::Stats, |
| @@ -625,14 +624,6 @@ pub struct CreateBackup; | |||
| 625 | #[derive(Debug, Clone, Encode, Decode)] | 624 | #[derive(Debug, Clone, Encode, Decode)] |
| 626 | pub struct ListBackups; | 625 | pub struct ListBackups; |
| 627 | 626 | ||
| 628 | -#[derive(Debug, Clone, Encode, Decode)] | ||
| 629 | -pub struct GetRelease; | ||
| 630 | - | ||
| 631 | -#[derive(Debug, Clone, Encode, Decode)] | ||
| 632 | -pub struct PushRelease { | ||
| 633 | - pub manifest: Vec<u8>, | ||
| 634 | -} | ||
| 635 | - | ||
| 636 | #[derive(Debug, Clone, Encode, Decode)] | 627 | #[derive(Debug, Clone, Encode, Decode)] |
| 637 | pub struct FollowStats { | 628 | pub struct FollowStats { |
| 638 | pub user_id: Option<Id>, | 629 | pub user_id: Option<Id>, |
| @@ -772,8 +763,6 @@ calls! { | |||
| 772 | CreateBackup: Builder -> BackupInfo; | 763 | CreateBackup: Builder -> BackupInfo; |
| 773 | ListBackups: Builder -> Vec<BackupInfo>; | 764 | ListBackups: Builder -> Vec<BackupInfo>; |
| 774 | DeleteBackup: Builder -> (); | 765 | DeleteBackup: Builder -> (); |
| 775 | - GetRelease: Builder -> Option<Release>; | ||
| 776 | - PushRelease: Builder -> Release; | ||
| 777 | FollowStats: Builder -> Option<Stats>; | 766 | FollowStats: Builder -> Option<Stats>; |
| 778 | PushStats: User -> (); | 767 | PushStats: User -> (); |
| 779 | GetServerStats: Builder -> Stats; | 768 | GetServerStats: Builder -> Stats; |
crates/common/src/error.rsmodified+0 -2
| @@ -145,8 +145,6 @@ pub enum Error { | |||
| 145 | RateLimited { retry_after_seconds: u64 }, | 145 | RateLimited { retry_after_seconds: u64 }, |
| 146 | #[error("{field} {}", .problem.describe(.field))] | 146 | #[error("{field} {}", .problem.describe(.field))] |
| 147 | Invalid { field: Field, problem: Problem }, | 147 | Invalid { field: Field, problem: Problem }, |
| 148 | - #[error("release: {0}")] | ||
| 149 | - Release(String), | ||
| 150 | #[error("server error")] | 148 | #[error("server error")] |
| 151 | Server, | 149 | Server, |
| 152 | } | 150 | } |
crates/common/src/event.rsmodified+0 -1
| @@ -86,7 +86,6 @@ pub enum Event { | |||
| 86 | user_id: Id, | 86 | user_id: Id, |
| 87 | stats: Stats, | 87 | stats: Stats, |
| 88 | }, | 88 | }, |
| 89 | - Release, | ||
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | #[derive(Debug, Clone, Encode, Decode)] | 91 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/lib.rsmodified+0 -1
| @@ -13,5 +13,4 @@ pub mod share; | |||
| 13 | pub mod stats; | 13 | pub mod stats; |
| 14 | pub mod time; | 14 | pub mod time; |
| 15 | pub mod transport; | 15 | pub mod transport; |
| 16 | -pub mod update; | ||
| 17 | pub mod validate; | 16 | pub mod validate; |
crates/common/src/model.rsmodified+0 -18
| @@ -114,7 +114,6 @@ pub struct Account { | |||
| 114 | pub struct SessionInfo { | 114 | pub struct SessionInfo { |
| 115 | pub id: Id, | 115 | pub id: Id, |
| 116 | pub device: String, | 116 | pub device: String, |
| 117 | - pub release: Option<u64>, | ||
| 118 | pub last_seen: Option<u64>, | 117 | pub last_seen: Option<u64>, |
| 119 | } | 118 | } |
| 120 | 119 | ||
| @@ -266,7 +265,6 @@ pub enum AdminAction { | |||
| 266 | BackupCreated { name: String }, | 265 | BackupCreated { name: String }, |
| 267 | BackupDeleted { name: String }, | 266 | BackupDeleted { name: String }, |
| 268 | BackupDownloaded { name: String }, | 267 | BackupDownloaded { name: String }, |
| 269 | - ReleasePushed { seq: u64, minimum: u64 }, | ||
| 270 | Community(LogAction), | 268 | Community(LogAction), |
| 271 | } | 269 | } |
| 272 | 270 | ||
| @@ -304,7 +302,6 @@ string_enum! { | |||
| 304 | BackupCreated => "backup_created", | 302 | BackupCreated => "backup_created", |
| 305 | BackupDeleted => "backup_deleted", | 303 | BackupDeleted => "backup_deleted", |
| 306 | BackupDownloaded => "backup_downloaded", | 304 | BackupDownloaded => "backup_downloaded", |
| 307 | - ReleasePushed => "release_pushed", | ||
| 308 | Community => "community", | 305 | Community => "community", |
| 309 | } | 306 | } |
| 310 | } | 307 | } |
| @@ -343,7 +340,6 @@ impl AdminAction { | |||
| 343 | AdminAction::BackupCreated { .. } => AdminActionKind::BackupCreated, | 340 | AdminAction::BackupCreated { .. } => AdminActionKind::BackupCreated, |
| 344 | AdminAction::BackupDeleted { .. } => AdminActionKind::BackupDeleted, | 341 | AdminAction::BackupDeleted { .. } => AdminActionKind::BackupDeleted, |
| 345 | AdminAction::BackupDownloaded { .. } => AdminActionKind::BackupDownloaded, | 342 | AdminAction::BackupDownloaded { .. } => AdminActionKind::BackupDownloaded, |
| 346 | - AdminAction::ReleasePushed { .. } => AdminActionKind::ReleasePushed, | ||
| 347 | AdminAction::Community(_) => AdminActionKind::Community, | 343 | AdminAction::Community(_) => AdminActionKind::Community, |
| 348 | } | 344 | } |
| 349 | } | 345 | } |
| @@ -429,13 +425,6 @@ pub struct AttachmentInfo { | |||
| 429 | pub community: String, | 425 | pub community: String, |
| 430 | } | 426 | } |
| 431 | 427 | ||
| 432 | -#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | ||
| 433 | -pub struct Release { | ||
| 434 | - pub seq: u64, | ||
| 435 | - pub minimum: u64, | ||
| 436 | - pub version: String, | ||
| 437 | -} | ||
| 438 | - | ||
| 439 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 428 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
| 440 | pub struct BackupInfo { | 429 | pub struct BackupInfo { |
| 441 | pub name: String, | 430 | pub name: String, |
| @@ -489,13 +478,6 @@ pub struct Overview { | |||
| 489 | pub online: u64, | 478 | pub online: u64, |
| 490 | pub voice: u64, | 479 | pub voice: u64, |
| 491 | pub storage_bytes: u64, | 480 | pub storage_bytes: u64, |
| 492 | - pub releases: Vec<ReleaseCount>, | ||
| 493 | -} | ||
| 494 | - | ||
| 495 | -#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] | ||
| 496 | -pub struct ReleaseCount { | ||
| 497 | - pub release: Option<u64>, | ||
| 498 | - pub clients: u64, | ||
| 499 | } | 481 | } |
| 500 | 482 | ||
| 501 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] | 483 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] |
crates/common/src/open.rsmodified+0 -8
| @@ -7,14 +7,6 @@ pub enum Open { | |||
| 7 | Call(Box<Request>), | 7 | Call(Box<Request>), |
| 8 | Upload(Upload), | 8 | Upload(Upload), |
| 9 | Fetch(Blob), | 9 | Fetch(Blob), |
| 10 | - Publish(Publish), | ||
| 11 | -} | ||
| 12 | - | ||
| 13 | -#[derive(Debug, Clone, Encode, Decode)] | ||
| 14 | -pub struct Publish { | ||
| 15 | - pub name: String, | ||
| 16 | - pub size: u64, | ||
| 17 | - pub sha256: [u8; 32], | ||
| 18 | } | 10 | } |
| 19 | 11 | ||
| 20 | #[derive(Debug, Clone, Encode, Decode)] | 12 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/session.rsmodified+0 -1
| @@ -6,7 +6,6 @@ use crate::model::User; | |||
| 6 | pub struct Hello { | 6 | pub struct Hello { |
| 7 | pub token: Option<String>, | 7 | pub token: Option<String>, |
| 8 | pub device: String, | 8 | pub device: String, |
| 9 | - pub release: Option<u64>, | ||
| 10 | } | 9 | } |
| 11 | 10 | ||
| 12 | #[derive(Debug, Clone, Encode, Decode)] | 11 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/transport.rsmodified+1 -4
| @@ -174,11 +174,10 @@ pub enum Close { | |||
| 174 | Maintenance = 4, | 174 | Maintenance = 4, |
| 175 | Slow = 5, | 175 | Slow = 5, |
| 176 | Protocol = 6, | 176 | Protocol = 6, |
| 177 | - Outdated = 7, | ||
| 178 | } | 177 | } |
| 179 | 178 | ||
| 180 | impl Close { | 179 | impl Close { |
| 181 | - pub const ALL: [Self; 8] = [ | 180 | + pub const ALL: [Self; 7] = [ |
| 182 | Self::Normal, | 181 | Self::Normal, |
| 183 | Self::SignedOut, | 182 | Self::SignedOut, |
| 184 | Self::Revoked, | 183 | Self::Revoked, |
| @@ -186,7 +185,6 @@ impl Close { | |||
| 186 | Self::Maintenance, | 185 | Self::Maintenance, |
| 187 | Self::Slow, | 186 | Self::Slow, |
| 188 | Self::Protocol, | 187 | Self::Protocol, |
| 189 | - Self::Outdated, | ||
| 190 | ]; | 188 | ]; |
| 191 | 189 | ||
| 192 | pub fn of(code: VarInt) -> Option<Self> { | 190 | pub fn of(code: VarInt) -> Option<Self> { |
| @@ -202,7 +200,6 @@ impl Close { | |||
| 202 | Self::Maintenance => "maintenance", | 200 | Self::Maintenance => "maintenance", |
| 203 | Self::Slow => "slow", | 201 | Self::Slow => "slow", |
| 204 | Self::Protocol => "protocol error", | 202 | Self::Protocol => "protocol error", |
| 205 | - Self::Outdated => "outdated", | ||
| 206 | } | 203 | } |
| 207 | } | 204 | } |
| 208 | 205 | ||
crates/common/src/update.rsdeleted+0 -187
| @@ -1,187 +0,0 @@ | |||
| 1 | -use quinn::{RecvStream, SendStream}; | ||
| 2 | - | ||
| 3 | -pub const ALPN: &[u8] = b"yumush-update/1"; | ||
| 4 | -pub const MANIFEST: &str = "manifest"; | ||
| 5 | -pub const MANIFEST_MAX: u64 = 64 << 10; | ||
| 6 | -pub const FILE_MAX: u64 = 512 << 20; | ||
| 7 | -const NAME_MAX: usize = 32; | ||
| 8 | -const MISSING: u64 = u64::MAX; | ||
| 9 | - | ||
| 10 | -#[derive(Debug, thiserror::Error)] | ||
| 11 | -pub enum UpdateError { | ||
| 12 | - #[error(transparent)] | ||
| 13 | - Write(#[from] quinn::WriteError), | ||
| 14 | - #[error(transparent)] | ||
| 15 | - Read(#[from] quinn::ReadExactError), | ||
| 16 | - #[error(transparent)] | ||
| 17 | - ReadToEnd(#[from] quinn::ReadToEndError), | ||
| 18 | - #[error(transparent)] | ||
| 19 | - Closed(#[from] quinn::ClosedStream), | ||
| 20 | - #[error("invalid name")] | ||
| 21 | - Name, | ||
| 22 | - #[error("missing")] | ||
| 23 | - Missing, | ||
| 24 | - #[error("size {0}")] | ||
| 25 | - Size(u64), | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -pub fn valid_name(name: &str) -> bool { | ||
| 29 | - !name.is_empty() | ||
| 30 | - && name.len() <= NAME_MAX | ||
| 31 | - && name.bytes().all(|byte| { | ||
| 32 | - byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'_' || byte == b'-' | ||
| 33 | - }) | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -pub async fn ask(send: &mut SendStream, name: &str) -> Result<(), UpdateError> { | ||
| 37 | - if !valid_name(name) { | ||
| 38 | - return Err(UpdateError::Name); | ||
| 39 | - } | ||
| 40 | - send.write_all(&[name.len() as u8]).await?; | ||
| 41 | - send.write_all(name.as_bytes()).await?; | ||
| 42 | - send.finish()?; | ||
| 43 | - Ok(()) | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | -pub async fn asked(receive: &mut RecvStream) -> Result<String, UpdateError> { | ||
| 47 | - let mut length = [0u8; 1]; | ||
| 48 | - receive.read_exact(&mut length).await?; | ||
| 49 | - let length = length[0] as usize; | ||
| 50 | - if length > NAME_MAX { | ||
| 51 | - return Err(UpdateError::Name); | ||
| 52 | - } | ||
| 53 | - let mut name = vec![0u8; length]; | ||
| 54 | - receive.read_exact(&mut name).await?; | ||
| 55 | - let name = String::from_utf8(name).map_err(|_| UpdateError::Name)?; | ||
| 56 | - if !valid_name(&name) { | ||
| 57 | - return Err(UpdateError::Name); | ||
| 58 | - } | ||
| 59 | - Ok(name) | ||
| 60 | -} | ||
| 61 | - | ||
| 62 | -pub async fn answer_size(send: &mut SendStream, size: Option<u64>) -> Result<(), UpdateError> { | ||
| 63 | - send.write_all(&size.unwrap_or(MISSING).to_le_bytes()) | ||
| 64 | - .await?; | ||
| 65 | - Ok(()) | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -pub async fn receive(receive: &mut RecvStream, maximum: u64) -> Result<Vec<u8>, UpdateError> { | ||
| 69 | - let mut size = [0u8; 8]; | ||
| 70 | - receive.read_exact(&mut size).await?; | ||
| 71 | - let size = u64::from_le_bytes(size); | ||
| 72 | - if size == MISSING { | ||
| 73 | - return Err(UpdateError::Missing); | ||
| 74 | - } | ||
| 75 | - if size > maximum { | ||
| 76 | - return Err(UpdateError::Size(size)); | ||
| 77 | - } | ||
| 78 | - let bytes = receive.read_to_end(maximum as usize).await?; | ||
| 79 | - if bytes.len() as u64 != size { | ||
| 80 | - return Err(UpdateError::Size(bytes.len() as u64)); | ||
| 81 | - } | ||
| 82 | - Ok(bytes) | ||
| 83 | -} | ||
| 84 | - | ||
| 85 | -pub const MAGIC: &str = "yumush-update 1"; | ||
| 86 | -pub const SIGNATURE_BYTES: usize = 64; | ||
| 87 | - | ||
| 88 | -#[derive(Debug, PartialEq, Eq)] | ||
| 89 | -pub struct Manifest { | ||
| 90 | - pub seq: u64, | ||
| 91 | - pub minimum: u64, | ||
| 92 | - pub version: String, | ||
| 93 | - pub files: Vec<File>, | ||
| 94 | -} | ||
| 95 | - | ||
| 96 | -#[derive(Debug, PartialEq, Eq)] | ||
| 97 | -pub struct File { | ||
| 98 | - pub name: String, | ||
| 99 | - pub size: u64, | ||
| 100 | - pub sha256: [u8; 32], | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -pub fn file_name(target: &str, seq: u64) -> String { | ||
| 104 | - format!("{target}-{seq}") | ||
| 105 | -} | ||
| 106 | - | ||
| 107 | -impl Manifest { | ||
| 108 | - pub fn release(&self) -> crate::model::Release { | ||
| 109 | - crate::model::Release { | ||
| 110 | - seq: self.seq, | ||
| 111 | - minimum: self.minimum, | ||
| 112 | - version: self.version.clone(), | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - pub fn file(&self, name: &str) -> Option<&File> { | ||
| 117 | - self.files.iter().find(|file| file.name == name) | ||
| 118 | - } | ||
| 119 | -} | ||
| 120 | - | ||
| 121 | -pub fn split(signed: &[u8]) -> Option<(&[u8], &[u8])> { | ||
| 122 | - signed.split_at_checked(SIGNATURE_BYTES) | ||
| 123 | -} | ||
| 124 | - | ||
| 125 | -pub fn parse(body: &[u8]) -> Option<Manifest> { | ||
| 126 | - let text = std::str::from_utf8(body).ok()?; | ||
| 127 | - let mut lines = text.split('\n'); | ||
| 128 | - if lines.next() != Some(MAGIC) { | ||
| 129 | - return None; | ||
| 130 | - } | ||
| 131 | - let seq = number(lines.next(), "seq")?; | ||
| 132 | - let minimum = number(lines.next(), "minimum").filter(|minimum| *minimum <= seq)?; | ||
| 133 | - let version = field(lines.next(), "version") | ||
| 134 | - .filter(|value| !value.is_empty())? | ||
| 135 | - .to_string(); | ||
| 136 | - let mut files: Vec<File> = Vec::new(); | ||
| 137 | - for line in lines.filter(|line| !line.is_empty()) { | ||
| 138 | - let mut parts = line.split(' '); | ||
| 139 | - let (Some(name), Some(size), Some(hash), None) = | ||
| 140 | - (parts.next(), parts.next(), parts.next(), parts.next()) | ||
| 141 | - else { | ||
| 142 | - return None; | ||
| 143 | - }; | ||
| 144 | - if !valid_name(name) || name == MANIFEST || files.iter().any(|file| file.name == name) { | ||
| 145 | - return None; | ||
| 146 | - } | ||
| 147 | - files.push(File { | ||
| 148 | - name: name.to_string(), | ||
| 149 | - size: size | ||
| 150 | - .parse() | ||
| 151 | - .ok() | ||
| 152 | - .filter(|size| (1..=FILE_MAX).contains(size))?, | ||
| 153 | - sha256: hex32(hash)?, | ||
| 154 | - }); | ||
| 155 | - } | ||
| 156 | - Some(Manifest { | ||
| 157 | - seq, | ||
| 158 | - minimum, | ||
| 159 | - version, | ||
| 160 | - files, | ||
| 161 | - }) | ||
| 162 | -} | ||
| 163 | - | ||
| 164 | -fn field<'a>(line: Option<&'a str>, key: &str) -> Option<&'a str> { | ||
| 165 | - line?.strip_prefix(key)?.strip_prefix(' ') | ||
| 166 | -} | ||
| 167 | - | ||
| 168 | -fn number(line: Option<&str>, key: &str) -> Option<u64> { | ||
| 169 | - field(line, key)?.parse().ok().filter(|value| *value > 0) | ||
| 170 | -} | ||
| 171 | - | ||
| 172 | -fn hex32(text: &str) -> Option<[u8; 32]> { | ||
| 173 | - let bytes = text.as_bytes(); | ||
| 174 | - if bytes.len() != 64 { | ||
| 175 | - return None; | ||
| 176 | - } | ||
| 177 | - let digit = |byte: u8| match byte { | ||
| 178 | - b'0'..=b'9' => Some(byte - b'0'), | ||
| 179 | - b'a'..=b'f' => Some(byte - b'a' + 10), | ||
| 180 | - _ => None, | ||
| 181 | - }; | ||
| 182 | - let mut out = [0u8; 32]; | ||
| 183 | - for (index, pair) in bytes.chunks(2).enumerate() { | ||
| 184 | - out[index] = digit(pair[0])? << 4 | digit(pair[1])?; | ||
| 185 | - } | ||
| 186 | - Some(out) | ||
| 187 | -} | ||
crates/server/src/authentication.rsmodified+0 -1
| @@ -234,7 +234,6 @@ mod tests { | |||
| 234 | services: Services::default(), | 234 | services: Services::default(), |
| 235 | directory: test::directory(), | 235 | directory: test::directory(), |
| 236 | backups: test::directory(), | 236 | backups: test::directory(), |
| 237 | - updates: test::directory(), | ||
| 238 | }; | 237 | }; |
| 239 | let client = Client::detached(None); | 238 | let client = Client::detached(None); |
| 240 | 239 | ||
crates/server/src/call/admin.rsmodified+7 -41
| @@ -1,19 +1,18 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | call::{ | 2 | call::{ |
| 3 | BanUser, ClearProfile, CreateBackup, CreateInviteCode, CreateUser, DeleteAttachment, | 3 | BanUser, ClearProfile, CreateBackup, CreateInviteCode, CreateUser, DeleteAttachment, |
| 4 | - DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetRelease, | 4 | + DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetStorageUsage, |
| 5 | - GetStorageUsage, ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, | 5 | + ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, ListInviteCodes, |
| 6 | - ListInviteCodes, ListServerBans, ListUsers, Logout, PurgeUser, PushRelease, | 6 | + ListServerBans, ListUsers, Logout, PurgeUser, RemoveServerBan, RenameUser, ResetPassword, |
| 7 | - RemoveServerBan, RenameUser, ResetPassword, RevokeSessions, SearchCommunity, | 7 | + RevokeSessions, SearchCommunity, SearchMessages, SetCommunityVoice, SetGhost, StorageUsage, |
| 8 | - SearchMessages, SetCommunityVoice, SetGhost, StorageUsage, SuspendUser, TimeoutUser, | 8 | + SuspendUser, TimeoutUser, TransferOwnership, UpdateServerSettings, WatchCommunity, |
| 9 | - TransferOwnership, UpdateServerSettings, WatchCommunity, | ||
| 10 | }, | 9 | }, |
| 11 | error::Error, | 10 | error::Error, |
| 12 | event::Event, | 11 | event::Event, |
| 13 | model::{ | 12 | model::{ |
| 14 | Account, AdminAction, AdminLogEntry, AttachmentInfo, BackupInfo, BanScope, Community, | 13 | Account, AdminAction, AdminLogEntry, AttachmentInfo, BackupInfo, BanScope, Community, |
| 15 | - CommunitySummary, DayStat, InviteCode, LogAction, MessageHit, Overview, Rank, Release, | 14 | + CommunitySummary, DayStat, InviteCode, LogAction, MessageHit, Overview, Rank, ServerBan, |
| 16 | - ReleaseCount, ServerBan, ServerBanKind, ServerSettings, User, | 15 | + ServerBanKind, ServerSettings, User, |
| 17 | }, | 16 | }, |
| 18 | permission, | 17 | permission, |
| 19 | time::{self, MINUTE_MILLIS}, | 18 | time::{self, MINUTE_MILLIS}, |
| @@ -190,17 +189,6 @@ impl Handle for GetOverview { | |||
| 190 | online: cx.sh.services.hub.online() as u64, | 189 | online: cx.sh.services.hub.online() as u64, |
| 191 | voice: cx.sh.services.rooms.count() as u64, | 190 | voice: cx.sh.services.rooms.count() as u64, |
| 192 | storage_bytes, | 191 | storage_bytes, |
| 193 | - releases: cx | ||
| 194 | - .sh | ||
| 195 | - .services | ||
| 196 | - .hub | ||
| 197 | - .releases() | ||
| 198 | - .into_iter() | ||
| 199 | - .map(|(release, clients)| ReleaseCount { | ||
| 200 | - release: (release != u64::MAX).then_some(release), | ||
| 201 | - clients, | ||
| 202 | - }) | ||
| 203 | - .collect(), | ||
| 204 | }) | 192 | }) |
| 205 | } | 193 | } |
| 206 | } | 194 | } |
| @@ -642,28 +630,6 @@ impl Handle for CreateBackup { | |||
| 642 | } | 630 | } |
| 643 | } | 631 | } |
| 644 | 632 | ||
| 645 | -impl Handle for GetRelease { | ||
| 646 | - async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Option<Release>, ServerError> { | ||
| 647 | - Ok(crate::update::live(&cx.sh.updates) | ||
| 648 | - .await | ||
| 649 | - .map(|manifest| manifest.release())) | ||
| 650 | - } | ||
| 651 | -} | ||
| 652 | - | ||
| 653 | -impl Handle for PushRelease { | ||
| 654 | - async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<Release, ServerError> { | ||
| 655 | - let me = me.user()?; | ||
| 656 | - let release = crate::update::push(&self.manifest, cx.sh).await?; | ||
| 657 | - let action = AdminAction::ReleasePushed { | ||
| 658 | - seq: release.seq, | ||
| 659 | - minimum: release.minimum, | ||
| 660 | - }; | ||
| 661 | - log::record_admin(Some(me.id), None, None, &action, cx.db).await?; | ||
| 662 | - | ||
| 663 | - Ok(release) | ||
| 664 | - } | ||
| 665 | -} | ||
| 666 | - | ||
| 667 | impl Handle for ListBackups { | 633 | impl Handle for ListBackups { |
| 668 | async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Vec<BackupInfo>, ServerError> { | 634 | async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Vec<BackupInfo>, ServerError> { |
| 669 | backup::list(&cx.sh.backups) | 635 | backup::list(&cx.sh.backups) |
crates/server/src/call/mod.rsmodified+0 -2
| @@ -214,8 +214,6 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | |||
| 214 | Request::SetGhost(call) => serve(call, cx).await, | 214 | Request::SetGhost(call) => serve(call, cx).await, |
| 215 | Request::CreateBackup(call) => serve(call, cx).await, | 215 | Request::CreateBackup(call) => serve(call, cx).await, |
| 216 | Request::ListBackups(call) => serve(call, cx).await, | 216 | Request::ListBackups(call) => serve(call, cx).await, |
| 217 | - Request::GetRelease(call) => serve(call, cx).await, | ||
| 218 | - Request::PushRelease(call) => serve(call, cx).await, | ||
| 219 | Request::DeleteBackup(call) => serve(call, cx).await, | 217 | Request::DeleteBackup(call) => serve(call, cx).await, |
| 220 | Request::FollowStats(call) => serve(call, cx).await, | 218 | Request::FollowStats(call) => serve(call, cx).await, |
| 221 | Request::PushStats(call) => serve(call, cx).await, | 219 | Request::PushStats(call) => serve(call, cx).await, |
crates/server/src/certificate.rsmodified+1 -4
| @@ -115,10 +115,7 @@ pub fn load(certificate_path: &str, key_path: &str) -> Result<quinn::ServerConfi | |||
| 115 | .with_no_client_auth() | 115 | .with_no_client_auth() |
| 116 | .with_cert_resolver(reloader.clone()); | 116 | .with_cert_resolver(reloader.clone()); |
| 117 | tls.max_early_data_size = u32::MAX; | 117 | tls.max_early_data_size = u32::MAX; |
| 118 | - tls.alpn_protocols = vec![ | 118 | + tls.alpn_protocols = vec![common::transport::ALPN.to_vec()]; |
| 119 | - common::transport::ALPN.to_vec(), | ||
| 120 | - common::update::ALPN.to_vec(), | ||
| 121 | - ]; | ||
| 122 | 119 | ||
| 123 | let crypto = | 120 | let crypto = |
| 124 | quinn::crypto::rustls::QuicServerConfig::try_from(tls).map_err(certificate_error)?; | 121 | quinn::crypto::rustls::QuicServerConfig::try_from(tls).map_err(certificate_error)?; |
crates/server/src/db/schema.sqlmodified+0 -1
| @@ -21,7 +21,6 @@ CREATE TABLE session ( | |||
| 21 | token_hash BLOB NOT NULL UNIQUE, | 21 | token_hash BLOB NOT NULL UNIQUE, |
| 22 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, | 22 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, |
| 23 | device TEXT NOT NULL DEFAULT '', | 23 | device TEXT NOT NULL DEFAULT '', |
| 24 | - release INTEGER, | ||
| 25 | last_seen INTEGER | 24 | last_seen INTEGER |
| 26 | ) STRICT; | 25 | ) STRICT; |
| 27 | CREATE INDEX session_user ON session (user_id); | 26 | CREATE INDEX session_user ON session (user_id); |
crates/server/src/db/session.rsmodified+4 -10
| @@ -60,16 +60,11 @@ pub async fn seen(session_id: Id, db: &Connection) -> Result<(), ServerError> { | |||
| 60 | Ok(()) | 60 | Ok(()) |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -pub async fn set_device( | 63 | +pub async fn set_device(session_id: Id, device: &str, db: &Connection) -> Result<(), ServerError> { |
| 64 | - session_id: Id, | ||
| 65 | - device: &str, | ||
| 66 | - release: Option<u64>, | ||
| 67 | - db: &Connection, | ||
| 68 | -) -> Result<(), ServerError> { | ||
| 69 | run( | 64 | run( |
| 70 | db, | 65 | db, |
| 71 | - "UPDATE session SET device = ?2, release = ?3 WHERE id = ?1", | 66 | + "UPDATE session SET device = ?2 WHERE id = ?1", |
| 72 | - (session_id, device, release.map(|release| release as i64)), | 67 | + (session_id, device), |
| 73 | ) | 68 | ) |
| 74 | .await?; | 69 | .await?; |
| 75 | 70 | ||
| @@ -79,13 +74,12 @@ pub async fn set_device( | |||
| 79 | pub async fn list(user_id: Id, db: &Connection) -> Result<Vec<SessionInfo>, ServerError> { | 74 | pub async fn list(user_id: Id, db: &Connection) -> Result<Vec<SessionInfo>, ServerError> { |
| 80 | all( | 75 | all( |
| 81 | db, | 76 | db, |
| 82 | - "SELECT id, device, release, last_seen FROM session WHERE user_id = ?1 ORDER BY last_seen DESC", | 77 | + "SELECT id, device, last_seen FROM session WHERE user_id = ?1 ORDER BY last_seen DESC", |
| 83 | (user_id,), | 78 | (user_id,), |
| 84 | |r| { | 79 | |r| { |
| 85 | Ok(SessionInfo { | 80 | Ok(SessionInfo { |
| 86 | id: r.get()?, | 81 | id: r.get()?, |
| 87 | device: r.get()?, | 82 | device: r.get()?, |
| 88 | - release: r.get::<Option<i64>>()?.map(|release| release as u64), | ||
| 89 | last_seen: r.get()?, | 83 | last_seen: r.get()?, |
| 90 | }) | 84 | }) |
| 91 | }, | 85 | }, |
crates/server/src/error.rsmodified+0 -1
| @@ -75,6 +75,5 @@ internal_from! { | |||
| 75 | bitcode::Error, | 75 | bitcode::Error, |
| 76 | common::config::ConfigError, | 76 | common::config::ConfigError, |
| 77 | common::frame::FrameError, | 77 | common::frame::FrameError, |
| 78 | - common::update::UpdateError, | ||
| 79 | tokio::time::error::Elapsed, | 78 | tokio::time::error::Elapsed, |
| 80 | } | 79 | } |
crates/server/src/hub.rsmodified+0 -26
| @@ -29,7 +29,6 @@ pub struct Client { | |||
| 29 | pub me: Option<Signed>, | 29 | pub me: Option<Signed>, |
| 30 | tx: mpsc::Sender<Bytes>, | 30 | tx: mpsc::Sender<Bytes>, |
| 31 | pub closed: AtomicBool, | 31 | pub closed: AtomicBool, |
| 32 | - pub release: AtomicU64, | ||
| 33 | watching: Mutex<Option<Id>>, | 32 | watching: Mutex<Option<Id>>, |
| 34 | ghost_logged: Mutex<HashSet<Id>>, | 33 | ghost_logged: Mutex<HashSet<Id>>, |
| 35 | } | 34 | } |
| @@ -43,7 +42,6 @@ impl Client { | |||
| 43 | me, | 42 | me, |
| 44 | tx, | 43 | tx, |
| 45 | closed: AtomicBool::new(false), | 44 | closed: AtomicBool::new(false), |
| 46 | - release: AtomicU64::new(u64::MAX), | ||
| 47 | watching: Mutex::new(None), | 45 | watching: Mutex::new(None), |
| 48 | ghost_logged: Mutex::new(HashSet::new()), | 46 | ghost_logged: Mutex::new(HashSet::new()), |
| 49 | }); | 47 | }); |
| @@ -194,30 +192,6 @@ impl Hub { | |||
| 194 | } | 192 | } |
| 195 | } | 193 | } |
| 196 | 194 | ||
| 197 | - pub fn releases(&self) -> std::collections::BTreeMap<u64, u64> { | ||
| 198 | - let mut counts = std::collections::BTreeMap::new(); | ||
| 199 | - for client in self.0.lock().unwrap().values() { | ||
| 200 | - *counts | ||
| 201 | - .entry(client.release.load(Ordering::Relaxed)) | ||
| 202 | - .or_default() += 1; | ||
| 203 | - } | ||
| 204 | - counts | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - pub fn kick_outdated(&self, minimum: u64) { | ||
| 208 | - let targets: Vec<Arc<Client>> = self | ||
| 209 | - .0 | ||
| 210 | - .lock() | ||
| 211 | - .unwrap() | ||
| 212 | - .values() | ||
| 213 | - .filter(|client| client.release.load(Ordering::Relaxed) < minimum) | ||
| 214 | - .cloned() | ||
| 215 | - .collect(); | ||
| 216 | - for client in targets { | ||
| 217 | - client.close(Close::Outdated); | ||
| 218 | - } | ||
| 219 | - } | ||
| 220 | - | ||
| 221 | pub fn kick_user(&self, user_id: Id, close: Close) { | 195 | pub fn kick_user(&self, user_id: Id, close: Close) { |
| 222 | self.kick_where(|me| me.user_id == user_id, close); | 196 | self.kick_where(|me| me.user_id == user_id, close); |
| 223 | } | 197 | } |
crates/server/src/lib.rsmodified+0 -3
| @@ -14,7 +14,6 @@ pub mod request; | |||
| 14 | pub mod retention; | 14 | pub mod retention; |
| 15 | pub mod rooms; | 15 | pub mod rooms; |
| 16 | pub mod stats; | 16 | pub mod stats; |
| 17 | -pub mod update; | ||
| 18 | 17 | ||
| 19 | #[cfg(test)] | 18 | #[cfg(test)] |
| 20 | mod test; | 19 | mod test; |
| @@ -74,7 +73,6 @@ pub async fn showtime() -> Result<(), ServerError> { | |||
| 74 | let certificate = certificate::load(&config.certificate_path, &config.key_path)?; | 73 | let certificate = certificate::load(&config.certificate_path, &config.key_path)?; |
| 75 | let attachments = sibling_directory(&config.database_path, "attachments")?; | 74 | let attachments = sibling_directory(&config.database_path, "attachments")?; |
| 76 | let backups = sibling_directory(&config.database_path, "backups")?; | 75 | let backups = sibling_directory(&config.database_path, "backups")?; |
| 77 | - let updates = sibling_directory(&config.database_path, "updates")?; | ||
| 78 | tokio::spawn(files::collect(database.clone(), attachments.clone())); | 76 | tokio::spawn(files::collect(database.clone(), attachments.clone())); |
| 79 | 77 | ||
| 80 | network::serve( | 78 | network::serve( |
| @@ -83,7 +81,6 @@ pub async fn showtime() -> Result<(), ServerError> { | |||
| 83 | database, | 81 | database, |
| 84 | attachments, | 82 | attachments, |
| 85 | backups, | 83 | backups, |
| 86 | - updates, | ||
| 87 | ) | 84 | ) |
| 88 | .await | 85 | .await |
| 89 | } | 86 | } |
crates/server/src/network.rsmodified+1 -26
| @@ -40,7 +40,6 @@ pub struct Services { | |||
| 40 | pub rate_limit: RateLimit, | 40 | pub rate_limit: RateLimit, |
| 41 | pub stats: Follows, | 41 | pub stats: Follows, |
| 42 | pub machine: Machine, | 42 | pub machine: Machine, |
| 43 | - pub minimum: std::sync::Arc<std::sync::atomic::AtomicU64>, | ||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | #[derive(Clone)] | 45 | #[derive(Clone)] |
| @@ -49,7 +48,6 @@ pub(crate) struct Shared { | |||
| 49 | pub(crate) services: Services, | 48 | pub(crate) services: Services, |
| 50 | pub(crate) directory: PathBuf, | 49 | pub(crate) directory: PathBuf, |
| 51 | pub(crate) backups: PathBuf, | 50 | pub(crate) backups: PathBuf, |
| 52 | - pub(crate) updates: PathBuf, | ||
| 53 | } | 51 | } |
| 54 | 52 | ||
| 55 | struct Pending { | 53 | struct Pending { |
| @@ -65,7 +63,6 @@ pub async fn serve( | |||
| 65 | db: Db, | 63 | db: Db, |
| 66 | directory: PathBuf, | 64 | directory: PathBuf, |
| 67 | backups: PathBuf, | 65 | backups: PathBuf, |
| 68 | - updates: PathBuf, | ||
| 69 | ) -> Result<(), ServerError> { | 66 | ) -> Result<(), ServerError> { |
| 70 | let endpoint = transport::endpoint( | 67 | let endpoint = transport::endpoint( |
| 71 | server_address.parse()?, | 68 | server_address.parse()?, |
| @@ -79,12 +76,10 @@ pub async fn serve( | |||
| 79 | services: Services::default(), | 76 | services: Services::default(), |
| 80 | directory, | 77 | directory, |
| 81 | backups, | 78 | backups, |
| 82 | - updates, | ||
| 83 | }; | 79 | }; |
| 84 | shared.services.machine.watch(shared.directory.clone()); | 80 | shared.services.machine.watch(shared.directory.clone()); |
| 85 | 81 | ||
| 86 | tokio::spawn(retention::collect(shared.clone())); | 82 | tokio::spawn(retention::collect(shared.clone())); |
| 87 | - crate::update::load(&shared).await; | ||
| 88 | 83 | ||
| 89 | while let Some(incoming) = endpoint.accept().await { | 84 | while let Some(incoming) = endpoint.accept().await { |
| 90 | tokio::spawn(handle_connection(incoming, shared.clone())); | 85 | tokio::spawn(handle_connection(incoming, shared.clone())); |
| @@ -113,14 +108,6 @@ async fn serve_connection(incoming: Incoming, shared: Shared) -> Result<(), Serv | |||
| 113 | return Ok(()); | 108 | return Ok(()); |
| 114 | } | 109 | } |
| 115 | let connection = incoming.await?; | 110 | let connection = incoming.await?; |
| 116 | - let alpn = connection | ||
| 117 | - .handshake_data() | ||
| 118 | - .and_then(|data| data.downcast::<quinn::crypto::rustls::HandshakeData>().ok()) | ||
| 119 | - .and_then(|data| data.protocol); | ||
| 120 | - if alpn.as_deref() == Some(common::update::ALPN) { | ||
| 121 | - crate::update::serve(connection, shared.updates.clone()).await; | ||
| 122 | - return Ok(()); | ||
| 123 | - } | ||
| 124 | let pending = match tokio::time::timeout(HELLO_DEADLINE, greet(&connection, &shared)).await { | 111 | let pending = match tokio::time::timeout(HELLO_DEADLINE, greet(&connection, &shared)).await { |
| 125 | Ok(Ok(Some(pending))) => pending, | 112 | Ok(Ok(Some(pending))) => pending, |
| 126 | Ok(Ok(None)) => return Ok(()), | 113 | Ok(Ok(None)) => return Ok(()), |
| @@ -232,16 +219,9 @@ async fn greet(connection: &Connection, shared: &Shared) -> Result<Option<Pendin | |||
| 232 | let (send_stream, mut receive_stream) = connection.accept_bi().await?; | 219 | let (send_stream, mut receive_stream) = connection.accept_bi().await?; |
| 233 | let mut reply_stream = Sending::new(send_stream); | 220 | let mut reply_stream = Sending::new(send_stream); |
| 234 | let hello: Hello = frame::read(&mut receive_stream, UP_MAX).await?; | 221 | let hello: Hello = frame::read(&mut receive_stream, UP_MAX).await?; |
| 235 | - let release = hello.release.unwrap_or(u64::MAX); | ||
| 236 | - if release < shared.services.minimum.load(Ordering::Relaxed) { | ||
| 237 | - close(connection, Close::Outdated); | ||
| 238 | - return Ok(None); | ||
| 239 | - } | ||
| 240 | - | ||
| 241 | match admit(hello, connection, shared).await { | 222 | match admit(hello, connection, shared).await { |
| 242 | Ok((me, user)) => { | 223 | Ok((me, user)) => { |
| 243 | let (client, events) = Client::new(Some(connection.clone()), me); | 224 | let (client, events) = Client::new(Some(connection.clone()), me); |
| 244 | - client.release.store(release, Ordering::Relaxed); | ||
| 245 | 225 | ||
| 246 | Ok(Some(Pending { | 226 | Ok(Some(Pending { |
| 247 | client, | 227 | client, |
| @@ -278,7 +258,7 @@ async fn admit( | |||
| 278 | db::user::set_last_ip(user.id, &ip, db).await?; | 258 | db::user::set_last_ip(user.id, &ip, db).await?; |
| 279 | let device = async { | 259 | let device = async { |
| 280 | validate_device(&hello.device)?; | 260 | validate_device(&hello.device)?; |
| 281 | - db::session::set_device(session_id, &hello.device, hello.release, db).await | 261 | + db::session::set_device(session_id, &hello.device, db).await |
| 282 | } | 262 | } |
| 283 | .await; | 263 | .await; |
| 284 | if let Err(error) = device { | 264 | if let Err(error) = device { |
| @@ -342,11 +322,6 @@ async fn route( | |||
| 342 | ) | 322 | ) |
| 343 | .await | 323 | .await |
| 344 | } | 324 | } |
| 345 | - Open::Publish(publish) => { | ||
| 346 | - let user = signed_user(&client, &shared).await?; | ||
| 347 | - crate::update::publish(user.as_ref(), publish, receive_stream, send_stream, &shared) | ||
| 348 | - .await | ||
| 349 | - } | ||
| 350 | Open::Fetch(blob) => { | 325 | Open::Fetch(blob) => { |
| 351 | let user = signed_user(&client, &shared).await?; | 326 | let user = signed_user(&client, &shared).await?; |
| 352 | files::fetch( | 327 | files::fetch( |
crates/server/src/request.rsmodified+0 -1
| @@ -373,7 +373,6 @@ mod tests { | |||
| 373 | services: services.clone(), | 373 | services: services.clone(), |
| 374 | directory: test::directory(), | 374 | directory: test::directory(), |
| 375 | backups: test::directory(), | 375 | backups: test::directory(), |
| 376 | - updates: test::directory(), | ||
| 377 | } | 376 | } |
| 378 | } | 377 | } |
| 379 | 378 | ||
crates/server/src/update.rsdeleted+0 -274
| @@ -1,274 +0,0 @@ | |||
| 1 | -use std::{ | ||
| 2 | - collections::HashMap, | ||
| 3 | - net::IpAddr, | ||
| 4 | - path::{Path, PathBuf}, | ||
| 5 | - sync::Mutex, | ||
| 6 | - time::Duration, | ||
| 7 | -}; | ||
| 8 | - | ||
| 9 | -use common::{ | ||
| 10 | - error::Error, | ||
| 11 | - frame::{self, DOWN_MAX, Sending}, | ||
| 12 | - model::{Release, User}, | ||
| 13 | - open::Publish, | ||
| 14 | - permission, | ||
| 15 | - update::{self, FILE_MAX, MANIFEST, MANIFEST_MAX, Manifest}, | ||
| 16 | -}; | ||
| 17 | -use quinn::{Connection, RecvStream, SendStream}; | ||
| 18 | -use sha2::{Digest, Sha256}; | ||
| 19 | -use std::sync::atomic::Ordering; | ||
| 20 | -use tokio::{ | ||
| 21 | - io::{AsyncReadExt, AsyncWriteExt}, | ||
| 22 | - sync::Semaphore, | ||
| 23 | - time::timeout, | ||
| 24 | -}; | ||
| 25 | -use tracing::warn; | ||
| 26 | - | ||
| 27 | -use crate::{ | ||
| 28 | - error::{ServerError, ensure}, | ||
| 29 | - network::Shared, | ||
| 30 | -}; | ||
| 31 | - | ||
| 32 | -const STREAMS: usize = 4; | ||
| 33 | -const ACCEPT_DEADLINE: Duration = Duration::from_secs(30); | ||
| 34 | -const ASK_DEADLINE: Duration = Duration::from_secs(5); | ||
| 35 | -const TRANSFER_DEADLINE: Duration = Duration::from_secs(15 * 60); | ||
| 36 | -const STALL_DEADLINE: Duration = Duration::from_secs(30); | ||
| 37 | -static TURN: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); | ||
| 38 | -const CHUNK: usize = 64 << 10; | ||
| 39 | -static PERMITS: Semaphore = Semaphore::const_new(16); | ||
| 40 | -const PER_PEER: u8 = 4; | ||
| 41 | -static PEERS: Mutex<Option<HashMap<IpAddr, u8>>> = Mutex::new(None); | ||
| 42 | - | ||
| 43 | -struct Peer(IpAddr); | ||
| 44 | - | ||
| 45 | -impl Peer { | ||
| 46 | - fn claim(ip: IpAddr) -> Option<Self> { | ||
| 47 | - let mut peers = PEERS.lock().unwrap(); | ||
| 48 | - let count = peers.get_or_insert_default().entry(ip).or_default(); | ||
| 49 | - if *count >= PER_PEER { | ||
| 50 | - return None; | ||
| 51 | - } | ||
| 52 | - *count += 1; | ||
| 53 | - Some(Self(ip)) | ||
| 54 | - } | ||
| 55 | -} | ||
| 56 | - | ||
| 57 | -impl Drop for Peer { | ||
| 58 | - fn drop(&mut self) { | ||
| 59 | - if let Some(peers) = PEERS.lock().unwrap().as_mut() | ||
| 60 | - && let Some(count) = peers.get_mut(&self.0) | ||
| 61 | - { | ||
| 62 | - *count -= 1; | ||
| 63 | - if *count == 0 { | ||
| 64 | - peers.remove(&self.0); | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - } | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -pub async fn serve(connection: Connection, directory: PathBuf) { | ||
| 71 | - let (Some(_peer), Ok(_permit)) = ( | ||
| 72 | - Peer::claim(connection.remote_address().ip()), | ||
| 73 | - PERMITS.try_acquire(), | ||
| 74 | - ) else { | ||
| 75 | - connection.close(0u32.into(), b"busy"); | ||
| 76 | - return; | ||
| 77 | - }; | ||
| 78 | - for _ in 0..STREAMS { | ||
| 79 | - let Ok(Ok((mut send, mut receive))) = | ||
| 80 | - timeout(ACCEPT_DEADLINE, connection.accept_bi()).await | ||
| 81 | - else { | ||
| 82 | - break; | ||
| 83 | - }; | ||
| 84 | - let sent = timeout( | ||
| 85 | - TRANSFER_DEADLINE, | ||
| 86 | - transfer(&mut send, &mut receive, &directory), | ||
| 87 | - ) | ||
| 88 | - .await; | ||
| 89 | - if let Err(error) = sent.map_err(ServerError::from).and_then(|sent| sent) { | ||
| 90 | - warn!("update: {error}"); | ||
| 91 | - break; | ||
| 92 | - } | ||
| 93 | - } | ||
| 94 | - let _ = timeout(ACCEPT_DEADLINE, connection.closed()).await; | ||
| 95 | - connection.close(0u32.into(), b""); | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -async fn transfer( | ||
| 99 | - send: &mut SendStream, | ||
| 100 | - receive: &mut RecvStream, | ||
| 101 | - directory: &Path, | ||
| 102 | -) -> Result<(), ServerError> { | ||
| 103 | - let name = timeout(ASK_DEADLINE, update::asked(receive)).await??; | ||
| 104 | - let maximum = if name == MANIFEST { | ||
| 105 | - MANIFEST_MAX | ||
| 106 | - } else { | ||
| 107 | - FILE_MAX | ||
| 108 | - }; | ||
| 109 | - let path = directory.join(&name); | ||
| 110 | - let metadata = tokio::fs::metadata(&path) | ||
| 111 | - .await | ||
| 112 | - .ok() | ||
| 113 | - .filter(|metadata| metadata.is_file() && metadata.len() <= maximum); | ||
| 114 | - let Some(metadata) = metadata else { | ||
| 115 | - update::answer_size(send, None).await?; | ||
| 116 | - send.finish()?; | ||
| 117 | - return Ok(()); | ||
| 118 | - }; | ||
| 119 | - | ||
| 120 | - update::answer_size(send, Some(metadata.len())).await?; | ||
| 121 | - let mut file = tokio::fs::File::open(&path).await?; | ||
| 122 | - let mut remaining = metadata.len(); | ||
| 123 | - let mut chunk = vec![0u8; CHUNK]; | ||
| 124 | - while remaining > 0 { | ||
| 125 | - let want = remaining.min(CHUNK as u64) as usize; | ||
| 126 | - let read = file.read(&mut chunk[..want]).await?; | ||
| 127 | - if read == 0 { | ||
| 128 | - break; | ||
| 129 | - } | ||
| 130 | - timeout(STALL_DEADLINE, send.write_all(&chunk[..read])).await??; | ||
| 131 | - remaining -= read as u64; | ||
| 132 | - } | ||
| 133 | - send.finish()?; | ||
| 134 | - | ||
| 135 | - Ok(()) | ||
| 136 | -} | ||
| 137 | - | ||
| 138 | -pub(crate) async fn live(directory: &Path) -> Option<Manifest> { | ||
| 139 | - let signed = tokio::fs::read(directory.join(MANIFEST)).await.ok()?; | ||
| 140 | - let (_, body) = update::split(&signed)?; | ||
| 141 | - update::parse(body) | ||
| 142 | -} | ||
| 143 | - | ||
| 144 | -pub(crate) async fn load(shared: &Shared) { | ||
| 145 | - if let Some(manifest) = live(&shared.updates).await { | ||
| 146 | - shared | ||
| 147 | - .services | ||
| 148 | - .minimum | ||
| 149 | - .store(manifest.minimum, Ordering::Relaxed); | ||
| 150 | - } | ||
| 151 | -} | ||
| 152 | - | ||
| 153 | -fn rejected(problem: impl std::fmt::Display) -> ServerError { | ||
| 154 | - Error::Release(problem.to_string()).into() | ||
| 155 | -} | ||
| 156 | - | ||
| 157 | -pub(crate) async fn push(signed: &[u8], shared: &Shared) -> Result<Release, ServerError> { | ||
| 158 | - let _turn = TURN.lock().await; | ||
| 159 | - let directory = &shared.updates; | ||
| 160 | - let manifest = update::split(signed) | ||
| 161 | - .and_then(|(_, body)| update::parse(body)) | ||
| 162 | - .ok_or_else(|| rejected("bad manifest"))?; | ||
| 163 | - if let Some(current) = live(directory).await | ||
| 164 | - && manifest.seq <= current.seq | ||
| 165 | - { | ||
| 166 | - return Err(rejected(format!( | ||
| 167 | - "{} is not above live {}", | ||
| 168 | - manifest.seq, current.seq | ||
| 169 | - ))); | ||
| 170 | - } | ||
| 171 | - let mut keep = vec![MANIFEST.to_string()]; | ||
| 172 | - for file in &manifest.files { | ||
| 173 | - let name = update::file_name(&file.name, manifest.seq); | ||
| 174 | - let size = tokio::fs::metadata(directory.join(&name)) | ||
| 175 | - .await | ||
| 176 | - .map(|metadata| metadata.len()) | ||
| 177 | - .ok(); | ||
| 178 | - if size != Some(file.size) { | ||
| 179 | - return Err(rejected(format!("{name} not uploaded"))); | ||
| 180 | - } | ||
| 181 | - keep.push(name); | ||
| 182 | - } | ||
| 183 | - let part = directory.join("manifest.part"); | ||
| 184 | - tokio::fs::write(&part, signed).await?; | ||
| 185 | - tokio::fs::File::open(&part).await?.sync_all().await?; | ||
| 186 | - tokio::fs::rename(&part, directory.join(MANIFEST)).await?; | ||
| 187 | - let mut entries = tokio::fs::read_dir(directory).await?; | ||
| 188 | - while let Some(entry) = entries.next_entry().await? { | ||
| 189 | - let name = entry.file_name().to_string_lossy().into_owned(); | ||
| 190 | - if !keep.contains(&name) && !name.ends_with(".part") { | ||
| 191 | - let _ = tokio::fs::remove_file(entry.path()).await; | ||
| 192 | - } | ||
| 193 | - } | ||
| 194 | - | ||
| 195 | - let services = &shared.services; | ||
| 196 | - services.minimum.store(manifest.minimum, Ordering::Relaxed); | ||
| 197 | - services.hub.kick_outdated(manifest.minimum); | ||
| 198 | - announce(shared); | ||
| 199 | - | ||
| 200 | - Ok(manifest.release()) | ||
| 201 | -} | ||
| 202 | - | ||
| 203 | -pub(crate) async fn publish( | ||
| 204 | - user: Option<&User>, | ||
| 205 | - header: Publish, | ||
| 206 | - mut receive: RecvStream, | ||
| 207 | - mut send: Sending, | ||
| 208 | - shared: &Shared, | ||
| 209 | -) -> Result<(), ServerError> { | ||
| 210 | - let stored = store(user, &header, &mut receive, &shared.updates).await; | ||
| 211 | - let rejected = stored.is_err(); | ||
| 212 | - let reply = stored.map_err(Error::from); | ||
| 213 | - frame::write(&mut send, &reply, DOWN_MAX).await?; | ||
| 214 | - send.finish()?; | ||
| 215 | - if rejected { | ||
| 216 | - let _ = receive.stop(0u32.into()); | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - Ok(()) | ||
| 220 | -} | ||
| 221 | - | ||
| 222 | -async fn store( | ||
| 223 | - user: Option<&User>, | ||
| 224 | - header: &Publish, | ||
| 225 | - receive: &mut RecvStream, | ||
| 226 | - directory: &Path, | ||
| 227 | -) -> Result<(), ServerError> { | ||
| 228 | - let user = user.ok_or(Error::Unauthenticated)?; | ||
| 229 | - ensure(permission::is_builder(user.role))?; | ||
| 230 | - let name = &header.name; | ||
| 231 | - if !update::valid_name(name) || name == MANIFEST || !(1..=FILE_MAX).contains(&header.size) { | ||
| 232 | - return Err(rejected("bad file")); | ||
| 233 | - } | ||
| 234 | - let part = directory.join(format!("{name}.part")); | ||
| 235 | - let written = async { | ||
| 236 | - let mut file = tokio::fs::File::create(&part).await?; | ||
| 237 | - let mut hash = Sha256::new(); | ||
| 238 | - let mut remaining = header.size; | ||
| 239 | - let mut chunk = vec![0u8; CHUNK]; | ||
| 240 | - while remaining > 0 { | ||
| 241 | - let want = remaining.min(CHUNK as u64) as usize; | ||
| 242 | - let read = timeout(STALL_DEADLINE, receive.read(&mut chunk[..want])) | ||
| 243 | - .await? | ||
| 244 | - .map_err(|error| ServerError::Internal(error.to_string()))? | ||
| 245 | - .ok_or_else(|| rejected("short upload"))?; | ||
| 246 | - hash.update(&chunk[..read]); | ||
| 247 | - file.write_all(&chunk[..read]).await?; | ||
| 248 | - remaining -= read as u64; | ||
| 249 | - } | ||
| 250 | - if hash.finalize().as_slice() != header.sha256 { | ||
| 251 | - return Err(rejected("hash mismatch")); | ||
| 252 | - } | ||
| 253 | - file.sync_all().await?; | ||
| 254 | - tokio::fs::rename(&part, directory.join(name)).await?; | ||
| 255 | - | ||
| 256 | - Ok(()) | ||
| 257 | - } | ||
| 258 | - .await; | ||
| 259 | - if written.is_err() { | ||
| 260 | - let _ = tokio::fs::remove_file(&part).await; | ||
| 261 | - } | ||
| 262 | - | ||
| 263 | - written | ||
| 264 | -} | ||
| 265 | -fn announce(shared: &Shared) { | ||
| 266 | - let down = common::event::Down::Event(Box::new(common::event::Event::Release)); | ||
| 267 | - match common::frame::encode(&down, common::frame::DOWN_MAX) { | ||
| 268 | - Ok(bytes) => { | ||
| 269 | - let hub = &shared.services.hub; | ||
| 270 | - hub.send(&hub.all(), &bytes.into(), true); | ||
| 271 | - } | ||
| 272 | - Err(error) => warn!("update: announce {error}"), | ||
| 273 | - } | ||
| 274 | -} | ||
packaging/release-windows.ps1deleted+0 -22
| @@ -1,22 +0,0 @@ | |||
| 1 | -param( | ||
| 2 | - [Parameter(Mandatory)][ValidatePattern('^[1-9][0-9]{0,17}$')][string]$Seq, | ||
| 3 | - [Parameter(Mandatory)][string]$Levels | ||
| 4 | -) | ||
| 5 | -$ErrorActionPreference = 'Stop' | ||
| 6 | -Set-Location (Split-Path $PSScriptRoot) | ||
| 7 | -$env:Path += ";$env:USERPROFILE\.cargo\bin" | ||
| 8 | -$env:YUMUSH_RELEASE_SEQ = $Seq | ||
| 9 | -New-Item -ItemType Directory -Force "dist\$Seq" | Out-Null | ||
| 10 | -foreach ($level in $Levels.Split(' ')) { | ||
| 11 | - $name = "x86_64_$level-windows" | ||
| 12 | - $cpu = if ($level -eq 'v1') { 'x86-64' } else { "x86-64-$level" } | ||
| 13 | - $env:RUSTFLAGS = "-C target-feature=+crt-static -C target-cpu=$cpu -C link-arg=/OPT:REF -C link-arg=/OPT:ICF" | ||
| 14 | - $env:CARGO_TARGET_DIR = "..\target-release-$level" | ||
| 15 | - cargo build --release --locked -p client | ||
| 16 | - if ($LASTEXITCODE -ne 0) { throw 'build failed' } | ||
| 17 | - $exe = "..\target-release-$level\release\client.exe" | ||
| 18 | - try { $out = (& $exe --selftest | Out-String).Trim() } catch { $out = $Seq; Write-Output "$name cannot run on this CPU, selftest skipped" } | ||
| 19 | - if ($out -ne $Seq) { throw "$name selftest printed '$out'" } | ||
| 20 | - Copy-Item $exe "dist\$Seq\$name" | ||
| 21 | - Set-Content -NoNewline "dist\$Seq\$name.seq" $Seq | ||
| 22 | -} | ||
packaging/release.shdeleted+0 -53
| @@ -1,53 +0,0 @@ | |||
| 1 | -#!/usr/bin/env bash | ||
| 2 | -set -euo pipefail | ||
| 3 | -ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| 4 | -LEVELS="v1 v3 v4" | ||
| 5 | -cd "$ROOT" | ||
| 6 | -usage() { echo "usage: $0 linux|windows <seq>" >&2; exit 1; } | ||
| 7 | -[[ $# -eq 2 && "$2" =~ ^[1-9][0-9]{0,17}$ ]] || usage | ||
| 8 | -SEQ="$2" | ||
| 9 | -DIST="$ROOT/dist/$SEQ" | ||
| 10 | -[[ -z "$(git status --porcelain)" ]] || { echo "working tree is dirty" >&2; exit 1; } | ||
| 11 | -grep -q 0x crates/client/src/update/keys.rs || { echo "no signing keys in keys.rs" >&2; exit 1; } | ||
| 12 | -for done in "$ROOT"/dist/*/; do | ||
| 13 | - [[ -d "$done" && "$(basename "$done")" != "$SEQ" ]] || continue | ||
| 14 | - (( $(basename "$done") < SEQ )) || { echo "seq $SEQ is not above $(basename "$done")" >&2; exit 1; } | ||
| 15 | -done | ||
| 16 | -mkdir -p "$DIST" | ||
| 17 | - | ||
| 18 | -case "$1" in | ||
| 19 | -linux) | ||
| 20 | - for level in $LEVELS; do | ||
| 21 | - name="$(uname -m)_$level-linux" | ||
| 22 | - cpu="x86-64-$level"; [[ $level == v1 ]] && cpu="x86-64" | ||
| 23 | - RUSTFLAGS="-C target-cpu=$cpu -C link-arg=-Wl,--gc-sections -C link-arg=-Wl,-O2" \ | ||
| 24 | - CARGO_TARGET_DIR="target/release-$level" YUMUSH_RELEASE_SEQ="$SEQ" \ | ||
| 25 | - cargo build --release --locked -p client | ||
| 26 | - cp "target/release-$level/release/client" "$DIST/$name" | ||
| 27 | - if built=$("$DIST/$name" --selftest); then | ||
| 28 | - [[ "$built" == "$SEQ" ]] || { echo "$name selftest printed '$built'" >&2; exit 1; } | ||
| 29 | - else | ||
| 30 | - echo "$name cannot run on this CPU, selftest skipped" | ||
| 31 | - fi | ||
| 32 | - printf '%s' "$SEQ" > "$DIST/$name.seq" | ||
| 33 | - echo "built $name" | ||
| 34 | - done | ||
| 35 | - ;; | ||
| 36 | -windows) | ||
| 37 | - ssh_win() { ssh -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o LogLevel=ERROR -p 2222 yumush@127.0.0.1 "$@"; } | ||
| 38 | - scp_win() { scp -q -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -P 2222 "$@"; } | ||
| 39 | - TAR="$(mktemp --suffix=.tgz)" | ||
| 40 | - trap 'rm -f "$TAR"' EXIT | ||
| 41 | - git ls-files | tar czf "$TAR" -T - | ||
| 42 | - ssh_win 'Remove-Item -Recurse -Force release -ErrorAction SilentlyContinue; New-Item -ItemType Directory release | Out-Null' | ||
| 43 | - scp_win "$TAR" yumush@127.0.0.1:release.tgz | ||
| 44 | - ssh_win "tar xmzf release.tgz -C release; powershell -NoProfile -ExecutionPolicy Bypass -File release\\packaging\\release-windows.ps1 -Seq $SEQ -Levels '$LEVELS'" | ||
| 45 | - for level in $LEVELS; do | ||
| 46 | - name="x86_64_$level-windows" | ||
| 47 | - scp_win "yumush@127.0.0.1:release/dist/$SEQ/$name" "yumush@127.0.0.1:release/dist/$SEQ/$name.seq" "$DIST/" | ||
| 48 | - [[ "$(cat "$DIST/$name.seq")" == "$SEQ" ]] || { echo "$name seq mismatch" >&2; exit 1; } | ||
| 49 | - echo "built $name" | ||
| 50 | - done | ||
| 51 | - ;; | ||
| 52 | -*) usage ;; | ||
| 53 | -esac | ||