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:
1 parent
5ba55ac3a9
commit
c21b655fe1
5 files changed
+82
-4
No files matched your search
@@ -378,9 +378,9 @@ def _parse_tsresol(options, endian):
|
||||
if code == 9 and length == 1:
|
||||
b = options[i]
|
||||
if b & 0x80:
|
||||
return 10 ** (-(b & 0x7F))
|
||||
return 2 ** (-(b & 0x7F))
|
||||
return 10 ** (-b)
|
||||
i += length + (length & 1) # options are padded to 32-bit
|
||||
i += length + ((-length) % 4) # options are padded to a 32-bit boundary
|
||||
return 1e-6 # default: microseconds
|
||||
|
||||
|
||||
|
||||
@@ -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=?',
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user