def deposit_cb(self, widget, event=None): """Attempts to deposit all coins- for debugging only""" coins = Bank.get().get_acoins(Bank.get().get_wallet_balance()) if not coins: log_msg("No ACoins left!") return Bank.get().deposit_acoins(coins)
def start_payment_loop(self): coin = Bank.get().get_acoins(1) if not coin: log_msg("No ACoins left!") return coin = coin[0] #generate ACoin request request = BankMessages.make_acoin_request(Bank.get(), Bank.get().currentACoinInterval, 1) #make the message: bankMsg = Basic.write_byte(1) bankMsg += coin.write_binary() + request.msg key = EncryptedDatagram.ClientSymKey(Bank.get().PUBLIC_KEY) bankMsg = Basic.write_byte(1) + key.encrypt(Basic.write_byte(3) + bankMsg) payment = UDPPayment.UDPPayment(Bank.get(), bankMsg) paymentDeferred = payment.get_deferred() def success(result, request=request): log_msg("success") self.payments += 1 # self.start_payment_loop() #validate the ACoin code, sig = Basic.read_byte(result) coin = BankMessages.parse_acoin_response(Bank.get(), sig, request, False) if not coin: log_msg("Invalid ACoin sent for payment!") else: Bank.get().on_earned_coin(coin) paymentDeferred.addCallback(success) def failure(error): self.start_payment_loop() log_ex(error, "Failure during test?") self.failures += 1 paymentDeferred.addErrback(failure)
def _do_quit(self): self.dia.hide() if Bank.get() and Bank.get().is_starting(): Bank.get().stop() GlobalEvents.throw_event("quit_signal") #intentionally called twice, we dont want to be waiting around for bittorrent tracker shutdown if we havent even logged in GlobalEvents.throw_event("quit_signal")
def _create_applications(self): """Creates all application classes that the MainLoop coordinates. This does NOT start them- that's done later. WARNING: the gui assumes the apps exist! """ #create the Bank application: Bank.start() self.bankApp = Bank.get() #create the Tor application: Tor.start() self.torApp = Tor.get() #create the pseudo applications for InnomiNet BitBlinder.start(self.torApp, self.bankApp) self.bbApp = BitBlinder.get() #create the applications: BitTorrentClient.start(self.torApp) self.btApp = BitTorrentClient.get() self.bbApp.add_application(self.btApp) if System.IS_WINDOWS: FirefoxPortable.start(self.torApp) self.ffApp = FirefoxPortable.get() self.bbApp.add_application(self.ffApp) self.gui.on_applications_created(self.bankApp, self.torApp, self.bbApp, self.btApp, self.ffApp)
def launch_test_upload(self, widget, event=None): test = None #get the selected item (either a Stream or Circuit) circ = self.getSelected() #if there was no selection or the selection was a stream, let BitBlinder pick the circuit if not circ or circ.__class__.__name__ != "Circuit" or not circ.is_open(): log_msg("Cannot upload through that %s" % (circ), 0) return class TestUploader(Int32StringReceiver): def connectionMade(self): self.bytesLeft = 2 * 1024 * 1024 self.transport.write(struct.pack("!I", self.bytesLeft)) self.sendEvent = Scheduler.schedule_repeat(0.1, self.send_more, 1024 * 10) def send_more(self, numBytes): self.transport.write("1"*numBytes) self.bytesLeft -= numBytes if self.bytesLeft <= 0: return False else: return True def stringReceived(self, data): log_msg("Upload hopefully done?") return factory = protocol.ClientFactory() factory.protocol = TestUploader #connect to the bank and send some trash: d = BitBlinder.get().launch_external_factory(Bank.get().host, Bank.get().port, factory, circ.handle_stream, "Test Upload")
def on_response(self, dialog, response_id): if (response_id == gtk.RESPONSE_OK): #get the login details, etc: self.username = str(self.nameEntry.get_text()) self.password = str(self.pwEntry.get_text()) if not self.username or not self.password: self.label.set_text( "You must enter a non-empty username and password!") return #check that the username is possibly valid: if not Globals.USERNAME_REGEX.match(self.username): self.label.set_text( "Usernames can only contain A-Z, a-z, 0-9, -, _, and spaces in the middle" ) return #log in to the bank: self.label.set_text("Connecting to bank...") Bank.get().login(self.username, self.password) self.nameEntry.set_sensitive(False) self.pwEntry.set_sensitive(False) self.loginButton.set_sensitive(False) self.quitButton.set_sensitive(False) elif (response_id == gtk.RESPONSE_CANCEL): self._do_quit() else: self.label.set_text("How did that even happen?")
def start_deposit_loop(self): coin = Bank.get().get_acoins(1) if not coin: log_msg("No ACoins left!") return Globals.reactor.connectTCP( Bank.get().host, Bank.get().port, ACoinDepositFactory.ACoinDepositFactory(Bank.get(), coin))
def success(result, request=request): log_msg("success") self.payments += 1 # self.start_payment_loop() #validate the ACoin code, sig = Basic.read_byte(result) coin = BankMessages.parse_acoin_response(Bank.get(), sig, request, False) if not coin: log_msg("Invalid ACoin sent for payment!") else: Bank.get().on_earned_coin(coin)
def do_verification_prompt(self, bankApp): #load a global config that said whether to store the last user that logged in (and his password) settings = GlobalSettings.load() #just directly login: self.username = str(settings.username) self.password = str(settings.password) self.savePass = settings.save_password while not self.username or not self.password: self.username = str(raw_input('Enter your username: '******'Enter your password: '******'Should save password? (yes/no) ')) self.savePass = shouldSave.lower() in ("yes", "y") #just directly login: Bank.get().login(self.username, self.password)
def __init__(self, controller): buttons = (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO) dia = gtk.Dialog("Credits Low", None, 0, buttons) self.controller = controller vbox = gtk.VBox() title = gtk.Label() markup = "<span size='large' weight='bold'>You Are Running out of Credits</span>" title.set_markup(markup) title.set_justify(gtk.JUSTIFY_CENTER) vbox.pack_start(title, True, False, 0) #A text entry telling the user what to do: balance = Bank.get().get_expected_balance() balanceGB = Format.convert_to_gb(balance) label = gtk.Label() text = "You only have %s (%s) credits remaining. You must set up a relay to gain more credits. \ This will allow other users to send traffic via your computer.\n\nWould you like to set up a relay now?" % (balance, balanceGB) label.set_markup(text) label.set_line_wrap(True) vbox.pack_start(label, True, True, 5) #if we should always check: self.askAboutRelay = gtk.CheckButton("Always ask about help setting up relay") vbox.pack_start(self.askAboutRelay, True, True, 10) #initialize the checkbox: self.askAboutRelay.set_active(CoreSettings.get().askAboutRelay) vbox = GTKUtils.add_padding(vbox, 5) dia.vbox.pack_start(vbox, True, True, 0) dia.connect("response", self.on_response) self.dia = dia #start the dialog dia.show_all()
def on_update(self): """updates the gui via pulling infos out of tor and the bank- slow, stupid, and easy""" # don't do updates if we arent visible if not GTKUtils.is_visible(self.container): return configuredAsRelay = self.torApp.is_server() if configuredAsRelay: self.relayRow.update_row_image(True) else: self.relayRow.reset_row_image() relayStatus, relayStateString = self.torApp.get_relay_status() if self.torApp.is_server(): self.statusRow.update_row_image(relayStatus) else: self.statusRow.reset_row_image() self.statusRow.widget.set_markup('<span size="large">%s</span>' % (relayStateString)) # update as appropriate for rows when we are trying to be a relay if configuredAsRelay: boolToStringMapping = {True: "is reachable", False: "is unreachable", None: "testing..."} # do updates where we have the info relayPortsState = self.torApp.get_all_port_status() for row in self.statusRows: updateForGUIPort = row.rowName in relayPortsState if updateForGUIPort: port = relayPortsState[row.rowName] row.update_row_image(port[0]) statusText = boolToStringMapping[port[0]] row.widget.set_markup('<span size="large">%s %s</span>' % (port[1], statusText)) # else, null everything out else: for row in [self.udpRelayPortRow, self.tcpRelayPortRow, self.dirPortRow, self.statusRow]: row.reset_row_image() row.widget.set_markup('<span size="large">offline</span>') # update the balance bank = Bank.get() if not bank: return credits = bank.get_expected_balance() if not credits: return self.creditsRow.widget.set_markup( '<span size="large">%s (%s)</span>' % (credits, Format.convert_to_gb(credits)) ) if credits > 200: creditState = True elif credits > 100: creditState = None else: creditState = False self.creditsRow.update_row_image(creditState)
def on_update(self): """updates the gui via pulling infos out of tor and the bank- slow, stupid, and easy""" #don't do updates if we arent visible if not GTKUtils.is_visible(self.container): return configuredAsRelay = self.torApp.is_server() if configuredAsRelay: self.relayRow.update_row_image(True) else: self.relayRow.reset_row_image() relayStatus, relayStateString = self.torApp.get_relay_status() if self.torApp.is_server(): self.statusRow.update_row_image(relayStatus) else: self.statusRow.reset_row_image() self.statusRow.widget.set_markup('<span size="large">%s</span>' % (relayStateString)) #update as appropriate for rows when we are trying to be a relay if configuredAsRelay: boolToStringMapping = {True: 'is reachable', False: 'is unreachable', None: 'testing...'} #do updates where we have the info relayPortsState = self.torApp.get_all_port_status() for row in self.statusRows: updateForGUIPort = row.rowName in relayPortsState if updateForGUIPort: port = relayPortsState[row.rowName] row.update_row_image(port[0]) statusText = boolToStringMapping[port[0]] row.widget.set_markup('<span size="large">%s %s</span>' % (port[1], statusText)) #else, null everything out else: for row in [self.udpRelayPortRow, self.tcpRelayPortRow, self.dirPortRow, self.statusRow]: row.reset_row_image() row.widget.set_markup('<span size="large">offline</span>') #update the balance bank = Bank.get() if not bank: return credits = bank.get_expected_balance() if not credits: return self.creditsRow.widget.set_markup('<span size="large">%s (%s)</span>'%\ (credits, Format.convert_to_gb(credits))) if credits > 200: creditState = True elif credits > 100: creditState = None else: creditState = False self.creditsRow.update_row_image(creditState)
def on_update(self): """is responsible for updating the stat_dict""" global _showedLowMoneyWarning currentBalance = Bank.get().get_expected_balance() #if you have <HIGH_WATER credits: if currentBalance < LOW_MONEY_WARNING_LEVEL: #if you are NOT correctly set up as a relay, inform the user that they must be a relay for this system to keep working #are we not yet acting as a relay? if not Tor.get().settings.beRelay: #have we already warned them? if not _showedLowMoneyWarning: _showedLowMoneyWarning = True #Prompt the user about whether they want to run a relay and earn credits or not: if CoreSettings.get().askAboutRelay: GUIController.get().on_low_credits() self.statistics["Local Balance"].stat_value = str(Bank.get().get_wallet_balance()) self.statistics["Bank Balance"].stat_value = str(currentBalance) self.statistics["Credits Earned"].stat_value = str(Bank.get().get_earnings()) for text, label in self.statistics.iteritems(): label.set_text(text + ": " + label.stat_value)
def start_payment_loop(self): coin = Bank.get().get_acoins(1) if not coin: log_msg("No ACoins left!") return coin = coin[0] #generate ACoin request request = BankMessages.make_acoin_request( Bank.get(), Bank.get().currentACoinInterval, 1) #make the message: bankMsg = Basic.write_byte(1) bankMsg += coin.write_binary() + request.msg key = EncryptedDatagram.ClientSymKey(Bank.get().PUBLIC_KEY) bankMsg = Basic.write_byte(1) + key.encrypt( Basic.write_byte(3) + bankMsg) payment = UDPPayment.UDPPayment(Bank.get(), bankMsg) paymentDeferred = payment.get_deferred() def success(result, request=request): log_msg("success") self.payments += 1 # self.start_payment_loop() #validate the ACoin code, sig = Basic.read_byte(result) coin = BankMessages.parse_acoin_response(Bank.get(), sig, request, False) if not coin: log_msg("Invalid ACoin sent for payment!") else: Bank.get().on_earned_coin(coin) paymentDeferred.addCallback(success) def failure(error): self.start_payment_loop() log_ex(error, "Failure during test?") self.failures += 1 paymentDeferred.addErrback(failure)
def on_update(self): """is responsible for updating the stat_dict""" global _showedLowMoneyWarning currentBalance = Bank.get().get_expected_balance() #if you have <HIGH_WATER credits: if currentBalance < LOW_MONEY_WARNING_LEVEL: #if you are NOT correctly set up as a relay, inform the user that they must be a relay for this system to keep working #are we not yet acting as a relay? if not Tor.get().settings.beRelay: #have we already warned them? if not _showedLowMoneyWarning: _showedLowMoneyWarning = True #Prompt the user about whether they want to run a relay and earn credits or not: if CoreSettings.get().askAboutRelay: GUIController.get().on_low_credits() self.statistics["Local Balance"].stat_value = str( Bank.get().get_wallet_balance()) self.statistics["Bank Balance"].stat_value = str(currentBalance) self.statistics["Credits Earned"].stat_value = str( Bank.get().get_earnings()) for text, label in self.statistics.iteritems(): label.set_text(text + ": " + label.stat_value)
def on_response(self, dialog, response_id): if (response_id == gtk.RESPONSE_OK): #get the login details, etc: self.username = str(self.nameEntry.get_text()) self.password = str(self.pwEntry.get_text()) if not self.username or not self.password: self.label.set_text("You must enter a non-empty username and password!") return #check that the username is possibly valid: if not Globals.USERNAME_REGEX.match(self.username): self.label.set_text("Usernames can only contain A-Z, a-z, 0-9, -, _, and spaces in the middle") return #log in to the bank: self.label.set_text("Connecting to bank...") Bank.get().login(self.username, self.password) self.nameEntry.set_sensitive(False) self.pwEntry.set_sensitive(False) self.loginButton.set_sensitive(False) self.quitButton.set_sensitive(False) elif (response_id == gtk.RESPONSE_CANCEL): self._do_quit() else: self.label.set_text("How did that even happen?")
def update(self, globalDownRate, globalUpRate, globalDownAmount, globalUpAmount): if self.btApp.is_ready(): try: nodes = self.btApp.btInstance.dht.get_dht_peers() except: nodes = ("unknown", "disabled") self.dhtText.set_markup('<span>DHT Nodes: %s (%s)</span>' % nodes) globalDownRate = Format.bytes_per_second(globalDownRate) globalDownAmount = Format.format_bytes(globalDownAmount) self.downText.set_markup('<span>U: %s %s</span>' % (globalDownRate, globalDownAmount)) globalUpRate = Format.bytes_per_second(globalUpRate) globalUpAmount = Format.format_bytes(globalUpAmount) self.upText.set_markup('<span>D: %s %s</span>' % (globalUpRate, globalUpAmount)) credits = Bank.get().get_total_asset_value() self.creditText.set_markup('<span>Credits: %s (%s)</span>' % (credits, Format.convert_to_gb(credits)))
def launch_test_upload(self, widget, event=None): test = None #get the selected item (either a Stream or Circuit) circ = self.getSelected() #if there was no selection or the selection was a stream, let BitBlinder pick the circuit if not circ or circ.__class__.__name__ != "Circuit" or not circ.is_open( ): log_msg("Cannot upload through that %s" % (circ), 0) return class TestUploader(Int32StringReceiver): def connectionMade(self): self.bytesLeft = 2 * 1024 * 1024 self.transport.write(struct.pack("!I", self.bytesLeft)) self.sendEvent = Scheduler.schedule_repeat( 0.1, self.send_more, 1024 * 10) def send_more(self, numBytes): self.transport.write("1" * numBytes) self.bytesLeft -= numBytes if self.bytesLeft <= 0: return False else: return True def stringReceived(self, data): log_msg("Upload hopefully done?") return factory = protocol.ClientFactory() factory.protocol = TestUploader #connect to the bank and send some trash: d = BitBlinder.get().launch_external_factory(Bank.get().host, Bank.get().port, factory, circ.handle_stream, "Test Upload")
def _stop_done(self, result): Basic.validate_result(result, "BitTorrentWindow::_stop_done") if not BitBlinder.get().is_running(): GlobalEvents.throw_event("quit_signal") else: #are there any other apps using bitblinder? for app in BitBlinder.get().applications.values(): #if there is another app, dont bother shutting down everything if app.is_running() and app != Bank.get(): return #ok, check if there is a relay then if Tor.get().settings.beRelay: #then we should prompt about shutdown def callback(dialog, response): if response == gtk.RESPONSE_YES: self._do_quit() msgText = "BitBlinder is acting as a server and help others be anonymous, and earning you more credits!\n\nDo you also want to stop the server?" GUIController.get().show_preference_prompt(msgText, "Stop Relay?", callback, "promptAboutRelayQuit") else: #otherwise shutdown completely: self._do_quit()
def __init__(self, controller): buttons = (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO) dia = gtk.Dialog("Credits Low", None, 0, buttons) self.controller = controller vbox = gtk.VBox() title = gtk.Label() markup = "<span size='large' weight='bold'>You Are Running out of Credits</span>" title.set_markup(markup) title.set_justify(gtk.JUSTIFY_CENTER) vbox.pack_start(title, True, False, 0) #A text entry telling the user what to do: balance = Bank.get().get_expected_balance() balanceGB = Format.convert_to_gb(balance) label = gtk.Label() text = "You only have %s (%s) credits remaining. You must set up a relay to gain more credits. \ This will allow other users to send traffic via your computer.\n\nWould you like to set up a relay now?" % ( balance, balanceGB) label.set_markup(text) label.set_line_wrap(True) vbox.pack_start(label, True, True, 5) #if we should always check: self.askAboutRelay = gtk.CheckButton( "Always ask about help setting up relay") vbox.pack_start(self.askAboutRelay, True, True, 10) #initialize the checkbox: self.askAboutRelay.set_active(CoreSettings.get().askAboutRelay) vbox = GTKUtils.add_padding(vbox, 5) dia.vbox.pack_start(vbox, True, True, 0) dia.connect("response", self.on_response) self.dia = dia #start the dialog dia.show_all()
def _stop_done(self, result): Basic.validate_result(result, "BitTorrentWindow::_stop_done") if not BitBlinder.get().is_running(): GlobalEvents.throw_event("quit_signal") else: #are there any other apps using bitblinder? for app in BitBlinder.get().applications.values(): #if there is another app, dont bother shutting down everything if app.is_running() and app != Bank.get(): return #ok, check if there is a relay then if Tor.get().settings.beRelay: #then we should prompt about shutdown def callback(dialog, response): if response == gtk.RESPONSE_YES: self._do_quit() msgText = "BitBlinder is acting as a server and help others be anonymous, and earning you more credits!\n\nDo you also want to stop the server?" GUIController.get().show_preference_prompt( msgText, "Stop Relay?", callback, "promptAboutRelayQuit") else: #otherwise shutdown completely: self._do_quit()
def request_cb(self, widget, event=None): """Attempts to get the acoin low level number of coins- for debugging only. Note, this might send the number past the high level at which point the client will automatically attempt to deposit coins to meet the target level""" Bank.get().request_coins(1, Bank.ACOIN_LOW_LEVEL)
def __init__(self, torApp): BitBlinder.BitBlinderApplication.__init__(self, "FirefoxPortable", FirefoxPortableSettings, "Browse the Internet.", torApp, Bank.get()) #It's also weird because our resolver is terrible, it isnt resolving my IP as american #TODO: get a better method for resolving which country a router is in. Perhaps when they sign up... #self.exitCountry = "us" #: the process id of polipo.exe in windows. Necessary to handle the case of the first launch of firefox self.polipoProc = None #: used to track portable FF when it restarts on us self.checkFFEvent = None #: if not provided another launch page, this one will be used. Default is our Torcheck page self.startPage = "http://login.bitblinder.com:81/check/" #add us to the list of known applications: BitBlinder.KNOWN_APPLICATIONS.append(self.name) if System.IS_WINDOWS: self.isInstalled = True else: self.isInstalled = False #need to handle startup arguments: self.catch_event("new_args")
def entry_cb(self, *args): balance = int(self.entry.get_text()) Bank.get()._forceSetBalance = balance Bank.get().on_new_balance_from_bank(balance)
def on_low_credits(self): log_msg("You only have %s credits remaining. Make sure that your ports are forwarded and you are acting as a relay, otherwise you will run out!" % (Bank.get().get_expected_balance()))
def start_deposit_loop(self): coin = Bank.get().get_acoins(1) if not coin: log_msg("No ACoins left!") return Globals.reactor.connectTCP(Bank.get().host, Bank.get().port, ACoinDepositFactory.ACoinDepositFactory(Bank.get(), coin))
def on_low_credits(self): log_msg( "You only have %s credits remaining. Make sure that your ports are forwarded and you are acting as a relay, otherwise you will run out!" % (Bank.get().get_expected_balance()))
def start_withdrawal_loop(self): Globals.reactor.connectTCP(Bank.get().host, Bank.get().port, ACoinRequestFactory.ACoinRequestFactory(Bank.get(), 1, 40))
def start_withdrawal_loop(self): Globals.reactor.connectTCP( Bank.get().host, Bank.get().port, ACoinRequestFactory.ACoinRequestFactory(Bank.get(), 1, 40))