1. Mesaje GET_CLIENTS
-----> tipul mesajului GET_CLIENTS
- <----- lista de liste [client_name, pid, torrent_file]
-
+ <----- [ACK, lista de liste [client_name, pid, torrent_file]]
+ sau [ERROR, msg]
2. Mesaje GET_OUTPUT
-----> tipul mesajului GET_OUTPUT
- <----- lista : [client_name, metafile, [(file_type, file_path), ...]]
+ <----- [ACK, lista : [client_name, metafile, [(file_type, file_path), ...]]]
+
3. Mesaje ARCHIVE
-----> tipul mesajului ARCHIVE
- <----- ACK/ERROR
+ <----- [ACK, lista fisiere arhivate]
+ sau [ERROR, msg]
+
- Serverul:
- arhiveaza fis din fisierul local de sessions
- sterge fis care au fost arhivate
TORRENT:"/home/p2p/p2p-meta/" + torrent_name+".torrent",
DL_DIR: "/home/p2p/p2p-dld/tribler",
LOG_DIR: "/home/p2p/p2p-log/tribler",
+ OUT_DIR: "/home/p2p/p2p-log/tribler",
OUT_FILE: torrent_name + ".out", #status messages
LOG_FILE: "tribler-" + torrent_name + ".log", #verbose messages
TORRENT: "/home/p2p/p2p-meta/" + torrent_name+".torrent",
DL_DIR: "/home/p2p/p2p-dld/transmission",
LOG_DIR: "/home/p2p/p2p-log/transmission",
+ OUT_DIR: "/home/p2p/p2p-log/transmission",
OUT_FILE: torrent_name + ".out", #status messages
LOG_FILE: "transmission-" + torrent_name + ".log", #verbose messages
TORRENT: "/home/p2p/p2p-meta/" + torrent_name+".torrent",
DL_DIR: "/home/p2p/p2p-dld/hrktorrent",
LOG_DIR: "/home/p2p/p2p-log/hrktorrent",
+ OUT_DIR: "/home/p2p/p2p-log/hrktorrent",
OUT_FILE: torrent_name + ".out", #status messages
LOG_FILE: "hrktorrent-" + torrent_name + ".log", #verbose messages
}
- #print s.send_command(GET_OUTPUT, "")
- response = s.send_command(START_MSG, start_data_tribler)
+ print s.send_command(ARCHIVE, "")
+ """response = s.send_command(START_MSG, start_data_tribler)
print response
pid1 = response[1]
print pid1
s.connect(SERVER_HOST, SERVER_PORT)
response = s.send_command(STOP_MSG, pid1)
print response
-
+ """
def test_send_recv():
# test 1
#!/usr/bin/env python
import sys, os, socket
+import os.path
import time
import pickle
import signal
info_list = [info_dict[CLIENT],info_dict[TORRENT]]
if LOG_DIR in info_dict:
info_list.append((info_dict[LOG_DIR], LOG_DIR))
+ if OUT_DIR in info_dict:
+ info_list.append((info_dict[OUT_DIR], OUT_DIR))
if OUT_FILE in info_dict:
info_list.append((info_dict[OUT_FILE], OUT_FILE))
if LOG_FILE in info_dict:
file_list.append (info_list)
return 0 # success
+
+ def archive_files(self, info_dict, archives_list):
+ """ Archives status and verbose message log files. """
+ log_path = ""
+ out_path = ""
+ err_msg = ""
+ if LOG_DIR in info_dict:
+ log_path = info_dict[LOG_DIR]
+ if LOG_FILE in info_dict:
+ file_path = log_path + "/" + info_dict[LOG_FILE]
+ if create_archive_file(file_path) < -1:
+ err_msg = "File does not exist: ", file_path
+ else: archives_list.append(file_path)
+
+ if OUT_DIR in info_dict:
+ out_path = info_dict[OUT_DIR]
+ else:
+ out_path = log_path
+
+ if OUT_FILE in info_dict:
+ file_path = out_path + "/" + info_dict[OUT_FILE]
+ if create_archive_file(file_path) < -1:
+ err_msg = "File does not exist: ", file_path
+ else: archives_list.append(file_path)
+
+ print "Server Error: ", err_msg
- def read_download_info(self, file_list):
+ def read_download_info(self, file_list, create_archive = False, archives_list = []):
""" Reads all the contents of the file that stores info about
logging files and folders.
"""
- import os.path
if not os.path.exists(SESSIONS_FILE):
print "Server Error: No sessions_file"
return -1
info_dict = {}
try:
while line != '':
+ print line
if size == 0 :
- if info_dict != {} and self.add_to_output_msg(file_list, info_dict) < 0:
+ if info_dict != {} :
+ if self.add_to_output_msg(file_list, info_dict) < 0:
raise Exception
- size = int(line)
- info_dict = {}
+ if create_archive:
+ self.archive_files(info_dict,archives_list)
+
+ size = int(line)
+ info_dict = {}
else:
parts = line.strip().split(':')
if len(parts) != 2:
size = size - 1
line = f.readline()
- if size == 0 and info_dict != {} and self.add_to_output_msg(file_list, info_dict) < 0:
- raise Exception
-
- except Exception:
+ if size == 0 and info_dict != {}:
+ if self.add_to_output_msg(file_list, info_dict) < 0:
+ raise Exception
+ if create_archive:
+ self.archive_files(info_dict, archives_list)
+
+ except Exception, e:
print "Server Error: wrong file type for sessions file"
- err_msg = "Error encountered while reading file"
+ print e
f.close()
return -1
f.close()
return 0
+
+
+
def start_bt_client(self, bt_client_data):
""" Starts a process for a BitTorrent client and returns its pid.
@return: -1, if any error is encountered
else:
return -1
- btcr.config_run(bt_client_data[DL_DIR], bt_client_data[LOG_DIR],
+ btcr.config_run(bt_client_data[DL_DIR], bt_client_data[OUT_DIR],
bt_client_data[OUT_FILE], bt_client_data[LOG_DIR],
bt_client_data[LOG_FILE], bt_client_data[PORT],
bt_client_data[TORRENT])
response.append([self.processes_info[k][0], k, self.processes_info[k][1]]) # client_name, pid, torrent file
except Exception:
err_msg = "Error: could not retrive running clients list"
-
+
+ elif msg[0] == ARCHIVE:
+ response = []
+ if self.read_download_info([], True, response) < 0: # read file path and create archives
+ err_msg = "Error: could not archive log files."
+ else: # erase sessions file
+ f = open(SESSIONS_FILE, "w")
+ f.close()
else:
err_msg = "Error: wrong message type";