From 52d99cd34b1774d06d049ee75a9577d539851d5a Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 28 Aug 2013 09:42:56 +0800 Subject: ptp v0.5 and std-compliant server --- server/piztor/prober.py | 14 +++++++++----- server/piztor/ptp.rst | 16 ++++++++++++---- server/piztor/server.py | 6 +++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/server/piztor/prober.py b/server/piztor/prober.py index ec6afa8..9cfde24 100644 --- a/server/piztor/prober.py +++ b/server/piztor/prober.py @@ -25,8 +25,8 @@ class _SectionSize: LOCATION_ENTRY = USER_ID + LATITUDE + LONGITUDE PADDING = 1 -host = "localhost" -port = 2222 +host = "69.85.86.42" #"localhost" +port = 2223 def gen_auth(username, password): length = _SectionSize.LENGTH + \ @@ -177,6 +177,9 @@ def request_user_info(token, username, uid): logger.error("Request user info: incorrect packet length") idx = 6 + comp_id = None + sec_id = None + sex = None while idx < pl: info_key, = unpack("!B", resp[idx:idx + 1]) idx += 1 @@ -210,9 +213,10 @@ for i in xrange(10): update_location(token, username, random(), random()) comp_id, sec_id, sex = request_user_info(token, username, uid) - request_location(token, username, comp_id * 256 + sec_id) - request_location(token, username, comp_id * 256 + 0xff) + if comp_id: + request_location(token, username, comp_id * 256 + sec_id) + request_location(token, username, comp_id * 256 + 0xff) - logout(token, username) + logout(token, username) sleep(10) diff --git a/server/piztor/ptp.rst b/server/piztor/ptp.rst index 492a44f..3d7a575 100644 --- a/server/piztor/ptp.rst +++ b/server/piztor/ptp.rst @@ -1,4 +1,4 @@ -Piztor Transmission Protocol v0.4a +Piztor Transmission Protocol v0.5 ---------------------------------- - General @@ -91,9 +91,17 @@ Piztor Transmission Protocol v0.4a :: - +--1b---+------?b------+------4b-----+ + +--1b---+------?b------+------2b-----+ | 0x02 | AUTH_HEAD | GROUP_ID | - +-uchar-+--------------+-----int-----+ + +-uchar-+--------------+-------------+ + + ``GROUP_ID``: + + :: + + +---1b----+---1b---+ + | COMP_ID | SEC_ID | + +--uchar--+-uchar--+ - Response @@ -139,7 +147,7 @@ Piztor Transmission Protocol v0.4a ``INFO_KEY`` : - :``0x00``: gid (value is a 4-byte ``long int``) + :``0x00``: gid (value is a 2-byte ``GROUP_ID``) :``0x01``: sex (value is a 1-byte ``boolean``: ``0x01`` for male, ``0x00`` for female) - User Logout diff --git a/server/piztor/server.py b/server/piztor/server.py index 08a2981..3f1f2cb 100644 --- a/server/piztor/server.py +++ b/server/piztor/server.py @@ -32,7 +32,7 @@ class _SectionSize: STATUS = 1 USER_ID = 4 USER_TOKEN = 32 - GROUP_ID = 4 + GROUP_ID = 2 ENTRY_CNT = 4 LATITUDE = 8 LONGITUDE = 8 @@ -232,7 +232,7 @@ class LocationInfoHandler(RequestHandler): username, tail = RequestHandler.trunc_padding(tr_data[32:]) if username is None: raise struct.error - a, b, comp_id, sec_id = struct.unpack("!BBBB", tail) + comp_id, sec_id = struct.unpack("!BB", tail) except struct.error: raise BadReqError("Location request: Malformed request body") @@ -268,7 +268,7 @@ class LocationInfoHandler(RequestHandler): return reply def pack_gid(user): - return struct.pack("!BBBB", 0, 0, user.comp_id, user.sec_id) + return struct.pack("!BB", user.comp_id, user.sec_id) def pack_sex(user): return struct.pack("!B", 0x01 if user.sex else 0x00) -- cgit v1.2.3-70-g09d2 From 1bc497952316e08e73c71d6839a9e42e40196fb6 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 28 Aug 2013 16:32:16 +0800 Subject: ptp v1.0 --- server/piztor/ptp.rst | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/server/piztor/ptp.rst b/server/piztor/ptp.rst index 3d7a575..a5523a8 100644 --- a/server/piztor/ptp.rst +++ b/server/piztor/ptp.rst @@ -1,4 +1,4 @@ -Piztor Transmission Protocol v0.5 +Piztor Transmission Protocol v1.0 ---------------------------------- - General @@ -168,3 +168,38 @@ Piztor Transmission Protocol v0.5 | 0x04 | STATUS | +------+--------+ +- Push Tunnel + + - Request + + :: + + +--1b--+-----?b------+ + | 0x05 | AUTH_HEAD | + +------+-------------+ + + - Response + + :: + + +--1b--+---1b---+ + | 0x05 | STATUS | + +------+--------+ + +- Push Text Message + + - Request + + :: + + +--1b--+----?b----+ + | 0x10 | MESSAGE | + +------+--string--+ + + - Response + + :: + + +--1b--+ + | 0x10 | + +------+ -- cgit v1.2.3-70-g09d2