mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-07 01:03:34 +02:00
Drop unnecessary decryption columns and rely on FK to messages table as indicator of decryption. Also, reboot retries radio connection
This commit is contained in:
+17
-31
@@ -483,10 +483,7 @@ class TestRawPacketRepository:
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL UNIQUE,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
message_id INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.commit()
|
||||
@@ -523,10 +520,7 @@ class TestRawPacketRepository:
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL UNIQUE,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
message_id INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.commit()
|
||||
@@ -567,10 +561,7 @@ class TestRawPacketRepository:
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL UNIQUE,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
message_id INTEGER
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -578,20 +569,21 @@ class TestRawPacketRepository:
|
||||
old_timestamp = now - (15 * 86400) # 15 days ago
|
||||
recent_timestamp = now - (5 * 86400) # 5 days ago
|
||||
|
||||
# Insert old undecrypted packet
|
||||
# Insert old undecrypted packet (message_id NULL = undecrypted)
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 0)",
|
||||
"INSERT INTO raw_packets (timestamp, data) VALUES (?, ?)",
|
||||
(old_timestamp, b"\x01\x02\x03"),
|
||||
)
|
||||
# Insert recent undecrypted packet
|
||||
# Insert recent undecrypted packet (message_id NULL = undecrypted)
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 0)",
|
||||
"INSERT INTO raw_packets (timestamp, data) VALUES (?, ?)",
|
||||
(recent_timestamp, b"\x04\x05\x06"),
|
||||
)
|
||||
# Insert old but decrypted packet (should NOT be deleted)
|
||||
# message_id NOT NULL = decrypted
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 1)",
|
||||
(old_timestamp, b"\x07\x08\x09"),
|
||||
"INSERT INTO raw_packets (timestamp, data, message_id) VALUES (?, ?, ?)",
|
||||
(old_timestamp, b"\x07\x08\x09", 1),
|
||||
)
|
||||
await conn.commit()
|
||||
|
||||
@@ -630,19 +622,16 @@ class TestRawPacketRepository:
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL UNIQUE,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
message_id INTEGER
|
||||
)
|
||||
""")
|
||||
|
||||
now = int(time.time())
|
||||
recent_timestamp = now - (5 * 86400) # 5 days ago
|
||||
|
||||
# Insert only recent packet
|
||||
# Insert only recent packet (message_id NULL = undecrypted)
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 0)",
|
||||
"INSERT INTO raw_packets (timestamp, data) VALUES (?, ?)",
|
||||
(recent_timestamp, b"\x01\x02\x03"),
|
||||
)
|
||||
await conn.commit()
|
||||
@@ -680,23 +669,20 @@ class TestMaintenanceEndpoint:
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL UNIQUE,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
message_id INTEGER
|
||||
)
|
||||
""")
|
||||
|
||||
now = int(time.time())
|
||||
old_timestamp = now - (20 * 86400) # 20 days ago
|
||||
|
||||
# Insert old undecrypted packets
|
||||
# Insert old undecrypted packets (message_id NULL = undecrypted)
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 0)",
|
||||
"INSERT INTO raw_packets (timestamp, data) VALUES (?, ?)",
|
||||
(old_timestamp, b"\x01\x02\x03"),
|
||||
)
|
||||
await conn.execute(
|
||||
"INSERT INTO raw_packets (timestamp, data, decrypted) VALUES (?, ?, 0)",
|
||||
"INSERT INTO raw_packets (timestamp, data) VALUES (?, ?)",
|
||||
(old_timestamp, b"\x04\x05\x06"),
|
||||
)
|
||||
await conn.commit()
|
||||
|
||||
@@ -65,13 +65,26 @@ class TestMigration001:
|
||||
on_radio INTEGER DEFAULT 0
|
||||
)
|
||||
""")
|
||||
# Raw packets table with old schema (for migrations 2 and 3)
|
||||
await conn.execute("""
|
||||
CREATE TABLE raw_packets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
|
||||
await conn.commit()
|
||||
|
||||
# Run migrations
|
||||
applied = await run_migrations(conn)
|
||||
|
||||
assert applied == 1
|
||||
assert await get_version(conn) == 1
|
||||
assert applied == 3 # All 3 migrations run
|
||||
assert await get_version(conn) == 3
|
||||
|
||||
# Verify columns exist by inserting and selecting
|
||||
await conn.execute(
|
||||
@@ -117,15 +130,28 @@ class TestMigration001:
|
||||
name TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
# Raw packets table with old schema (for migrations 2 and 3)
|
||||
await conn.execute("""
|
||||
CREATE TABLE raw_packets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
|
||||
await conn.commit()
|
||||
|
||||
# Run migrations twice
|
||||
applied1 = await run_migrations(conn)
|
||||
applied2 = await run_migrations(conn)
|
||||
|
||||
assert applied1 == 1
|
||||
assert applied1 == 3 # All 3 migrations run
|
||||
assert applied2 == 0 # No migrations on second run
|
||||
assert await get_version(conn) == 1
|
||||
assert await get_version(conn) == 3
|
||||
finally:
|
||||
await conn.close()
|
||||
|
||||
@@ -150,14 +176,27 @@ class TestMigration001:
|
||||
last_read_at INTEGER
|
||||
)
|
||||
""")
|
||||
# Raw packets table with old schema (for migrations 2 and 3)
|
||||
await conn.execute("""
|
||||
CREATE TABLE raw_packets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
|
||||
await conn.commit()
|
||||
|
||||
# Run migrations - should not fail
|
||||
applied = await run_migrations(conn)
|
||||
|
||||
# Still counts as applied (version incremented) but no error
|
||||
assert applied == 1
|
||||
assert await get_version(conn) == 1
|
||||
# All 3 migrations applied (version incremented) but no error
|
||||
assert applied == 3
|
||||
assert await get_version(conn) == 3
|
||||
finally:
|
||||
await conn.close()
|
||||
|
||||
@@ -182,6 +221,19 @@ class TestMigration001:
|
||||
is_hashtag INTEGER DEFAULT 0
|
||||
)
|
||||
""")
|
||||
# Raw packets table with old schema (for migrations 2 and 3)
|
||||
await conn.execute("""
|
||||
CREATE TABLE raw_packets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
decrypted INTEGER DEFAULT 0,
|
||||
message_id INTEGER,
|
||||
decrypt_attempts INTEGER DEFAULT 0,
|
||||
last_attempt INTEGER
|
||||
)
|
||||
""")
|
||||
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
|
||||
await conn.execute(
|
||||
"INSERT INTO contacts (public_key, name, type) VALUES (?, ?, ?)",
|
||||
("existingkey", "ExistingContact", 1),
|
||||
|
||||
@@ -519,9 +519,9 @@ class TestCreateMessageFromDecrypted:
|
||||
received_at=1700000001,
|
||||
)
|
||||
|
||||
# Verify packet is marked decrypted
|
||||
# Verify packet is marked decrypted (has message_id set)
|
||||
undecrypted = await RawPacketRepository.get_undecrypted(limit=100)
|
||||
packet_ids = [p[0] for p in undecrypted]
|
||||
packet_ids = [p.id for p in undecrypted]
|
||||
assert packet_id not in packet_ids # Should be marked as decrypted
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user