summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/server/piztor/import.py7
-rw-r--r--misc/server/piztor/model.py5
-rw-r--r--misc/server/piztor_server.py2
-rw-r--r--misc/server/ptp.rst51
4 files changed, 38 insertions, 27 deletions
diff --git a/misc/server/piztor/import.py b/misc/server/piztor/import.py
index 1521849..84c990f 100644
--- a/misc/server/piztor/import.py
+++ b/misc/server/piztor/import.py
@@ -5,9 +5,10 @@ from model import *
path = "piztor.sqlite"
class UserData:
- def __init__(self, username, password, sex):
+ def __init__(self, username, password, gid, sex):
self.username = username
self.password = password
+ self.gid = gid
self.sex = sex
def create_database():
@@ -20,7 +21,7 @@ def import_user_data(data):
Session = sessionmaker(bind = engine)
session = Session()
for user in data:
- um = UserModel(username = user.username, sex = user.sex)
+ um = UserModel(username = user.username, gid = user.gid, sex = user.sex)
um.auth = UserAuth(user.password)
um.location = LocationInfo(lat = 0, lng = 0)
session.add(um)
@@ -38,7 +39,7 @@ if __name__ == '__main__':
while True:
line = f.readline().split()
if len(line) == 0: break
- data.append(UserData(line[0], line[1], line[2]))
+ data.append(UserData(line[0], line[1], line[2], line[3]))
create_database()
import_user_data(data)
diff --git a/misc/server/piztor/model.py b/misc/server/piztor/model.py
index 70ca431..4621bbe 100644
--- a/misc/server/piztor/model.py
+++ b/misc/server/piztor/model.py
@@ -16,6 +16,7 @@ class UserModel(Base):
__tablename__ = _TableName.UserModel
id = Column(Integer, primary_key = True)
+ gid = Column(Integer)
username = Column(String)
sex = Column(Boolean)
location = None
@@ -24,7 +25,7 @@ class UserModel(Base):
class LocationInfo(Base):
__tablename__ = _TableName.LocationInfo
- uid = Column(Integer, ForeignKey('users.id'), primary_key = True)
+ uid = Column(Integer, ForeignKey(_TableName.UserModel + '.id'), primary_key = True)
lat = Column(Float(precesion = 64))
lng = Column(Float(precesion = 64))
user = relationship("UserModel", uselist = False,
@@ -48,7 +49,7 @@ def _random_binary_string(length):
class UserAuth(Base):
__tablename__ = _TableName.UserAuth
- uid = Column(Integer, ForeignKey('users.id'), primary_key = True)
+ uid = Column(Integer, ForeignKey(_TableName.UserModel + '.id'), primary_key = True)
password = Column(LargeBinary)
salt = Column(LargeBinary)
token = Column(LargeBinary)
diff --git a/misc/server/piztor_server.py b/misc/server/piztor_server.py
index 514f95f..81805b3 100644
--- a/misc/server/piztor_server.py
+++ b/misc/server/piztor_server.py
@@ -230,5 +230,5 @@ class PiztorServer():
if __name__ == "__main__":
- ps = PiztorServer("localhost", 9990)
+ ps = PiztorServer("localhost", 9999)
ps.run()
diff --git a/misc/server/ptp.rst b/misc/server/ptp.rst
index 8aef2b7..7c40a3b 100644
--- a/misc/server/ptp.rst
+++ b/misc/server/ptp.rst
@@ -1,4 +1,4 @@
-Piztor Transmission Protocol v0.2
+Piztor Transmission Protocol v0.3
---------------------------------
- General
@@ -8,7 +8,7 @@ Piztor Transmission Protocol v0.2
::
+---4b---+---1b---+-------?b--------+
- | LENGTH | OPT ID | SPECIFIC DATA |
+ | LENGTH | OPT_ID | SPECIFIC DATA |
+--int---+-uchar--+-----------------+
- Response
@@ -16,11 +16,20 @@ Piztor Transmission Protocol v0.2
::
+---4b---+---1b---+------?b---------+
- | LENGTH | OPT ID | SPECIFIC DATA |
+ | LENGTH | OPT_ID | SPECIFIC DATA |
+--int---+-uchar--+-----------------+
- Notice that in following sections, ``LENGTH`` part is left out for clarity.
- TODO: All secure requests should have username or uid provided.
+ Notice:
+
+ - In following sections, ``LENGTH`` part is left out for clarity.
+ - ``PADDING`` has value ``0``.
+ - ``AUTH_HEAD`` structure:
+
+ ::
+
+ +----32b-----+----?b----+----1b---+
+ | USER_TOKEN | USERNAME | PADDING |
+ +----raw-----+----------+---------+
- Authentication
@@ -28,22 +37,22 @@ Piztor Transmission Protocol v0.2
::
- +--1b---+-----?b------+-----?b-----+
- | 0x00 | USERNAME | PASSWORD |
- +-uchar-+-------------+------------+
+ +--1b---+-----?b------+----1b----+-----?b-----+
+ | 0x00 | USERNAME | PADDING | PASSWORD |
+ +-uchar-+-------------+----------+------------+
- Response
::
- +--1b---+---1b---+---4b----+----16b-----+
+ +--1b---+---1b---+---4b----+----32b-----+
| 0x00 | STATUS | USER_ID | USER_TOKEN |
+-uchar-+--uchar-+---int---+----raw-----+
``STATUS`` :
- - 0x00 for success
- - 0x01 for failure
+ - ``0x00`` for success
+ - ``0x01`` for failure
- Location Update
@@ -51,22 +60,22 @@ Piztor Transmission Protocol v0.2
::
- +--1b---+-----16b------+-----8b-----+------8b-----+
- | 0x02 | USER_TOKEN | LATITUDE | LONGITUDE |
- +-uchar-+------raw-----+---double---+---double----+
+ +--1b---+-----?b------+----8b------+------8b-----+
+ | 0x01 | AUTH_HEAD | LATITUDE | LONGITUDE |
+ +-uchar-+-------------+---double---+---double----+
- Response
::
+--1b---+---1b---+
- | 0x02 | STATUS |
+ | 0x01 | STATUS |
+-uchar-+--uchar-+
``STATUS`` :
- - 0x00 for success
- - 0x01 for invalid token
+ - ``0x00`` for success
+ - ``0x01`` for invalid token
- Location Information
@@ -74,16 +83,16 @@ Piztor Transmission Protocol v0.2
::
- +--1b---+-----16b------+------4b-----+
- | 0x03 | USER_TOKEN | GROUP_ID |
- +-uchar-+-----raw------+-----int-----+
+ +--1b---+------?b------+------4b-----+
+ | 0x02 | AUTH_HEAD | GROUP_ID |
+ +-uchar-+--------------+-----int-----+
- Response
::
+--1b---+---1b---+-----4b----+------20b-------+-----+
- | 0x03 | STATUS | ENTRY_CNT | LOCATION_ENTRY | ... |
+ | 0x02 | STATUS | ENTRY_CNT | LOCATION_ENTRY | ... |
+-uchar-+-uchar--+----int----+----------------+-----+
``LOCATION_ENTRY`` :