From ee578a306e2df8f2ddd0844da6ec99c0207cba67 Mon Sep 17 00:00:00 2001 From: Adriana Draghici Date: Fri, 19 Mar 2010 15:02:02 +0000 Subject: [PATCH] bt_comm: fixed bugs for running Tribler. --- bt_comm/server/Client.py | 18 ++++++++-- bt_comm/server/Server.py | 35 ++++++++++--------- bt_comm/start-clients/TriblerRun.py | 11 ++++-- .../Core/APIImplementation/SingleDownload.py | 3 +- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/bt_comm/server/Client.py b/bt_comm/server/Client.py index e547e16..ae461cf 100644 --- a/bt_comm/server/Client.py +++ b/bt_comm/server/Client.py @@ -55,7 +55,7 @@ def test_all_commands(torrent_file): start_data_tribler = { CLIENT: TRIBLER, PORT:10150, - BASE_DIR:"/home/p2p/p2p-clients/tribler" + BASE_DIR:"/home/p2p/p2p-clients/tribler", TORRENT:"/home/p2p/p2p-meta/" + torrent_name+".torrent", DL_DIR: "/home/p2p/p2p-dld/tribler", LOG_DIR: "/home/p2p/p2p-log/tribler", @@ -64,14 +64,26 @@ def test_all_commands(torrent_file): } start_data_transmission = { - CLIENT: TRANSMISSION, PORT:10150, - BASE_DIR:"/usr/bin/" + CLIENT: TRANSMISSION, PORT:10250, + BASE_DIR:"/usr/bin/", TORRENT: "/home/p2p/p2p-meta/" + torrent_name+".torrent", DL_DIR: "/home/p2p/p2p-dld/transmission", LOG_DIR: "/home/p2p/p2p-log/transmission", OUT_FILE: torrent_name + ".out", #status messages LOG_FILE: "transmission-" + torrent_name + ".log", #verbose messages + } + + start_data_hrktorrent = { + CLIENT: HRKTORRENT, PORT:10350, + BASE_DIR:"/home/p2p/p2p-clients/hrktorrent", + TORRENT: "/home/p2p/p2p-meta/" + torrent_name+".torrent", + DL_DIR: "/home/p2p/p2p-dld/hrktorrent", + LOG_DIR: "/home/p2p/p2p-log/hrktorrent", + OUT_FILE: torrent_name + ".out", #status messages + LOG_FILE: "hrktorrent-" + torrent_name + ".log", #verbose messages + + } response = s.send_command(START_MSG, start_data_tribler) print response diff --git a/bt_comm/server/Server.py b/bt_comm/server/Server.py index 2cc964b..9976613 100644 --- a/bt_comm/server/Server.py +++ b/bt_comm/server/Server.py @@ -44,9 +44,9 @@ class MyDaemon(Daemon): def recv_pickled_data(self, clientsock): # while chunk: - # chunk = clientsock.recv(BUFFER_SIZE) + # chunk = clientsock.recv(self.BUFFER_SIZE) # data += chunk - data = clientsock.recv(BUFFER_SIZE) + data = clientsock.recv(self.BUFFER_SIZE) dd = pickle.loads(data) return dd @@ -106,6 +106,7 @@ class MyDaemon(Daemon): def doServer(self, ip, port): serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if(DEBUG): print "Server: host ip = %s, port = %d"%(SERVER_HOST,SERVER_PORT) serversocket.bind((ip,port)); @@ -118,48 +119,48 @@ class MyDaemon(Daemon): if(DEBUG): print "Server: accepted connection from ", address - if clientsock not in states: - states[clientsock] = WAITING_MSG_TYPE; + if clientsock not in self.states: + self.states[clientsock] = self.WAITING_MSG_TYPE; - if states[clientsock] == WAITING_MSG_TYPE: - print states[clientsock] - msg = clientsock.recv(BUFFER_SIZE) + if self.states[clientsock] == self.WAITING_MSG_TYPE: + print self.states[clientsock] + msg = clientsock.recv(self.BUFFER_SIZE) if(DEBUG): print "Server: received message:\n", msg msg_types = { - START_MSG: WAITING_START_DATA, - STOP_MSG: WAITING_STOP_DATA, - STATUS_MSG: WAITING_STATUS_DATA + START_MSG: self.WAITING_START_DATA, + STOP_MSG: self.WAITING_STOP_DATA, + STATUS_MSG: self.WAITING_STATUS_DATA } if msg not in msg_types: clientsock.send(ERROR_MSG +"wrong message type " + msg) else: - states[clientsock] = msg_types[msg] + self.states[clientsock] = msg_types[msg] clientsock.send(ACK_MSG) #else: - print states[clientsock] + print self.states[clientsock] - if states[clientsock] == WAITING_START_DATA: + if self.states[clientsock] == self.WAITING_START_DATA: bt_client_data = self.recv_pickled_data(clientsock) if(DEBUG): print "Server: received message:\n", msg client_pid = self.start_bt_client(bt_client_data) clientsock.send(ACK_MSG +" "+ str(client_pid)) - elif states[clientsock] == WAITING_STOP_DATA: + elif self.states[clientsock] == self.WAITING_STOP_DATA: client_pid = self.recv_pickled_data(clientsock) if(DEBUG): print "Server: received message:\n", msg self.stop_bt_client(client_pid) clientsock.send(ACK_MSG) - elif states[clientsock] == WAITING_STATUS_DATA: + elif self.states[clientsock] == self.WAITING_STATUS_DATA: config = self.recv_pickled_data(clientsock) clientsock.send(ACK_MSG) - states[clientsock] = WAITING_MSG_TYPE + self.states[clientsock] = self.WAITING_MSG_TYPE - # clientsock.recv(BUFFER_SIZE) + # clientsock.recv(self.BUFFER_SIZE) # recv_pickled_data(clientsock) clientsock.close() diff --git a/bt_comm/start-clients/TriblerRun.py b/bt_comm/start-clients/TriblerRun.py index 5fb836a..8e62760 100644 --- a/bt_comm/start-clients/TriblerRun.py +++ b/bt_comm/start-clients/TriblerRun.py @@ -36,6 +36,7 @@ class TriblerRun(BitTorrentClientRun): instr_line = "\nsys.path.append('"+base_path+"')\n" exists = False position = -1 + exists = False for line in f: if line.find("import")>=0 and line.find("sys")>=0 and (not line.find("sys."))>=0: #position = f.tell() + len(line) + 1 @@ -43,13 +44,17 @@ class TriblerRun(BitTorrentClientRun): f_copy.write(instr_line) continue if line == instr_line: - continue + exists = True + break f_copy.write(line) f_copy.close() - os.remove(filename) - os.rename(tmp_filename, filename) f.close() + if not exists: + os.remove(filename) + os.rename(tmp_filename, filename) + else: + os.remove(tmp_filename) def main(): diff --git a/tribler-mod/Tribler/Core/APIImplementation/SingleDownload.py b/tribler-mod/Tribler/Core/APIImplementation/SingleDownload.py index 95b81ec..c1d23bb 100644 --- a/tribler-mod/Tribler/Core/APIImplementation/SingleDownload.py +++ b/tribler-mod/Tribler/Core/APIImplementation/SingleDownload.py @@ -33,6 +33,7 @@ DEBUG = True #False # Transfers' status info is output into status_file. FILE_NAME = "status_msg_single_download.log" #+ strftime("_%d_%b_%Y_%H_%M_%S", localtime()) + ".log" status_file = open(FILE_NAME, 'w'); +status_file = sys.stdout class SingleDownload: """ This class is accessed solely by the network thread """ @@ -117,7 +118,7 @@ class SingleDownload: """ Return the local filename to which to save the file 'name' in the torrent """ if DEBUG: print >>status_file, strftime("%d-%m-%Y %H:%M:%S", localtime())," ","SingleDownload: save_as(",`name`,length,`saveas`,isdir,")" - status_file.close() + #status_file.close() # comment when status_file is stdout try: if not os.access(saveas,os.F_OK): os.mkdir(saveas) -- 2.20.1