Fix pcapng timestamp resolution + imported-session duration

- pcap.py: _parse_tsresol now pads options to a 32-bit boundary
  ((-length) % 4) and uses 2** for the MSB-set (power-of-2) case, so
  nanosecond if_tsresol is read correctly (was defaulting to µs and
  scaling timestamps 1000x)
- database/server: set imported session started/ended from the first/last
  packet timestamps (falling back to wall-clock for synthetic SPB)
- frontend: formatDuration renders hours
- tests: tsresol (ns after padded option, default µs, ns round-trip) and
  session-window/fallback (119 total)
This commit is contained in:
catarrh committed 2026-08-15 02:02:44 +03:00
1 parent 5ba55ac3a9
commit c21b655fe1
5 files changed
+82 -4

No files matched your search

+11
View File
@@ -37,6 +37,11 @@ def _iso_now():
f'{time.time() % 1 * 1000:03.0f}'
def _iso_from_ts(ts):
return time.strftime('%Y-%m-%dT%H:%M:%S.', time.localtime(ts)) + \
f'{ts % 1 * 1000:03.0f}'
class Database:
def __init__(self, db_path=None):
if db_path is None:
@@ -64,6 +69,12 @@ class Database:
(_iso_now(), session_id))
self._conn.commit()
def set_session_times_from_ts(self, session_id, first_ts, last_ts):
self._conn.execute(
'UPDATE sessions SET started=?, ended=? WHERE id=?',
(_iso_from_ts(first_ts), _iso_from_ts(last_ts), session_id))
self._conn.commit()
def rename_session(self, session_id, name):
self._conn.execute(
'UPDATE sessions SET name=? WHERE id=?',
+9 -1
View File
@@ -322,12 +322,20 @@ class RequestHandler(BaseHTTPRequestHandler):
self.db.rename_session(session_id, name)
first_ts = packets[0][0]
last_ts = packets[-1][0]
rows = []
for ts, msg_type, payload in packets:
elapsed = round(ts - first_ts, 6) if ts is not None else 0.0
rows.append((max(0.0, elapsed), msg_type, payload, 0))
self.db.insert_messages(session_id, rows)
self.db.close_session(session_id)
# Use the packet timestamps as the session window when they are real
# (classic pcap / pcapng EPB). pcapng SPB-only files have synthetic
# 0,1,2,… timestamps, so fall back to the import wall-clock time.
_REAL_TS_MIN = 946684800 # 2000-01-01
if first_ts is not None and first_ts > _REAL_TS_MIN:
self.db.set_session_times_from_ts(session_id, first_ts, last_ts)
else:
self.db.close_session(session_id)
self._send_json({
'session_id': session_id,