contacts
This commit is contained in:
parent
ad479a615a
commit
0f9f331754
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
<data-source source="LOCAL" name="test" uuid="c31e2821-78f4-457d-a96f-a4f0fc76708c">
|
<data-source source="LOCAL" name="dev" uuid="264a9472-6fd0-4fcc-8354-d6d121fc5bba">
|
||||||
<driver-ref>sqlite.xerial</driver-ref>
|
<driver-ref>sqlite.xerial</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||||
<jdbc-url>jdbc:sqlite:D:\source\PyCharm\v25\test.db</jdbc-url>
|
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$\dev.db</jdbc-url>
|
||||||
<libraries>
|
<libraries>
|
||||||
<library>
|
<library>
|
||||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.31.1/license.txt</url>
|
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.31.1/license.txt</url>
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
"db": "sqlite:///dev.db",
|
"db": "sqlite:///dev.db",
|
||||||
"subjects": {
|
"subjects": {
|
||||||
"ro6ncuJxA_cGQ51hPKw11Q84of08j7GtOjL0Xr5GaFs=": {
|
"ro6ncuJxA_cGQ51hPKw11Q84of08j7GtOjL0Xr5GaFs=": {
|
||||||
"allowed": null
|
"allowed": null,
|
||||||
|
"contacts": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ import json
|
|||||||
from typing import Tuple, Optional, Iterable
|
from typing import Tuple, Optional, Iterable
|
||||||
|
|
||||||
from nacl.bindings import crypto_sign_PUBLICKEYBYTES
|
from nacl.bindings import crypto_sign_PUBLICKEYBYTES
|
||||||
from sqlalchemy import create_engine, LargeBinary, Column, REAL, BLOB, String, or_, and_, ForeignKeyConstraint, Integer
|
from sqlalchemy import create_engine, LargeBinary, Column, REAL, BLOB, String, or_, and_, ForeignKeyConstraint, \
|
||||||
|
Integer, UniqueConstraint
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker, Query
|
from sqlalchemy.orm import sessionmaker, Query
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ Base = declarative_base()
|
|||||||
|
|
||||||
class SSSJ(Base):
|
class SSSJ(Base):
|
||||||
"""Subject Status Storage JSON"""
|
"""Subject Status Storage JSON"""
|
||||||
__tablename__ = 'ssse'
|
__tablename__ = 'sssj'
|
||||||
|
|
||||||
subject = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES), primary_key=True)
|
subject = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES), primary_key=True)
|
||||||
status = Column(String, nullable=False, default='{}')
|
status = Column(String, nullable=False, default='{}')
|
||||||
@ -34,17 +35,18 @@ class Msg(Base):
|
|||||||
__tablename__ = 'msgs'
|
__tablename__ = 'msgs'
|
||||||
|
|
||||||
oid = Column(Integer, autoincrement=True, primary_key=True)
|
oid = Column(Integer, autoincrement=True, primary_key=True)
|
||||||
sf = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES))
|
sf = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES), index=True)
|
||||||
st = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES))
|
st = Column(LargeBinary(crypto_sign_PUBLICKEYBYTES), index=True)
|
||||||
idn = Column(LargeBinary(NONCE_SIZE))
|
idn = Column(LargeBinary(NONCE_SIZE), index=True)
|
||||||
ts = Column(REAL, nullable=False, index=True)
|
ts = Column(REAL, nullable=False, index=True)
|
||||||
en = Column(LargeBinary(NONCE_SIZE), nullable=False)
|
en = Column(LargeBinary(NONCE_SIZE), nullable=False, index=True)
|
||||||
ec = Column(BLOB, nullable=False)
|
ec = Column(BLOB, nullable=False)
|
||||||
flags = Column(String, nullable=False)
|
flags = Column(String, nullable=False)
|
||||||
|
|
||||||
__table_args__ = (ForeignKeyConstraint((sf, st, idn,),
|
__table_args__ = (ForeignKeyConstraint((sf, st, idn,),
|
||||||
(MsgSgn.sf, MsgSgn.st, MsgSgn.idn,),
|
(MsgSgn.sf, MsgSgn.st, MsgSgn.idn,),
|
||||||
),
|
),
|
||||||
|
UniqueConstraint(sf, st, idn, ),
|
||||||
)
|
)
|
||||||
|
|
||||||
def sgn(self):
|
def sgn(self):
|
||||||
@ -78,6 +80,17 @@ class DBStorage(AbstractStorage):
|
|||||||
def check(self, subject: Subject) -> dict:
|
def check(self, subject: Subject) -> dict:
|
||||||
session = self.Session()
|
session = self.Session()
|
||||||
status = json.loads(session.query(SSSJ).filter_by(subject=subject.vkey.encode()).one_or_none().status) or {}
|
status = json.loads(session.query(SSSJ).filter_by(subject=subject.vkey.encode()).one_or_none().status) or {}
|
||||||
|
if 'contacts' in status:
|
||||||
|
query: Query = session.query(Msg).filter(or_(
|
||||||
|
Msg.sf == subject.vkey.encode(),
|
||||||
|
Msg.st == subject.vkey.encode(),
|
||||||
|
))
|
||||||
|
query = query.with_entities(Msg.sf, Msg.st)
|
||||||
|
contacts = set()
|
||||||
|
for sf, st in query:
|
||||||
|
contacts.add(sf)
|
||||||
|
contacts.add(st)
|
||||||
|
status['contacts'] = list(map(Encoding.encode, contacts))
|
||||||
session.close()
|
session.close()
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user