From: Adriana Draghici Date: Fri, 13 Nov 2009 16:31:04 +0000 (+0000) Subject: Tribler: LogParser writes to database BT_HAVE and BT_REQUEST messages X-Git-Tag: getopt_long~259 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=8962520c2d23c0661a8245cb9a6918b511d87ae8;p=cs-p2p-next.git Tribler: LogParser writes to database BT_HAVE and BT_REQUEST messages --- diff --git a/log-parser/tribler/LogParser.py b/log-parser/tribler/LogParser.py index 51527f7..dc45555 100644 --- a/log-parser/tribler/LogParser.py +++ b/log-parser/tribler/LogParser.py @@ -13,7 +13,7 @@ import getopt import re # the names used by Tribler for the BitTorrent messages -msg_types = {"BT_REQUEST": "new_request"} +msg_types = {"BT_REQUEST": "new_request", "BT_CHOKE": "_rechoke", "BT_HAVE": "got_have"} msg_db_code = {"BT_CHOKE" : 0, "BT_HAVE" : 4, "BT_REQUEST" : 6} DEBUG = True @@ -31,7 +31,21 @@ def usage(): print "\t--help" print "\t-h\t\t\tprint this help screen" -""" line format: 20-10-2009 12:56:39 Downloader: new_request 52 98304 16384 to 141.85.37.41 14398 +""" Get date and timestamp and transform it into datetime format. + Format: dd-mm-yyyy hh:mm:ss +""" +def tribler_parse_timestamp(date, time): + + date_array = date.split("-"); + time_array = time.split(":"); + if len(date_array) != 3 or len(time_array) != 3: + return None + + timestamp = datetime.datetime(int(date_array[2]), int(date_array[1]), int(date_array[0]), #year, month, day + int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec + return timestamp + +""" line format example: 20-10-2009 12:56:39 Downloader: new_request 52 98304 16384 to 141.85.37.41 14398 BitTorrent protocol message: request: Returns a list (timestamp, peer_ip, peer_port, message_type, index, begin, length, listen_port) """ @@ -46,16 +60,11 @@ def tribler_parse_request_msg(line): print "Error: invalid line format for Downloader." return None - # get date and timestamp and transform it in datetime format - - date_array = line_parts[0].split("-"); - time_array = line_parts[1].split(":"); - if len(date_array) != 3 or len(time_array) != 3: + timestamp = tribler_parse_timestamp(line_parts[0], line_parts[1]) + if timestamp == None: print "Error: invalid line format for Downloader." return None - timestamp = datetime.datetime(int(date_array[2]), int(date_array[1]), int(date_array[0]), #year, month, day - int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec index = int(line_parts[4]) begin = int(line_parts[5]) length = int(line_parts[6]) @@ -64,13 +73,47 @@ def tribler_parse_request_msg(line): return (timestamp, peer_ip, peer_port, msg_db_code["BT_REQUEST"], index, begin, length, 0) + +""" + line format example: 20-10-2009 12:56:39 Downloader: got_have 12 + BitTorrent message format: have + Returns a list :... +""" def tribler_parse_have_msg(line): - pass + if line.find(msg_types["BT_HAVE"]) == -1: + return None + # the messages can also have the format: Downloader: got_have is invalid piece + if line.find("invalid") != -1: + return None # didn't decide yet what to do with it + + line_parts = re.split(" *", line) + timestamp = tribler_parse_timestamp(line_parts[0], line_parts[1]) + + if timestamp == None: + print "Error: invalid date & time format for Downloader." + return None + + if len(line_parts) < 5 : + print "Error: invalid line format for Downloader." + return None + + index = int(line_parts[4]) + return (timestamp, None, None, msg_db_code["BT_HAVE"], index, None, None, 0) + + + +""" + Parses a line that contains choke/unchoke messages. + line format: choker: _rechoke +""" def tribler_parse_choke_msg(line): + if line.find(msg_types["BT_CHOKE"]) == -1: + return None pass + def tribler_parse_piece_msg(line): pass @@ -81,6 +124,7 @@ def tribler_parse_line(line): return result result = tribler_parse_have_msg(line) + if result != None: return result @@ -209,6 +253,7 @@ def main_with_DB(): if __name__ == "__main__": sys.exit(main_with_DB()) + #sys.exit(main_just_parse())