class dcTorrentTrackerService(win32serviceutil.ServiceFramework):
    _svc_name_ = "dcTorrentTrackerService"
    _svc_display_name_ = "dcTorrent tracker service"
    _svc_description_ = "The tracker is a web service (http://[ip]:6969/announce) that assists in the communication between peers using the BitTorrent protocol."

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        self.server = TrackerServer()

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)
        self.server.stop()

    def SvcDoRun(self):
        import servicemanager

        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, "")
        )

        try:
            argv = ["--port", "6969", "--dfile", "e:\\temp\\dstate", "--logfile", "e:\\temp\\tracker.log"]
            self.server.track(argv)
        except:
            print "Unexpected error:", sys.exc_info()[0]
Beispiel #2
0
        print '%s start tracker/seed/peer' % argv[0]
        print '%s make torrent' % argv[0]
        print
        sys.exit(2) # common exit code for syntax error

    if len(argv) == 3 and argv[1] == 'test':
        testDcTorrent(argv);

    if len(argv) > 3:
        if not os.path.exists(defaultDirs['log']):
            os.makedirs(defaultDirs['log'])
        start = argv[1]
        action = argv[2]
        if action == 'track':
            dcTorrentLogging.setRootLogger(os.path.join(defaultDirs['log'], 'track.log'), logging.DEBUG)
            t = TrackerServer(trackerAnnouceCallback)
            t.track(argv[3:])
        elif action == 'torrent':
            source = argv[3]
            filename = os.path.basename(source)
            dir = os.path.dirname(source)
            host = socket.gethostbyname(socket.gethostname())
            trackers = [host]
            make_torrent(filename, dir, trackers)
        elif action == 'torrents':
            # dir, tracker port
            host = socket.gethostbyname(socket.gethostname())
            dir = argv[3]
            trackers = [host]
            make_torrents(dir, trackers)
        elif action == 'seed' or action == 'download':
 def __init__(self, args):
     win32serviceutil.ServiceFramework.__init__(self, args)
     self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
     self.server = TrackerServer()