summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/piztor/ptp.rst1
-rw-r--r--server/piztor/server.py47
2 files changed, 48 insertions, 0 deletions
diff --git a/server/piztor/ptp.rst b/server/piztor/ptp.rst
index e174fe3..05fb17f 100644
--- a/server/piztor/ptp.rst
+++ b/server/piztor/ptp.rst
@@ -235,6 +235,7 @@ Piztor Transmission Protocol v2.0a
- Request
::
+
+-------------+----8b------+------8b-----+----4b----+
| AUTH_HEAD | LATITUDE | LONGITUDE | DEADLINE |
+-------------+---double---+---double----+---int----+
diff --git a/server/piztor/server.py b/server/piztor/server.py
index d2d1974..dab0ccb 100644
--- a/server/piztor/server.py
+++ b/server/piztor/server.py
@@ -38,6 +38,7 @@ class _SectionSize:
LATITUDE = 8
LONGITUDE = 8
PADDING = 1
+ DEADLINE = 4
_MAX_AUTH_HEAD_SIZE = _SectionSize.USER_TOKEN + \
MAX_USERNAME_SIZE + \
@@ -57,6 +58,7 @@ class _OptCode:
user_logout = 0x04
open_push_tunnel = 0x05
send_text_mesg = 0x06
+ set_marker = 0x07
class _StatusCode:
sucess = 0x00
@@ -576,6 +578,51 @@ class SendTextMessageHandler(RequestHandler):
logger.info("Sent text mesg successfully!")
return self.pack(struct.pack("!B", _StatusCode.sucess))
+class SetMarkerHandler(RequestHandler):
+
+ _optcode = _OptCode.set_marker
+ _max_tr_data_size = _MAX_AUTH_HEAD_SIZE + \
+ _SectionSize.LATITUDE + \
+ _SectionSize.LONGITUDE + \
+ _SectionSize.DEADLINE
+
+ def handle(self, tr_data, conn):
+ self.check_size(tr_data)
+ logger.info("Reading set marker data...")
+ try:
+ token, = struct.unpack("!32s", tr_data[:32])
+ username, tail = RequestHandler.trunc_padding(tr_data[32:])
+ lat, lng, deadline = struct.unpack("!ddl", tail)
+ if username is None:
+ raise struct.error
+ except struct.error:
+ raise BadReqError("Send text mesg: Malformed request body")
+
+ logger.info("Trying to send text mesg with "
+ "(token = {0}, username = {1})"\
+ .format(get_hex(token), username))
+
+ uauth = RequestHandler.get_uauth(token, username, self.session)
+ # Authentication failure
+ if uauth is None:
+ logger.warning("Authentication failure")
+ return self.pack(struct.pack("!B", _StatusCode.failure))
+
+ pt = RequestHandler.push_tunnels
+ u = uauth.user
+ ulist = self.session.query(UserModel) \
+ .filter(UserModel.sec_id == u.sec_id).all()
+
+ for user in ulist:
+ uid = user.id
+ if uid == uauth.uid: continue
+ if pt.has_key(uid):
+ tunnel = pt[uid]
+ tunnel.add(PushTextMesgData(mesg))
+ tunnel.push()
+ logger.info("Sent text mesg successfully!")
+ return self.pack(struct.pack("!B", _StatusCode.sucess))
+
class PTP(Protocol, TimeoutMixin):