[verified] Add QR codec and ratatui roster.

M2: onionwire:v1 signed payload, Unicode QR, same-k locator update,
unknown-k approval in TUI. F4 is a no-op stub. No Tor in the bin.
This commit is contained in:
Sirius DevOps 2026-09-10 01:54:19 -04:00
commit 4fb4648552
No known key found for this signature in database
8 changed files with 959 additions and 32 deletions

View file

@ -47,6 +47,7 @@ pub struct Friend {
pub fingerprint: String,
pub petname: Option<String>,
pub onion: String,
pub last_connect_ok: bool,
}
impl Store {
@ -69,7 +70,8 @@ impl Store {
petname TEXT,
onion TEXT NOT NULL,
onion_updated_at INTEGER NOT NULL,
added_at INTEGER NOT NULL
added_at INTEGER NOT NULL,
last_connect_ok INTEGER NOT NULL DEFAULT 1
);
CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY,
@ -88,10 +90,26 @@ impl Store {
",
)?;
let store = Self { conn };
store.migrate()?;
store.ensure_self()?;
Ok(store)
}
fn migrate(&self) -> Result<()> {
let has: i64 = self.conn.query_row(
"SELECT COUNT(*) FROM pragma_table_info('friends') WHERE name = 'last_connect_ok'",
[],
|row| row.get(0),
)?;
if has == 0 {
self.conn.execute(
"ALTER TABLE friends ADD COLUMN last_connect_ok INTEGER NOT NULL DEFAULT 1",
[],
)?;
}
Ok(())
}
fn ensure_self(&self) -> Result<()> {
let exists: i64 =
self.conn
@ -151,7 +169,7 @@ impl Store {
pub fn get_friend(&self, pubkey: &[u8]) -> Result<Option<Friend>> {
self.conn
.query_row(
"SELECT pubkey, fingerprint, petname, onion FROM friends WHERE pubkey = ?1",
"SELECT pubkey, fingerprint, petname, onion, last_connect_ok FROM friends WHERE pubkey = ?1",
params![pubkey],
|row| {
Ok(Friend {
@ -159,12 +177,34 @@ impl Store {
fingerprint: row.get(1)?,
petname: row.get(2)?,
onion: row.get(3)?,
last_connect_ok: row.get::<_, i64>(4)? != 0,
})
},
)
.optional()
.map_err(Into::into)
}
pub fn list_friends(&self) -> Result<Vec<Friend>> {
let mut stmt = self.conn.prepare(
"SELECT pubkey, fingerprint, petname, onion, last_connect_ok FROM friends
ORDER BY COALESCE(petname, fingerprint) COLLATE NOCASE",
)?;
let rows = stmt.query_map([], |row| {
Ok(Friend {
pubkey: row.get(0)?,
fingerprint: row.get(1)?,
petname: row.get(2)?,
onion: row.get(3)?,
last_connect_ok: row.get::<_, i64>(4)? != 0,
})
})?;
let mut out = Vec::new();
for row in rows {
out.push(row?);
}
Ok(out)
}
}
fn home_dir() -> Result<PathBuf> {