#!/usr/bin/env python
import sys, os, socket
+import time
import pickle
import signal
+
from daemon import Daemon
from Util import *
from Util import SERVER_HOST, SERVER_PORT
if sent == 0:
raise RuntimeError, "socket connection broken"
totalsent = totalsent + sent
+
+ """
+ Stores data about log files in a text file.
+ """
+ def save_download_info(self, data):
+ f = open(SESSIONS_FILE, 'a')
+
+ #f.write ("# session " + strftime("%d-%m-%Y %H:%M:%S", localtime())+ "\n")
+
+ num_lines = len(data.keys())
+ if PORT in data:
+ num_lines = num_lines -1;
+ if BASE_DIR in data:
+ num_lines = num_lines -1;
+
+ f.write(str(num_lines)+"\n")
+ for k in data.keys():
+ if k == PORT or k == BASE_DIR:
+ continue
+ f.write(str(k)+":"+str(data[k])+"\n")
+ f.close()
+
""" Starts a process for a BitTorrent client and returns its pid.
@return: -1, if any error is encountered
"""
if msg[0] == START_MSG:
bt_client_data = msg[1]
client_pid = self.start_bt_client(bt_client_data)
+ self.save_download_info(bt_client_data)
self.send_pickled_data(clientsock, (ACK_MSG, client_pid))
elif msg[0] == STOP_MSG:
print "Server: received message:\n", msg
self.stop_bt_client(client_pid)
self.send_pickled_data(clientsock, (ACK_MSG,""))
-
+
+ elif msg[0] == GET_CLIENTS:
+ pass
+ elif msg[0] == GET_OUTPUT:
+
+ pass
+
else:
self.send_pickled_data(clientsock,( ERROR_MSG,"Error: wrong message type "))
if __name__ == "__main__":
if len(sys.argv) >= 2:
+
if 'start' == sys.argv[1]:
#if(len(sys.argv) != 4):
elif 'restart' == sys.argv[1]:
daemon = MyDaemon('/tmp/daemon-example.pid')
daemon.restart()
+ elif 'no' == sys.argv[1]: #no daemon
+ daemon = MyDaemon('/tmp/daemon-example.pid', SERVER_HOST, stdout = '/home/p2p/out', stderr = '/home/p2p/err')
+ daemon.doServer("","")
else:
print "Unknown command"
sys.exit(2)