]> www.average.org Git - loctrkd.git/blobdiff - gps303/evstore.py
Rename gps303proto to zx303proto
[loctrkd.git] / gps303 / evstore.py
index a52a64c1e5ad468676349ad299e6fb14b174eceb..07b6dc4b760b7de08349611e844168ab0e80470a 100644 (file)
@@ -1,6 +1,7 @@
 """ sqlite event store """
 
 from sqlite3 import connect, OperationalError
+from typing import Any, List, Tuple
 
 __all__ = "fetch", "initdb", "stow"
 
@@ -11,12 +12,12 @@ SCHEMA = """create table if not exists events (
     imei text,
     peeraddr text not null,
     is_incoming int not null default TRUE,
-    proto int not null,
+    proto text not null,
     packet blob
 )"""
 
 
-def initdb(dbname):
+def initdb(dbname: str) -> None:
     global DB
     DB = connect(dbname)
     try:
@@ -28,7 +29,7 @@ def initdb(dbname):
         DB.execute(SCHEMA)
 
 
-def stow(**kwargs):
+def stow(**kwargs: Any) -> None:
     assert DB is not None
     parms = {
         k: kwargs[k] if k in kwargs else v
@@ -37,7 +38,7 @@ def stow(**kwargs):
             ("peeraddr", None),
             ("when", 0.0),
             ("imei", None),
-            ("proto", -1),
+            ("proto", "UNKNOWN"),
             ("packet", b""),
         )
     }
@@ -53,7 +54,9 @@ def stow(**kwargs):
     DB.commit()
 
 
-def fetch(imei, matchlist, backlog):
+def fetch(
+    imei: str, matchlist: List[Tuple[bool, str]], backlog: int
+) -> List[Tuple[bool, float, bytes]]:
     # matchlist is a list of tuples (is_incoming, proto)
     # returns a list of tuples (is_incoming, timestamp, packet)
     assert DB is not None