示例#1
0
 def process_event(self, cmd, value, ip, peerInfo, _prep):
     if cmd.startswith("HELO_LOGFILE"):
         if self.w == None:
             return
         from lunchinator.datathread.dt_qthread import DataReceiverThread
         #someone will send me his logfile on tcp
         values = value.split()
         file_size=int(values[0])
         tcp_port = 0
         if len(values) > 1:
             tcp_port = int(values[1])
         
         pID = peerInfo.get(LunchPeers.PEER_ID_KEY, ip)
         
         logDir = os.path.join(get_settings().get_main_config_dir(), "logs", pID)
         if not os.path.exists(logDir):
             os.makedirs(logDir)
         
         if cmd.startswith("HELO_LOGFILE_TGZ"):
             file_name= os.path.join(logDir, "tmp.tgz")
         else:
             file_name= os.path.join(logDir, "tmp.log")
         
         dr = DataReceiverThread.receiveSingleFile(ip, file_name, file_size, tcp_port, self.logger, "log%s"%ip, parent=self.w)
         dr.successfullyTransferred.connect(self.w.membersWidget.cb_log_transfer_success)
         dr.errorOnTransfer.connect(self.w.membersWidget.cb_log_transfer_error)
         dr.finished.connect(dr.deleteLater)
         dr.start()
示例#2
0
 def quit(self, exitCode=0):
     if self.mainWindow is not None:
         self.mainWindow.close()
     if self.settingsWindow is not None:
         self.settingsWindow.close()
     
     if self.serverThread != None and not sip.isdeleted(self.serverThread) and self.serverThread.isRunning():
         self.serverThread.finished.disconnect(self.serverFinishedUnexpectedly)
         get_server().stop_server()
         getCoreLogger().info("Waiting maximal 30s for server to stop...")
         # wait maximal 30s 
         if self.serverThread.wait(30000):
             getCoreLogger().info("server stopped")
         else:
             getCoreLogger().warning("server not stopped properly")
     else:
         getCoreLogger().info("server not running")
     
     if self.running:
         if get_settings().get_plugins_enabled():
             get_plugin_manager().deactivatePlugins(get_plugin_manager().getAllPlugins(), save_state=False)
             getCoreLogger().info("all plug-ins deactivated")
         if self.mainWindow is not None:
             self.mainWindow.finish()
         if self.settingsWindow is not None:
             self.settingsWindow.finish()
         self.running = False
         
     finalExitCode = 0
     if exitCode != 0:
         finalExitCode = exitCode
     elif self.exitCode != 0:
         finalExitCode = self.exitCode
     else:
         finalExitCode = get_server().exitCode
         
     get_settings().write_config_to_hd()
     DataReceiverThread.cleanup()
         
     self.exitCode = finalExitCode
     
     self._coldShutdown(finalExitCode)
     return finalExitCode
示例#3
0
 def request_log(self, member=None, logNum=0):
     if member == None:
         member = self.get_selected_log_member()
     if member != None:
         self.logger.debug("Requesting log %d from %s", logNum, member)
         get_server().call(
             "HELO_REQUEST_LOGFILE %s %d" % (DataReceiverThread.getOpenPort(category="log%s" % member), logNum),
             set([member]),
         )
     else:
         self.log_area.setText("No Member selected!")
示例#4
0
 def receiveFileSlot(self, addr, file_size, file_name, tcp_port, successFunc, errorFunc):
     addr = convert_string(addr)
     file_name = convert_string(file_name)
     dr = DataReceiverThread.receiveSingleFile(addr, file_name, file_size, tcp_port, getCoreLogger(), "avatar%s" % addr, True, parent=self)
     if successFunc:
         dr.successfullyTransferred.connect(lambda _thread, _path : successFunc())
     if errorFunc:
         dr.errorOnTransfer.connect(lambda _thread, _msg : errorFunc())
     dr.successfullyTransferred.connect(self.successfullyReceivedFile)
     dr.errorOnTransfer.connect(self.errorOnTransfer)
     dr.finished.connect(dr.deleteLater)
     dr.start()
示例#5
0
 def getOpenPort(self, ip):
     return DataReceiverThread.getOpenPort(category="avatar%s" % ip)
 def _processSendRequestSlot(self, peerID, peerIP, value, transferDict):
     if transferDict is None:
         try:
             transferDict = json.loads(value)
             
             if not type(transferDict) is dict:
                 self.logger.warning("transferDict is no dict.")
                 return
         except:
             self.logger.exception("Could not parse transfer dict.")
             return
     
     if not u"id" in transferDict:
         self.logger.warning("No transfer ID in transfer dict. Cannot accept request")
         return
     
     if not u"name" in transferDict:
         self.logger.warning("No file name in transfer dict. Cannot accept request")
         return
     
     if not u"size" in transferDict:
         self.logger.warning("No file size in transfer dict. Cannot accept request")
         return
     
     transferID = transferDict[u"id"]
     size = transferDict[u"size"]
     name = transferDict.get(u"name", None)
     numFiles = transferDict.get(u"count", 1)
     
     if ((peerID, transferID) in self._incoming):
         self.logger.debug(u"Ignoring duplicate file transfer from peer %s (%d)", peerID, transferID)
         return
     
     if not os.path.exists(self._downloadDir):
         os.makedirs(self._downloadDir)
     elif not os.path.isdir(self._downloadDir):
         self.logger.error("Download path %s is no directory. Cannot accept file.")
         return
     
     if numFiles > 1:
         peerName = get_peers().getDisplayedPeerName(pID=peerID)
         if peerName:
             dirName = u"%s (%s)" % (sanitizeForFilename(peerName), peerID)
         else:
             dirName = peerID
         targetDir = os.path.join(self._downloadDir, dirName)
         if not os.path.exists(targetDir) or not os.path.isdir(targetDir):
             targetDir = getUniquePath(targetDir)
             os.makedirs(targetDir)
     else:
         targetDir = self._downloadDir
     
     port = DataReceiverThread.getOpenPort(blockPort=True)
     inThread = DataReceiverThread.receive(peerIP, targetDir, port, transferDict, self.logger, overwrite=self._overwrite, parent=self)
     inThread.setUserData((peerID, transferID))
     inThread.errorOnTransfer.connect(self._errorDownloading)
     inThread.successfullyTransferred.connect(self._removeDownload)
     inThread.transferCanceled.connect(self._transferCanceled)
     inThread.finished.connect(inThread.deleteLater)
     self._incoming[(peerID, transferID)] = inThread
     inThread.start()
     
     self.incomingTransferStarted.emit(peerID, transferID, targetDir, numFiles, size, name, inThread)
     
     answerDict = {u"id" : transferID,
                   u"port" : port}
     get_server().call("HELO_FT_ACK %s" % json.dumps(answerDict), peerIPs=[peerIP])