From aa937f1bee0c46cf4eb5442fdddd5ca5e24a217a Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 26 Aug 2013 16:55:36 +0800 Subject: ... --- server/piztor/prob.py | 12 ++++++++---- server/piztor/server.py | 10 ++++------ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'server') diff --git a/server/piztor/prob.py b/server/piztor/prob.py index 0ed328f..17e7972 100644 --- a/server/piztor/prob.py +++ b/server/piztor/prob.py @@ -6,7 +6,7 @@ def get_hex(data): return "".join([hex(ord(c))[2:].zfill(2) for c in data]) host = "localhost" -port = 9990 +port = 2222 def gen_auth(username, password): length = 4 + 1 + len(username) + 1 + len(password) + 1 @@ -56,13 +56,17 @@ def send(data): from sys import argv -if len(argv) == 2: - host = argv[1] - username = "hello" password = "world" gid = 1 +if len(argv) == 2: + host = argv[1] + +if len(argv) == 3: + username = argv[1] + password = arv[2] + resp = send(gen_auth(username, password)) pl, optcode, status, uid, token = unpack("!LBBL32s", resp) print "size: " + str((pl, len(resp))) diff --git a/server/piztor/server.py b/server/piztor/server.py index 5d2382d..d0cfc34 100644 --- a/server/piztor/server.py +++ b/server/piztor/server.py @@ -139,7 +139,7 @@ class UserAuthHandler(RequestHandler): logger.info("Logged in sucessfully: {0}".format(username)) uauth.regen_token() session.commit() - logger.info("new token generated: " + get_hex(uauth.token)) + logger.info("New token generated: " + get_hex(uauth.token)) return struct.pack("!LBBL32s", UserAuthHandler._response_size, _OptCode.user_auth, _StatusCode.sucess, @@ -333,7 +333,7 @@ class PTP(Protocol, TimeoutMixin): def dataReceived(self, data): self.buff += data self.resetTimeout() - print len(self.buff) + logger.info("Buffer length is now: %d", len(self.buff)) if len(self.buff) > 4: try: self.length, self.optcode = struct.unpack("!LB", self.buff[:5]) @@ -342,9 +342,7 @@ class PTP(Protocol, TimeoutMixin): except struct.error: logger.warning("Invalid request header") raise BadReqError("Malformed request header") - print self.length - if self.length == -1: - return + if self.length == -1: return if len(self.buff) == self.length: h = handlers[self.optcode]() reply = h.handle(self.buff[5:]) @@ -366,6 +364,6 @@ class PTPFactory(Factory): def buildProtocol(self, addr): return PTP(self) -endpoint = TCP4ServerEndpoint(reactor, 9990) +endpoint = TCP4ServerEndpoint(reactor, 2222) endpoint.listen(PTPFactory()) reactor.run() -- cgit v1.2.3-70-g09d2 From eb303ea6f1f6aa3e9a0cd4b00ef3fda6b06f0027 Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 26 Aug 2013 17:33:09 +0800 Subject: ... --- server/piztor/prob.py | 89 ++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'server') diff --git a/server/piztor/prob.py b/server/piztor/prob.py index 17e7972..20b6779 100644 --- a/server/piztor/prob.py +++ b/server/piztor/prob.py @@ -65,47 +65,50 @@ if len(argv) == 2: if len(argv) == 3: username = argv[1] - password = arv[2] - -resp = send(gen_auth(username, password)) -pl, optcode, status, uid, token = unpack("!LBBL32s", resp) -print "size: " + str((pl, len(resp))) -print "opt: " + str(optcode) -print "status: " + str(status) -print "uid: " + str(uid) -print "token: " + get_hex(token) - -resp = send(gen_update_location(token, username, random(), random())) -pl, optcode, status = unpack("!LBB", resp) -print "size: " + str((pl, len(resp))) -print "opt: " + str(optcode) -print "status: " + str(status) - -resp = send(gen_request_location(token, username, gid)) -print len(resp) -pl, optcode, status = unpack("!LBB", resp[:6]) -print "size: " + str((pl, len(resp))) -idx = 6 -print "length: " + str(len(resp[6:])) -while idx < pl: - print len(resp[idx:idx + 20]) - uid, lat, lng = unpack("!Ldd", resp[idx:idx + 20]) - idx += 20 - print (uid, lat, lng) - -resp = send(gen_request_user_info(token, username, uid)) -pl, optcode, status = unpack("!LBB", resp[:6]) -print "size: " + str((pl, len(resp))) - -idx = 6 -while idx < pl: - info_key, = unpack("!B", resp[idx:idx + 1]) - idx += 1 - print info_key - if info_key == 0x00: - info_value, = unpack("!L", resp[idx:idx + 4]) - idx += 4 - elif info_key == 0x01: - info_value, = unpack("!B", resp[idx:idx + 1]) + password = argv[2] + +for i in xrange(10): + resp = send(gen_auth(username, password)) + pl, optcode, status, uid, token = unpack("!LBBL32s", resp) + print "size: " + str((pl, len(resp))) + print "opt: " + str(optcode) + print "status: " + str(status) + print "uid: " + str(uid) + print "token: " + get_hex(token) + + resp = send(gen_update_location(token, username, random(), random())) + pl, optcode, status = unpack("!LBB", resp) + print "size: " + str((pl, len(resp))) + print "opt: " + str(optcode) + print "status: " + str(status) + + resp = send(gen_request_location(token, username, gid)) + print len(resp) + pl, optcode, status = unpack("!LBB", resp[:6]) + print "size: " + str((pl, len(resp))) + idx = 6 + print "length: " + str(len(resp[6:])) + while idx < pl: + print len(resp[idx:idx + 20]) + uid, lat, lng = unpack("!Ldd", resp[idx:idx + 20]) + idx += 20 + print (uid, lat, lng) + + resp = send(gen_request_user_info(token, username, uid)) + pl, optcode, status = unpack("!LBB", resp[:6]) + print "size: " + str((pl, len(resp))) + + idx = 6 + while idx < pl: + info_key, = unpack("!B", resp[idx:idx + 1]) idx += 1 - print (info_key, info_value) + print info_key + if info_key == 0x00: + info_value, = unpack("!L", resp[idx:idx + 4]) + idx += 4 + elif info_key == 0x01: + info_value, = unpack("!B", resp[idx:idx + 1]) + idx += 1 + print (info_key, info_value) + from time import sleep + sleep(10) -- cgit v1.2.3-70-g09d2