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"}
log_msg_dir = {"RECEIVE": 0, "SEND": 1}
-DEBUG = True
+DEBUG = False
def usage():
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)
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: <len=0013><id=6><index><begin><length>
"""
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)
+
"""