summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/piztor/mesg_sender.py11
-rw-r--r--server/piztor/ptp.rst6
-rw-r--r--server/piztor/server.py13
3 files changed, 20 insertions, 10 deletions
diff --git a/server/piztor/mesg_sender.py b/server/piztor/mesg_sender.py
index f7df236..bc11a70 100644
--- a/server/piztor/mesg_sender.py
+++ b/server/piztor/mesg_sender.py
@@ -20,11 +20,12 @@ if len(argv) == 4:
token = user_auth(username, password)
-update_location(token, username, 31.028616, 121.434661)
-update_location(token, username, 31.028616, 121.434661)
-set_marker(token, username, 10.028716, 121.545661, 0x7fffffff)
-send_text_mesg(token, username, mesg)
+#update_location(token, username, 31.028616, 121.434661)
+for i in xrange(100):
+ update_location(token, username, 31.028616, 121.434661)
+ set_marker(token, username, 10.028716, 121.545661, 0x7fffffff)
+ send_text_mesg(token, username, mesg)
#send_text_mesg(token, username, "a")
#send_text_mesg(token, username, "the last")
-
+#update_sub(token, username, [(0, 0)])
logout(token, username)
diff --git a/server/piztor/ptp.rst b/server/piztor/ptp.rst
index 4473e5c..24a9612 100644
--- a/server/piztor/ptp.rst
+++ b/server/piztor/ptp.rst
@@ -1,4 +1,4 @@
-Piztor Transmission Protocol v2.0c
+Piztor Transmission Protocol v2.0d
----------------------------------
- Pull
@@ -176,6 +176,10 @@ Piztor Transmission Protocol v2.0c
+--------+
| STATUS |
+--------+
+
+ - ``0x00`` for success
+ - ``0x01`` for invalid token
+ - ``0x04`` for group not found
- User Logout ``0x04``
diff --git a/server/piztor/server.py b/server/piztor/server.py
index 9435ccc..2b6acb0 100644
--- a/server/piztor/server.py
+++ b/server/piztor/server.py
@@ -8,6 +8,7 @@ from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from collections import deque
+from time import time
import struct
import os
@@ -52,7 +53,7 @@ _HEADER_SIZE = _SectionSize.LENGTH + \
_MAX_TEXT_MESG_SIZE = 1024
_MAX_SUB_LIST_SIZE = 10
-_MAX_PENDING_PUSH = 100
+_MAX_PENDING_PUSH = 10
class _OptCode:
user_auth = 0x00
@@ -70,11 +71,12 @@ class _StatusCode:
auth_fail = 0x01
insuf_lvl = 0x02
wrong_pass = 0x03
+ grp_not_found = 0x04
class PushData(object):
from hashlib import sha256
def pack(self, optcode, data):
- self.finger_print = sha256(data).digest()
+ self.finger_print = sha256(data + struct.pack("!d", time())).digest()
buff = struct.pack("!B32s", optcode, self.finger_print)
buff += data
buff = struct.pack("!L", _SectionSize.LENGTH + len(buff)) + buff
@@ -106,7 +108,7 @@ class PushTunnel(object):
def add(self, pdata):
logger.info("-- Push data enqued --")
self.pending.append(pdata)
- if len(self.pending) > _MAX_PENDING_PUSH:
+ if not self.blocked and len(self.pending) > _MAX_PENDING_PUSH:
logger.info("-- Push queue is full, discarded an obsolete push --")
self.pending.popleft() # discard old push
@@ -476,7 +478,10 @@ class UpdateSubscription(RequestHandler):
logger.warning("Authentication failure")
return self.pack(struct.pack("!B", _StatusCode.auth_fail))
- uauth.user.sub = map(self._find_group, sub_list)
+ try:
+ uauth.user.sub = map(self._find_group, sub_list)
+ except BadReqError:
+ return self.pack(struct.pack("!B", _StatusCode.grp_not_found))
self.session.commit()
logger.info("Subscription is updated sucessfully")