From 196f10f3ff4b54a54c6dbeaab913d12a86b6dfe6 Mon Sep 17 00:00:00 2001 From: Adriana Draghici Date: Fri, 4 Dec 2009 12:44:23 +0000 Subject: [PATCH] Tribler - LogParser parses BT_REQUEST messages in both directions. --- log-parser/tribler/LogParser.py | 51 +++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/log-parser/tribler/LogParser.py b/log-parser/tribler/LogParser.py index 8b603b6..1344e0b 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", "BT_CHOKE": "CHOKE from", "BT_UNCHOKE": "UNCHOKE from", +msg_types = {"BT_REQUEST_SEND": "new_request", "BT_REQUEST_RECV": "REQUEST(", "BT_CHOKE": "CHOKE from", "BT_UNCHOKE": "UNCHOKE from", "BT_HAVE": "HAVE(", "BT_PIECE": "PIECE(", "BT_BITFIELD": "BITFIELD from", "BT_CANCEL": "sent cancel"} @@ -22,7 +22,7 @@ msg_db_code = {"BT_CHOKE" : 0, "BT_UNCHOKE": 1, "BT_INTERESTED": 2, "BT_NOT_INTE log_msg_dir = {"RECEIVE": 0, "SEND": 1} -DEBUG = True +DEBUG = False def usage(): @@ -60,7 +60,7 @@ def tribler_parse_timestamp(date, time): def tribler_parse_choke_msg(line): is_choke = line.find(msg_types["BT_CHOKE"]) is_unchoke = line.find(msg_types["BT_UNCHOKE"]) - if is_choke == -1 or is_unchoke == -1: + if is_choke == -1 and is_unchoke == -1: return None line_parts = re.split(" *", line) @@ -138,33 +138,54 @@ def tribler_parse_bitfield_msg(line): return (timestamp, direction, peer_ip, None, msg_db_code["BT_BITFIELD"], None, None, None, 0) -""" sample line: 20-10-2009 12:56:39 Downloader: new_request 52 98304 16384 to 141.85.37.41 14398 +""" sample lines for sending and receiving requests: + 20-10-2009 12:56:39 Downloader: new_request 52 98304 16384 to 141.85.37.41 14398 + 27-11-2009 18:01:22 connecter: Got REQUEST( 1218 ) from 87.0.15.75 BitTorrent protocol message: request: """ def tribler_parse_request_msg(line): - if line.find(msg_types["BT_REQUEST"]) == -1: + req_send = line.find(msg_types["BT_REQUEST_SEND"]) + req_recv = line.find(msg_types["BT_REQUEST_RECV"]) + if req_send == -1 and req_recv == -1: return None + msg_parts = 9 + file = "Connecter" + + if req_send != -1 : + msg_parts = 10 + file = "Downloader" + timestamp = None line_parts = re.split(" *", line) - if len(line_parts) < 10 : - print "Error: invalid line format for Downloader." + + if len(line_parts) < msg_parts : + print "Error: invalid line format for ", file, return None timestamp = tribler_parse_timestamp(line_parts[0], line_parts[1]) if timestamp == None: - print "Error: invalid line format for Downloader." + print "Error: invalid line format for ", file return None - index = int(line_parts[4]) - begin = int(line_parts[5]) - length = int(line_parts[6]) + # Send request message + if req_send != -1: + index = int(line_parts[4]) + begin = int(line_parts[5]) + length = int(line_parts[6]) + peer_ip = line_parts[8] + peer_port = int(line_parts[9]) + + direction = log_msg_dir["SEND"]; + return (timestamp, direction, peer_ip, peer_port, msg_db_code["BT_REQUEST"], index, begin, length, 0) + + # Receive request message + index = int(line_parts[5]) peer_ip = line_parts[8] - peer_port = int(line_parts[9]) - - direction = log_msg_dir["SEND"]; - return (timestamp, direction, peer_ip, peer_port, msg_db_code["BT_REQUEST"], index, begin, length, 0) + direction = log_msg_dir["RECEIVE"]; + return (timestamp, direction, peer_ip, None, msg_db_code["BT_REQUEST"], index, None, None, 0) + """ -- 2.20.1