def reject(self): self.timer.stop() self.hide() UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining cancelled"))) self.done(QtGui.QDialog.Rejected)
def accept(self): """Proceed in joining the chan""" self.timer.stop() self.hide() apiAddressGeneratorReturnQueue.queue.clear() if self.chanAddress.text().toUtf8() == "": addressGeneratorQueue.put( ('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True)) else: addressGeneratorQueue.put( ('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()), str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True)) addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True) if addressGeneratorReturnValue and addressGeneratorReturnValue[ 0] != 'chan name does not match address': UISignalQueue.put( ('updateStatusBar', _translate("newchandialog", "Successfully created / joined chan %1").arg( unicode(self.chanPassPhrase.text())))) self.parent.ui.tabWidget.setCurrentIndex( self.parent.ui.tabWidget.indexOf(self.parent.ui.chans)) self.done(QtGui.QDialog.Accepted) else: UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining failed"))) self.done(QtGui.QDialog.Rejected)
def handle_close(self): if self.isOutbound and not self.fullyEstablished: knownnodes.decreaseRating(self.destination) if self.fullyEstablished: UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, False, self.destination))) if self.isOutbound: Dandelion().maybeRemoveStem(self) BMProto.handle_close(self)
def click_pushButtonAddBlacklist(self): self.NewBlacklistDialogInstance = AddAddressDialog(self) if self.NewBlacklistDialogInstance.exec_(): if self.NewBlacklistDialogInstance.labelAddressCheck.text() == \ _translate("MainWindow", "Address is valid."): address = addBMIfNotPresent( str(self.NewBlacklistDialogInstance.lineEditAddress.text()) ) # First we must check to see if the address is already in the # address book. The user cannot add it again or else it will # cause problems when updating and deleting the entry. t = (address, ) if BMConfigParser().get('bitmessagesettings', 'blackwhitelist') == 'black': sql = '''select * from blacklist where address=?''' else: sql = '''select * from whitelist where address=?''' queryreturn = sqlQuery(sql, *t) if queryreturn == []: self.tableWidgetBlacklist.setSortingEnabled(False) self.tableWidgetBlacklist.insertRow(0) newItem = QtGui.QTableWidgetItem( unicode( self.NewBlacklistDialogInstance.lineEditLabel.text( ).toUtf8(), 'utf-8')) newItem.setIcon(avatarize(address)) self.tableWidgetBlacklist.setItem(0, 0, newItem) newItem = QtGui.QTableWidgetItem(address) newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.tableWidgetBlacklist.setItem(0, 1, newItem) self.tableWidgetBlacklist.setSortingEnabled(True) t = (str(self.NewBlacklistDialogInstance.lineEditLabel. text().toUtf8()), address, True) if BMConfigParser().get('bitmessagesettings', 'blackwhitelist') == 'black': sql = '''INSERT INTO blacklist VALUES (?,?,?)''' else: sql = '''INSERT INTO whitelist VALUES (?,?,?)''' sqlExecute(sql, *t) else: UISignalQueue.put( ('updateStatusBar', _translate( "MainWindow", "Error: You cannot add the same address to your" " list twice. Perhaps rename the existing one" " if you want."))) else: UISignalQueue.put( ('updateStatusBar', _translate( "MainWindow", "The address you entered was invalid. Ignoring it.")))
def set_connection_fully_established(self): if not self.isOutbound and not self.local: shared.clientHasReceivedIncomingConnections = True UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('updateNetworkStatusTab', 'no data')) self.antiIntersectionDelay(True) self.fullyEstablished = True if self.isOutbound: knownnodes.increaseRating(self.destination) self.sendAddr() self.sendBigInv()
def set_connection_fully_established(self): if not self.isOutbound and not self.local: shared.clientHasReceivedIncomingConnections = True UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, True, self.destination))) self.antiIntersectionDelay(True) self.fullyEstablished = True if self.isOutbound: knownnodes.increaseRating(self.destination) if self.isOutbound: Dandelion().maybeAddStem(self) self.sendAddr() self.sendBigInv()
def set_connection_fully_established(self): """Initiate inventory synchronisation.""" if not self.isOutbound and not self.local: shared.clientHasReceivedIncomingConnections = True UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, True, self.destination))) self.antiIntersectionDelay(True) self.fullyEstablished = True if self.isOutbound: knownnodes.increaseRating(self.destination) if self.isOutbound: Dandelion().maybeAddStem(self) self.sendAddr() self.sendBigInv()
def handle_close(self): """Callback for connection being closed.""" host_is_global = self.isOutbound or not self.local and not state.socksIP if self.fullyEstablished: UISignalQueue.put(( 'updateNetworkStatusTab', (self.isOutbound, False, self.destination) )) if host_is_global: knownnodes.addKnownNode( self.streams, self.destination, time.time()) Dandelion().maybeRemoveStem(self) elif host_is_global: knownnodes.decreaseRating(self.destination) BMProto.handle_close(self)
def accept(self): self.timer.stop() self.hide() apiAddressGeneratorReturnQueue.queue.clear() if self.chanAddress.text().toUtf8() == "": addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True)) else: addressGeneratorQueue.put(('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()), str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True)) addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True) if len(addressGeneratorReturnValue) > 0 and addressGeneratorReturnValue[0] != 'chan name does not match address': UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Successfully created / joined chan %1").arg(unicode(self.chanPassPhrase.text())))) self.parent.ui.tabWidget.setCurrentIndex(3) self.done(QtGui.QDialog.Accepted) else: UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining failed"))) self.done(QtGui.QDialog.Rejected)
def __init__(self, address=None, sock=None): BMProto.__init__(self, address=address, sock=sock) self.verackReceived = False self.verackSent = False self.streams = [0] self.fullyEstablished = False self.connectedAt = 0 self.skipUntil = 0 if address is None and sock is not None: self.destination = state.Peer(sock.getpeername()[0], sock.getpeername()[1]) self.isOutbound = False TLSDispatcher.__init__(self, sock, server_side=True) self.connectedAt = time.time() logger.debug("Received connection from %s:%i", self.destination.host, self.destination.port) self.nodeid = randomBytes(8) elif address is not None and sock is not None: TLSDispatcher.__init__(self, sock, server_side=False) self.isOutbound = True logger.debug("Outbound proxy connection to %s:%i", self.destination.host, self.destination.port) else: self.destination = address self.isOutbound = True if ":" in address.host: self.create_socket(socket.AF_INET6, socket.SOCK_STREAM) else: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) TLSDispatcher.__init__(self, sock, server_side=False) self.connect(self.destination) logger.debug("Connecting to %s:%i", self.destination.host, self.destination.port) encodedAddr = protocol.encodeHost(self.destination.host) if protocol.checkIPAddress( encodedAddr, True) and not protocol.checkSocksIP(self.destination.host): self.local = True else: self.local = False #shared.connectedHostsList[self.destination] = 0 ObjectTracker.__init__(self) UISignalQueue.put(('updateNetworkStatusTab', 'no data')) self.bm_proto_reset() self.set_state("bm_header", expectBytes=protocol.Header.size)
def set_connection_fully_established(self): """Initiate inventory synchronisation.""" if not self.isOutbound and not self.local: state.clientHasReceivedIncomingConnections = True UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(( 'updateNetworkStatusTab', (self.isOutbound, True, self.destination) )) self.antiIntersectionDelay(True) self.fullyEstablished = True # The connection having host suitable for knownnodes if self.isOutbound or not self.local and not state.socksIP: knownnodes.increaseRating(self.destination) knownnodes.addKnownNode( self.streams, self.destination, time.time()) Dandelion().maybeAddStem(self) self.sendAddr() self.sendBigInv()
def doCleanShutdown(): state.shutdown = 1 #Used to tell proof of work worker threads and the objectProcessorThread to exit. objectProcessorQueue.put(('checkShutdownVariable', 'no data')) for thread in threading.enumerate(): if thread.isAlive() and isinstance(thread, StoppableThread): thread.stopThread() UISignalQueue.put( ('updateStatusBar', 'Saving the knownNodes list of peers to disk...')) logger.info('Saving knownNodes list of peers to disk') saveKnownNodes() logger.info('Done saving knownNodes list of peers to disk') UISignalQueue.put(('updateStatusBar', 'Done saving the knownNodes list of peers to disk.')) logger.info('Flushing inventory in memory out to disk...') UISignalQueue.put(( 'updateStatusBar', 'Flushing inventory in memory out to disk. This should normally only take a second...' )) Inventory().flush() # Verify that the objectProcessor has finished exiting. It should have incremented the # shutdown variable from 1 to 2. This must finish before we command the sqlThread to exit. while state.shutdown == 1: time.sleep(.1) # This one last useless query will guarantee that the previous flush committed and that the # objectProcessorThread committed before we close the program. sqlQuery('SELECT address FROM subscriptions') logger.info('Finished flushing inventory.') sqlStoredProcedure('exit') # Wait long enough to guarantee that any running proof of work worker threads will check the # shutdown variable and exit. If the main thread closes before they do then they won't stop. time.sleep(.25) for thread in threading.enumerate(): if thread is not threading.currentThread() and isinstance( thread, StoppableThread): logger.debug("Waiting for thread %s", thread.name) thread.join() # flush queued for queue in (workerQueue, UISignalQueue, addressGeneratorQueue, objectProcessorQueue): while True: try: queue.get(False) queue.task_done() except Queue.Empty: break if shared.thisapp.daemon: logger.info('Clean shutdown complete.') shared.thisapp.cleanup() os._exit(0) else: logger.info('Core shutdown complete.') for thread in threading.enumerate(): logger.debug("Thread %s still running", thread.name)
def doCleanShutdown(): state.shutdown = 1 #Used to tell proof of work worker threads and the objectProcessorThread to exit. #Stop sources of new threads for thread in threading.enumerate(): if type(thread).__name__ not in ('outgoingSynSender', 'singleListener'): continue thread.stopThread() thread.join() protocol.broadcastToSendDataQueues((0, 'shutdown', 'no data')) objectProcessorQueue.put(('checkShutdownVariable', 'no data')) for thread in threading.enumerate(): if thread.isAlive() and isinstance(thread, StoppableThread): thread.stopThread() UISignalQueue.put( ('updateStatusBar', 'Saving the knownNodes list of peers to disk...')) logger.info('Saving knownNodes list of peers to disk') saveKnownNodes() logger.info('Done saving knownNodes list of peers to disk') UISignalQueue.put(('updateStatusBar', 'Done saving the knownNodes list of peers to disk.')) logger.info('Flushing inventory in memory out to disk...') UISignalQueue.put(( 'updateStatusBar', 'Flushing inventory in memory out to disk. This should normally only take a second...' )) Inventory().flush() # Verify that the objectProcessor has finished exiting. It should have incremented the # shutdown variable from 1 to 2. This must finish before we command the sqlThread to exit. for thread in threading.enumerate(): if type(thread).__name__ != 'objectProcessor': continue thread.join() break # This will guarantee that the previous flush committed and that the # objectProcessorThread committed before we close the program. sqlStoredProcedure('commit') logger.info('Finished flushing inventory.') sqlStoredProcedure('exit') for thread in threading.enumerate(): if type(thread).__name__ != 'sqlThread': continue thread.join() break # Wait long enough to guarantee that any running proof of work worker threads will check the # shutdown variable and exit. If the main thread closes before they do then they won't stop. time.sleep(.25) for thread in threading.enumerate(): if isinstance(thread, sendDataThread): thread.sendDataThreadQueue.put((0, 'shutdown', 'no data')) if thread is not threading.currentThread() and isinstance( thread, StoppableThread) and not isinstance(thread, outgoingSynSender): logger.debug("Waiting for thread %s", thread.name) thread.join() # flush queued for queue in (workerQueue, UISignalQueue, addressGeneratorQueue, objectProcessorQueue): while True: try: queue.get(False) queue.task_done() except Queue.Empty: break logger.info('Clean shutdown complete.') for thread in threading.enumerate(): if thread is threading.currentThread(): continue logger.debug("Thread %s still running", thread.name) if BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'): shared.thisapp.cleanup() os._exit(0)