Removed unused and unreachable/dead code
Signed-off-by: Venkatesh Pitta <venkateshpitta@gmail.com>
This commit is contained in:
parent
634a49cd6d
commit
c548ff96a1
|
@ -7,7 +7,7 @@ import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
for root, dirnames, filenames in os.walk('src'):
|
for root, _, filenames in os.walk('src'):
|
||||||
for filename in fnmatch.filter(filenames, '*.py'):
|
for filename in fnmatch.filter(filenames, '*.py'):
|
||||||
matches.append(os.path.join(root, filename))
|
matches.append(os.path.join(root, filename))
|
||||||
|
|
||||||
|
|
|
@ -169,11 +169,9 @@ def testCompiler():
|
||||||
)
|
)
|
||||||
|
|
||||||
dist = Distribution()
|
dist = Distribution()
|
||||||
dist.ext_modules = [bitmsghash]
|
|
||||||
cmd = build_ext(dist)
|
cmd = build_ext(dist)
|
||||||
cmd.initialize_options()
|
cmd.initialize_options()
|
||||||
cmd.finalize_options()
|
cmd.finalize_options()
|
||||||
cmd.force = True
|
|
||||||
try:
|
try:
|
||||||
cmd.run()
|
cmd.run()
|
||||||
except CompileError:
|
except CompileError:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from os import stat, getenv, path
|
from os import getenv, path
|
||||||
from pybloom import BloomFilter as BloomFilter1
|
from pybloom import BloomFilter as BloomFilter1
|
||||||
from pybloomfilter import BloomFilter as BloomFilter2
|
from pybloomfilter import BloomFilter as BloomFilter2
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
@ -9,7 +9,6 @@ from time import time
|
||||||
|
|
||||||
conn = sqlite3.connect(path.join(getenv("HOME"), '.config/PyBitmessage/messages.dat'))
|
conn = sqlite3.connect(path.join(getenv("HOME"), '.config/PyBitmessage/messages.dat'))
|
||||||
|
|
||||||
conn.text_factory = str
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
rawlen = 0
|
rawlen = 0
|
||||||
itemcount = 0
|
itemcount = 0
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import importlib
|
|
||||||
from os import listdir, path
|
from os import listdir, path
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -44,6 +44,5 @@ signal.signal(signal.SIGTERM, signal_handler)
|
||||||
bso = ctypes.CDLL(os.path.join("bitmsghash", "bitmsghash.so"))
|
bso = ctypes.CDLL(os.path.join("bitmsghash", "bitmsghash.so"))
|
||||||
|
|
||||||
bmpow = bso.BitmessagePOW
|
bmpow = bso.BitmessagePOW
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
|
||||||
|
|
||||||
_doCPoW(2**44, "")
|
_doCPoW(2**44, "")
|
||||||
|
|
|
@ -45,8 +45,6 @@ def sslHandshake(sock, server=False):
|
||||||
context = ssl.SSLContext(sslProtocolVersion())
|
context = ssl.SSLContext(sslProtocolVersion())
|
||||||
context.set_ciphers(sslProtocolCiphers())
|
context.set_ciphers(sslProtocolCiphers())
|
||||||
context.set_ecdh_curve("secp256k1")
|
context.set_ecdh_curve("secp256k1")
|
||||||
context.check_hostname = False
|
|
||||||
context.verify_mode = ssl.CERT_NONE
|
|
||||||
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
||||||
sslSock = context.wrap_socket(sock, server_side = server, do_handshake_on_connect=False)
|
sslSock = context.wrap_socket(sock, server_side = server, do_handshake_on_connect=False)
|
||||||
else:
|
else:
|
||||||
|
|
2
packages/collectd/pybitmessagestatus.py
Normal file → Executable file
2
packages/collectd/pybitmessagestatus.py
Normal file → Executable file
|
@ -40,12 +40,10 @@ def read_callback():
|
||||||
|
|
||||||
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
|
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
|
||||||
metric = collectd.Values()
|
metric = collectd.Values()
|
||||||
metric.plugin = "pybitmessagestatus"
|
|
||||||
if i[0:6] == "number":
|
if i[0:6] == "number":
|
||||||
metric.type = 'counter'
|
metric.type = 'counter'
|
||||||
else:
|
else:
|
||||||
metric.type = 'gauge'
|
metric.type = 'gauge'
|
||||||
metric.type_instance = i.lower()
|
|
||||||
try:
|
try:
|
||||||
metric.values = [clientStatus[i]]
|
metric.values = [clientStatus[i]]
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -5,16 +5,6 @@ from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
#from debug import logger
|
#from debug import logger
|
||||||
|
|
||||||
#There is another copy of this function in Bitmessagemain.py
|
|
||||||
def convertIntToString(n):
|
|
||||||
a = __builtins__.hex(n)
|
|
||||||
if a[-1:] == 'L':
|
|
||||||
a = a[:-1]
|
|
||||||
if (len(a) % 2) == 0:
|
|
||||||
return unhexlify(a[2:])
|
|
||||||
else:
|
|
||||||
return unhexlify('0'+a[2:])
|
|
||||||
|
|
||||||
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
|
|
||||||
def encodeBase58(num, alphabet=ALPHABET):
|
def encodeBase58(num, alphabet=ALPHABET):
|
||||||
|
|
173
src/api.py
173
src/api.py
|
@ -56,7 +56,6 @@ class APIError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
||||||
allow_reuse_address = True
|
|
||||||
|
|
||||||
def serve_forever(self):
|
def serve_forever(self):
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
|
@ -68,79 +67,79 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
||||||
# http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
|
# http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
|
||||||
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
|
|
||||||
def do_POST(self):
|
# def do_POST(self):
|
||||||
# Handles the HTTP POST request.
|
# # Handles the HTTP POST request.
|
||||||
# Attempts to interpret all HTTP POST requests as XML-RPC calls,
|
# # Attempts to interpret all HTTP POST requests as XML-RPC calls,
|
||||||
# which are forwarded to the server's _dispatch method for handling.
|
# # which are forwarded to the server's _dispatch method for handling.
|
||||||
|
|
||||||
# Note: this method is the same as in SimpleXMLRPCRequestHandler,
|
# # Note: this method is the same as in SimpleXMLRPCRequestHandler,
|
||||||
# just hacked to handle cookies
|
# # just hacked to handle cookies
|
||||||
|
|
||||||
# Check that the path is legal
|
# # Check that the path is legal
|
||||||
if not self.is_rpc_path_valid():
|
# if not self.is_rpc_path_valid():
|
||||||
self.report_404()
|
# self.report_404()
|
||||||
return
|
# return
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
# Get arguments by reading body of request.
|
# # Get arguments by reading body of request.
|
||||||
# We read this in chunks to avoid straining
|
# # We read this in chunks to avoid straining
|
||||||
# socket.read(); around the 10 or 15Mb mark, some platforms
|
# # socket.read(); around the 10 or 15Mb mark, some platforms
|
||||||
# begin to have problems (bug #792570).
|
# # begin to have problems (bug #792570).
|
||||||
max_chunk_size = 10 * 1024 * 1024
|
# max_chunk_size = 10 * 1024 * 1024
|
||||||
size_remaining = int(self.headers["content-length"])
|
# size_remaining = int(self.headers["content-length"])
|
||||||
L = []
|
# L = []
|
||||||
while size_remaining:
|
# while size_remaining:
|
||||||
chunk_size = min(size_remaining, max_chunk_size)
|
# chunk_size = min(size_remaining, max_chunk_size)
|
||||||
L.append(self.rfile.read(chunk_size))
|
# L.append(self.rfile.read(chunk_size))
|
||||||
size_remaining -= len(L[-1])
|
# size_remaining -= len(L[-1])
|
||||||
data = ''.join(L)
|
# data = ''.join(L)
|
||||||
|
|
||||||
# In previous versions of SimpleXMLRPCServer, _dispatch
|
# # In previous versions of SimpleXMLRPCServer, _dispatch
|
||||||
# could be overridden in this class, instead of in
|
# # could be overridden in this class, instead of in
|
||||||
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
|
# # SimpleXMLRPCDispatcher. To maintain backwards compatibility,
|
||||||
# check to see if a subclass implements _dispatch and dispatch
|
# # check to see if a subclass implements _dispatch and dispatch
|
||||||
# using that method if present.
|
# # using that method if present.
|
||||||
response = self.server._marshaled_dispatch(
|
# response = self.server._marshaled_dispatch(
|
||||||
data, getattr(self, '_dispatch', None)
|
# data, getattr(self, '_dispatch', None)
|
||||||
)
|
# )
|
||||||
except: # This should only happen if the module is buggy
|
# except: # This should only happen if the module is buggy
|
||||||
# internal error, report as HTTP server error
|
# # internal error, report as HTTP server error
|
||||||
self.send_response(500)
|
# self.send_response(500)
|
||||||
self.end_headers()
|
# self.end_headers()
|
||||||
else:
|
# else:
|
||||||
# got a valid XML RPC response
|
# # got a valid XML RPC response
|
||||||
self.send_response(200)
|
# self.send_response(200)
|
||||||
self.send_header("Content-type", "text/xml")
|
# self.send_header("Content-type", "text/xml")
|
||||||
self.send_header("Content-length", str(len(response)))
|
# self.send_header("Content-length", str(len(response)))
|
||||||
|
|
||||||
# HACK :start -> sends cookies here
|
# # HACK :start -> sends cookies here
|
||||||
if self.cookies:
|
# if self.cookies:
|
||||||
for cookie in self.cookies:
|
# for cookie in self.cookies:
|
||||||
self.send_header('Set-Cookie', cookie.output(header=''))
|
# self.send_header('Set-Cookie', cookie.output(header=''))
|
||||||
# HACK :end
|
# # HACK :end
|
||||||
|
|
||||||
self.end_headers()
|
# self.end_headers()
|
||||||
self.wfile.write(response)
|
# self.wfile.write(response)
|
||||||
|
|
||||||
# shut down the connection
|
# # shut down the connection
|
||||||
self.wfile.flush()
|
# self.wfile.flush()
|
||||||
self.connection.shutdown(1)
|
# self.connection.shutdown(1)
|
||||||
|
|
||||||
def APIAuthenticateClient(self):
|
# def APIAuthenticateClient(self):
|
||||||
if 'Authorization' in self.headers:
|
# if 'Authorization' in self.headers:
|
||||||
# handle Basic authentication
|
# # handle Basic authentication
|
||||||
(enctype, encstr) = self.headers.get('Authorization').split()
|
# (_, encstr) = self.headers.get('Authorization').split()
|
||||||
(emailid, password) = encstr.decode('base64').split(':')
|
# (emailid, password) = encstr.decode('base64').split(':')
|
||||||
if emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and password == BMConfigParser().get('bitmessagesettings', 'apipassword'):
|
# if emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and password == BMConfigParser().get('bitmessagesettings', 'apipassword'):
|
||||||
return True
|
# return True
|
||||||
else:
|
# else:
|
||||||
return False
|
# return False
|
||||||
else:
|
# else:
|
||||||
logger.warn('Authentication failed because header lacks Authentication field')
|
# logger.warn('Authentication failed because header lacks Authentication field')
|
||||||
time.sleep(2)
|
# time.sleep(2)
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def _decode(self, text, decode_type):
|
def _decode(self, text, decode_type):
|
||||||
try:
|
try:
|
||||||
|
@ -445,7 +444,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
if len(addressGeneratorReturnValue) == 0:
|
if len(addressGeneratorReturnValue) == 0:
|
||||||
raise APIError(24, 'Chan address is already present.')
|
raise APIError(24, 'Chan address is already present.')
|
||||||
#TODO: this variable is not used to anything
|
#TODO: this variable is not used to anything
|
||||||
createdAddress = addressGeneratorReturnValue[0] # in case we ever want it for anything.
|
#createdAddress = addressGeneratorReturnValue[0] # in case we ever want it for anything, uncomment
|
||||||
return "success"
|
return "success"
|
||||||
|
|
||||||
def HandleLeaveChan(self, params):
|
def HandleLeaveChan(self, params):
|
||||||
|
@ -1042,29 +1041,29 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
handlers['deleteAndVacuum'] = HandleDeleteAndVacuum
|
handlers['deleteAndVacuum'] = HandleDeleteAndVacuum
|
||||||
handlers['shutdown'] = HandleShutdown
|
handlers['shutdown'] = HandleShutdown
|
||||||
|
|
||||||
def _handle_request(self, method, params):
|
# def _handle_request(self, method, params):
|
||||||
if (self.handlers.has_key(method)):
|
# if (self.handlers.has_key(method)):
|
||||||
return self.handlers[method](self, params)
|
# return self.handlers[method](self, params)
|
||||||
else:
|
# else:
|
||||||
raise APIError(20, 'Invalid method: %s' % method)
|
# raise APIError(20, 'Invalid method: %s' % method)
|
||||||
|
|
||||||
def _dispatch(self, method, params):
|
# def _dispatch(self, method, params):
|
||||||
self.cookies = []
|
# self.cookies = []
|
||||||
|
|
||||||
validuser = self.APIAuthenticateClient()
|
# validuser = self.APIAuthenticateClient()
|
||||||
if not validuser:
|
# if not validuser:
|
||||||
time.sleep(2)
|
# time.sleep(2)
|
||||||
return "RPC Username or password incorrect or HTTP header lacks authentication at all."
|
# return "RPC Username or password incorrect or HTTP header lacks authentication at all."
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
return self._handle_request(method, params)
|
# return self._handle_request(method, params)
|
||||||
except APIError as e:
|
# except APIError as e:
|
||||||
return str(e)
|
# return str(e)
|
||||||
except varintDecodeError as e:
|
# except varintDecodeError as e:
|
||||||
logger.error(e)
|
# logger.error(e)
|
||||||
return "API Error 0026: Data contains a malformed varint. Some details: %s" % e
|
# return "API Error 0026: Data contains a malformed varint. Some details: %s" % e
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
logger.exception(e)
|
# logger.exception(e)
|
||||||
return "API Error 0021: Unexpected API Failure - %s" % str(e)
|
# return "API Error 0021: Unexpected API Failure - %s" % str(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import StringIO
|
|
||||||
from textwrap import *
|
from textwrap import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
@ -35,7 +34,6 @@ import shutdown
|
||||||
quit = False
|
quit = False
|
||||||
menutab = 1
|
menutab = 1
|
||||||
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
|
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
|
||||||
naptime = 100
|
|
||||||
log = ""
|
log = ""
|
||||||
logpad = None
|
logpad = None
|
||||||
inventorydata = 0
|
inventorydata = 0
|
||||||
|
@ -47,7 +45,6 @@ sentbox = []
|
||||||
sentcur = 0
|
sentcur = 0
|
||||||
addresses = []
|
addresses = []
|
||||||
addrcur = 0
|
addrcur = 0
|
||||||
addrcopy = 0
|
|
||||||
subscriptions = []
|
subscriptions = []
|
||||||
subcur = 0
|
subcur = 0
|
||||||
addrbook = []
|
addrbook = []
|
||||||
|
@ -71,7 +68,6 @@ class errLog:
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
printlog = printLog()
|
printlog = printLog()
|
||||||
errlog = errLog()
|
|
||||||
|
|
||||||
|
|
||||||
def cpair(a):
|
def cpair(a):
|
||||||
|
|
|
@ -418,12 +418,12 @@ All parameters are optional.
|
||||||
|
|
||||||
|
|
||||||
#TODO: nice function but no one is using this
|
#TODO: nice function but no one is using this
|
||||||
def getApiAddress(self):
|
# def getApiAddress(self):
|
||||||
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
|
# if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
|
||||||
return None
|
# return None
|
||||||
address = BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
# address = BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
||||||
port = BMConfigParser().getint('bitmessagesettings', 'apiport')
|
# port = BMConfigParser().getint('bitmessagesettings', 'apiport')
|
||||||
return {'address':address,'port':port}
|
# return {'address':address,'port':port}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -17,7 +17,7 @@ from bmconfigparser import BMConfigParser
|
||||||
import defaults
|
import defaults
|
||||||
from namecoin import namecoinConnection
|
from namecoin import namecoinConnection
|
||||||
from messageview import MessageView
|
from messageview import MessageView
|
||||||
from migrationwizard import Ui_MigrationWizard
|
# from migrationwizard import Ui_MigrationWizard
|
||||||
from foldertree import (
|
from foldertree import (
|
||||||
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
|
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
|
||||||
MessageList_AddressWidget, MessageList_SubjectWidget,
|
MessageList_AddressWidget, MessageList_SubjectWidget,
|
||||||
|
@ -280,10 +280,10 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow", "Copy address to clipboard"),
|
"MainWindow", "Copy address to clipboard"),
|
||||||
self.on_action_Clipboard)
|
self.on_action_Clipboard)
|
||||||
self.actionSpecialAddressBehavior = self.ui.addressContextMenuToolbar.addAction(
|
# self.actionSpecialAddressBehavior = self.ui.addressContextMenuToolbar.addAction(
|
||||||
_translate(
|
# _translate(
|
||||||
"MainWindow", "Special address behavior..."),
|
# "MainWindow", "Special address behavior..."),
|
||||||
self.on_action_SpecialAddressBehaviorDialog)
|
# self.on_action_SpecialAddressBehaviorDialog)
|
||||||
|
|
||||||
self.ui.treeWidgetChans.setContextMenuPolicy(
|
self.ui.treeWidgetChans.setContextMenuPolicy(
|
||||||
QtCore.Qt.CustomContextMenu)
|
QtCore.Qt.CustomContextMenu)
|
||||||
|
@ -851,12 +851,12 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.appIndicatorShowOrHideWindow()
|
self.appIndicatorShowOrHideWindow()
|
||||||
|
|
||||||
# unchecks the show item on the application indicator
|
# unchecks the show item on the application indicator
|
||||||
def appIndicatorHide(self):
|
# def appIndicatorHide(self):
|
||||||
if self.actionShow is None:
|
# if self.actionShow is None:
|
||||||
return
|
# return
|
||||||
if self.actionShow.isChecked():
|
# if self.actionShow.isChecked():
|
||||||
self.actionShow.setChecked(False)
|
# self.actionShow.setChecked(False)
|
||||||
self.appIndicatorShowOrHideWindow()
|
# self.appIndicatorShowOrHideWindow()
|
||||||
|
|
||||||
def appIndicatorSwitchQuietMode(self):
|
def appIndicatorSwitchQuietMode(self):
|
||||||
BMConfigParser().set(
|
BMConfigParser().set(
|
||||||
|
@ -1546,32 +1546,32 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
elif dialog.radioButtonConfigureNetwork.isChecked():
|
elif dialog.radioButtonConfigureNetwork.isChecked():
|
||||||
self.click_actionSettings()
|
self.click_actionSettings()
|
||||||
|
|
||||||
def showMigrationWizard(self, level):
|
# def showMigrationWizard(self, level):
|
||||||
self.migrationWizardInstance = Ui_MigrationWizard(["a"])
|
# self.migrationWizardInstance = Ui_MigrationWizard(["a"])
|
||||||
if self.migrationWizardInstance.exec_():
|
# if self.migrationWizardInstance.exec_():
|
||||||
pass
|
# pass
|
||||||
else:
|
# else:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def changeEvent(self, event):
|
# def changeEvent(self, event):
|
||||||
if event.type() == QtCore.QEvent.LanguageChange:
|
# if event.type() == QtCore.QEvent.LanguageChange:
|
||||||
self.ui.retranslateUi(self)
|
# self.ui.retranslateUi(self)
|
||||||
self.init_inbox_popup_menu(False)
|
# self.init_inbox_popup_menu(False)
|
||||||
self.init_identities_popup_menu(False)
|
# self.init_identities_popup_menu(False)
|
||||||
self.init_chan_popup_menu(False)
|
# self.init_chan_popup_menu(False)
|
||||||
self.init_addressbook_popup_menu(False)
|
# self.init_addressbook_popup_menu(False)
|
||||||
self.init_subscriptions_popup_menu(False)
|
# self.init_subscriptions_popup_menu(False)
|
||||||
self.init_sent_popup_menu(False)
|
# self.init_sent_popup_menu(False)
|
||||||
self.ui.blackwhitelist.init_blacklist_popup_menu(False)
|
# self.ui.blackwhitelist.init_blacklist_popup_menu(False)
|
||||||
if event.type() == QtCore.QEvent.WindowStateChange:
|
# if event.type() == QtCore.QEvent.WindowStateChange:
|
||||||
if self.windowState() & QtCore.Qt.WindowMinimized:
|
# if self.windowState() & QtCore.Qt.WindowMinimized:
|
||||||
if BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
|
# if BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
|
||||||
QtCore.QTimer.singleShot(0, self.appIndicatorHide)
|
# QtCore.QTimer.singleShot(0, self.appIndicatorHide)
|
||||||
elif event.oldState() & QtCore.Qt.WindowMinimized:
|
# elif event.oldState() & QtCore.Qt.WindowMinimized:
|
||||||
# The window state has just been changed to
|
# # The window state has just been changed to
|
||||||
# Normal/Maximised/FullScreen
|
# # Normal/Maximised/FullScreen
|
||||||
pass
|
# pass
|
||||||
# QtGui.QWidget.changeEvent(self, event)
|
# # QtGui.QWidget.changeEvent(self, event)
|
||||||
|
|
||||||
def __icon_activated(self, reason):
|
def __icon_activated(self, reason):
|
||||||
if reason == QtGui.QSystemTrayIcon.Trigger:
|
if reason == QtGui.QSystemTrayIcon.Trigger:
|
||||||
|
@ -2135,17 +2135,17 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate(
|
||||||
"MainWindow", "Broadcast queued."))
|
"MainWindow", "Broadcast queued."))
|
||||||
|
|
||||||
def click_pushButtonLoadFromAddressBook(self):
|
# def click_pushButtonLoadFromAddressBook(self):
|
||||||
self.ui.tabWidget.setCurrentIndex(5)
|
# self.ui.tabWidget.setCurrentIndex(5)
|
||||||
for i in range(4):
|
# for i in range(4):
|
||||||
time.sleep(0.1)
|
# time.sleep(0.1)
|
||||||
self.statusbar.clearMessage()
|
# self.statusbar.clearMessage()
|
||||||
time.sleep(0.1)
|
# time.sleep(0.1)
|
||||||
self.updateStatusBar(_translate(
|
# self.updateStatusBar(_translate(
|
||||||
"MainWindow",
|
# "MainWindow",
|
||||||
"Right click one or more entries in your address book and"
|
# "Right click one or more entries in your address book and"
|
||||||
" select \'Send message to this address\'."
|
# " select \'Send message to this address\'."
|
||||||
))
|
# ))
|
||||||
|
|
||||||
def click_pushButtonFetchNamecoinID(self):
|
def click_pushButtonFetchNamecoinID(self):
|
||||||
nc = namecoinConnection()
|
nc = namecoinConnection()
|
||||||
|
@ -2846,25 +2846,25 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
# window close event
|
# window close event
|
||||||
def closeEvent(self, event):
|
# def closeEvent(self, event):
|
||||||
self.appIndicatorHide()
|
# self.appIndicatorHide()
|
||||||
trayonclose = False
|
# trayonclose = False
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
trayonclose = BMConfigParser().getboolean(
|
# trayonclose = BMConfigParser().getboolean(
|
||||||
'bitmessagesettings', 'trayonclose')
|
# 'bitmessagesettings', 'trayonclose')
|
||||||
except Exception:
|
# except Exception:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
# always ignore, it shuts down by itself
|
# # always ignore, it shuts down by itself
|
||||||
if self.quitAccepted:
|
# if self.quitAccepted:
|
||||||
event.accept()
|
# event.accept()
|
||||||
return
|
# return
|
||||||
|
|
||||||
event.ignore()
|
# event.ignore()
|
||||||
if not trayonclose:
|
# if not trayonclose:
|
||||||
# quit the application
|
# # quit the application
|
||||||
self.quit()
|
# self.quit()
|
||||||
|
|
||||||
def on_action_InboxMessageForceHtml(self):
|
def on_action_InboxMessageForceHtml(self):
|
||||||
msgid = self.getCurrentMessageId()
|
msgid = self.getCurrentMessageId()
|
||||||
|
@ -3092,24 +3092,24 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
"Error: You cannot add the same address to your blacklist"
|
"Error: You cannot add the same address to your blacklist"
|
||||||
" twice. Try renaming the existing one if you want."))
|
" twice. Try renaming the existing one if you want."))
|
||||||
|
|
||||||
def deleteRowFromMessagelist(self, row = None, inventoryHash = None, ackData = None, messageLists = None):
|
# def deleteRowFromMessagelist(self, row = None, inventoryHash = None, ackData = None, messageLists = None):
|
||||||
if messageLists is None:
|
# if messageLists is None:
|
||||||
messageLists = (self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxSubscriptions)
|
# messageLists = (self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxSubscriptions)
|
||||||
elif type(messageLists) not in (list, tuple):
|
# elif type(messageLists) not in (list, tuple):
|
||||||
messageLists = (messageLists)
|
# messageLists = (messageLists)
|
||||||
for messageList in messageLists:
|
# for messageList in messageLists:
|
||||||
if row is not None:
|
# if row is not None:
|
||||||
inventoryHash = str(messageList.item(row, 3).data(
|
# inventoryHash = str(messageList.item(row, 3).data(
|
||||||
QtCore.Qt.UserRole).toPyObject())
|
# QtCore.Qt.UserRole).toPyObject())
|
||||||
messageList.removeRow(row)
|
# messageList.removeRow(row)
|
||||||
elif inventoryHash is not None:
|
# elif inventoryHash is not None:
|
||||||
for i in range(messageList.rowCount() - 1, -1, -1):
|
# for i in range(messageList.rowCount() - 1, -1, -1):
|
||||||
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash:
|
# if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash:
|
||||||
messageList.removeRow(i)
|
# messageList.removeRow(i)
|
||||||
elif ackData is not None:
|
# elif ackData is not None:
|
||||||
for i in range(messageList.rowCount() - 1, -1, -1):
|
# for i in range(messageList.rowCount() - 1, -1, -1):
|
||||||
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData:
|
# if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData:
|
||||||
messageList.removeRow(i)
|
# messageList.removeRow(i)
|
||||||
|
|
||||||
# Send item on the Inbox tab to trash
|
# Send item on the Inbox tab to trash
|
||||||
def on_action_InboxTrash(self):
|
def on_action_InboxTrash(self):
|
||||||
|
@ -3457,16 +3457,16 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getAccountTreeWidget(self, account):
|
# def getAccountTreeWidget(self, account):
|
||||||
try:
|
# try:
|
||||||
if account.type == AccountMixin.CHAN:
|
# if account.type == AccountMixin.CHAN:
|
||||||
return self.ui.treeWidgetChans
|
# return self.ui.treeWidgetChans
|
||||||
elif account.type == AccountMixin.SUBSCRIPTION:
|
# elif account.type == AccountMixin.SUBSCRIPTION:
|
||||||
return self.ui.treeWidgetSubscriptions
|
# return self.ui.treeWidgetSubscriptions
|
||||||
else:
|
# else:
|
||||||
return self.ui.treeWidgetYourIdentities
|
# return self.ui.treeWidgetYourIdentities
|
||||||
except:
|
# except:
|
||||||
return self.ui.treeWidgetYourIdentities
|
# return self.ui.treeWidgetYourIdentities
|
||||||
|
|
||||||
def getCurrentMessagelist(self):
|
def getCurrentMessagelist(self):
|
||||||
currentIndex = self.ui.tabWidget.currentIndex();
|
currentIndex = self.ui.tabWidget.currentIndex();
|
||||||
|
|
|
@ -129,8 +129,8 @@ class AddressPassPhraseValidatorMixin():
|
||||||
else:
|
else:
|
||||||
return (QtGui.QValidator.Intermediate, pos)
|
return (QtGui.QValidator.Intermediate, pos)
|
||||||
|
|
||||||
def checkData(self):
|
# def checkData(self):
|
||||||
return self.validate("", 0)
|
# return self.validate("", 0)
|
||||||
|
|
||||||
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
|
||||||
def __init__(self, parent=None, passPhraseObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True):
|
def __init__(self, parent=None, passPhraseObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True):
|
||||||
|
|
|
@ -1669,7 +1669,7 @@ qt_resource_struct = "\
|
||||||
def qInitResources():
|
def qInitResources():
|
||||||
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
|
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
|
||||||
|
|
||||||
def qCleanupResources():
|
# def qCleanupResources():
|
||||||
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
|
# QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
|
||||||
|
|
||||||
qInitResources()
|
qInitResources()
|
||||||
|
|
|
@ -763,7 +763,7 @@ class Ui_MainWindow(object):
|
||||||
self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None))
|
self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None))
|
||||||
self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None))
|
self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None))
|
||||||
|
|
||||||
import bitmessage_icons_rc
|
# import bitmessage_icons_rc
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -108,9 +108,9 @@ class Blacklist(QtGui.QWidget, RetranslateMixin):
|
||||||
# Popup menu for the Blacklist page
|
# Popup menu for the Blacklist page
|
||||||
self.blacklistContextMenuToolbar = QtGui.QToolBar()
|
self.blacklistContextMenuToolbar = QtGui.QToolBar()
|
||||||
# Actions
|
# Actions
|
||||||
self.actionBlacklistNew = self.blacklistContextMenuToolbar.addAction(
|
# self.actionBlacklistNew = self.blacklistContextMenuToolbar.addAction(
|
||||||
_translate(
|
# _translate(
|
||||||
"MainWindow", "Add new entry"), self.on_action_BlacklistNew)
|
# "MainWindow", "Add new entry"), self.on_action_BlacklistNew)
|
||||||
self.actionBlacklistDelete = self.blacklistContextMenuToolbar.addAction(
|
self.actionBlacklistDelete = self.blacklistContextMenuToolbar.addAction(
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow", "Delete"), self.on_action_BlacklistDelete)
|
"MainWindow", "Delete"), self.on_action_BlacklistDelete)
|
||||||
|
@ -174,8 +174,8 @@ class Blacklist(QtGui.QWidget, RetranslateMixin):
|
||||||
self.tableWidgetBlacklist.setSortingEnabled(True)
|
self.tableWidgetBlacklist.setSortingEnabled(True)
|
||||||
|
|
||||||
# Group of functions for the Blacklist dialog box
|
# Group of functions for the Blacklist dialog box
|
||||||
def on_action_BlacklistNew(self):
|
# def on_action_BlacklistNew(self):
|
||||||
self.click_pushButtonAddBlacklist()
|
# self.click_pushButtonAddBlacklist()
|
||||||
|
|
||||||
def on_action_BlacklistDelete(self):
|
def on_action_BlacklistDelete(self):
|
||||||
currentRow = self.tableWidgetBlacklist.currentRow()
|
currentRow = self.tableWidgetBlacklist.currentRow()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from string import find, rfind, rstrip, lstrip
|
from string import find, rstrip, lstrip# , rfind
|
||||||
|
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
@ -501,46 +501,46 @@ class AddressBookCompleter(QtGui.QCompleter):
|
||||||
if oldPos != self.cursorPos:
|
if oldPos != self.cursorPos:
|
||||||
self.cursorPos = -1
|
self.cursorPos = -1
|
||||||
|
|
||||||
def splitPath(self, path):
|
# def splitPath(self, path):
|
||||||
stringList = []
|
# stringList = []
|
||||||
text = unicode(path.toUtf8(), encoding="UTF-8")
|
# text = unicode(path.toUtf8(), encoding="UTF-8")
|
||||||
splitIndex = rfind(text[0:self.widget().cursorPosition()], ";") + 1
|
# splitIndex = rfind(text[0:self.widget().cursorPosition()], ";") + 1
|
||||||
str = text[splitIndex:self.widget().cursorPosition()]
|
# str = text[splitIndex:self.widget().cursorPosition()]
|
||||||
str = rstrip(lstrip(str))
|
# str = rstrip(lstrip(str))
|
||||||
stringList.append(str)
|
# stringList.append(str)
|
||||||
return stringList
|
# return stringList
|
||||||
|
|
||||||
def pathFromIndex(self, index):
|
# def pathFromIndex(self, index):
|
||||||
autoString = unicode(index.data(QtCore.Qt.EditRole).toString().toUtf8(), encoding="UTF-8")
|
# autoString = unicode(index.data(QtCore.Qt.EditRole).toString().toUtf8(), encoding="UTF-8")
|
||||||
text = unicode(self.widget().text().toUtf8(), encoding="UTF-8")
|
# text = unicode(self.widget().text().toUtf8(), encoding="UTF-8")
|
||||||
|
|
||||||
# If cursor position was saved, restore it, else save it
|
# # If cursor position was saved, restore it, else save it
|
||||||
if self.cursorPos != -1:
|
# if self.cursorPos != -1:
|
||||||
self.widget().setCursorPosition(self.cursorPos)
|
# self.widget().setCursorPosition(self.cursorPos)
|
||||||
else:
|
# else:
|
||||||
self.cursorPos = self.widget().cursorPosition()
|
# self.cursorPos = self.widget().cursorPosition()
|
||||||
|
|
||||||
# Get current prosition
|
# # Get current prosition
|
||||||
curIndex = self.widget().cursorPosition()
|
# curIndex = self.widget().cursorPosition()
|
||||||
|
|
||||||
# prev_delimiter_index should actually point at final white space AFTER the delimiter
|
# # prev_delimiter_index should actually point at final white space AFTER the delimiter
|
||||||
# Get index of last delimiter before current position
|
# # Get index of last delimiter before current position
|
||||||
prevDelimiterIndex = rfind(text[0:curIndex], ";")
|
# prevDelimiterIndex = rfind(text[0:curIndex], ";")
|
||||||
while text[prevDelimiterIndex + 1] == " ":
|
# while text[prevDelimiterIndex + 1] == " ":
|
||||||
prevDelimiterIndex += 1
|
# prevDelimiterIndex += 1
|
||||||
|
|
||||||
# Get index of first delimiter after current position (or EOL if no delimiter after cursor)
|
# # Get index of first delimiter after current position (or EOL if no delimiter after cursor)
|
||||||
nextDelimiterIndex = find(text, ";", curIndex)
|
# nextDelimiterIndex = find(text, ";", curIndex)
|
||||||
if nextDelimiterIndex == -1:
|
# if nextDelimiterIndex == -1:
|
||||||
nextDelimiterIndex = len(text)
|
# nextDelimiterIndex = len(text)
|
||||||
|
|
||||||
# Get part of string that occurs before cursor
|
# # Get part of string that occurs before cursor
|
||||||
part1 = text[0:prevDelimiterIndex + 1]
|
# part1 = text[0:prevDelimiterIndex + 1]
|
||||||
|
|
||||||
# Get string value from before auto finished string is selected
|
# # Get string value from before auto finished string is selected
|
||||||
pre = text[prevDelimiterIndex + 1:curIndex - 1];
|
# pre = text[prevDelimiterIndex + 1:curIndex - 1];
|
||||||
|
|
||||||
# Get part of string that occurs AFTER cursor
|
# # Get part of string that occurs AFTER cursor
|
||||||
part2 = text[nextDelimiterIndex:]
|
# part2 = text[nextDelimiterIndex:]
|
||||||
|
|
||||||
return part1 + autoString + part2;
|
# return part1 + autoString + part2;
|
||||||
|
|
|
@ -12,7 +12,7 @@ class LanguageBox(QtGui.QComboBox):
|
||||||
self.populate()
|
self.populate()
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
self.languages = []
|
# self.languages = []
|
||||||
self.clear()
|
self.clear()
|
||||||
localesPath = os.path.join (paths.codePath(), 'translations')
|
localesPath = os.path.join (paths.codePath(), 'translations')
|
||||||
configuredLocale = "system"
|
configuredLocale = "system"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
import multiprocessing
|
# import multiprocessing
|
||||||
import Queue
|
import Queue
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from safehtmlparser import *
|
from safehtmlparser import *
|
||||||
|
@ -75,9 +75,9 @@ class MessageView(QtGui.QTextBrowser):
|
||||||
if reply == QtGui.QMessageBox.Yes:
|
if reply == QtGui.QMessageBox.Yes:
|
||||||
QtGui.QDesktopServices.openUrl(link)
|
QtGui.QDesktopServices.openUrl(link)
|
||||||
|
|
||||||
def loadResource (self, restype, name):
|
# def loadResource (self, restype, name):
|
||||||
if restype == QtGui.QTextDocument.ImageResource and name.scheme() == "bmmsg":
|
# if restype == QtGui.QTextDocument.ImageResource and name.scheme() == "bmmsg":
|
||||||
pass
|
# pass
|
||||||
# QImage correctImage;
|
# QImage correctImage;
|
||||||
# lookup the correct QImage from a cache
|
# lookup the correct QImage from a cache
|
||||||
# return QVariant::fromValue(correctImage);
|
# return QVariant::fromValue(correctImage);
|
||||||
|
@ -85,8 +85,8 @@ class MessageView(QtGui.QTextBrowser):
|
||||||
# elif restype == QtGui.QTextDocument.ImageResource:
|
# elif restype == QtGui.QTextDocument.ImageResource:
|
||||||
# elif restype == QtGui.QTextDocument.StyleSheetResource:
|
# elif restype == QtGui.QTextDocument.StyleSheetResource:
|
||||||
# elif restype == QtGui.QTextDocument.UserResource:
|
# elif restype == QtGui.QTextDocument.UserResource:
|
||||||
else:
|
# else:
|
||||||
pass
|
# pass
|
||||||
# by default, this will interpret it as a local file
|
# by default, this will interpret it as a local file
|
||||||
# QtGui.QTextBrowser.loadResource(restype, name)
|
# QtGui.QTextBrowser.loadResource(restype, name)
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ class MessageView(QtGui.QTextBrowser):
|
||||||
self.html = SafeHTMLParser()
|
self.html = SafeHTMLParser()
|
||||||
self.html.reset()
|
self.html.reset()
|
||||||
self.html.reset_safe()
|
self.html.reset_safe()
|
||||||
self.html.allow_picture = True
|
# self.html.allow_picture = True
|
||||||
self.html.feed(data)
|
self.html.feed(data)
|
||||||
self.html.close()
|
self.html.close()
|
||||||
self.showPlain()
|
self.showPlain()
|
||||||
|
|
14
src/bitmessageqt/migrationwizard.py
Normal file → Executable file
14
src/bitmessageqt/migrationwizard.py
Normal file → Executable file
|
@ -14,8 +14,8 @@ class MigrationWizardIntroPage(QtGui.QWizardPage):
|
||||||
layout.addWidget(label)
|
layout.addWidget(label)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 1
|
# return 1
|
||||||
|
|
||||||
|
|
||||||
class MigrationWizardAddressesPage(QtGui.QWizardPage):
|
class MigrationWizardAddressesPage(QtGui.QWizardPage):
|
||||||
|
@ -30,8 +30,8 @@ class MigrationWizardAddressesPage(QtGui.QWizardPage):
|
||||||
layout.addWidget(label)
|
layout.addWidget(label)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 10
|
# return 10
|
||||||
|
|
||||||
|
|
||||||
class MigrationWizardGPUPage(QtGui.QWizardPage):
|
class MigrationWizardGPUPage(QtGui.QWizardPage):
|
||||||
|
@ -46,8 +46,8 @@ class MigrationWizardGPUPage(QtGui.QWizardPage):
|
||||||
layout.addWidget(label)
|
layout.addWidget(label)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 10
|
# return 10
|
||||||
|
|
||||||
|
|
||||||
class MigrationWizardConclusionPage(QtGui.QWizardPage):
|
class MigrationWizardConclusionPage(QtGui.QWizardPage):
|
||||||
|
@ -67,7 +67,7 @@ class Ui_MigrationWizard(QtGui.QWizard):
|
||||||
def __init__(self, addresses):
|
def __init__(self, addresses):
|
||||||
super(QtGui.QWizard, self).__init__()
|
super(QtGui.QWizard, self).__init__()
|
||||||
|
|
||||||
self.pages = {}
|
# self.pages = {}
|
||||||
|
|
||||||
page = MigrationWizardIntroPage()
|
page = MigrationWizardIntroPage()
|
||||||
self.setPage(0, page)
|
self.setPage(0, page)
|
||||||
|
|
100
src/bitmessageqt/newaddresswizard.py
Normal file → Executable file
100
src/bitmessageqt/newaddresswizard.py
Normal file → Executable file
|
@ -23,11 +23,11 @@ class NewAddressWizardIntroPage(QtGui.QWizardPage):
|
||||||
layout.addWidget(self.onlyBM)
|
layout.addWidget(self.onlyBM)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
if self.emailAsWell.isChecked():
|
# if self.emailAsWell.isChecked():
|
||||||
return 4
|
# return 4
|
||||||
else:
|
# else:
|
||||||
return 1
|
# return 1
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardRngPassphrasePage(QtGui.QWizardPage):
|
class NewAddressWizardRngPassphrasePage(QtGui.QWizardPage):
|
||||||
|
@ -58,11 +58,11 @@ class NewAddressWizardRngPassphrasePage(QtGui.QWizardPage):
|
||||||
layout.addWidget(self.deterministicAddress)
|
layout.addWidget(self.deterministicAddress)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
if self.randomAddress.isChecked():
|
# if self.randomAddress.isChecked():
|
||||||
return 2
|
# return 2
|
||||||
else:
|
# else:
|
||||||
return 3
|
# return 3
|
||||||
|
|
||||||
class NewAddressWizardRandomPage(QtGui.QWizardPage):
|
class NewAddressWizardRandomPage(QtGui.QWizardPage):
|
||||||
def __init__(self, addresses):
|
def __init__(self, addresses):
|
||||||
|
@ -111,8 +111,8 @@ class NewAddressWizardRandomPage(QtGui.QWizardPage):
|
||||||
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
|
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
|
||||||
# self.emailAsWell.setChecked(True)
|
# self.emailAsWell.setChecked(True)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 6
|
# return 6
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardPassphrasePage(QtGui.QWizardPage):
|
class NewAddressWizardPassphrasePage(QtGui.QWizardPage):
|
||||||
|
@ -154,8 +154,8 @@ class NewAddressWizardPassphrasePage(QtGui.QWizardPage):
|
||||||
layout.addWidget(label4, 7, 2, 1, 2)
|
layout.addWidget(label4, 7, 2, 1, 2)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 6
|
# return 6
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardEmailProviderPage(QtGui.QWizardPage):
|
class NewAddressWizardEmailProviderPage(QtGui.QWizardPage):
|
||||||
|
@ -176,8 +176,8 @@ class NewAddressWizardEmailProviderPage(QtGui.QWizardPage):
|
||||||
# layout.addWidget(self.mailchuck)
|
# layout.addWidget(self.mailchuck)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 5
|
# return 5
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardEmailAddressPage(QtGui.QWizardPage):
|
class NewAddressWizardEmailAddressPage(QtGui.QWizardPage):
|
||||||
|
@ -202,8 +202,8 @@ class NewAddressWizardEmailAddressPage(QtGui.QWizardPage):
|
||||||
layout.addWidget(self.randomEmail)
|
layout.addWidget(self.randomEmail)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 6
|
# return 6
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardWaitPage(QtGui.QWizardPage):
|
class NewAddressWizardWaitPage(QtGui.QWizardPage):
|
||||||
|
@ -240,32 +240,32 @@ class NewAddressWizardWaitPage(QtGui.QWizardPage):
|
||||||
if i == 50:
|
if i == 50:
|
||||||
self.emit(QtCore.SIGNAL('completeChanged()'))
|
self.emit(QtCore.SIGNAL('completeChanged()'))
|
||||||
|
|
||||||
def isComplete(self):
|
# def isComplete(self):
|
||||||
# print "val = " + str(self.progressBar.value())
|
# print "val = " + str(self.progressBar.value())
|
||||||
if self.progressBar.value() >= 50:
|
# if self.progressBar.value() >= 50:
|
||||||
return True
|
# return True
|
||||||
else:
|
# else:
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def initializePage(self):
|
# def initializePage(self):
|
||||||
if self.field("emailAsWell").toBool():
|
# if self.field("emailAsWell").toBool():
|
||||||
val = "yes/"
|
# val = "yes/"
|
||||||
else:
|
# else:
|
||||||
val = "no/"
|
# val = "no/"
|
||||||
if self.field("onlyBM").toBool():
|
# if self.field("onlyBM").toBool():
|
||||||
val += "yes"
|
# val += "yes"
|
||||||
else:
|
# else:
|
||||||
val += "no"
|
# val += "no"
|
||||||
|
|
||||||
self.label.setText("Wait! " + val)
|
# self.label.setText("Wait! " + val)
|
||||||
# self.wizard().button(QtGui.QWizard.NextButton).setEnabled(False)
|
# self.wizard().button(QtGui.QWizard.NextButton).setEnabled(False)
|
||||||
self.progressBar.setValue(0)
|
# self.progressBar.setValue(0)
|
||||||
self.thread = NewAddressThread()
|
# self.thread = NewAddressThread()
|
||||||
self.connect(self.thread, self.thread.signal, self.update)
|
# self.connect(self.thread, self.thread.signal, self.update)
|
||||||
self.thread.start()
|
# self.thread.start()
|
||||||
|
|
||||||
def nextId(self):
|
# def nextId(self):
|
||||||
return 10
|
# return 10
|
||||||
|
|
||||||
|
|
||||||
class NewAddressWizardConclusionPage(QtGui.QWizardPage):
|
class NewAddressWizardConclusionPage(QtGui.QWizardPage):
|
||||||
|
@ -284,7 +284,7 @@ class Ui_NewAddressWizard(QtGui.QWizard):
|
||||||
def __init__(self, addresses):
|
def __init__(self, addresses):
|
||||||
super(QtGui.QWizard, self).__init__()
|
super(QtGui.QWizard, self).__init__()
|
||||||
|
|
||||||
self.pages = {}
|
# self.pages = {}
|
||||||
|
|
||||||
page = NewAddressWizardIntroPage()
|
page = NewAddressWizardIntroPage()
|
||||||
self.setPage(0, page)
|
self.setPage(0, page)
|
||||||
|
@ -316,20 +316,20 @@ class NewAddressThread(QtCore.QThread):
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def createDeterministic(self):
|
# def createDeterministic(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def createPassphrase(self):
|
# def createPassphrase(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def broadcastAddress(self):
|
# def broadcastAddress(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def registerMailchuck(self):
|
# def registerMailchuck(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def waitRegistration(self):
|
# def waitRegistration(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import time
|
import time
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
from HTMLParser import HTMLParser
|
from HTMLParser import HTMLParser
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
from urllib import quote, quote_plus
|
# from urllib import quote_plus# , quote
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
class SafeHTMLParser(HTMLParser):
|
class SafeHTMLParser(HTMLParser):
|
||||||
# from html5lib.sanitiser
|
# from html5lib.sanitiser
|
||||||
acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',
|
# acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',
|
||||||
'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',
|
# 'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',
|
||||||
'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
|
# 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
|
||||||
'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
|
# 'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
|
||||||
'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
|
# 'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
|
||||||
'figcaption', 'figure', 'footer', 'font', 'header', 'h1',
|
# 'figcaption', 'figure', 'footer', 'font', 'header', 'h1',
|
||||||
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins',
|
# 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins',
|
||||||
'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',
|
# 'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',
|
||||||
'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
|
# 'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
|
||||||
'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
|
# 'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
|
||||||
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
|
# 'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
|
||||||
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
|
# 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
|
||||||
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
|
# 'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
|
||||||
replaces_pre = [["&", "&"], ["\"", """], ["<", "<"], [">", ">"]]
|
replaces_pre = [["&", "&"], ["\"", """], ["<", "<"], [">", ">"]]
|
||||||
replaces_post = [["\n", "<br/>"], ["\t", " "], [" ", " "], [" ", " "], ["<br/> ", "<br/> "]]
|
replaces_post = [["\n", "<br/>"], ["\t", " "], [" ", " "], [" ", " "], ["<br/> ", "<br/> "]]
|
||||||
src_schemes = [ "data" ]
|
# src_schemes = [ "data" ]
|
||||||
#uriregex1 = re.compile(r'(?i)\b((?:(https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
|
#uriregex1 = re.compile(r'(?i)\b((?:(https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
|
||||||
uriregex1 = re.compile(r'((https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])(?:[a-zA-Z]|[0-9]|[$-_@.&+#]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)')
|
uriregex1 = re.compile(r'((https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])(?:[a-zA-Z]|[0-9]|[$-_@.&+#]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)')
|
||||||
uriregex2 = re.compile(r'<a href="([^"]+)&')
|
uriregex2 = re.compile(r'<a href="([^"]+)&')
|
||||||
|
@ -46,56 +46,56 @@ class SafeHTMLParser(HTMLParser):
|
||||||
self.reset_safe()
|
self.reset_safe()
|
||||||
|
|
||||||
def reset_safe(self):
|
def reset_safe(self):
|
||||||
self.elements = set()
|
# self.elements = set()
|
||||||
self.raw = u""
|
self.raw = u""
|
||||||
self.sanitised = u""
|
self.sanitised = u""
|
||||||
self.has_html = False
|
self.has_html = False
|
||||||
self.allow_picture = False
|
# self.allow_picture = False
|
||||||
self.allow_external_src = False
|
# self.allow_external_src = False
|
||||||
|
|
||||||
def add_if_acceptable(self, tag, attrs = None):
|
# def add_if_acceptable(self, tag, attrs = None):
|
||||||
if tag not in SafeHTMLParser.acceptable_elements:
|
# if tag not in SafeHTMLParser.acceptable_elements:
|
||||||
return
|
# return
|
||||||
self.sanitised += "<"
|
# self.sanitised += "<"
|
||||||
if inspect.stack()[1][3] == "handle_endtag":
|
# if inspect.stack()[1][3] == "handle_endtag":
|
||||||
self.sanitised += "/"
|
# self.sanitised += "/"
|
||||||
self.sanitised += tag
|
# self.sanitised += tag
|
||||||
if attrs is not None:
|
# if attrs is not None:
|
||||||
for attr, val in attrs:
|
# for attr, val in attrs:
|
||||||
if tag == "img" and attr == "src" and not self.allow_picture:
|
# if tag == "img" and attr == "src" and not self.allow_picture:
|
||||||
val = ""
|
# val = ""
|
||||||
elif attr == "src" and not self.allow_external_src:
|
# elif attr == "src" and not self.allow_external_src:
|
||||||
url = urlparse(val)
|
# url = urlparse(val)
|
||||||
if url.scheme not in SafeHTMLParser.src_schemes:
|
# if url.scheme not in SafeHTMLParser.src_schemes:
|
||||||
val = ""
|
# val = ""
|
||||||
self.sanitised += " " + quote_plus(attr)
|
# self.sanitised += " " + quote_plus(attr)
|
||||||
if not (val is None):
|
# if not (val is None):
|
||||||
self.sanitised += "=\"" + val + "\""
|
# self.sanitised += "=\"" + val + "\""
|
||||||
if inspect.stack()[1][3] == "handle_startendtag":
|
# if inspect.stack()[1][3] == "handle_startendtag":
|
||||||
self.sanitised += "/"
|
# self.sanitised += "/"
|
||||||
self.sanitised += ">"
|
# self.sanitised += ">"
|
||||||
|
|
||||||
def handle_starttag(self, tag, attrs):
|
# def handle_starttag(self, tag, attrs):
|
||||||
if tag in SafeHTMLParser.acceptable_elements:
|
# if tag in SafeHTMLParser.acceptable_elements:
|
||||||
self.has_html = True
|
# self.has_html = True
|
||||||
self.add_if_acceptable(tag, attrs)
|
# self.add_if_acceptable(tag, attrs)
|
||||||
|
|
||||||
def handle_endtag(self, tag):
|
# def handle_endtag(self, tag):
|
||||||
self.add_if_acceptable(tag)
|
# self.add_if_acceptable(tag)
|
||||||
|
|
||||||
def handle_startendtag(self, tag, attrs):
|
# def handle_startendtag(self, tag, attrs):
|
||||||
if tag in SafeHTMLParser.acceptable_elements:
|
# if tag in SafeHTMLParser.acceptable_elements:
|
||||||
self.has_html = True
|
# self.has_html = True
|
||||||
self.add_if_acceptable(tag, attrs)
|
# self.add_if_acceptable(tag, attrs)
|
||||||
|
|
||||||
def handle_data(self, data):
|
# def handle_data(self, data):
|
||||||
self.sanitised += data
|
# self.sanitised += data
|
||||||
|
|
||||||
def handle_charref(self, name):
|
# def handle_charref(self, name):
|
||||||
self.sanitised += "&#" + name + ";"
|
# self.sanitised += "&#" + name + ";"
|
||||||
|
|
||||||
def handle_entityref(self, name):
|
# def handle_entityref(self, name):
|
||||||
self.sanitised += "&" + name + ";"
|
# self.sanitised += "&" + name + ";"
|
||||||
|
|
||||||
def feed(self, data):
|
def feed(self, data):
|
||||||
try:
|
try:
|
||||||
|
@ -112,11 +112,11 @@ class SafeHTMLParser(HTMLParser):
|
||||||
tmp = SafeHTMLParser.replace_post(tmp)
|
tmp = SafeHTMLParser.replace_post(tmp)
|
||||||
self.raw += tmp
|
self.raw += tmp
|
||||||
|
|
||||||
def is_html(self, text = None, allow_picture = False):
|
# def is_html(self, text = None, allow_picture = False):
|
||||||
if text:
|
# if text:
|
||||||
self.reset()
|
# self.reset()
|
||||||
self.reset_safe()
|
# self.reset_safe()
|
||||||
self.allow_picture = allow_picture
|
# self.allow_picture = allow_picture
|
||||||
self.feed(text)
|
# self.feed(text)
|
||||||
self.close()
|
# self.close()
|
||||||
return self.has_html
|
# return self.has_html
|
||||||
|
|
|
@ -513,4 +513,4 @@ class Ui_settingsDialog(object):
|
||||||
self.label_23.setText(_translate("settingsDialog", "months.", None))
|
self.label_23.setText(_translate("settingsDialog", "months.", None))
|
||||||
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendsExpire), _translate("settingsDialog", "Resends Expire", None))
|
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendsExpire), _translate("settingsDialog", "Resends Expire", None))
|
||||||
|
|
||||||
import bitmessage_icons_rc
|
# import bitmessage_icons_rc
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# sound type constants
|
# sound type constants
|
||||||
SOUND_NONE = 0
|
# SOUND_NONE = 0
|
||||||
SOUND_KNOWN = 1
|
SOUND_KNOWN = 1
|
||||||
SOUND_UNKNOWN = 2
|
SOUND_UNKNOWN = 2
|
||||||
SOUND_CONNECTED = 3
|
SOUND_CONNECTED = 3
|
||||||
|
|
|
@ -119,11 +119,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def validate_bitmessagesettings_maxoutboundconnections(self, value):
|
# def validate_bitmessagesettings_maxoutboundconnections(self, value):
|
||||||
try:
|
# try:
|
||||||
value = int(value)
|
# value = int(value)
|
||||||
except ValueError:
|
# except ValueError:
|
||||||
return False
|
# return False
|
||||||
if value < 0 or value > 8:
|
# if value < 0 or value > 8:
|
||||||
return False
|
# return False
|
||||||
return True
|
# return True
|
||||||
|
|
|
@ -47,8 +47,8 @@ class objectHashHolder(threading.Thread):
|
||||||
def holdPeer(self,peerDetails):
|
def holdPeer(self,peerDetails):
|
||||||
self.collectionOfPeerLists[random.randrange(0, objectHashHolder.size)].append(peerDetails)
|
self.collectionOfPeerLists[random.randrange(0, objectHashHolder.size)].append(peerDetails)
|
||||||
|
|
||||||
def hashCount(self):
|
# def hashCount(self):
|
||||||
return sum([len(x) for x in self.collectionOfHashLists if type(x) is list])
|
# return sum([len(x) for x in self.collectionOfHashLists if type(x) is list])
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.shutdown = True
|
self.shutdown = True
|
||||||
|
|
|
@ -15,7 +15,7 @@ import highlevelcrypto
|
||||||
from addresses import *
|
from addresses import *
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
import helper_generic
|
import helper_generic
|
||||||
from helper_generic import addDataPadding
|
# from helper_generic import addDataPadding
|
||||||
import helper_bitcoin
|
import helper_bitcoin
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_msgcoding
|
import helper_msgcoding
|
||||||
|
@ -209,7 +209,7 @@ class objectProcessor(threading.Thread):
|
||||||
if len(data) < 146: # sanity check. This is the minimum possible length.
|
if len(data) < 146: # sanity check. This is the minimum possible length.
|
||||||
logger.debug('(within processpubkey) payloadLength less than 146. Sanity check failed.')
|
logger.debug('(within processpubkey) payloadLength less than 146. Sanity check failed.')
|
||||||
return
|
return
|
||||||
bitfieldBehaviors = data[readPosition:readPosition + 4]
|
# bitfieldBehaviors = data[readPosition:readPosition + 4]
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
publicSigningKey = data[readPosition:readPosition + 64]
|
publicSigningKey = data[readPosition:readPosition + 64]
|
||||||
# Is it possible for a public key to be invalid such that trying to
|
# Is it possible for a public key to be invalid such that trying to
|
||||||
|
@ -258,16 +258,16 @@ class objectProcessor(threading.Thread):
|
||||||
if len(data) < 170: # sanity check.
|
if len(data) < 170: # sanity check.
|
||||||
logger.warning('(within processpubkey) payloadLength less than 170. Sanity check failed.')
|
logger.warning('(within processpubkey) payloadLength less than 170. Sanity check failed.')
|
||||||
return
|
return
|
||||||
bitfieldBehaviors = data[readPosition:readPosition + 4]
|
# bitfieldBehaviors = data[readPosition:readPosition + 4]
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
publicSigningKey = '\x04' + data[readPosition:readPosition + 64]
|
publicSigningKey = '\x04' + data[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
publicEncryptionKey = '\x04' + data[readPosition:readPosition + 64]
|
publicEncryptionKey = '\x04' + data[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
specifiedNonceTrialsPerByte, specifiedNonceTrialsPerByteLength = decodeVarint(
|
_, specifiedNonceTrialsPerByteLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 10])
|
data[readPosition:readPosition + 10])
|
||||||
readPosition += specifiedNonceTrialsPerByteLength
|
readPosition += specifiedNonceTrialsPerByteLength
|
||||||
specifiedPayloadLengthExtraBytes, specifiedPayloadLengthExtraBytesLength = decodeVarint(
|
_, specifiedPayloadLengthExtraBytesLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 10])
|
data[readPosition:readPosition + 10])
|
||||||
readPosition += specifiedPayloadLengthExtraBytesLength
|
readPosition += specifiedPayloadLengthExtraBytesLength
|
||||||
endOfSignedDataPosition = readPosition
|
endOfSignedDataPosition = readPosition
|
||||||
|
@ -874,18 +874,18 @@ class objectProcessor(threading.Thread):
|
||||||
else:
|
else:
|
||||||
return '[' + mailingListName + '] ' + subject
|
return '[' + mailingListName + '] ' + subject
|
||||||
|
|
||||||
def decodeType2Message(self, message):
|
# def decodeType2Message(self, message):
|
||||||
bodyPositionIndex = string.find(message, '\nBody:')
|
# bodyPositionIndex = string.find(message, '\nBody:')
|
||||||
if bodyPositionIndex > 1:
|
# if bodyPositionIndex > 1:
|
||||||
subject = message[8:bodyPositionIndex]
|
# subject = message[8:bodyPositionIndex]
|
||||||
# Only save and show the first 500 characters of the subject.
|
# # Only save and show the first 500 characters of the subject.
|
||||||
# Any more is probably an attack.
|
# # Any more is probably an attack.
|
||||||
subject = subject[:500]
|
# subject = subject[:500]
|
||||||
body = message[bodyPositionIndex + 6:]
|
# body = message[bodyPositionIndex + 6:]
|
||||||
else:
|
# else:
|
||||||
subject = ''
|
# subject = ''
|
||||||
body = message
|
# body = message
|
||||||
# Throw away any extra lines (headers) after the subject.
|
# # Throw away any extra lines (headers) after the subject.
|
||||||
if subject:
|
# if subject:
|
||||||
subject = subject.splitlines()[0]
|
# subject = subject.splitlines()[0]
|
||||||
return subject, body
|
# return subject, body
|
||||||
|
|
|
@ -26,7 +26,7 @@ from binascii import hexlify
|
||||||
from addresses import *
|
from addresses import *
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from class_objectHashHolder import objectHashHolder
|
from class_objectHashHolder import objectHashHolder
|
||||||
from helper_generic import addDataPadding, isHostInPrivateIPRange
|
from helper_generic import isHostInPrivateIPRange# , addDataPadding
|
||||||
from helper_sql import sqlQuery
|
from helper_sql import sqlQuery
|
||||||
import knownnodes
|
import knownnodes
|
||||||
from debug import logger
|
from debug import logger
|
||||||
|
@ -278,8 +278,8 @@ class receiveDataThread(threading.Thread):
|
||||||
context = ssl.SSLContext(protocol.sslProtocolVersion)
|
context = ssl.SSLContext(protocol.sslProtocolVersion)
|
||||||
context.set_ciphers(protocol.sslProtocolCiphers)
|
context.set_ciphers(protocol.sslProtocolCiphers)
|
||||||
context.set_ecdh_curve("secp256k1")
|
context.set_ecdh_curve("secp256k1")
|
||||||
context.check_hostname = False
|
# context.check_hostname = False
|
||||||
context.verify_mode = ssl.CERT_NONE
|
# context.verify_mode = ssl.CERT_NONE
|
||||||
# also exclude TLSv1 and TLSv1.1 in the future
|
# also exclude TLSv1 and TLSv1.1 in the future
|
||||||
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
||||||
self.sslSock = context.wrap_socket(self.sock, server_side = not self.initiatedConnection, do_handshake_on_connect=False)
|
self.sslSock = context.wrap_socket(self.sock, server_side = not self.initiatedConnection, do_handshake_on_connect=False)
|
||||||
|
@ -791,7 +791,7 @@ class receiveDataThread(threading.Thread):
|
||||||
timestamp, = unpack('>Q', data[12:20])
|
timestamp, = unpack('>Q', data[12:20])
|
||||||
self.timeOffset = timestamp - int(time.time())
|
self.timeOffset = timestamp - int(time.time())
|
||||||
|
|
||||||
self.myExternalIP = socket.inet_ntoa(data[40:44])
|
# self.myExternalIP = socket.inet_ntoa(data[40:44])
|
||||||
# print 'myExternalIP', self.myExternalIP
|
# print 'myExternalIP', self.myExternalIP
|
||||||
self.remoteNodeIncomingPort, = unpack('>H', data[70:72])
|
self.remoteNodeIncomingPort, = unpack('>H', data[70:72])
|
||||||
# print 'remoteNodeIncomingPort', self.remoteNodeIncomingPort
|
# print 'remoteNodeIncomingPort', self.remoteNodeIncomingPort
|
||||||
|
|
|
@ -10,7 +10,7 @@ import socket
|
||||||
from ssl import SSLError, SSL_ERROR_WANT_WRITE
|
from ssl import SSLError, SSL_ERROR_WANT_WRITE
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from helper_generic import addDataPadding
|
# from helper_generic import addDataPadding
|
||||||
from class_objectHashHolder import *
|
from class_objectHashHolder import *
|
||||||
from addresses import *
|
from addresses import *
|
||||||
from debug import logger
|
from debug import logger
|
||||||
|
@ -71,7 +71,7 @@ class sendDataThread(threading.Thread):
|
||||||
# if not 'Bad file descriptor' in err:
|
# if not 'Bad file descriptor' in err:
|
||||||
logger.error('sock.sendall error: %s\n' % err)
|
logger.error('sock.sendall error: %s\n' % err)
|
||||||
|
|
||||||
self.versionSent = 1
|
# self.versionSent = 1
|
||||||
|
|
||||||
def sendBytes(self, data = ""):
|
def sendBytes(self, data = ""):
|
||||||
self.buffer += data
|
self.buffer += data
|
||||||
|
|
|
@ -16,7 +16,7 @@ from debug import logger
|
||||||
import defaults
|
import defaults
|
||||||
from helper_sql import *
|
from helper_sql import *
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
from helper_generic import addDataPadding
|
# from helper_generic import addDataPadding
|
||||||
import helper_msgcoding
|
import helper_msgcoding
|
||||||
from helper_threading import *
|
from helper_threading import *
|
||||||
from inventory import Inventory, PendingUpload
|
from inventory import Inventory, PendingUpload
|
||||||
|
@ -232,7 +232,7 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
|
|
||||||
TTL = int(28 * 24 * 60 * 60 + random.randrange(-300, 300))# 28 days from now plus or minus five minutes
|
TTL = int(28 * 24 * 60 * 60 + random.randrange(-300, 300))# 28 days from now plus or minus five minutes
|
||||||
embeddedTime = int(time.time() + TTL)
|
embeddedTime = int(time.time() + TTL)
|
||||||
signedTimeForProtocolV2 = embeddedTime - TTL
|
# signedTimeForProtocolV2 = embeddedTime - TTL
|
||||||
"""
|
"""
|
||||||
According to the protocol specification, the expiresTime along with the pubkey information is
|
According to the protocol specification, the expiresTime along with the pubkey information is
|
||||||
signed. But to be backwards compatible during the upgrade period, we shall sign not the
|
signed. But to be backwards compatible during the upgrade period, we shall sign not the
|
||||||
|
@ -536,7 +536,7 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
toaddress, fromaddress, subject, message, ackdata, status, TTL, retryNumber, encoding = row
|
toaddress, fromaddress, subject, message, ackdata, status, TTL, retryNumber, encoding = row
|
||||||
toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress(
|
toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress(
|
||||||
toaddress)
|
toaddress)
|
||||||
fromStatus, fromAddressVersionNumber, fromStreamNumber, fromRipe = decodeAddress(
|
_, fromAddressVersionNumber, fromStreamNumber, _ = decodeAddress(
|
||||||
fromaddress)
|
fromaddress)
|
||||||
|
|
||||||
# We may or may not already have the pubkey for this toAddress. Let's check.
|
# We may or may not already have the pubkey for this toAddress. Let's check.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import asyncore
|
import asyncore
|
||||||
import base64
|
import base64
|
||||||
import email
|
import email
|
||||||
from email.parser import Parser
|
# from email.parser import Parser
|
||||||
from email.header import decode_header
|
from email.header import decode_header
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
|
@ -24,30 +24,30 @@ SMTPDOMAIN = "bmaddr.lan"
|
||||||
LISTENPORT = 8425
|
LISTENPORT = 8425
|
||||||
|
|
||||||
class smtpServerChannel(smtpd.SMTPChannel):
|
class smtpServerChannel(smtpd.SMTPChannel):
|
||||||
def smtp_EHLO(self, arg):
|
# def smtp_EHLO(self, arg):
|
||||||
if not arg:
|
# if not arg:
|
||||||
self.push('501 Syntax: HELO hostname')
|
# self.push('501 Syntax: HELO hostname')
|
||||||
return
|
# return
|
||||||
self.push('250-PyBitmessage %s' % softwareVersion)
|
# self.push('250-PyBitmessage %s' % softwareVersion)
|
||||||
self.push('250 AUTH PLAIN')
|
# self.push('250 AUTH PLAIN')
|
||||||
|
|
||||||
def smtp_AUTH(self, arg):
|
# def smtp_AUTH(self, arg):
|
||||||
if not arg or arg[0:5] not in ["PLAIN"]:
|
# if not arg or arg[0:5] not in ["PLAIN"]:
|
||||||
self.push('501 Syntax: AUTH PLAIN')
|
# self.push('501 Syntax: AUTH PLAIN')
|
||||||
return
|
# return
|
||||||
authstring = arg[6:]
|
# authstring = arg[6:]
|
||||||
try:
|
# try:
|
||||||
decoded = base64.b64decode(authstring)
|
# decoded = base64.b64decode(authstring)
|
||||||
correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \
|
# correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \
|
||||||
"\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "")
|
# "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "")
|
||||||
logger.debug("authstring: %s / %s", correctauth, decoded)
|
# logger.debug("authstring: %s / %s", correctauth, decoded)
|
||||||
if correctauth == decoded:
|
# if correctauth == decoded:
|
||||||
self.auth = True
|
# self.auth = True
|
||||||
self.push('235 2.7.0 Authentication successful')
|
# self.push('235 2.7.0 Authentication successful')
|
||||||
else:
|
# else:
|
||||||
raise Exception("Auth fail")
|
# raise Exception("Auth fail")
|
||||||
except:
|
# except:
|
||||||
self.push('501 Authentication fail')
|
# self.push('501 Authentication fail')
|
||||||
|
|
||||||
def smtp_DATA(self, arg):
|
def smtp_DATA(self, arg):
|
||||||
if not hasattr(self, "auth") or not self.auth:
|
if not hasattr(self, "auth") or not self.auth:
|
||||||
|
@ -62,7 +62,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
conn, addr = pair
|
conn, addr = pair
|
||||||
# print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
|
# print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
|
||||||
self.channel = smtpServerChannel(self, conn, addr)
|
# self.channel = smtpServerChannel(self, conn, addr)
|
||||||
|
|
||||||
def send(self, fromAddress, toAddress, subject, message):
|
def send(self, fromAddress, toAddress, subject, message):
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
|
||||||
|
@ -101,61 +101,61 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
# def process_message(self, peer, mailfrom, rcpttos, data):
|
||||||
# print 'Receiving message from:', peer
|
# print 'Receiving message from:', peer
|
||||||
p = re.compile(".*<([^>]+)>")
|
# p = re.compile(".*<([^>]+)>")
|
||||||
if not hasattr(self.channel, "auth") or not self.channel.auth:
|
# if not hasattr(self.channel, "auth") or not self.channel.auth:
|
||||||
logger.error("Missing or invalid auth")
|
# logger.error("Missing or invalid auth")
|
||||||
return
|
# return
|
||||||
try:
|
# try:
|
||||||
self.msg_headers = Parser().parsestr(data)
|
# self.msg_headers = Parser().parsestr(data)
|
||||||
except:
|
# except:
|
||||||
logger.error("Invalid headers")
|
# logger.error("Invalid headers")
|
||||||
return
|
# return
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
sender, domain = p.sub(r'\1', mailfrom).split("@")
|
# sender, domain = p.sub(r'\1', mailfrom).split("@")
|
||||||
if domain != SMTPDOMAIN:
|
# if domain != SMTPDOMAIN:
|
||||||
raise Exception("Bad domain %s", domain)
|
# raise Exception("Bad domain %s", domain)
|
||||||
if sender not in BMConfigParser().addresses():
|
# if sender not in BMConfigParser().addresses():
|
||||||
raise Exception("Nonexisting user %s", sender)
|
# raise Exception("Nonexisting user %s", sender)
|
||||||
except Exception as err:
|
# except Exception as err:
|
||||||
logger.debug("Bad envelope from %s: %s", mailfrom, repr(err))
|
# logger.debug("Bad envelope from %s: %s", mailfrom, repr(err))
|
||||||
msg_from = self.decode_header("from")
|
# msg_from = self.decode_header("from")
|
||||||
try:
|
# try:
|
||||||
msg_from = p.sub(r'\1', self.decode_header("from")[0])
|
# msg_from = p.sub(r'\1', self.decode_header("from")[0])
|
||||||
sender, domain = msg_from.split("@")
|
# sender, domain = msg_from.split("@")
|
||||||
if domain != SMTPDOMAIN:
|
# if domain != SMTPDOMAIN:
|
||||||
raise Exception("Bad domain %s", domain)
|
# raise Exception("Bad domain %s", domain)
|
||||||
if sender not in BMConfigParser().addresses():
|
# if sender not in BMConfigParser().addresses():
|
||||||
raise Exception("Nonexisting user %s", sender)
|
# raise Exception("Nonexisting user %s", sender)
|
||||||
except Exception as err:
|
# except Exception as err:
|
||||||
logger.error("Bad headers from %s: %s", msg_from, repr(err))
|
# logger.error("Bad headers from %s: %s", msg_from, repr(err))
|
||||||
return
|
# return
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
msg_subject = self.decode_header('subject')[0]
|
# msg_subject = self.decode_header('subject')[0]
|
||||||
except:
|
# except:
|
||||||
msg_subject = "Subject missing..."
|
# msg_subject = "Subject missing..."
|
||||||
|
|
||||||
msg_tmp = email.message_from_string(data)
|
# msg_tmp = email.message_from_string(data)
|
||||||
body = u''
|
# body = u''
|
||||||
for part in msg_tmp.walk():
|
# for part in msg_tmp.walk():
|
||||||
if part and part.get_content_type() == "text/plain":
|
# if part and part.get_content_type() == "text/plain":
|
||||||
body += part.get_payload(decode=1).decode(part.get_content_charset('utf-8'), errors='replace')
|
# body += part.get_payload(decode=1).decode(part.get_content_charset('utf-8'), errors='replace')
|
||||||
|
|
||||||
for to in rcpttos:
|
# for to in rcpttos:
|
||||||
try:
|
# try:
|
||||||
rcpt, domain = p.sub(r'\1', to).split("@")
|
# rcpt, domain = p.sub(r'\1', to).split("@")
|
||||||
if domain != SMTPDOMAIN:
|
# if domain != SMTPDOMAIN:
|
||||||
raise Exception("Bad domain %s", domain)
|
# raise Exception("Bad domain %s", domain)
|
||||||
logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
|
# logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
|
||||||
self.send(sender, rcpt, msg_subject, body)
|
# self.send(sender, rcpt, msg_subject, body)
|
||||||
logger.info("Relayed %s to %s", sender, rcpt)
|
# logger.info("Relayed %s to %s", sender, rcpt)
|
||||||
except Exception as err:
|
# except Exception as err:
|
||||||
logger.error( "Bad to %s: %s", to, repr(err))
|
# logger.error( "Bad to %s: %s", to, repr(err))
|
||||||
continue
|
# continue
|
||||||
return
|
# return
|
||||||
|
|
||||||
class smtpServer(threading.Thread, StoppableThread):
|
class smtpServer(threading.Thread, StoppableThread):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
@ -167,16 +167,16 @@ class smtpServer(threading.Thread, StoppableThread):
|
||||||
super(smtpServer, self).stopThread()
|
super(smtpServer, self).stopThread()
|
||||||
self.server.close()
|
self.server.close()
|
||||||
return
|
return
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
# for ip in ('127.0.0.1', BMConfigParser().get('bitmessagesettings', 'onionbindip')):
|
# for ip in ('127.0.0.1', BMConfigParser().get('bitmessagesettings', 'onionbindip')):
|
||||||
for ip in ('127.0.0.1'):
|
# for ip in ('127.0.0.1'):
|
||||||
try:
|
# try:
|
||||||
s.connect((ip, LISTENPORT))
|
# s.connect((ip, LISTENPORT))
|
||||||
s.shutdown(socket.SHUT_RDWR)
|
# s.shutdown(socket.SHUT_RDWR)
|
||||||
s.close()
|
# s.close()
|
||||||
break
|
# break
|
||||||
except:
|
# except:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
asyncore.loop(1)
|
asyncore.loop(1)
|
||||||
|
|
|
@ -28,7 +28,7 @@ class sqlThread(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
|
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
|
||||||
self.conn.text_factory = str
|
# self.conn.text_factory = str
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
|
|
||||||
self.cur.execute('PRAGMA secure_delete = true')
|
self.cur.execute('PRAGMA secure_delete = true')
|
||||||
|
@ -525,7 +525,7 @@ class sqlThread(threading.Thread):
|
||||||
shutil.move(
|
shutil.move(
|
||||||
paths.lookupAppdataFolder() + 'messages.dat', paths.lookupExeFolder() + 'messages.dat')
|
paths.lookupAppdataFolder() + 'messages.dat', paths.lookupExeFolder() + 'messages.dat')
|
||||||
self.conn = sqlite3.connect(paths.lookupExeFolder() + 'messages.dat')
|
self.conn = sqlite3.connect(paths.lookupExeFolder() + 'messages.dat')
|
||||||
self.conn.text_factory = str
|
# self.conn.text_factory = str
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
elif item == 'movemessagstoappdata':
|
elif item == 'movemessagstoappdata':
|
||||||
logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
|
logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
|
||||||
|
@ -541,7 +541,7 @@ class sqlThread(threading.Thread):
|
||||||
shutil.move(
|
shutil.move(
|
||||||
paths.lookupExeFolder() + 'messages.dat', paths.lookupAppdataFolder() + 'messages.dat')
|
paths.lookupExeFolder() + 'messages.dat', paths.lookupAppdataFolder() + 'messages.dat')
|
||||||
self.conn = sqlite3.connect(paths.lookupAppdataFolder() + 'messages.dat')
|
self.conn = sqlite3.connect(paths.lookupAppdataFolder() + 'messages.dat')
|
||||||
self.conn.text_factory = str
|
# self.conn.text_factory = str
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
elif item == 'deleteandvacuume':
|
elif item == 'deleteandvacuume':
|
||||||
self.cur.execute('''delete from inbox where folder='trash' ''')
|
self.cur.execute('''delete from inbox where folder='trash' ''')
|
||||||
|
|
|
@ -28,8 +28,8 @@ helper_startup.loadConfig()
|
||||||
# examples are here: https://bitmessage.org/forum/index.php/topic,4820.msg11163.html#msg11163
|
# examples are here: https://bitmessage.org/forum/index.php/topic,4820.msg11163.html#msg11163
|
||||||
log_level = 'WARNING'
|
log_level = 'WARNING'
|
||||||
|
|
||||||
def log_uncaught_exceptions(ex_cls, ex, tb):
|
# def log_uncaught_exceptions(ex_cls, ex, tb):
|
||||||
logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb))
|
# logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb))
|
||||||
|
|
||||||
def configureLogging():
|
def configureLogging():
|
||||||
have_logging = False
|
have_logging = False
|
||||||
|
@ -45,7 +45,7 @@ def configureLogging():
|
||||||
# no need to confuse the user if the logger config is missing entirely
|
# no need to confuse the user if the logger config is missing entirely
|
||||||
print "Using default logger configuration"
|
print "Using default logger configuration"
|
||||||
|
|
||||||
sys.excepthook = log_uncaught_exceptions
|
# sys.excepthook = log_uncaught_exceptions
|
||||||
|
|
||||||
if have_logging:
|
if have_logging:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -187,8 +187,8 @@ class DuplicateKeyException(UnpackException):
|
||||||
|
|
||||||
|
|
||||||
# Backwards compatibility
|
# Backwards compatibility
|
||||||
KeyNotPrimitiveException = UnhashableKeyException
|
# KeyNotPrimitiveException = UnhashableKeyException
|
||||||
KeyDuplicateException = DuplicateKeyException
|
# KeyDuplicateException = DuplicateKeyException
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# Exported Functions and Glob
|
# Exported Functions and Glob
|
||||||
|
@ -196,9 +196,9 @@ KeyDuplicateException = DuplicateKeyException
|
||||||
|
|
||||||
# Exported functions and variables, set up in __init()
|
# Exported functions and variables, set up in __init()
|
||||||
pack = None
|
pack = None
|
||||||
packb = None
|
# packb = None
|
||||||
unpack = None
|
unpack = None
|
||||||
unpackb = None
|
# unpackb = None
|
||||||
dump = None
|
dump = None
|
||||||
dumps = None
|
dumps = None
|
||||||
load = None
|
load = None
|
||||||
|
@ -982,21 +982,21 @@ def __init():
|
||||||
# Map packb and unpackb to the appropriate version
|
# Map packb and unpackb to the appropriate version
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
pack = _pack3
|
pack = _pack3
|
||||||
packb = _packb3
|
# packb = _packb3
|
||||||
dump = _pack3
|
dump = _pack3
|
||||||
dumps = _packb3
|
dumps = _packb3
|
||||||
unpack = _unpack3
|
unpack = _unpack3
|
||||||
unpackb = _unpackb3
|
# unpackb = _unpackb3
|
||||||
load = _unpack3
|
load = _unpack3
|
||||||
loads = _unpackb3
|
loads = _unpackb3
|
||||||
xrange = range
|
xrange = range
|
||||||
else:
|
else:
|
||||||
pack = _pack2
|
pack = _pack2
|
||||||
packb = _packb2
|
# packb = _packb2
|
||||||
dump = _pack2
|
dump = _pack2
|
||||||
dumps = _packb2
|
dumps = _packb2
|
||||||
unpack = _unpack2
|
unpack = _unpack2
|
||||||
unpackb = _unpackb2
|
# unpackb = _unpackb2
|
||||||
load = _unpack2
|
load = _unpack2
|
||||||
loads = _unpackb2
|
loads = _unpackb2
|
||||||
|
|
||||||
|
|
|
@ -21,17 +21,17 @@ def powQueueSize():
|
||||||
pass
|
pass
|
||||||
return curWorkerQueue
|
return curWorkerQueue
|
||||||
|
|
||||||
def convertIntToString(n):
|
# def convertIntToString(n):
|
||||||
a = __builtins__.hex(n)
|
# a = __builtins__.hex(n)
|
||||||
if a[-1:] == 'L':
|
# if a[-1:] == 'L':
|
||||||
a = a[:-1]
|
# a = a[:-1]
|
||||||
if (len(a) % 2) == 0:
|
# if (len(a) % 2) == 0:
|
||||||
return unhexlify(a[2:])
|
# return unhexlify(a[2:])
|
||||||
else:
|
# else:
|
||||||
return unhexlify('0' + a[2:])
|
# return unhexlify('0' + a[2:])
|
||||||
|
|
||||||
def convertStringToInt(s):
|
# def convertStringToInt(s):
|
||||||
return int(hexlify(s), 16)
|
# return int(hexlify(s), 16)
|
||||||
|
|
||||||
def allThreadTraceback(frame):
|
def allThreadTraceback(frame):
|
||||||
id2name = dict([(th.ident, th.name) for th in enumerate()])
|
id2name = dict([(th.ident, th.name) for th in enumerate()])
|
||||||
|
@ -84,5 +84,5 @@ def isHostInPrivateIPRange(host):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def addDataPadding(data, desiredMsgLength = 12, paddingChar = '\x00'):
|
# def addDataPadding(data, desiredMsgLength = 12, paddingChar = '\x00'):
|
||||||
return data + paddingChar * (desiredMsgLength - len(data))
|
# return data + paddingChar * (desiredMsgLength - len(data))
|
||||||
|
|
2
src/helper_msgcoding.py
Normal file → Executable file
2
src/helper_msgcoding.py
Normal file → Executable file
|
@ -15,7 +15,7 @@ from debug import logger
|
||||||
import messagetypes
|
import messagetypes
|
||||||
from tr import _translate
|
from tr import _translate
|
||||||
|
|
||||||
BITMESSAGE_ENCODING_IGNORE = 0
|
# BITMESSAGE_ENCODING_IGNORE = 0
|
||||||
BITMESSAGE_ENCODING_TRIVIAL = 1
|
BITMESSAGE_ENCODING_TRIVIAL = 1
|
||||||
BITMESSAGE_ENCODING_SIMPLE = 2
|
BITMESSAGE_ENCODING_SIMPLE = 2
|
||||||
BITMESSAGE_ENCODING_EXTENDED = 3
|
BITMESSAGE_ENCODING_EXTENDED = 3
|
||||||
|
|
|
@ -28,8 +28,8 @@ def encrypt(msg,hexPubkey):
|
||||||
def decrypt(msg,hexPrivkey):
|
def decrypt(msg,hexPrivkey):
|
||||||
return makeCryptor(hexPrivkey).decrypt(msg)
|
return makeCryptor(hexPrivkey).decrypt(msg)
|
||||||
# Decrypts message with an existing pyelliptic.ECC.ECC object
|
# Decrypts message with an existing pyelliptic.ECC.ECC object
|
||||||
def decryptFast(msg,cryptor):
|
# def decryptFast(msg,cryptor):
|
||||||
return cryptor.decrypt(msg)
|
# return cryptor.decrypt(msg)
|
||||||
# Signs with hex private key
|
# Signs with hex private key
|
||||||
def sign(msg,hexPrivkey):
|
def sign(msg,hexPrivkey):
|
||||||
# pyelliptic is upgrading from SHA1 to SHA256 for signing. We must
|
# pyelliptic is upgrading from SHA1 to SHA256 for signing. We must
|
||||||
|
|
|
@ -10,8 +10,8 @@ from helper_sql import *
|
||||||
from singleton import Singleton
|
from singleton import Singleton
|
||||||
|
|
||||||
# TODO make this dynamic, and watch out for frozen, like with messagetypes
|
# TODO make this dynamic, and watch out for frozen, like with messagetypes
|
||||||
import storage.sqlite
|
# import storage.sqlite
|
||||||
import storage.filesystem
|
# import storage.filesystem
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class Inventory():
|
class Inventory():
|
||||||
|
@ -103,7 +103,7 @@ class PendingUpload(object):
|
||||||
self.deadline = 0
|
self.deadline = 0
|
||||||
self.maxLen = 0
|
self.maxLen = 0
|
||||||
# during shutdown, wait up to 20 seconds to finish uploading
|
# during shutdown, wait up to 20 seconds to finish uploading
|
||||||
self.shutdownWait = 20
|
# self.shutdownWait = 20
|
||||||
# forget tracking objects after 60 seconds
|
# forget tracking objects after 60 seconds
|
||||||
self.objectWait = 60
|
self.objectWait = 60
|
||||||
# wait 10 seconds between clears
|
# wait 10 seconds between clears
|
||||||
|
|
|
@ -20,15 +20,15 @@ def saveKnownNodes(dirName = None):
|
||||||
with open(os.path.join(dirName, 'knownnodes.dat'), 'wb') as output:
|
with open(os.path.join(dirName, 'knownnodes.dat'), 'wb') as output:
|
||||||
pickle.dump(knownNodes, output)
|
pickle.dump(knownNodes, output)
|
||||||
|
|
||||||
def increaseRating(peer):
|
# def increaseRating(peer):
|
||||||
increaseAmount = 0.1
|
# increaseAmount = 0.1
|
||||||
maxRating = 1
|
# maxRating = 1
|
||||||
with knownNodesLock:
|
# with knownNodesLock:
|
||||||
for stream in knownNodes.keys():
|
# for stream in knownNodes.keys():
|
||||||
try:
|
# try:
|
||||||
knownNodes[stream][peer]["rating"] = min(knownNodes[stream][peer]["rating"] + increaseAmount, maxRating)
|
# knownNodes[stream][peer]["rating"] = min(knownNodes[stream][peer]["rating"] + increaseAmount, maxRating)
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def decreaseRating(peer):
|
def decreaseRating(peer):
|
||||||
decreaseAmount = 0.1
|
decreaseAmount = 0.1
|
||||||
|
|
|
@ -13,7 +13,7 @@ from binascii import hexlify
|
||||||
appdata = paths.lookupAppdataFolder()
|
appdata = paths.lookupAppdataFolder()
|
||||||
|
|
||||||
conn = sqlite3.connect( appdata + 'messages.dat' )
|
conn = sqlite3.connect( appdata + 'messages.dat' )
|
||||||
conn.text_factory = str
|
# conn.text_factory = str
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
def readInbox():
|
def readInbox():
|
||||||
|
@ -25,78 +25,78 @@ def readInbox():
|
||||||
for row in output:
|
for row in output:
|
||||||
print row
|
print row
|
||||||
|
|
||||||
def readSent():
|
# def readSent():
|
||||||
print 'Printing everything in Sent table:'
|
# print 'Printing everything in Sent table:'
|
||||||
item = '''select * from sent where folder !='trash' '''
|
# item = '''select * from sent where folder !='trash' '''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
for row in output:
|
# for row in output:
|
||||||
msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, sleeptill, status, retrynumber, folder, encodingtype, ttl = row
|
# msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, sleeptill, status, retrynumber, folder, encodingtype, ttl = row
|
||||||
print hexlify(msgid), toaddress, 'toripe:', hexlify(toripe), 'fromaddress:', fromaddress, 'ENCODING TYPE:', encodingtype, 'SUBJECT:', repr(subject), 'MESSAGE:', repr(message), 'ACKDATA:', hexlify(ackdata), lastactiontime, status, retrynumber, folder
|
# print hexlify(msgid), toaddress, 'toripe:', hexlify(toripe), 'fromaddress:', fromaddress, 'ENCODING TYPE:', encodingtype, 'SUBJECT:', repr(subject), 'MESSAGE:', repr(message), 'ACKDATA:', hexlify(ackdata), lastactiontime, status, retrynumber, folder
|
||||||
|
|
||||||
def readSubscriptions():
|
# def readSubscriptions():
|
||||||
print 'Printing everything in subscriptions table:'
|
# print 'Printing everything in subscriptions table:'
|
||||||
item = '''select * from subscriptions'''
|
# item = '''select * from subscriptions'''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
for row in output:
|
# for row in output:
|
||||||
print row
|
# print row
|
||||||
|
|
||||||
def readPubkeys():
|
# def readPubkeys():
|
||||||
print 'Printing everything in pubkeys table:'
|
# print 'Printing everything in pubkeys table:'
|
||||||
item = '''select address, transmitdata, time, usedpersonally from pubkeys'''
|
# item = '''select address, transmitdata, time, usedpersonally from pubkeys'''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
for row in output:
|
# for row in output:
|
||||||
address, transmitdata, time, usedpersonally = row
|
# address, transmitdata, time, usedpersonally = row
|
||||||
print 'Address:', address, '\tTime first broadcast:', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(time)),'utf-8'), '\tUsed by me personally:', usedpersonally, '\tFull pubkey message:', hexlify(transmitdata)
|
# print 'Address:', address, '\tTime first broadcast:', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(time)),'utf-8'), '\tUsed by me personally:', usedpersonally, '\tFull pubkey message:', hexlify(transmitdata)
|
||||||
|
|
||||||
def readInventory():
|
# def readInventory():
|
||||||
print 'Printing everything in inventory table:'
|
# print 'Printing everything in inventory table:'
|
||||||
item = '''select hash, objecttype, streamnumber, payload, expirestime from inventory'''
|
# item = '''select hash, objecttype, streamnumber, payload, expirestime from inventory'''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
for row in output:
|
# for row in output:
|
||||||
hash, objecttype, streamnumber, payload, expirestime = row
|
# hash, objecttype, streamnumber, payload, expirestime = row
|
||||||
print 'Hash:', hexlify(hash), objecttype, streamnumber, '\t', hexlify(payload), '\t', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(expirestime)),'utf-8')
|
# print 'Hash:', hexlify(hash), objecttype, streamnumber, '\t', hexlify(payload), '\t', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(expirestime)),'utf-8')
|
||||||
|
|
||||||
|
|
||||||
def takeInboxMessagesOutOfTrash():
|
# def takeInboxMessagesOutOfTrash():
|
||||||
item = '''update inbox set folder='inbox' where folder='trash' '''
|
# item = '''update inbox set folder='inbox' where folder='trash' '''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
conn.commit()
|
# conn.commit()
|
||||||
print 'done'
|
# print 'done'
|
||||||
|
|
||||||
def takeSentMessagesOutOfTrash():
|
# def takeSentMessagesOutOfTrash():
|
||||||
item = '''update sent set folder='sent' where folder='trash' '''
|
# item = '''update sent set folder='sent' where folder='trash' '''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
conn.commit()
|
# conn.commit()
|
||||||
print 'done'
|
# print 'done'
|
||||||
|
|
||||||
def markAllInboxMessagesAsUnread():
|
# def markAllInboxMessagesAsUnread():
|
||||||
item = '''update inbox set read='0' '''
|
# item = '''update inbox set read='0' '''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
conn.commit()
|
# conn.commit()
|
||||||
queues.UISignalQueue.put(('changedInboxUnread', None))
|
# queues.UISignalQueue.put(('changedInboxUnread', None))
|
||||||
print 'done'
|
# print 'done'
|
||||||
|
|
||||||
def vacuum():
|
# def vacuum():
|
||||||
item = '''VACUUM'''
|
# item = '''VACUUM'''
|
||||||
parameters = ''
|
# parameters = ''
|
||||||
cur.execute(item, parameters)
|
# cur.execute(item, parameters)
|
||||||
output = cur.fetchall()
|
# output = cur.fetchall()
|
||||||
conn.commit()
|
# conn.commit()
|
||||||
print 'done'
|
# print 'done'
|
||||||
|
|
||||||
#takeInboxMessagesOutOfTrash()
|
#takeInboxMessagesOutOfTrash()
|
||||||
#takeSentMessagesOutOfTrash()
|
#takeSentMessagesOutOfTrash()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from collections import deque
|
# from collections import deque
|
||||||
import Queue
|
import Queue
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
@ -12,23 +12,23 @@ class MultiQueue(Queue.Queue):
|
||||||
Queue.Queue.__init__(self, maxsize)
|
Queue.Queue.__init__(self, maxsize)
|
||||||
|
|
||||||
# Initialize the queue representation
|
# Initialize the queue representation
|
||||||
def _init(self, maxsize):
|
# def _init(self, maxsize):
|
||||||
self.iter = 0
|
# self.iter = 0
|
||||||
self.queues = []
|
# self.queues = []
|
||||||
for i in range(self.queueCount):
|
# for i in range(self.queueCount):
|
||||||
self.queues.append(deque())
|
# self.queues.append(deque())
|
||||||
|
|
||||||
def _qsize(self, len=len):
|
# def _qsize(self, len=len):
|
||||||
return len(self.queues[self.iter])
|
# return len(self.queues[self.iter])
|
||||||
|
|
||||||
# Put a new item in the queue
|
# Put a new item in the queue
|
||||||
def _put(self, item):
|
# def _put(self, item):
|
||||||
#self.queue.append(item)
|
# #self.queue.append(item)
|
||||||
self.queues[random.randrange(self.queueCount)].append((item))
|
# self.queues[random.randrange(self.queueCount)].append((item))
|
||||||
|
|
||||||
# Get an item from the queue
|
# Get an item from the queue
|
||||||
def _get(self):
|
# def _get(self):
|
||||||
return self.queues[self.iter].popleft()
|
# return self.queues[self.iter].popleft()
|
||||||
|
|
||||||
def iterate(self):
|
def iterate(self):
|
||||||
self.iter = (self.iter + 1) % self.queueCount
|
self.iter = (self.iter + 1) % self.queueCount
|
||||||
|
|
|
@ -119,8 +119,8 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
||||||
def handle_connect(self):
|
def handle_connect(self):
|
||||||
self.lastTx = time.time()
|
self.lastTx = time.time()
|
||||||
|
|
||||||
def state_close(self):
|
# def state_close(self):
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def handle_close(self):
|
def handle_close(self):
|
||||||
with self.readLock:
|
with self.readLock:
|
||||||
|
|
|
@ -302,7 +302,7 @@ def poll_poller(timeout=0.0, map=None):
|
||||||
|
|
||||||
# Aliases for backward compatibility
|
# Aliases for backward compatibility
|
||||||
poll = select_poller
|
poll = select_poller
|
||||||
poll2 = poll3 = poll_poller
|
# poll2 = poll3 = poll_poller
|
||||||
|
|
||||||
def epoll_poller(timeout=0.0, map=None):
|
def epoll_poller(timeout=0.0, map=None):
|
||||||
"""A poller which uses epoll(), supported on Linux 2.5.44 and newer."""
|
"""A poller which uses epoll(), supported on Linux 2.5.44 and newer."""
|
||||||
|
@ -468,7 +468,7 @@ class dispatcher:
|
||||||
connected = False
|
connected = False
|
||||||
accepting = False
|
accepting = False
|
||||||
connecting = False
|
connecting = False
|
||||||
closing = False
|
# closing = False
|
||||||
addr = None
|
addr = None
|
||||||
ignore_log_types = frozenset(['warning'])
|
ignore_log_types = frozenset(['warning'])
|
||||||
poller_registered = False
|
poller_registered = False
|
||||||
|
@ -563,7 +563,7 @@ class dispatcher:
|
||||||
self.poller_registered = False
|
self.poller_registered = False
|
||||||
|
|
||||||
def create_socket(self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
|
def create_socket(self, family=socket.AF_INET, socket_type=socket.SOCK_STREAM):
|
||||||
self.family_and_type = family, socket_type
|
# self.family_and_type = family, socket_type
|
||||||
sock = socket.socket(family, socket_type)
|
sock = socket.socket(family, socket_type)
|
||||||
sock.setblocking(0)
|
sock.setblocking(0)
|
||||||
self.set_socket(sock)
|
self.set_socket(sock)
|
||||||
|
@ -762,7 +762,7 @@ class dispatcher:
|
||||||
self.handle_expt()
|
self.handle_expt()
|
||||||
|
|
||||||
def handle_error(self):
|
def handle_error(self):
|
||||||
nil, t, v, tbinfo = compact_traceback()
|
_, t, v, tbinfo = compact_traceback()
|
||||||
|
|
||||||
# sometimes a user repr method will crash.
|
# sometimes a user repr method will crash.
|
||||||
try:
|
try:
|
||||||
|
@ -811,28 +811,28 @@ class dispatcher:
|
||||||
# [for more sophisticated usage use asynchat.async_chat]
|
# [for more sophisticated usage use asynchat.async_chat]
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
class dispatcher_with_send(dispatcher):
|
# class dispatcher_with_send(dispatcher):
|
||||||
|
|
||||||
def __init__(self, sock=None, map=None):
|
# def __init__(self, sock=None, map=None):
|
||||||
dispatcher.__init__(self, sock, map)
|
# dispatcher.__init__(self, sock, map)
|
||||||
self.out_buffer = b''
|
# self.out_buffer = b''
|
||||||
|
|
||||||
def initiate_send(self):
|
# def initiate_send(self):
|
||||||
num_sent = 0
|
# num_sent = 0
|
||||||
num_sent = dispatcher.send(self, self.out_buffer[:512])
|
# num_sent = dispatcher.send(self, self.out_buffer[:512])
|
||||||
self.out_buffer = self.out_buffer[num_sent:]
|
# self.out_buffer = self.out_buffer[num_sent:]
|
||||||
|
|
||||||
def handle_write(self):
|
# def handle_write(self):
|
||||||
self.initiate_send()
|
# self.initiate_send()
|
||||||
|
|
||||||
def writable(self):
|
# def writable(self):
|
||||||
return (not self.connected) or len(self.out_buffer)
|
# return (not self.connected) or len(self.out_buffer)
|
||||||
|
|
||||||
def send(self, data):
|
# def send(self, data):
|
||||||
if self.debug:
|
# if self.debug:
|
||||||
self.log_info('sending %s' % repr(data))
|
# self.log_info('sending %s' % repr(data))
|
||||||
self.out_buffer = self.out_buffer + data
|
# self.out_buffer = self.out_buffer + data
|
||||||
self.initiate_send()
|
# self.initiate_send()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# used for debugging.
|
# used for debugging.
|
||||||
|
@ -892,53 +892,53 @@ def close_all(map=None, ignore_all=False):
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
class file_wrapper:
|
# class file_wrapper:
|
||||||
# Here we override just enough to make a file
|
# # Here we override just enough to make a file
|
||||||
# look like a socket for the purposes of asyncore.
|
# # look like a socket for the purposes of asyncore.
|
||||||
# The passed fd is automatically os.dup()'d
|
# # The passed fd is automatically os.dup()'d
|
||||||
|
|
||||||
def __init__(self, fd):
|
# def __init__(self, fd):
|
||||||
self.fd = os.dup(fd)
|
# self.fd = os.dup(fd)
|
||||||
|
|
||||||
def recv(self, *args):
|
# def recv(self, *args):
|
||||||
return os.read(self.fd, *args)
|
# return os.read(self.fd, *args)
|
||||||
|
|
||||||
def send(self, *args):
|
# def send(self, *args):
|
||||||
return os.write(self.fd, *args)
|
# return os.write(self.fd, *args)
|
||||||
|
|
||||||
def getsockopt(self, level, optname, buflen=None):
|
# def getsockopt(self, level, optname, buflen=None):
|
||||||
if (level == socket.SOL_SOCKET and
|
# if (level == socket.SOL_SOCKET and
|
||||||
optname == socket.SO_ERROR and
|
# optname == socket.SO_ERROR and
|
||||||
not buflen):
|
# not buflen):
|
||||||
return 0
|
# return 0
|
||||||
raise NotImplementedError("Only asyncore specific behaviour "
|
# raise NotImplementedError("Only asyncore specific behaviour "
|
||||||
"implemented.")
|
# "implemented.")
|
||||||
|
|
||||||
read = recv
|
# read = recv
|
||||||
write = send
|
# write = send
|
||||||
|
|
||||||
def close(self):
|
# def close(self):
|
||||||
os.close(self.fd)
|
# os.close(self.fd)
|
||||||
|
|
||||||
def fileno(self):
|
# def fileno(self):
|
||||||
return self.fd
|
# return self.fd
|
||||||
|
|
||||||
class file_dispatcher(dispatcher):
|
# class file_dispatcher(dispatcher):
|
||||||
|
|
||||||
def __init__(self, fd, map=None):
|
# def __init__(self, fd, map=None):
|
||||||
dispatcher.__init__(self, None, map)
|
# dispatcher.__init__(self, None, map)
|
||||||
self.connected = True
|
# self.connected = True
|
||||||
try:
|
# try:
|
||||||
fd = fd.fileno()
|
# fd = fd.fileno()
|
||||||
except AttributeError:
|
# except AttributeError:
|
||||||
pass
|
# pass
|
||||||
self.set_file(fd)
|
# self.set_file(fd)
|
||||||
# set it to non-blocking mode
|
# # set it to non-blocking mode
|
||||||
flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0)
|
# flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0)
|
||||||
flags = flags | os.O_NONBLOCK
|
# flags = flags | os.O_NONBLOCK
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
|
# fcntl.fcntl(fd, fcntl.F_SETFL, flags)
|
||||||
|
|
||||||
def set_file(self, fd):
|
# def set_file(self, fd):
|
||||||
self.socket = file_wrapper(fd)
|
# self.socket = file_wrapper(fd)
|
||||||
self._fileno = self.socket.fileno()
|
# self._fileno = self.socket.fileno()
|
||||||
self.add_channel()
|
# self.add_channel()
|
||||||
|
|
|
@ -38,7 +38,7 @@ class BMProtoExcessiveDataError(BMProtoError):
|
||||||
|
|
||||||
class BMProto(AdvancedDispatcher, ObjectTracker):
|
class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
# ~1.6 MB which is the maximum possible size of an inv message.
|
# ~1.6 MB which is the maximum possible size of an inv message.
|
||||||
maxMessageSize = 1600100
|
# maxMessageSize = 1600100
|
||||||
# 2**18 = 256kB is the maximum size of an object payload
|
# 2**18 = 256kB is the maximum size of an object payload
|
||||||
maxObjectPayloadSize = 2**18
|
maxObjectPayloadSize = 2**18
|
||||||
# protocol specification says max 1000 addresses in one addr command
|
# protocol specification says max 1000 addresses in one addr command
|
||||||
|
@ -46,7 +46,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
# protocol specification says max 50000 objects in one inv command
|
# protocol specification says max 50000 objects in one inv command
|
||||||
maxObjectCount = 50000
|
maxObjectCount = 50000
|
||||||
# address is online if online less than this many seconds ago
|
# address is online if online less than this many seconds ago
|
||||||
addressAlive = 10800
|
# addressAlive = 10800
|
||||||
# maximum time offset
|
# maximum time offset
|
||||||
maxTimeOffset = 3600
|
maxTimeOffset = 3600
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
AdvancedDispatcher.__init__(self, sock)
|
AdvancedDispatcher.__init__(self, sock)
|
||||||
self.isOutbound = False
|
self.isOutbound = False
|
||||||
# packet/connection from a local IP
|
# packet/connection from a local IP
|
||||||
self.local = False
|
# self.local = False
|
||||||
|
|
||||||
def bm_proto_reset(self):
|
def bm_proto_reset(self):
|
||||||
self.magic = None
|
# self.magic = None
|
||||||
self.command = None
|
self.command = None
|
||||||
self.payloadLength = 0
|
self.payloadLength = 0
|
||||||
self.checksum = None
|
self.checksum = None
|
||||||
|
@ -67,22 +67,22 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
self.expectBytes = protocol.Header.size
|
self.expectBytes = protocol.Header.size
|
||||||
self.object = None
|
self.object = None
|
||||||
|
|
||||||
def state_bm_header(self):
|
# def state_bm_header(self):
|
||||||
self.magic, self.command, self.payloadLength, self.checksum = protocol.Header.unpack(self.read_buf[:protocol.Header.size])
|
# self.magic, self.command, self.payloadLength, self.checksum = protocol.Header.unpack(self.read_buf[:protocol.Header.size])
|
||||||
self.command = self.command.rstrip('\x00')
|
# self.command = self.command.rstrip('\x00')
|
||||||
if self.magic != 0xE9BEB4D9:
|
# if self.magic != 0xE9BEB4D9:
|
||||||
# skip 1 byte in order to sync
|
# # skip 1 byte in order to sync
|
||||||
self.set_state("bm_header", length=1)
|
# self.set_state("bm_header", length=1)
|
||||||
self.bm_proto_reset()
|
# self.bm_proto_reset()
|
||||||
logger.debug("Bad magic")
|
# logger.debug("Bad magic")
|
||||||
if self.socket.type == socket.SOCK_STREAM:
|
# if self.socket.type == socket.SOCK_STREAM:
|
||||||
self.close_reason = "Bad magic"
|
# self.close_reason = "Bad magic"
|
||||||
self.set_state("close")
|
# self.set_state("close")
|
||||||
return False
|
# return False
|
||||||
if self.payloadLength > BMProto.maxMessageSize:
|
# if self.payloadLength > BMProto.maxMessageSize:
|
||||||
self.invalid = True
|
# self.invalid = True
|
||||||
self.set_state("bm_command", length=protocol.Header.size, expectBytes=self.payloadLength)
|
# self.set_state("bm_command", length=protocol.Header.size, expectBytes=self.payloadLength)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_bm_command(self):
|
def state_bm_command(self):
|
||||||
self.payload = self.read_buf[:self.payloadLength]
|
self.payload = self.read_buf[:self.payloadLength]
|
||||||
|
@ -132,10 +132,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
# else assume the command requires a different state to follow
|
# else assume the command requires a different state to follow
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def decode_payload_string(self, length):
|
# def decode_payload_string(self, length):
|
||||||
value = self.payload[self.payloadOffset:self.payloadOffset+length]
|
# value = self.payload[self.payloadOffset:self.payloadOffset+length]
|
||||||
self.payloadOffset += length
|
# self.payloadOffset += length
|
||||||
return value
|
# return value
|
||||||
|
|
||||||
def decode_payload_varint(self):
|
def decode_payload_varint(self):
|
||||||
value, offset = addresses.decodeVarint(self.payload[self.payloadOffset:])
|
value, offset = addresses.decodeVarint(self.payload[self.payloadOffset:])
|
||||||
|
@ -272,60 +272,60 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
logger.error("%s:%i error: %i, %s", self.destination.host, self.destination.port, fatalStatus, errorText)
|
logger.error("%s:%i error: %i, %s", self.destination.host, self.destination.port, fatalStatus, errorText)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bm_command_getdata(self):
|
# def bm_command_getdata(self):
|
||||||
items = self.decode_payload_content("l32s")
|
# items = self.decode_payload_content("l32s")
|
||||||
# skip?
|
# # skip?
|
||||||
if time.time() < self.skipUntil:
|
# if time.time() < self.skipUntil:
|
||||||
return True
|
# return True
|
||||||
#TODO make this more asynchronous
|
# #TODO make this more asynchronous
|
||||||
random.shuffle(items)
|
# random.shuffle(items)
|
||||||
for i in map(str, items):
|
# for i in map(str, items):
|
||||||
if Dandelion().hasHash(i) and \
|
# if Dandelion().hasHash(i) and \
|
||||||
self != Dandelion().objectChildStem(i):
|
# self != Dandelion().objectChildStem(i):
|
||||||
self.antiIntersectionDelay()
|
# self.antiIntersectionDelay()
|
||||||
logger.info('%s asked for a stem object we didn\'t offer to it.', self.destination)
|
# logger.info('%s asked for a stem object we didn\'t offer to it.', self.destination)
|
||||||
break
|
# break
|
||||||
else:
|
# else:
|
||||||
try:
|
# try:
|
||||||
self.append_write_buf(protocol.CreatePacket('object', Inventory()[i].payload))
|
# self.append_write_buf(protocol.CreatePacket('object', Inventory()[i].payload))
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
self.antiIntersectionDelay()
|
# self.antiIntersectionDelay()
|
||||||
logger.info('%s asked for an object we don\'t have.', self.destination)
|
# logger.info('%s asked for an object we don\'t have.', self.destination)
|
||||||
break
|
# break
|
||||||
# I think that aborting after the first missing/stem object is more secure
|
# # I think that aborting after the first missing/stem object is more secure
|
||||||
# when using random reordering, as the recipient won't know exactly which objects we refuse to deliver
|
# # when using random reordering, as the recipient won't know exactly which objects we refuse to deliver
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def _command_inv(self, dandelion=False):
|
# def _command_inv(self, dandelion=False):
|
||||||
items = self.decode_payload_content("l32s")
|
# items = self.decode_payload_content("l32s")
|
||||||
|
|
||||||
if len(items) >= BMProto.maxObjectCount:
|
# if len(items) >= BMProto.maxObjectCount:
|
||||||
logger.error("Too many items in %sinv message!", "d" if dandelion else "")
|
# logger.error("Too many items in %sinv message!", "d" if dandelion else "")
|
||||||
raise BMProtoExcessiveDataError()
|
# raise BMProtoExcessiveDataError()
|
||||||
else:
|
# else:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
# ignore dinv if dandelion turned off
|
# # ignore dinv if dandelion turned off
|
||||||
if dandelion and not state.dandelion:
|
# if dandelion and not state.dandelion:
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
for i in map(str, items):
|
# for i in map(str, items):
|
||||||
if i in Inventory() and not Dandelion().hasHash(i):
|
# if i in Inventory() and not Dandelion().hasHash(i):
|
||||||
continue
|
# continue
|
||||||
if dandelion and not Dandelion().hasHash(i):
|
# if dandelion and not Dandelion().hasHash(i):
|
||||||
Dandelion().addHash(i, self)
|
# Dandelion().addHash(i, self)
|
||||||
self.handleReceivedInventory(i)
|
# self.handleReceivedInventory(i)
|
||||||
|
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_inv(self):
|
# def bm_command_inv(self):
|
||||||
return self._command_inv(False)
|
# return self._command_inv(False)
|
||||||
|
|
||||||
def bm_command_dinv(self):
|
# def bm_command_dinv(self):
|
||||||
"""
|
# """
|
||||||
Dandelion stem announce
|
# Dandelion stem announce
|
||||||
"""
|
# """
|
||||||
return self._command_inv(True)
|
# return self._command_inv(True)
|
||||||
|
|
||||||
def bm_command_object(self):
|
def bm_command_object(self):
|
||||||
objectOffset = self.payloadOffset
|
objectOffset = self.payloadOffset
|
||||||
|
@ -370,90 +370,90 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
invQueue.put((self.object.streamNumber, self.object.inventoryHash, self.destination))
|
invQueue.put((self.object.streamNumber, self.object.inventoryHash, self.destination))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _decode_addr(self):
|
# def _decode_addr(self):
|
||||||
return self.decode_payload_content("LQIQ16sH")
|
# return self.decode_payload_content("LQIQ16sH")
|
||||||
|
|
||||||
def bm_command_addr(self):
|
# def bm_command_addr(self):
|
||||||
addresses = self._decode_addr()
|
# addresses = self._decode_addr()
|
||||||
for i in addresses:
|
# for i in addresses:
|
||||||
seenTime, stream, services, ip, port = i
|
# seenTime, stream, services, ip, port = i
|
||||||
decodedIP = protocol.checkIPAddress(str(ip))
|
# decodedIP = protocol.checkIPAddress(str(ip))
|
||||||
if stream not in state.streamsInWhichIAmParticipating:
|
# if stream not in state.streamsInWhichIAmParticipating:
|
||||||
continue
|
# continue
|
||||||
if decodedIP is not False and seenTime > time.time() - BMProto.addressAlive:
|
# if decodedIP is not False and seenTime > time.time() - BMProto.addressAlive:
|
||||||
peer = state.Peer(decodedIP, port)
|
# peer = state.Peer(decodedIP, port)
|
||||||
try:
|
# try:
|
||||||
if knownnodes.knownNodes[stream][peer]["lastseen"] > seenTime:
|
# if knownnodes.knownNodes[stream][peer]["lastseen"] > seenTime:
|
||||||
continue
|
# continue
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
pass
|
# pass
|
||||||
if len(knownnodes.knownNodes[stream]) < int(BMConfigParser().get("knownnodes", "maxnodes")):
|
# if len(knownnodes.knownNodes[stream]) < int(BMConfigParser().get("knownnodes", "maxnodes")):
|
||||||
with knownnodes.knownNodesLock:
|
# with knownnodes.knownNodesLock:
|
||||||
try:
|
# try:
|
||||||
knownnodes.knownNodes[stream][peer]["lastseen"] = seenTime
|
# knownnodes.knownNodes[stream][peer]["lastseen"] = seenTime
|
||||||
except (TypeError, KeyError):
|
# except (TypeError, KeyError):
|
||||||
knownnodes.knownNodes[stream][peer] = {
|
# knownnodes.knownNodes[stream][peer] = {
|
||||||
"lastseen": seenTime,
|
# "lastseen": seenTime,
|
||||||
"rating": 0,
|
# "rating": 0,
|
||||||
"self": False,
|
# "self": False,
|
||||||
}
|
# }
|
||||||
addrQueue.put((stream, peer, self.destination))
|
# addrQueue.put((stream, peer, self.destination))
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_portcheck(self):
|
# def bm_command_portcheck(self):
|
||||||
portCheckerQueue.put(state.Peer(self.destination, self.peerNode.port))
|
# portCheckerQueue.put(state.Peer(self.destination, self.peerNode.port))
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_ping(self):
|
# def bm_command_ping(self):
|
||||||
self.append_write_buf(protocol.CreatePacket('pong'))
|
# self.append_write_buf(protocol.CreatePacket('pong'))
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_pong(self):
|
# def bm_command_pong(self):
|
||||||
# nothing really
|
# # nothing really
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_verack(self):
|
# def bm_command_verack(self):
|
||||||
self.verackReceived = True
|
# self.verackReceived = True
|
||||||
if self.verackSent:
|
# if self.verackSent:
|
||||||
if self.isSSL:
|
# if self.isSSL:
|
||||||
self.set_state("tls_init", length=self.payloadLength, expectBytes=0)
|
# self.set_state("tls_init", length=self.payloadLength, expectBytes=0)
|
||||||
return False
|
# return False
|
||||||
self.set_state("connection_fully_established", length=self.payloadLength, expectBytes=0)
|
# self.set_state("connection_fully_established", length=self.payloadLength, expectBytes=0)
|
||||||
return False
|
# return False
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_version(self):
|
# def bm_command_version(self):
|
||||||
self.remoteProtocolVersion, self.services, self.timestamp, self.sockNode, self.peerNode, self.nonce, \
|
# self.remoteProtocolVersion, self.services, self.timestamp, self.sockNode, self.peerNode, self.nonce, \
|
||||||
self.userAgent, self.streams = self.decode_payload_content("IQQiiQlsLv")
|
# self.userAgent, self.streams = self.decode_payload_content("IQQiiQlsLv")
|
||||||
self.nonce = struct.pack('>Q', self.nonce)
|
# self.nonce = struct.pack('>Q', self.nonce)
|
||||||
self.timeOffset = self.timestamp - int(time.time())
|
# self.timeOffset = self.timestamp - int(time.time())
|
||||||
logger.debug("remoteProtocolVersion: %i", self.remoteProtocolVersion)
|
# logger.debug("remoteProtocolVersion: %i", self.remoteProtocolVersion)
|
||||||
logger.debug("services: 0x%08X", self.services)
|
# logger.debug("services: 0x%08X", self.services)
|
||||||
logger.debug("time offset: %i", self.timestamp - int(time.time()))
|
# logger.debug("time offset: %i", self.timestamp - int(time.time()))
|
||||||
logger.debug("my external IP: %s", self.sockNode.host)
|
# logger.debug("my external IP: %s", self.sockNode.host)
|
||||||
logger.debug("remote node incoming address: %s:%i", self.destination.host, self.peerNode.port)
|
# logger.debug("remote node incoming address: %s:%i", self.destination.host, self.peerNode.port)
|
||||||
logger.debug("user agent: %s", self.userAgent)
|
# logger.debug("user agent: %s", self.userAgent)
|
||||||
logger.debug("streams: [%s]", ",".join(map(str,self.streams)))
|
# logger.debug("streams: [%s]", ",".join(map(str,self.streams)))
|
||||||
if not self.peerValidityChecks():
|
# if not self.peerValidityChecks():
|
||||||
# TODO ABORT
|
# # TODO ABORT
|
||||||
return True
|
# return True
|
||||||
#shared.connectedHostsList[self.destination] = self.streams[0]
|
# #shared.connectedHostsList[self.destination] = self.streams[0]
|
||||||
self.append_write_buf(protocol.CreatePacket('verack'))
|
# self.append_write_buf(protocol.CreatePacket('verack'))
|
||||||
self.verackSent = True
|
# self.verackSent = True
|
||||||
if not self.isOutbound:
|
# if not self.isOutbound:
|
||||||
self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
|
# self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
|
||||||
network.connectionpool.BMConnectionPool().streams, True, nodeid=self.nodeid))
|
# network.connectionpool.BMConnectionPool().streams, True, nodeid=self.nodeid))
|
||||||
#print "%s:%i: Sending version" % (self.destination.host, self.destination.port)
|
# #print "%s:%i: Sending version" % (self.destination.host, self.destination.port)
|
||||||
if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL) and
|
# if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL) and
|
||||||
protocol.haveSSL(not self.isOutbound)):
|
# protocol.haveSSL(not self.isOutbound)):
|
||||||
self.isSSL = True
|
# self.isSSL = True
|
||||||
if self.verackReceived:
|
# if self.verackReceived:
|
||||||
if self.isSSL:
|
# if self.isSSL:
|
||||||
self.set_state("tls_init", length=self.payloadLength, expectBytes=0)
|
# self.set_state("tls_init", length=self.payloadLength, expectBytes=0)
|
||||||
return False
|
# return False
|
||||||
self.set_state("connection_fully_established", length=self.payloadLength, expectBytes=0)
|
# self.set_state("connection_fully_established", length=self.payloadLength, expectBytes=0)
|
||||||
return False
|
# return False
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def peerValidityChecks(self):
|
def peerValidityChecks(self):
|
||||||
if self.remoteProtocolVersion < 3:
|
if self.remoteProtocolVersion < 3:
|
||||||
|
|
|
@ -50,13 +50,13 @@ class Dandelion():
|
||||||
stream,
|
stream,
|
||||||
self.poissonTimeout())
|
self.poissonTimeout())
|
||||||
|
|
||||||
def setHashStream(self, hashId, stream=1):
|
# def setHashStream(self, hashId, stream=1):
|
||||||
with self.lock:
|
# with self.lock:
|
||||||
if hashId in self.hashMap:
|
# if hashId in self.hashMap:
|
||||||
self.hashMap[hashId] = Stem(
|
# self.hashMap[hashId] = Stem(
|
||||||
self.hashMap[hashId].child,
|
# self.hashMap[hashId].child,
|
||||||
stream,
|
# stream,
|
||||||
self.poissonTimeout())
|
# self.poissonTimeout())
|
||||||
|
|
||||||
def removeHash(self, hashId, reason="no reason specified"):
|
def removeHash(self, hashId, reason="no reason specified"):
|
||||||
logging.debug("%s entering fluff mode due to %s.", ''.join('%02x'%ord(i) for i in hashId), reason)
|
logging.debug("%s entering fluff mode due to %s.", ''.join('%02x'%ord(i) for i in hashId), reason)
|
||||||
|
@ -72,16 +72,16 @@ class Dandelion():
|
||||||
def objectChildStem(self, hashId):
|
def objectChildStem(self, hashId):
|
||||||
return self.hashMap[hashId].child
|
return self.hashMap[hashId].child
|
||||||
|
|
||||||
def maybeAddStem(self, connection):
|
# def maybeAddStem(self, connection):
|
||||||
# fewer than MAX_STEMS outbound connections at last reshuffle?
|
# # fewer than MAX_STEMS outbound connections at last reshuffle?
|
||||||
with self.lock:
|
# with self.lock:
|
||||||
if len(self.stem) < MAX_STEMS:
|
# if len(self.stem) < MAX_STEMS:
|
||||||
self.stem.append(connection)
|
# self.stem.append(connection)
|
||||||
for k in (k for k, v in self.nodeMap.iteritems() if v is None):
|
# for k in (k for k, v in self.nodeMap.iteritems() if v is None):
|
||||||
self.nodeMap[k] = connection
|
# self.nodeMap[k] = connection
|
||||||
for k, v in {k: v for k, v in self.hashMap.iteritems() if v.child is None}.iteritems():
|
# for k, v in {k: v for k, v in self.hashMap.iteritems() if v.child is None}.iteritems():
|
||||||
self.hashMap[k] = Stem(connection, v.stream, self.poissonTimeout())
|
# self.hashMap[k] = Stem(connection, v.stream, self.poissonTimeout())
|
||||||
invQueue.put((v.stream, k, v.child))
|
# invQueue.put((v.stream, k, v.child))
|
||||||
|
|
||||||
|
|
||||||
def maybeRemoveStem(self, connection):
|
def maybeRemoveStem(self, connection):
|
||||||
|
|
|
@ -12,9 +12,9 @@ import protocol
|
||||||
from state import missingObjects
|
from state import missingObjects
|
||||||
|
|
||||||
class DownloadThread(threading.Thread, StoppableThread):
|
class DownloadThread(threading.Thread, StoppableThread):
|
||||||
minPending = 200
|
# minPending = 200
|
||||||
maxRequestChunk = 1000
|
maxRequestChunk = 1000
|
||||||
requestTimeout = 60
|
# requestTimeout = 60
|
||||||
cleanInterval = 60
|
cleanInterval = 60
|
||||||
requestExpires = 3600
|
requestExpires = 3600
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from proxy import Proxy, ProxyError, GeneralProxyError
|
||||||
from socks5 import Socks5Connection, Socks5Resolver, Socks5AuthError, Socks5Error
|
from socks5 import Socks5Connection, Socks5Resolver, Socks5AuthError, Socks5Error
|
||||||
from socks4a import Socks4aConnection, Socks4aResolver, Socks4aError
|
from socks4a import Socks4aConnection, Socks4aResolver, Socks4aError
|
||||||
|
|
||||||
class HttpError(ProxyError): pass
|
# class HttpError(ProxyError): pass
|
||||||
|
|
||||||
|
|
||||||
class HttpConnection(AdvancedDispatcher):
|
class HttpConnection(AdvancedDispatcher):
|
||||||
|
@ -24,13 +24,13 @@ class HttpConnection(AdvancedDispatcher):
|
||||||
self.set_state("http_request_sent", 0)
|
self.set_state("http_request_sent", 0)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def state_http_request_sent(self):
|
# def state_http_request_sent(self):
|
||||||
if len(self.read_buf) > 0:
|
# if len(self.read_buf) > 0:
|
||||||
print "Received %ib" % (len(self.read_buf))
|
# print "Received %ib" % (len(self.read_buf))
|
||||||
self.read_buf = b""
|
# self.read_buf = b""
|
||||||
if not self.connected:
|
# if not self.connected:
|
||||||
self.set_state("close", 0)
|
# self.set_state("close", 0)
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
|
|
||||||
class Socks5HttpConnection(Socks5Connection, HttpConnection):
|
class Socks5HttpConnection(Socks5Connection, HttpConnection):
|
||||||
|
@ -38,9 +38,9 @@ class Socks5HttpConnection(Socks5Connection, HttpConnection):
|
||||||
self.path = path
|
self.path = path
|
||||||
Socks5Connection.__init__(self, address=(host, 80))
|
Socks5Connection.__init__(self, address=(host, 80))
|
||||||
|
|
||||||
def state_socks_handshake_done(self):
|
# def state_socks_handshake_done(self):
|
||||||
HttpConnection.state_init(self)
|
# HttpConnection.state_init(self)
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
|
|
||||||
class Socks4aHttpConnection(Socks4aConnection, HttpConnection):
|
class Socks4aHttpConnection(Socks4aConnection, HttpConnection):
|
||||||
|
@ -48,9 +48,9 @@ class Socks4aHttpConnection(Socks4aConnection, HttpConnection):
|
||||||
Socks4aConnection.__init__(self, address=(host, 80))
|
Socks4aConnection.__init__(self, address=(host, 80))
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def state_socks_handshake_done(self):
|
# def state_socks_handshake_done(self):
|
||||||
HttpConnection.state_init(self)
|
# HttpConnection.state_init(self)
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -112,7 +112,7 @@ class HTTPServer(asyncore.dispatcher):
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.set_reuse_addr()
|
self.set_reuse_addr()
|
||||||
self.bind(('127.0.0.1', HTTPServer.port))
|
self.bind(('127.0.0.1', HTTPServer.port))
|
||||||
self.connections = 0
|
# self.connections = 0
|
||||||
self.listen(5)
|
self.listen(5)
|
||||||
|
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
|
@ -120,7 +120,7 @@ class HTTPServer(asyncore.dispatcher):
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, addr = pair
|
sock, addr = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
# print 'Incoming connection from %s' % repr(addr)
|
||||||
self.connections += 1
|
# self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
# if self.connections % 1000 == 0:
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
||||||
HTTPRequestHandler(sock)
|
HTTPRequestHandler(sock)
|
||||||
|
@ -138,7 +138,7 @@ class HTTPSServer(HTTPServer):
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, addr = pair
|
sock, addr = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
# print 'Incoming connection from %s' % repr(addr)
|
||||||
self.connections += 1
|
# self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
# if self.connections % 1000 == 0:
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
||||||
HTTPSRequestHandler(sock)
|
HTTPSRequestHandler(sock)
|
||||||
|
|
|
@ -26,10 +26,10 @@ haveBloom = False
|
||||||
|
|
||||||
class ObjectTracker(object):
|
class ObjectTracker(object):
|
||||||
invCleanPeriod = 300
|
invCleanPeriod = 300
|
||||||
invInitialCapacity = 50000
|
# invInitialCapacity = 50000
|
||||||
invErrorRate = 0.03
|
# invErrorRate = 0.03
|
||||||
trackingExpires = 3600
|
trackingExpires = 3600
|
||||||
initialTimeOffset = 60
|
# initialTimeOffset = 60
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.objectsNewToMe = RandomTrackingDict()
|
self.objectsNewToMe = RandomTrackingDict()
|
||||||
|
@ -39,17 +39,17 @@ class ObjectTracker(object):
|
||||||
self.initAddrBloom()
|
self.initAddrBloom()
|
||||||
self.lastCleaned = time.time()
|
self.lastCleaned = time.time()
|
||||||
|
|
||||||
def initInvBloom(self):
|
# def initInvBloom(self):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
# lock?
|
# lock?
|
||||||
self.invBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
|
# self.invBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
|
||||||
error_rate=ObjectTracker.invErrorRate)
|
# error_rate=ObjectTracker.invErrorRate)
|
||||||
|
|
||||||
def initAddrBloom(self):
|
# def initAddrBloom(self):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
# lock?
|
# lock?
|
||||||
self.addrBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
|
# self.addrBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
|
||||||
error_rate=ObjectTracker.invErrorRate)
|
# error_rate=ObjectTracker.invErrorRate)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.lastCleaned < time.time() - ObjectTracker.invCleanPeriod:
|
if self.lastCleaned < time.time() - ObjectTracker.invCleanPeriod:
|
||||||
|
@ -65,23 +65,23 @@ class ObjectTracker(object):
|
||||||
self.objectsNewToThem = {k: v for k, v in self.objectsNewToThem.iteritems() if v >= deadline}
|
self.objectsNewToThem = {k: v for k, v in self.objectsNewToThem.iteritems() if v >= deadline}
|
||||||
self.lastCleaned = time.time()
|
self.lastCleaned = time.time()
|
||||||
|
|
||||||
def hasObj(self, hashid):
|
# def hasObj(self, hashid):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
return hashid in self.invBloom
|
# return hashid in self.invBloom
|
||||||
else:
|
# else:
|
||||||
return hashid in self.objectsNewToMe
|
# return hashid in self.objectsNewToMe
|
||||||
|
|
||||||
def handleReceivedInventory(self, hashId):
|
# def handleReceivedInventory(self, hashId):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
self.invBloom.add(hashId)
|
# self.invBloom.add(hashId)
|
||||||
try:
|
# try:
|
||||||
with self.objectsNewToThemLock:
|
# with self.objectsNewToThemLock:
|
||||||
del self.objectsNewToThem[hashId]
|
# del self.objectsNewToThem[hashId]
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
pass
|
# pass
|
||||||
if hashId not in missingObjects:
|
# if hashId not in missingObjects:
|
||||||
missingObjects[hashId] = time.time()
|
# missingObjects[hashId] = time.time()
|
||||||
self.objectsNewToMe[hashId] = True
|
# self.objectsNewToMe[hashId] = True
|
||||||
|
|
||||||
def handleReceivedObject(self, streamNumber, hashid):
|
def handleReceivedObject(self, streamNumber, hashid):
|
||||||
for i in network.connectionpool.BMConnectionPool().inboundConnections.values() + network.connectionpool.BMConnectionPool().outboundConnections.values():
|
for i in network.connectionpool.BMConnectionPool().inboundConnections.values() + network.connectionpool.BMConnectionPool().outboundConnections.values():
|
||||||
|
@ -106,13 +106,13 @@ class ObjectTracker(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def hasAddr(self, addr):
|
# def hasAddr(self, addr):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
return addr in self.invBloom
|
# return addr in self.invBloom
|
||||||
|
|
||||||
def addAddr(self, hashid):
|
# def addAddr(self, hashid):
|
||||||
if haveBloom:
|
# if haveBloom:
|
||||||
self.addrBloom.add(hashid)
|
# self.addrBloom.add(hashid)
|
||||||
|
|
||||||
# addr sending -> per node upload queue, and flush every minute or so
|
# addr sending -> per node upload queue, and flush every minute or so
|
||||||
# inv sending -> if not in bloom, inv immediately, otherwise put into a per node upload queue and flush every minute or so
|
# inv sending -> if not in bloom, inv immediately, otherwise put into a per node upload queue and flush every minute or so
|
||||||
|
|
|
@ -71,13 +71,13 @@ class Proxy(AdvancedDispatcher):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
self.__class__._onion_proxy = address
|
self.__class__._onion_proxy = address
|
||||||
|
|
||||||
@property
|
# @property
|
||||||
def onion_auth(self):
|
# def onion_auth(self):
|
||||||
return self.__class__._onion_auth
|
# return self.__class__._onion_auth
|
||||||
|
|
||||||
@onion_auth.setter
|
# @onion_auth.setter
|
||||||
def onion_auth(self, authTuple):
|
# def onion_auth(self, authTuple):
|
||||||
self.__class__._onion_auth = authTuple
|
# self.__class__._onion_auth = authTuple
|
||||||
|
|
||||||
def __init__(self, address):
|
def __init__(self, address):
|
||||||
if not isinstance(address, state.Peer):
|
if not isinstance(address, state.Peer):
|
||||||
|
|
|
@ -54,33 +54,33 @@ class Socks4aConnection(Socks4a):
|
||||||
def __init__(self, address):
|
def __init__(self, address):
|
||||||
Socks4a.__init__(self, address=address)
|
Socks4a.__init__(self, address=address)
|
||||||
|
|
||||||
def state_auth_done(self):
|
# def state_auth_done(self):
|
||||||
# Now we can request the actual connection
|
# # Now we can request the actual connection
|
||||||
rmtrslv = False
|
# rmtrslv = False
|
||||||
self.append_write_buf(struct.pack('>BBH', 0x04, 0x01, self.destination[1]))
|
# self.append_write_buf(struct.pack('>BBH', 0x04, 0x01, self.destination[1]))
|
||||||
# If the given destination address is an IP address, we'll
|
# # If the given destination address is an IP address, we'll
|
||||||
# use the IPv4 address request even if remote resolving was specified.
|
# # use the IPv4 address request even if remote resolving was specified.
|
||||||
try:
|
# try:
|
||||||
self.ipaddr = socket.inet_aton(self.destination[0])
|
# self.ipaddr = socket.inet_aton(self.destination[0])
|
||||||
self.append_write_buf(self.ipaddr)
|
# self.append_write_buf(self.ipaddr)
|
||||||
except socket.error:
|
# except socket.error:
|
||||||
# Well it's not an IP number, so it's probably a DNS name.
|
# # Well it's not an IP number, so it's probably a DNS name.
|
||||||
if Proxy._remote_dns:
|
# if Proxy._remote_dns:
|
||||||
# Resolve remotely
|
# # Resolve remotely
|
||||||
rmtrslv = True
|
# rmtrslv = True
|
||||||
self.ipaddr = None
|
# self.ipaddr = None
|
||||||
self.append_write_buf(struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01))
|
# self.append_write_buf(struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01))
|
||||||
else:
|
# else:
|
||||||
# Resolve locally
|
# # Resolve locally
|
||||||
self.ipaddr = socket.inet_aton(socket.gethostbyname(self.destination[0]))
|
# self.ipaddr = socket.inet_aton(socket.gethostbyname(self.destination[0]))
|
||||||
self.append_write_buf(self.ipaddr)
|
# self.append_write_buf(self.ipaddr)
|
||||||
if self._auth:
|
# if self._auth:
|
||||||
self.append_write_buf(self._auth[0])
|
# self.append_write_buf(self._auth[0])
|
||||||
self.append_write_buf(chr(0x00).encode())
|
# self.append_write_buf(chr(0x00).encode())
|
||||||
if rmtrslv:
|
# if rmtrslv:
|
||||||
self.append_write_buf(self.destination[0] + chr(0x00).encode())
|
# self.append_write_buf(self.destination[0] + chr(0x00).encode())
|
||||||
self.set_state("pre_connect", length=0, expectBytes=8)
|
# self.set_state("pre_connect", length=0, expectBytes=8)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_pre_connect(self):
|
def state_pre_connect(self):
|
||||||
try:
|
try:
|
||||||
|
@ -96,16 +96,16 @@ class Socks4aResolver(Socks4a):
|
||||||
self.port = 8444
|
self.port = 8444
|
||||||
Socks4a.__init__(self, address=(self.host, self.port))
|
Socks4a.__init__(self, address=(self.host, self.port))
|
||||||
|
|
||||||
def state_auth_done(self):
|
# def state_auth_done(self):
|
||||||
# Now we can request the actual connection
|
# # Now we can request the actual connection
|
||||||
self.append_write_buf(struct.pack('>BBH', 0x04, 0xF0, self.destination[1]))
|
# self.append_write_buf(struct.pack('>BBH', 0x04, 0xF0, self.destination[1]))
|
||||||
self.append_write_buf(struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01))
|
# self.append_write_buf(struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01))
|
||||||
if self._auth:
|
# if self._auth:
|
||||||
self.append_write_buf(self._auth[0])
|
# self.append_write_buf(self._auth[0])
|
||||||
self.append_write_buf(chr(0x00).encode())
|
# self.append_write_buf(chr(0x00).encode())
|
||||||
self.append_write_buf(self.host + chr(0x00).encode())
|
# self.append_write_buf(self.host + chr(0x00).encode())
|
||||||
self.set_state("pre_connect", length=0, expectBytes=8)
|
# self.set_state("pre_connect", length=0, expectBytes=8)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def resolved(self):
|
def resolved(self):
|
||||||
print "Resolved %s as %s" % (self.host, self.proxy_sock_name())
|
print "Resolved %s as %s" % (self.host, self.proxy_sock_name())
|
||||||
|
|
|
@ -38,40 +38,40 @@ class Socks5(Proxy):
|
||||||
self.set_state("auth_1", length=0, expectBytes=2)
|
self.set_state("auth_1", length=0, expectBytes=2)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def state_auth_1(self):
|
# def state_auth_1(self):
|
||||||
ret = struct.unpack('BB', self.read_buf)
|
# ret = struct.unpack('BB', self.read_buf)
|
||||||
if ret[0] != 5:
|
# if ret[0] != 5:
|
||||||
# general error
|
# # general error
|
||||||
raise GeneralProxyError(1)
|
# raise GeneralProxyError(1)
|
||||||
elif ret[1] == 0:
|
# elif ret[1] == 0:
|
||||||
# no auth required
|
# # no auth required
|
||||||
self.set_state("auth_done", length=2)
|
# self.set_state("auth_done", length=2)
|
||||||
elif ret[1] == 2:
|
# elif ret[1] == 2:
|
||||||
# username/password
|
# # username/password
|
||||||
self.append_write_buf(struct.pack('BB', 1, len(self._auth[0])) + \
|
# self.append_write_buf(struct.pack('BB', 1, len(self._auth[0])) + \
|
||||||
self._auth[0] + struct.pack('B', len(self._auth[1])) + \
|
# self._auth[0] + struct.pack('B', len(self._auth[1])) + \
|
||||||
self._auth[1])
|
# self._auth[1])
|
||||||
self.set_state("auth_needed", length=2, expectBytes=2)
|
# self.set_state("auth_needed", length=2, expectBytes=2)
|
||||||
else:
|
# else:
|
||||||
if ret[1] == 0xff:
|
# if ret[1] == 0xff:
|
||||||
# auth error
|
# # auth error
|
||||||
raise Socks5AuthError(2)
|
# raise Socks5AuthError(2)
|
||||||
else:
|
# else:
|
||||||
# other error
|
# # other error
|
||||||
raise GeneralProxyError(1)
|
# raise GeneralProxyError(1)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_auth_needed(self):
|
# def state_auth_needed(self):
|
||||||
ret = struct.unpack('BB', self.read_buf[0:2])
|
# ret = struct.unpack('BB', self.read_buf[0:2])
|
||||||
if ret[0] != 1:
|
# if ret[0] != 1:
|
||||||
# general error
|
# # general error
|
||||||
raise GeneralProxyError(1)
|
# raise GeneralProxyError(1)
|
||||||
if ret[1] != 0:
|
# if ret[1] != 0:
|
||||||
# auth error
|
# # auth error
|
||||||
raise Socks5AuthError(3)
|
# raise Socks5AuthError(3)
|
||||||
# all ok
|
# # all ok
|
||||||
self.set_state("auth_done", length=2)
|
# self.set_state("auth_done", length=2)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_pre_connect(self):
|
def state_pre_connect(self):
|
||||||
# Get the response
|
# Get the response
|
||||||
|
@ -95,30 +95,30 @@ class Socks5(Proxy):
|
||||||
raise GeneralProxyError(1)
|
raise GeneralProxyError(1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def state_proxy_addr_1(self):
|
# def state_proxy_addr_1(self):
|
||||||
self.boundaddr = self.read_buf[0:4]
|
# self.boundaddr = self.read_buf[0:4]
|
||||||
self.set_state("proxy_port", length=4, expectBytes=2)
|
# self.set_state("proxy_port", length=4, expectBytes=2)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_proxy_addr_2_1(self):
|
# def state_proxy_addr_2_1(self):
|
||||||
self.address_length = ord(self.read_buf[0:1])
|
# self.address_length = ord(self.read_buf[0:1])
|
||||||
self.set_state("proxy_addr_2_2", length=1, expectBytes=self.address_length)
|
# self.set_state("proxy_addr_2_2", length=1, expectBytes=self.address_length)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_proxy_addr_2_2(self):
|
# def state_proxy_addr_2_2(self):
|
||||||
self.boundaddr = self.read_buf[0:self.address_length]
|
# self.boundaddr = self.read_buf[0:self.address_length]
|
||||||
self.set_state("proxy_port", length=self.address_length, expectBytes=2)
|
# self.set_state("proxy_port", length=self.address_length, expectBytes=2)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_proxy_port(self):
|
# def state_proxy_port(self):
|
||||||
self.boundport = struct.unpack(">H", self.read_buf[0:2])[0]
|
# self.boundport = struct.unpack(">H", self.read_buf[0:2])[0]
|
||||||
self.__proxysockname = (self.boundaddr, self.boundport)
|
# self.__proxysockname = (self.boundaddr, self.boundport)
|
||||||
if self.ipaddr is not None:
|
# if self.ipaddr is not None:
|
||||||
self.__proxypeername = (socket.inet_ntoa(self.ipaddr), self.destination[1])
|
# self.__proxypeername = (socket.inet_ntoa(self.ipaddr), self.destination[1])
|
||||||
else:
|
# else:
|
||||||
self.__proxypeername = (self.destination[0], self.destport)
|
# self.__proxypeername = (self.destination[0], self.destport)
|
||||||
self.set_state("proxy_handshake_done", length=2)
|
# self.set_state("proxy_handshake_done", length=2)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def proxy_sock_name(self):
|
def proxy_sock_name(self):
|
||||||
return socket.inet_ntoa(self.__proxysockname[0])
|
return socket.inet_ntoa(self.__proxysockname[0])
|
||||||
|
@ -128,27 +128,27 @@ class Socks5Connection(Socks5):
|
||||||
def __init__(self, address):
|
def __init__(self, address):
|
||||||
Socks5.__init__(self, address=address)
|
Socks5.__init__(self, address=address)
|
||||||
|
|
||||||
def state_auth_done(self):
|
# def state_auth_done(self):
|
||||||
# Now we can request the actual connection
|
# # Now we can request the actual connection
|
||||||
self.append_write_buf(struct.pack('BBB', 0x05, 0x01, 0x00))
|
# self.append_write_buf(struct.pack('BBB', 0x05, 0x01, 0x00))
|
||||||
# If the given destination address is an IP address, we'll
|
# # If the given destination address is an IP address, we'll
|
||||||
# use the IPv4 address request even if remote resolving was specified.
|
# # use the IPv4 address request even if remote resolving was specified.
|
||||||
try:
|
# try:
|
||||||
self.ipaddr = socket.inet_aton(self.destination[0])
|
# self.ipaddr = socket.inet_aton(self.destination[0])
|
||||||
self.append_write_buf(chr(0x01).encode() + self.ipaddr)
|
# self.append_write_buf(chr(0x01).encode() + self.ipaddr)
|
||||||
except socket.error:
|
# except socket.error:
|
||||||
# Well it's not an IP number, so it's probably a DNS name.
|
# # Well it's not an IP number, so it's probably a DNS name.
|
||||||
if Proxy._remote_dns:
|
# if Proxy._remote_dns:
|
||||||
# Resolve remotely
|
# # Resolve remotely
|
||||||
self.ipaddr = None
|
# self.ipaddr = None
|
||||||
self.append_write_buf(chr(0x03).encode() + chr(len(self.destination[0])).encode() + self.destination[0])
|
# self.append_write_buf(chr(0x03).encode() + chr(len(self.destination[0])).encode() + self.destination[0])
|
||||||
else:
|
# else:
|
||||||
# Resolve locally
|
# # Resolve locally
|
||||||
self.ipaddr = socket.inet_aton(socket.gethostbyname(self.destination[0]))
|
# self.ipaddr = socket.inet_aton(socket.gethostbyname(self.destination[0]))
|
||||||
self.append_write_buf(chr(0x01).encode() + self.ipaddr)
|
# self.append_write_buf(chr(0x01).encode() + self.ipaddr)
|
||||||
self.append_write_buf(struct.pack(">H", self.destination[1]))
|
# self.append_write_buf(struct.pack(">H", self.destination[1]))
|
||||||
self.set_state("pre_connect", length=0, expectBytes=4)
|
# self.set_state("pre_connect", length=0, expectBytes=4)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def state_pre_connect(self):
|
def state_pre_connect(self):
|
||||||
try:
|
try:
|
||||||
|
@ -164,13 +164,13 @@ class Socks5Resolver(Socks5):
|
||||||
self.port = 8444
|
self.port = 8444
|
||||||
Socks5.__init__(self, address=(self.host, self.port))
|
Socks5.__init__(self, address=(self.host, self.port))
|
||||||
|
|
||||||
def state_auth_done(self):
|
# def state_auth_done(self):
|
||||||
# Now we can request the actual connection
|
# # Now we can request the actual connection
|
||||||
self.append_write_buf(struct.pack('BBB', 0x05, 0xF0, 0x00))
|
# self.append_write_buf(struct.pack('BBB', 0x05, 0xF0, 0x00))
|
||||||
self.append_write_buf(chr(0x03).encode() + chr(len(self.host)).encode() + str(self.host))
|
# self.append_write_buf(chr(0x03).encode() + chr(len(self.host)).encode() + str(self.host))
|
||||||
self.append_write_buf(struct.pack(">H", self.port))
|
# self.append_write_buf(struct.pack(">H", self.port))
|
||||||
self.set_state("pre_connect", length=0, expectBytes=4)
|
# self.set_state("pre_connect", length=0, expectBytes=4)
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def resolved(self):
|
def resolved(self):
|
||||||
print "Resolved %s as %s" % (self.host, self.proxy_sock_name())
|
print "Resolved %s as %s" % (self.host, self.proxy_sock_name())
|
||||||
|
|
|
@ -66,10 +66,10 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
self.connect(self.destination)
|
self.connect(self.destination)
|
||||||
logger.debug("Connecting to %s:%i", self.destination.host, self.destination.port)
|
logger.debug("Connecting to %s:%i", self.destination.host, self.destination.port)
|
||||||
encodedAddr = protocol.encodeHost(self.destination.host)
|
encodedAddr = protocol.encodeHost(self.destination.host)
|
||||||
if protocol.checkIPAddress(encodedAddr, True) and not protocol.checkSocksIP(self.destination.host):
|
# if protocol.checkIPAddress(encodedAddr, True) and not protocol.checkSocksIP(self.destination.host):
|
||||||
self.local = True
|
# self.local = True
|
||||||
else:
|
# else:
|
||||||
self.local = False
|
# self.local = False
|
||||||
#shared.connectedHostsList[self.destination] = 0
|
#shared.connectedHostsList[self.destination] = 0
|
||||||
ObjectTracker.__init__(self)
|
ObjectTracker.__init__(self)
|
||||||
self.bm_proto_reset()
|
self.bm_proto_reset()
|
||||||
|
@ -91,68 +91,68 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
logger.debug("Skipping processing getdata due to missing object for %.2fs", delay)
|
logger.debug("Skipping processing getdata due to missing object for %.2fs", delay)
|
||||||
self.skipUntil = time.time() + delay
|
self.skipUntil = time.time() + delay
|
||||||
|
|
||||||
def state_connection_fully_established(self):
|
# def state_connection_fully_established(self):
|
||||||
self.set_connection_fully_established()
|
# self.set_connection_fully_established()
|
||||||
self.set_state("bm_header")
|
# self.set_state("bm_header")
|
||||||
self.bm_proto_reset()
|
# self.bm_proto_reset()
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def set_connection_fully_established(self):
|
# def set_connection_fully_established(self):
|
||||||
if not self.isOutbound and not self.local:
|
# if not self.isOutbound and not self.local:
|
||||||
shared.clientHasReceivedIncomingConnections = True
|
# shared.clientHasReceivedIncomingConnections = True
|
||||||
UISignalQueue.put(('setStatusIcon', 'green'))
|
# UISignalQueue.put(('setStatusIcon', 'green'))
|
||||||
UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, True, self.destination)))
|
# UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, True, self.destination)))
|
||||||
self.antiIntersectionDelay(True)
|
# self.antiIntersectionDelay(True)
|
||||||
self.fullyEstablished = True
|
# self.fullyEstablished = True
|
||||||
if self.isOutbound:
|
# if self.isOutbound:
|
||||||
knownnodes.increaseRating(self.destination)
|
# knownnodes.increaseRating(self.destination)
|
||||||
if self.isOutbound:
|
# if self.isOutbound:
|
||||||
Dandelion().maybeAddStem(self)
|
# Dandelion().maybeAddStem(self)
|
||||||
self.sendAddr()
|
# self.sendAddr()
|
||||||
self.sendBigInv()
|
# self.sendBigInv()
|
||||||
|
|
||||||
def sendAddr(self):
|
# def sendAddr(self):
|
||||||
# We are going to share a maximum number of 1000 addrs (per overlapping
|
# # We are going to share a maximum number of 1000 addrs (per overlapping
|
||||||
# stream) with our peer. 500 from overlapping streams, 250 from the
|
# # stream) with our peer. 500 from overlapping streams, 250 from the
|
||||||
# left child stream, and 250 from the right child stream.
|
# # left child stream, and 250 from the right child stream.
|
||||||
maxAddrCount = BMConfigParser().safeGetInt("bitmessagesettings", "maxaddrperstreamsend", 500)
|
# maxAddrCount = BMConfigParser().safeGetInt("bitmessagesettings", "maxaddrperstreamsend", 500)
|
||||||
|
|
||||||
# init
|
# # init
|
||||||
addressCount = 0
|
# # addressCount = 0
|
||||||
payload = b''
|
# payload = b''
|
||||||
|
|
||||||
templist = []
|
# templist = []
|
||||||
addrs = {}
|
# addrs = {}
|
||||||
for stream in self.streams:
|
# for stream in self.streams:
|
||||||
with knownnodes.knownNodesLock:
|
# with knownnodes.knownNodesLock:
|
||||||
if len(knownnodes.knownNodes[stream]) > 0:
|
# if len(knownnodes.knownNodes[stream]) > 0:
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream].items()
|
# filtered = {k: v for k, v in knownnodes.knownNodes[stream].items()
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
# if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
||||||
elemCount = len(filtered)
|
# elemCount = len(filtered)
|
||||||
if elemCount > maxAddrCount:
|
# if elemCount > maxAddrCount:
|
||||||
elemCount = maxAddrCount
|
# elemCount = maxAddrCount
|
||||||
# only if more recent than 3 hours
|
# # only if more recent than 3 hours
|
||||||
addrs[stream] = random.sample(filtered.items(), elemCount)
|
# addrs[stream] = random.sample(filtered.items(), elemCount)
|
||||||
# sent 250 only if the remote isn't interested in it
|
# # sent 250 only if the remote isn't interested in it
|
||||||
if len(knownnodes.knownNodes[stream * 2]) > 0 and stream not in self.streams:
|
# if len(knownnodes.knownNodes[stream * 2]) > 0 and stream not in self.streams:
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items()
|
# filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items()
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
# if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
||||||
elemCount = len(filtered)
|
# elemCount = len(filtered)
|
||||||
if elemCount > maxAddrCount / 2:
|
# if elemCount > maxAddrCount / 2:
|
||||||
elemCount = int(maxAddrCount / 2)
|
# elemCount = int(maxAddrCount / 2)
|
||||||
addrs[stream * 2] = random.sample(filtered.items(), elemCount)
|
# addrs[stream * 2] = random.sample(filtered.items(), elemCount)
|
||||||
if len(knownnodes.knownNodes[(stream * 2) + 1]) > 0 and stream not in self.streams:
|
# if len(knownnodes.knownNodes[(stream * 2) + 1]) > 0 and stream not in self.streams:
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream*2+1].items()
|
# filtered = {k: v for k, v in knownnodes.knownNodes[stream*2+1].items()
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
# if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
||||||
elemCount = len(filtered)
|
# elemCount = len(filtered)
|
||||||
if elemCount > maxAddrCount / 2:
|
# if elemCount > maxAddrCount / 2:
|
||||||
elemCount = int(maxAddrCount / 2)
|
# elemCount = int(maxAddrCount / 2)
|
||||||
addrs[stream * 2 + 1] = random.sample(filtered.items(), elemCount)
|
# addrs[stream * 2 + 1] = random.sample(filtered.items(), elemCount)
|
||||||
for substream in addrs.keys():
|
# for substream in addrs.keys():
|
||||||
for peer, params in addrs[substream]:
|
# for peer, params in addrs[substream]:
|
||||||
templist.append((substream, peer, params["lastseen"]))
|
# templist.append((substream, peer, params["lastseen"]))
|
||||||
if len(templist) > 0:
|
# if len(templist) > 0:
|
||||||
self.append_write_buf(BMProto.assembleAddr(templist))
|
# self.append_write_buf(BMProto.assembleAddr(templist))
|
||||||
|
|
||||||
def sendBigInv(self):
|
def sendBigInv(self):
|
||||||
def sendChunk():
|
def sendChunk():
|
||||||
|
@ -275,14 +275,14 @@ class TCPServer(AdvancedDispatcher):
|
||||||
BMConfigParser().save()
|
BMConfigParser().save()
|
||||||
break
|
break
|
||||||
self.destination = state.Peer(host, port)
|
self.destination = state.Peer(host, port)
|
||||||
self.bound = True
|
# self.bound = True
|
||||||
self.listen(5)
|
self.listen(5)
|
||||||
|
|
||||||
def is_bound(self):
|
# def is_bound(self):
|
||||||
try:
|
# try:
|
||||||
return self.bound
|
# return self.bound
|
||||||
except AttributeError:
|
# except AttributeError:
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
|
@ -314,12 +314,12 @@ if __name__ == "__main__":
|
||||||
asyncore.loop(timeout=10, count=1)
|
asyncore.loop(timeout=10, count=1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
proxy = Socks5BMConnection(host)
|
# proxy = Socks5BMConnection(host)
|
||||||
while len(asyncore.socket_map) > 0:
|
# while len(asyncore.socket_map) > 0:
|
||||||
# print "loop, state = %s" % (proxy.state)
|
# print "loop, state = %s" % (proxy.state)
|
||||||
asyncore.loop(timeout=10, count=1)
|
# asyncore.loop(timeout=10, count=1)
|
||||||
|
|
||||||
proxy = Socks4aBMConnection(host)
|
# proxy = Socks4aBMConnection(host)
|
||||||
while len(asyncore.socket_map) > 0:
|
# while len(asyncore.socket_map) > 0:
|
||||||
# print "loop, state = %s" % (proxy.state)
|
# print "loop, state = %s" % (proxy.state)
|
||||||
asyncore.loop(timeout=10, count=1)
|
# asyncore.loop(timeout=10, count=1)
|
||||||
|
|
|
@ -20,52 +20,52 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
def __init__(self, address=None, sock=None,
|
def __init__(self, address=None, sock=None,
|
||||||
certfile=None, keyfile=None, server_side=False, ciphers=protocol.sslProtocolCiphers):
|
certfile=None, keyfile=None, server_side=False, ciphers=protocol.sslProtocolCiphers):
|
||||||
self.want_read = self.want_write = True
|
self.want_read = self.want_write = True
|
||||||
if certfile is None:
|
# if certfile is None:
|
||||||
self.certfile = os.path.join(paths.codePath(), 'sslkeys', 'cert.pem')
|
# self.certfile = os.path.join(paths.codePath(), 'sslkeys', 'cert.pem')
|
||||||
else:
|
# else:
|
||||||
self.certfile = certfile
|
# self.certfile = certfile
|
||||||
if keyfile is None:
|
# if keyfile is None:
|
||||||
self.keyfile = os.path.join(paths.codePath(), 'sslkeys', 'key.pem')
|
# self.keyfile = os.path.join(paths.codePath(), 'sslkeys', 'key.pem')
|
||||||
else:
|
# else:
|
||||||
self.keyfile = keyfile
|
# self.keyfile = keyfile
|
||||||
self.server_side = server_side
|
# self.server_side = server_side
|
||||||
self.ciphers = ciphers
|
# self.ciphers = ciphers
|
||||||
self.tlsStarted = False
|
self.tlsStarted = False
|
||||||
self.tlsDone = False
|
self.tlsDone = False
|
||||||
self.tlsVersion = "N/A"
|
self.tlsVersion = "N/A"
|
||||||
self.isSSL = False
|
# self.isSSL = False
|
||||||
|
|
||||||
def state_tls_init(self):
|
# def state_tls_init(self):
|
||||||
self.isSSL = True
|
# self.isSSL = True
|
||||||
self.tlsStarted = True
|
# self.tlsStarted = True
|
||||||
# Once the connection has been established, it's safe to wrap the
|
# # Once the connection has been established, it's safe to wrap the
|
||||||
# socket.
|
# # socket.
|
||||||
if sys.version_info >= (2,7,9):
|
# if sys.version_info >= (2,7,9):
|
||||||
context = ssl.create_default_context(purpose = ssl.Purpose.SERVER_AUTH if self.server_side else ssl.Purpose.CLIENT_AUTH)
|
# context = ssl.create_default_context(purpose = ssl.Purpose.SERVER_AUTH if self.server_side else ssl.Purpose.CLIENT_AUTH)
|
||||||
context.set_ciphers(self.ciphers)
|
# context.set_ciphers(self.ciphers)
|
||||||
context.set_ecdh_curve("secp256k1")
|
# context.set_ecdh_curve("secp256k1")
|
||||||
context.check_hostname = False
|
# context.check_hostname = False
|
||||||
context.verify_mode = ssl.CERT_NONE
|
# context.verify_mode = ssl.CERT_NONE
|
||||||
# also exclude TLSv1 and TLSv1.1 in the future
|
# # also exclude TLSv1 and TLSv1.1 in the future
|
||||||
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
# context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
|
||||||
self.sslSocket = context.wrap_socket(self.socket, server_side = self.server_side, do_handshake_on_connect=False)
|
# self.sslSocket = context.wrap_socket(self.socket, server_side = self.server_side, do_handshake_on_connect=False)
|
||||||
else:
|
# else:
|
||||||
self.sslSocket = ssl.wrap_socket(self.socket,
|
# self.sslSocket = ssl.wrap_socket(self.socket,
|
||||||
server_side=self.server_side,
|
# server_side=self.server_side,
|
||||||
ssl_version=protocol.sslProtocolVersion,
|
# ssl_version=protocol.sslProtocolVersion,
|
||||||
certfile=self.certfile,
|
# certfile=self.certfile,
|
||||||
keyfile=self.keyfile,
|
# keyfile=self.keyfile,
|
||||||
ciphers=self.ciphers,
|
# ciphers=self.ciphers,
|
||||||
do_handshake_on_connect=False)
|
# do_handshake_on_connect=False)
|
||||||
self.sslSocket.setblocking(0)
|
# self.sslSocket.setblocking(0)
|
||||||
self.want_read = self.want_write = True
|
# self.want_read = self.want_write = True
|
||||||
self.set_state("tls_handshake")
|
# self.set_state("tls_handshake")
|
||||||
return False
|
# return False
|
||||||
# if hasattr(self.socket, "context"):
|
# # if hasattr(self.socket, "context"):
|
||||||
# self.socket.context.set_ecdh_curve("secp256k1")
|
# # self.socket.context.set_ecdh_curve("secp256k1")
|
||||||
|
|
||||||
def state_tls_handshake(self):
|
# def state_tls_handshake(self):
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def writable(self):
|
def writable(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -69,55 +69,55 @@ class UDPSocket(BMProto):
|
||||||
def bm_command_error(self):
|
def bm_command_error(self):
|
||||||
return BMProto.bm_command_error(self)
|
return BMProto.bm_command_error(self)
|
||||||
|
|
||||||
def bm_command_getdata(self):
|
# def bm_command_getdata(self):
|
||||||
return True
|
# return True
|
||||||
# return BMProto.bm_command_getdata(self)
|
# return BMProto.bm_command_getdata(self)
|
||||||
|
|
||||||
def bm_command_inv(self):
|
# def bm_command_inv(self):
|
||||||
return True
|
# return True
|
||||||
# return BMProto.bm_command_inv(self)
|
# return BMProto.bm_command_inv(self)
|
||||||
|
|
||||||
def bm_command_object(self):
|
def bm_command_object(self):
|
||||||
return BMProto.bm_command_object(self)
|
return BMProto.bm_command_object(self)
|
||||||
|
|
||||||
def bm_command_addr(self):
|
# def bm_command_addr(self):
|
||||||
# BMProto.bm_command_object(self)
|
# BMProto.bm_command_object(self)
|
||||||
addresses = self._decode_addr()
|
# addresses = self._decode_addr()
|
||||||
# only allow peer discovery from private IPs in order to avoid attacks from random IPs on the internet
|
# only allow peer discovery from private IPs in order to avoid attacks from random IPs on the internet
|
||||||
if not self.local:
|
# if not self.local:
|
||||||
return True
|
# return True
|
||||||
remoteport = False
|
# remoteport = False
|
||||||
for i in addresses:
|
# for i in addresses:
|
||||||
seenTime, stream, services, ip, port = i
|
# seenTime, stream, services, ip, port = i
|
||||||
decodedIP = protocol.checkIPAddress(str(ip))
|
# decodedIP = protocol.checkIPAddress(str(ip))
|
||||||
if stream not in state.streamsInWhichIAmParticipating:
|
# if stream not in state.streamsInWhichIAmParticipating:
|
||||||
continue
|
# continue
|
||||||
if seenTime < time.time() - BMProto.maxTimeOffset or seenTime > time.time() + BMProto.maxTimeOffset:
|
# if seenTime < time.time() - BMProto.maxTimeOffset or seenTime > time.time() + BMProto.maxTimeOffset:
|
||||||
continue
|
# continue
|
||||||
if decodedIP is False:
|
# if decodedIP is False:
|
||||||
# if the address isn't local, interpret it as the hosts' own announcement
|
# # if the address isn't local, interpret it as the hosts' own announcement
|
||||||
remoteport = port
|
# remoteport = port
|
||||||
if remoteport is False:
|
# if remoteport is False:
|
||||||
return True
|
# return True
|
||||||
logger.debug("received peer discovery from %s:%i (port %i):", self.destination.host, self.destination.port, remoteport)
|
# logger.debug("received peer discovery from %s:%i (port %i):", self.destination.host, self.destination.port, remoteport)
|
||||||
if self.local:
|
# if self.local:
|
||||||
state.discoveredPeers[state.Peer(self.destination.host, remoteport)] = time.time()
|
# state.discoveredPeers[state.Peer(self.destination.host, remoteport)] = time.time()
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_portcheck(self):
|
# def bm_command_portcheck(self):
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_ping(self):
|
# def bm_command_ping(self):
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_pong(self):
|
# def bm_command_pong(self):
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_verack(self):
|
# def bm_command_verack(self):
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def bm_command_version(self):
|
# def bm_command_version(self):
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
def handle_connect(self):
|
def handle_connect(self):
|
||||||
return
|
return
|
||||||
|
@ -137,10 +137,10 @@ class UDPSocket(BMProto):
|
||||||
|
|
||||||
self.destination = state.Peer(addr[0], addr[1])
|
self.destination = state.Peer(addr[0], addr[1])
|
||||||
encodedAddr = protocol.encodeHost(addr[0])
|
encodedAddr = protocol.encodeHost(addr[0])
|
||||||
if protocol.checkIPAddress(encodedAddr, True):
|
# if protocol.checkIPAddress(encodedAddr, True):
|
||||||
self.local = True
|
# self.local = True
|
||||||
else:
|
# else:
|
||||||
self.local = False
|
# self.local = False
|
||||||
# overwrite the old buffer to avoid mixing data and so that self.local works correctly
|
# overwrite the old buffer to avoid mixing data and so that self.local works correctly
|
||||||
self.read_buf[0:] = recdata
|
self.read_buf[0:] = recdata
|
||||||
self.bm_proto_reset()
|
self.bm_proto_reset()
|
||||||
|
@ -165,12 +165,12 @@ if __name__ == "__main__":
|
||||||
asyncore.loop(timeout=10, count=1)
|
asyncore.loop(timeout=10, count=1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
proxy = Socks5BMConnection(host)
|
# proxy = Socks5BMConnection(host)
|
||||||
while len(asyncore.socket_map) > 0:
|
# while len(asyncore.socket_map) > 0:
|
||||||
# print "loop, state = %s" % (proxy.state)
|
# print "loop, state = %s" % (proxy.state)
|
||||||
asyncore.loop(timeout=10, count=1)
|
# asyncore.loop(timeout=10, count=1)
|
||||||
|
|
||||||
proxy = Socks4aBMConnection(host)
|
# proxy = Socks4aBMConnection(host)
|
||||||
while len(asyncore.socket_map) > 0:
|
# while len(asyncore.socket_map) > 0:
|
||||||
# print "loop, state = %s" % (proxy.state)
|
# print "loop, state = %s" % (proxy.state)
|
||||||
asyncore.loop(timeout=10, count=1)
|
# asyncore.loop(timeout=10, count=1)
|
||||||
|
|
4
src/openclpow.py
Normal file → Executable file
4
src/openclpow.py
Normal file → Executable file
|
@ -92,11 +92,11 @@ def do_opencl_pow(hash, target):
|
||||||
cl.enqueue_read_buffer(queue, dest_buf, output)
|
cl.enqueue_read_buffer(queue, dest_buf, output)
|
||||||
queue.finish()
|
queue.finish()
|
||||||
progress += globamt
|
progress += globamt
|
||||||
sofar = time.time() - start
|
# sofar = time.time() - start
|
||||||
# logger.debug("Working for %.3fs, %.2f Mh/s", sofar, (progress / sofar) / 1000000)
|
# logger.debug("Working for %.3fs, %.2f Mh/s", sofar, (progress / sofar) / 1000000)
|
||||||
if shutdown != 0:
|
if shutdown != 0:
|
||||||
raise Exception ("Interrupted")
|
raise Exception ("Interrupted")
|
||||||
taken = time.time() - start
|
# taken = time.time() - start
|
||||||
# logger.debug("Took %d tries.", progress)
|
# logger.debug("Took %d tries.", progress)
|
||||||
return output[0][0]
|
return output[0][0]
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Image(qrcode.image.base.BaseImage):
|
||||||
def __init__(self, border, width, box_size):
|
def __init__(self, border, width, box_size):
|
||||||
self.border = border
|
self.border = border
|
||||||
self.width = width
|
self.width = width
|
||||||
self.box_size = box_size
|
# self.box_size = box_size
|
||||||
size = (width + border * 2) * box_size
|
size = (width + border * 2) * box_size
|
||||||
self._image = QtGui.QImage(
|
self._image = QtGui.QImage(
|
||||||
size, size, QtGui.QImage.Format_RGB16)
|
size, size, QtGui.QImage.Format_RGB16)
|
||||||
|
@ -25,16 +25,16 @@ class Image(qrcode.image.base.BaseImage):
|
||||||
def pixmap(self):
|
def pixmap(self):
|
||||||
return QtGui.QPixmap.fromImage(self._image)
|
return QtGui.QPixmap.fromImage(self._image)
|
||||||
|
|
||||||
def drawrect(self, row, col):
|
# def drawrect(self, row, col):
|
||||||
painter = QtGui.QPainter(self._image)
|
# painter = QtGui.QPainter(self._image)
|
||||||
painter.fillRect(
|
# painter.fillRect(
|
||||||
(col + self.border) * self.box_size,
|
# (col + self.border) * self.box_size,
|
||||||
(row + self.border) * self.box_size,
|
# (row + self.border) * self.box_size,
|
||||||
self.box_size, self.box_size,
|
# self.box_size, self.box_size,
|
||||||
QtCore.Qt.black)
|
# QtCore.Qt.black)
|
||||||
|
|
||||||
def save(self, stream, kind=None):
|
# def save(self, stream, kind=None):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
class Ui_qrcodeDialog(object):
|
class Ui_qrcodeDialog(object):
|
||||||
|
|
|
@ -126,30 +126,30 @@ def _doGPUPoW(target, initialHash):
|
||||||
logger.debug("GPU PoW done")
|
logger.debug("GPU PoW done")
|
||||||
return [trialValue, nonce]
|
return [trialValue, nonce]
|
||||||
|
|
||||||
def estimate(difficulty, format = False):
|
# def estimate(difficulty, format = False):
|
||||||
ret = difficulty / 10
|
# ret = difficulty / 10
|
||||||
if ret < 1:
|
# if ret < 1:
|
||||||
ret = 1
|
# ret = 1
|
||||||
if format:
|
# if format:
|
||||||
out = str(int(ret)) + " seconds"
|
# out = str(int(ret)) + " seconds"
|
||||||
if ret > 60:
|
# if ret > 60:
|
||||||
ret /= 60
|
# ret /= 60
|
||||||
out = str(int(ret)) + " minutes"
|
# out = str(int(ret)) + " minutes"
|
||||||
if ret > 60:
|
# if ret > 60:
|
||||||
ret /= 60
|
# ret /= 60
|
||||||
out = str(int(ret)) + " hours"
|
# out = str(int(ret)) + " hours"
|
||||||
if ret > 24:
|
# if ret > 24:
|
||||||
ret /= 24
|
# ret /= 24
|
||||||
out = str(int(ret)) + " days"
|
# out = str(int(ret)) + " days"
|
||||||
if ret > 7:
|
# if ret > 7:
|
||||||
out = str(int(ret)) + " weeks"
|
# out = str(int(ret)) + " weeks"
|
||||||
if ret > 31:
|
# if ret > 31:
|
||||||
out = str(int(ret)) + " months"
|
# out = str(int(ret)) + " months"
|
||||||
if ret > 366:
|
# if ret > 366:
|
||||||
ret /= 366
|
# ret /= 366
|
||||||
out = str(int(ret)) + " years"
|
# out = str(int(ret)) + " years"
|
||||||
else:
|
# else:
|
||||||
return ret
|
# return ret
|
||||||
|
|
||||||
def getPowType():
|
def getPowType():
|
||||||
if openclpow.openclEnabled():
|
if openclpow.openclEnabled():
|
||||||
|
@ -252,7 +252,7 @@ def init():
|
||||||
bso = ctypes.WinDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
bso = ctypes.WinDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
||||||
logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib)
|
logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib)
|
||||||
bmpow = bso.BitmessagePOW
|
bmpow = bso.BitmessagePOW
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
# bmpow.restype = ctypes.c_ulonglong
|
||||||
_doCPoW(2**63, "")
|
_doCPoW(2**63, "")
|
||||||
logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib)
|
logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib)
|
||||||
except:
|
except:
|
||||||
|
@ -262,7 +262,7 @@ def init():
|
||||||
bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
||||||
logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib)
|
logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib)
|
||||||
bmpow = bso.BitmessagePOW
|
bmpow = bso.BitmessagePOW
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
# bmpow.restype = ctypes.c_ulonglong
|
||||||
_doCPoW(2**63, "")
|
_doCPoW(2**63, "")
|
||||||
logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib)
|
logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib)
|
||||||
except:
|
except:
|
||||||
|
@ -286,7 +286,7 @@ def init():
|
||||||
if bso:
|
if bso:
|
||||||
try:
|
try:
|
||||||
bmpow = bso.BitmessagePOW
|
bmpow = bso.BitmessagePOW
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
# bmpow.restype = ctypes.c_ulonglong
|
||||||
except:
|
except:
|
||||||
bmpow = None
|
bmpow = None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -29,17 +29,17 @@ NODE_DANDELION = 8
|
||||||
BITFIELD_DOESACK = 1
|
BITFIELD_DOESACK = 1
|
||||||
|
|
||||||
#Error types
|
#Error types
|
||||||
STATUS_WARNING = 0
|
# STATUS_WARNING = 0
|
||||||
STATUS_ERROR = 1
|
# STATUS_ERROR = 1
|
||||||
STATUS_FATAL = 2
|
# STATUS_FATAL = 2
|
||||||
|
|
||||||
#Object types
|
#Object types
|
||||||
OBJECT_GETPUBKEY = 0
|
OBJECT_GETPUBKEY = 0
|
||||||
OBJECT_PUBKEY = 1
|
OBJECT_PUBKEY = 1
|
||||||
OBJECT_MSG = 2
|
OBJECT_MSG = 2
|
||||||
OBJECT_BROADCAST = 3
|
OBJECT_BROADCAST = 3
|
||||||
OBJECT_I2P = 0x493250
|
# OBJECT_I2P = 0x493250
|
||||||
OBJECT_ADDR = 0x61646472
|
# OBJECT_ADDR = 0x61646472
|
||||||
|
|
||||||
eightBytesOfRandomDataUsedToDetectConnectionsToSelf = pack(
|
eightBytesOfRandomDataUsedToDetectConnectionsToSelf = pack(
|
||||||
'>Q', random.randrange(1, 18446744073709551615))
|
'>Q', random.randrange(1, 18446744073709551615))
|
||||||
|
@ -48,7 +48,7 @@ eightBytesOfRandomDataUsedToDetectConnectionsToSelf = pack(
|
||||||
#New code should use CreatePacket instead of Header.pack
|
#New code should use CreatePacket instead of Header.pack
|
||||||
Header = Struct('!L12sL4s')
|
Header = Struct('!L12sL4s')
|
||||||
|
|
||||||
VersionPacket = Struct('>LqQ20s4s36sH')
|
# VersionPacket = Struct('>LqQ20s4s36sH')
|
||||||
|
|
||||||
# Bitfield
|
# Bitfield
|
||||||
|
|
||||||
|
@ -306,17 +306,17 @@ def decryptAndCheckPubkeyPayload(data, address):
|
||||||
return 'failed'
|
return 'failed'
|
||||||
|
|
||||||
readPosition = 0
|
readPosition = 0
|
||||||
bitfieldBehaviors = decryptedData[readPosition:readPosition + 4]
|
# bitfieldBehaviors = decryptedData[readPosition:readPosition + 4]
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
publicSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
publicSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
publicEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
publicEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
specifiedNonceTrialsPerByte, specifiedNonceTrialsPerByteLength = decodeVarint(
|
# specifiedNonceTrialsPerByte, specifiedNonceTrialsPerByteLength = decodeVarint(
|
||||||
decryptedData[readPosition:readPosition + 10])
|
# decryptedData[readPosition:readPosition + 10])
|
||||||
readPosition += specifiedNonceTrialsPerByteLength
|
readPosition += specifiedNonceTrialsPerByteLength
|
||||||
specifiedPayloadLengthExtraBytes, specifiedPayloadLengthExtraBytesLength = decodeVarint(
|
# specifiedPayloadLengthExtraBytes, specifiedPayloadLengthExtraBytesLength = decodeVarint(
|
||||||
decryptedData[readPosition:readPosition + 10])
|
# decryptedData[readPosition:readPosition + 10])
|
||||||
readPosition += specifiedPayloadLengthExtraBytesLength
|
readPosition += specifiedPayloadLengthExtraBytesLength
|
||||||
storedData += decryptedData[:readPosition]
|
storedData += decryptedData[:readPosition]
|
||||||
signedData += decryptedData[:readPosition]
|
signedData += decryptedData[:readPosition]
|
||||||
|
@ -415,8 +415,8 @@ def checkAndShareObjectWithPeers(data):
|
||||||
def _checkAndShareUndefinedObjectWithPeers(data):
|
def _checkAndShareUndefinedObjectWithPeers(data):
|
||||||
embeddedTime, = unpack('>Q', data[8:16])
|
embeddedTime, = unpack('>Q', data[8:16])
|
||||||
readPosition = 20 # bypass nonce, time, and object type
|
readPosition = 20 # bypass nonce, time, and object type
|
||||||
objectVersion, objectVersionLength = decodeVarint(
|
# objectVersion, objectVersionLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 9])
|
# data[readPosition:readPosition + 9])
|
||||||
readPosition += objectVersionLength
|
readPosition += objectVersionLength
|
||||||
streamNumber, streamNumberLength = decodeVarint(
|
streamNumber, streamNumberLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 9])
|
data[readPosition:readPosition + 9])
|
||||||
|
@ -438,8 +438,8 @@ def _checkAndShareUndefinedObjectWithPeers(data):
|
||||||
def _checkAndShareMsgWithPeers(data):
|
def _checkAndShareMsgWithPeers(data):
|
||||||
embeddedTime, = unpack('>Q', data[8:16])
|
embeddedTime, = unpack('>Q', data[8:16])
|
||||||
readPosition = 20 # bypass nonce, time, and object type
|
readPosition = 20 # bypass nonce, time, and object type
|
||||||
objectVersion, objectVersionLength = decodeVarint(
|
# objectVersion, objectVersionLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 9])
|
# data[readPosition:readPosition + 9])
|
||||||
readPosition += objectVersionLength
|
readPosition += objectVersionLength
|
||||||
streamNumber, streamNumberLength = decodeVarint(
|
streamNumber, streamNumberLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 9])
|
data[readPosition:readPosition + 9])
|
||||||
|
|
|
@ -16,4 +16,4 @@ __all__ = [
|
||||||
from .openssl import OpenSSL
|
from .openssl import OpenSSL
|
||||||
from .ecc import ECC
|
from .ecc import ECC
|
||||||
from .cipher import Cipher
|
from .cipher import Cipher
|
||||||
from .hash import hmac_sha256, hmac_sha512, pbkdf2
|
from .hash import hmac_sha256# , hmac_sha512, pbkdf2
|
||||||
|
|
|
@ -74,8 +74,8 @@ def hex_to_point(h): return (decode(h[2:66],16),decode(h[66:],16))
|
||||||
|
|
||||||
def point_to_hex(p): return '04'+encode(p[0],16,64)+encode(p[1],16,64)
|
def point_to_hex(p): return '04'+encode(p[0],16,64)+encode(p[1],16,64)
|
||||||
|
|
||||||
def multiply(privkey,pubkey):
|
# def multiply(privkey,pubkey):
|
||||||
return point_to_hex(base10_multiply(hex_to_point(pubkey),decode(privkey,16)))
|
# return point_to_hex(base10_multiply(hex_to_point(pubkey),decode(privkey,16)))
|
||||||
|
|
||||||
def privtopub(privkey):
|
def privtopub(privkey):
|
||||||
return point_to_hex(base10_multiply(G,decode(privkey,16)))
|
return point_to_hex(base10_multiply(G,decode(privkey,16)))
|
||||||
|
@ -86,21 +86,21 @@ def add(p1,p2):
|
||||||
else:
|
else:
|
||||||
return point_to_hex(base10_add(hex_to_point(p1),hex_to_point(p2)))
|
return point_to_hex(base10_add(hex_to_point(p1),hex_to_point(p2)))
|
||||||
|
|
||||||
def hash_160(string):
|
# def hash_160(string):
|
||||||
intermed = hashlib.sha256(string).digest()
|
# intermed = hashlib.sha256(string).digest()
|
||||||
ripemd160 = hashlib.new('ripemd160')
|
# ripemd160 = hashlib.new('ripemd160')
|
||||||
ripemd160.update(intermed)
|
# ripemd160.update(intermed)
|
||||||
return ripemd160.digest()
|
# return ripemd160.digest()
|
||||||
|
|
||||||
def dbl_sha256(string):
|
# def dbl_sha256(string):
|
||||||
return hashlib.sha256(hashlib.sha256(string).digest()).digest()
|
# return hashlib.sha256(hashlib.sha256(string).digest()).digest()
|
||||||
|
|
||||||
def bin_to_b58check(inp):
|
# def bin_to_b58check(inp):
|
||||||
inp_fmtd = '\x00' + inp
|
# inp_fmtd = '\x00' + inp
|
||||||
leadingzbytes = len(re.match('^\x00*',inp_fmtd).group(0))
|
# leadingzbytes = len(re.match('^\x00*',inp_fmtd).group(0))
|
||||||
checksum = dbl_sha256(inp_fmtd)[:4]
|
# checksum = dbl_sha256(inp_fmtd)[:4]
|
||||||
return '1' * leadingzbytes + changebase(inp_fmtd+checksum,256,58)
|
# return '1' * leadingzbytes + changebase(inp_fmtd+checksum,256,58)
|
||||||
|
|
||||||
#Convert a public key (in hex) to a Bitcoin address
|
#Convert a public key (in hex) to a Bitcoin address
|
||||||
def pubkey_to_address(pubkey):
|
# def pubkey_to_address(pubkey):
|
||||||
return bin_to_b58check(hash_160(changebase(pubkey,16,256)))
|
# return bin_to_b58check(hash_160(changebase(pubkey,16,256)))
|
||||||
|
|
20
src/pyelliptic/cipher.py
Normal file → Executable file
20
src/pyelliptic/cipher.py
Normal file → Executable file
|
@ -35,22 +35,22 @@ class Cipher:
|
||||||
else:
|
else:
|
||||||
raise Exception("RTFM ...")
|
raise Exception("RTFM ...")
|
||||||
|
|
||||||
@staticmethod
|
# @staticmethod
|
||||||
def get_all_cipher():
|
# def get_all_cipher():
|
||||||
"""
|
# """
|
||||||
static method, returns all ciphers available
|
# static method, returns all ciphers available
|
||||||
"""
|
# """
|
||||||
return OpenSSL.cipher_algo.keys()
|
# return OpenSSL.cipher_algo.keys()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_blocksize(ciphername):
|
def get_blocksize(ciphername):
|
||||||
cipher = OpenSSL.get_cipher(ciphername)
|
cipher = OpenSSL.get_cipher(ciphername)
|
||||||
return cipher.get_blocksize()
|
return cipher.get_blocksize()
|
||||||
|
|
||||||
@staticmethod
|
# @staticmethod
|
||||||
def gen_IV(ciphername):
|
# def gen_IV(ciphername):
|
||||||
cipher = OpenSSL.get_cipher(ciphername)
|
# cipher = OpenSSL.get_cipher(ciphername)
|
||||||
return OpenSSL.rand(cipher.get_blocksize())
|
# return OpenSSL.rand(cipher.get_blocksize())
|
||||||
|
|
||||||
def update(self, input):
|
def update(self, input):
|
||||||
i = OpenSSL.c_int(0)
|
i = OpenSSL.c_int(0)
|
||||||
|
|
80
src/pyelliptic/ecc.py
Normal file → Executable file
80
src/pyelliptic/ecc.py
Normal file → Executable file
|
@ -75,18 +75,18 @@ class ECC:
|
||||||
self.pubkey_y = pubkey_y
|
self.pubkey_y = pubkey_y
|
||||||
self.privkey = privkey
|
self.privkey = privkey
|
||||||
|
|
||||||
@staticmethod
|
# @staticmethod
|
||||||
def get_curves():
|
# def get_curves():
|
||||||
"""
|
# """
|
||||||
static method, returns the list of all the curves available
|
# static method, returns the list of all the curves available
|
||||||
"""
|
# """
|
||||||
return OpenSSL.curves.keys()
|
# return OpenSSL.curves.keys()
|
||||||
|
|
||||||
def get_curve(self):
|
def get_curve(self):
|
||||||
return OpenSSL.get_curve_by_id(self.curve)
|
return OpenSSL.get_curve_by_id(self.curve)
|
||||||
|
|
||||||
def get_curve_id(self):
|
# def get_curve_id(self):
|
||||||
return self.curve
|
# return self.curve
|
||||||
|
|
||||||
def get_pubkey(self):
|
def get_pubkey(self):
|
||||||
"""
|
"""
|
||||||
|
@ -100,15 +100,15 @@ class ECC:
|
||||||
self.pubkey_y
|
self.pubkey_y
|
||||||
))
|
))
|
||||||
|
|
||||||
def get_privkey(self):
|
# def get_privkey(self):
|
||||||
"""
|
# """
|
||||||
High level function which returns
|
# High level function which returns
|
||||||
curve(2) + len_of_privkey(2) + privkey
|
# curve(2) + len_of_privkey(2) + privkey
|
||||||
"""
|
# """
|
||||||
return b''.join((pack('!H', self.curve),
|
# return b''.join((pack('!H', self.curve),
|
||||||
pack('!H', len(self.privkey)),
|
# pack('!H', len(self.privkey)),
|
||||||
self.privkey
|
# self.privkey
|
||||||
))
|
# ))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _decode_pubkey(pubkey):
|
def _decode_pubkey(pubkey):
|
||||||
|
@ -178,15 +178,15 @@ class ECC:
|
||||||
OpenSSL.BN_free(pub_key_x)
|
OpenSSL.BN_free(pub_key_x)
|
||||||
OpenSSL.BN_free(pub_key_y)
|
OpenSSL.BN_free(pub_key_y)
|
||||||
|
|
||||||
def get_ecdh_key(self, pubkey):
|
# def get_ecdh_key(self, pubkey):
|
||||||
"""
|
# """
|
||||||
High level function. Compute public key with the local private key
|
# High level function. Compute public key with the local private key
|
||||||
and returns a 512bits shared key
|
# and returns a 512bits shared key
|
||||||
"""
|
# """
|
||||||
curve, pubkey_x, pubkey_y, i = ECC._decode_pubkey(pubkey)
|
# curve, pubkey_x, pubkey_y, i = ECC._decode_pubkey(pubkey)
|
||||||
if curve != self.curve:
|
# if curve != self.curve:
|
||||||
raise Exception("ECC keys must be from the same curve !")
|
# raise Exception("ECC keys must be from the same curve !")
|
||||||
return sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
|
# return sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
|
||||||
|
|
||||||
def raw_get_ecdh_key(self, pubkey_x, pubkey_y):
|
def raw_get_ecdh_key(self, pubkey_x, pubkey_y):
|
||||||
try:
|
try:
|
||||||
|
@ -243,20 +243,20 @@ class ECC:
|
||||||
OpenSSL.EC_KEY_free(own_key)
|
OpenSSL.EC_KEY_free(own_key)
|
||||||
OpenSSL.BN_free(own_priv_key)
|
OpenSSL.BN_free(own_priv_key)
|
||||||
|
|
||||||
def check_key(self, privkey, pubkey):
|
# def check_key(self, privkey, pubkey):
|
||||||
"""
|
# """
|
||||||
Check the public key and the private key.
|
# Check the public key and the private key.
|
||||||
The private key is optional (replace by None)
|
# The private key is optional (replace by None)
|
||||||
"""
|
# """
|
||||||
curve, pubkey_x, pubkey_y, i = ECC._decode_pubkey(pubkey)
|
# curve, pubkey_x, pubkey_y, i = ECC._decode_pubkey(pubkey)
|
||||||
if privkey is None:
|
# if privkey is None:
|
||||||
raw_privkey = None
|
# raw_privkey = None
|
||||||
curve2 = curve
|
# curve2 = curve
|
||||||
else:
|
# else:
|
||||||
curve2, raw_privkey, i = ECC._decode_privkey(privkey)
|
# curve2, raw_privkey, i = ECC._decode_privkey(privkey)
|
||||||
if curve != curve2:
|
# if curve != curve2:
|
||||||
raise Exception("Bad public and private key")
|
# raise Exception("Bad public and private key")
|
||||||
return self.raw_check_key(raw_privkey, pubkey_x, pubkey_y, curve)
|
# return self.raw_check_key(raw_privkey, pubkey_x, pubkey_y, curve)
|
||||||
|
|
||||||
def raw_check_key(self, privkey, pubkey_x, pubkey_y, curve=None):
|
def raw_check_key(self, privkey, pubkey_x, pubkey_y, curve=None):
|
||||||
if curve is None:
|
if curve is None:
|
||||||
|
|
40
src/pyelliptic/hash.py
Normal file → Executable file
40
src/pyelliptic/hash.py
Normal file → Executable file
|
@ -45,25 +45,25 @@ def hmac_sha256(k, m):
|
||||||
return md.raw
|
return md.raw
|
||||||
|
|
||||||
|
|
||||||
def hmac_sha512(k, m):
|
# def hmac_sha512(k, m):
|
||||||
"""
|
# """
|
||||||
Compute the key and the message with HMAC SHA512
|
# Compute the key and the message with HMAC SHA512
|
||||||
"""
|
# """
|
||||||
key = OpenSSL.malloc(k, len(k))
|
# key = OpenSSL.malloc(k, len(k))
|
||||||
d = OpenSSL.malloc(m, len(m))
|
# d = OpenSSL.malloc(m, len(m))
|
||||||
md = OpenSSL.malloc(0, 64)
|
# md = OpenSSL.malloc(0, 64)
|
||||||
i = OpenSSL.pointer(OpenSSL.c_int(0))
|
# i = OpenSSL.pointer(OpenSSL.c_int(0))
|
||||||
OpenSSL.HMAC(OpenSSL.EVP_sha512(), key, len(k), d, len(m), md, i)
|
# OpenSSL.HMAC(OpenSSL.EVP_sha512(), key, len(k), d, len(m), md, i)
|
||||||
return md.raw
|
# return md.raw
|
||||||
|
|
||||||
|
|
||||||
def pbkdf2(password, salt=None, i=10000, keylen=64):
|
# def pbkdf2(password, salt=None, i=10000, keylen=64):
|
||||||
if salt is None:
|
# if salt is None:
|
||||||
salt = OpenSSL.rand(8)
|
# salt = OpenSSL.rand(8)
|
||||||
p_password = OpenSSL.malloc(password, len(password))
|
# p_password = OpenSSL.malloc(password, len(password))
|
||||||
p_salt = OpenSSL.malloc(salt, len(salt))
|
# p_salt = OpenSSL.malloc(salt, len(salt))
|
||||||
output = OpenSSL.malloc(0, keylen)
|
# output = OpenSSL.malloc(0, keylen)
|
||||||
OpenSSL.PKCS5_PBKDF2_HMAC(p_password, len(password), p_salt,
|
# OpenSSL.PKCS5_PBKDF2_HMAC(p_password, len(password), p_salt,
|
||||||
len(p_salt), i, OpenSSL.EVP_sha256(),
|
# len(p_salt), i, OpenSSL.EVP_sha256(),
|
||||||
keylen, output)
|
# keylen, output)
|
||||||
return salt, output.raw
|
# return salt, output.raw
|
||||||
|
|
316
src/pyelliptic/openssl.py
Normal file → Executable file
316
src/pyelliptic/openssl.py
Normal file → Executable file
|
@ -24,8 +24,8 @@ class CipherName:
|
||||||
def get_pointer(self):
|
def get_pointer(self):
|
||||||
return self._pointer()
|
return self._pointer()
|
||||||
|
|
||||||
def get_name(self):
|
# def get_name(self):
|
||||||
return self._name
|
# return self._name
|
||||||
|
|
||||||
def get_blocksize(self):
|
def get_blocksize(self):
|
||||||
return self._blocksize
|
return self._blocksize
|
||||||
|
@ -39,20 +39,20 @@ def get_version(library):
|
||||||
#OpenSSL 1.1
|
#OpenSSL 1.1
|
||||||
OPENSSL_VERSION = 0
|
OPENSSL_VERSION = 0
|
||||||
OPENSSL_CFLAGS = 1
|
OPENSSL_CFLAGS = 1
|
||||||
library.OpenSSL_version.argtypes = [ctypes.c_int]
|
# library.OpenSSL_version.argtypes = [ctypes.c_int]
|
||||||
library.OpenSSL_version.restype = ctypes.c_char_p
|
# library.OpenSSL_version.restype = ctypes.c_char_p
|
||||||
version = library.OpenSSL_version(OPENSSL_VERSION)
|
# version = library.OpenSSL_version(OPENSSL_VERSION)
|
||||||
cflags = library.OpenSSL_version(OPENSSL_CFLAGS)
|
cflags = library.OpenSSL_version(OPENSSL_CFLAGS)
|
||||||
library.OpenSSL_version_num.restype = ctypes.c_long
|
# library.OpenSSL_version_num.restype = ctypes.c_long
|
||||||
hexversion = library.OpenSSL_version_num()
|
hexversion = library.OpenSSL_version_num()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
#OpenSSL 1.0
|
#OpenSSL 1.0
|
||||||
SSLEAY_VERSION = 0
|
SSLEAY_VERSION = 0
|
||||||
SSLEAY_CFLAGS = 2
|
SSLEAY_CFLAGS = 2
|
||||||
library.SSLeay.restype = ctypes.c_long
|
# library.SSLeay.restype = ctypes.c_long
|
||||||
library.SSLeay_version.restype = ctypes.c_char_p
|
# library.SSLeay_version.restype = ctypes.c_char_p
|
||||||
library.SSLeay_version.argtypes = [ctypes.c_int]
|
# library.SSLeay_version.argtypes = [ctypes.c_int]
|
||||||
version = library.SSLeay_version(SSLEAY_VERSION)
|
version = library.SSLeay_version(SSLEAY_VERSION)
|
||||||
cflags = library.SSLeay_version(SSLEAY_CFLAGS)
|
cflags = library.SSLeay_version(SSLEAY_CFLAGS)
|
||||||
hexversion = library.SSLeay()
|
hexversion = library.SSLeay()
|
||||||
|
@ -71,8 +71,8 @@ class _OpenSSL:
|
||||||
Build the wrapper
|
Build the wrapper
|
||||||
"""
|
"""
|
||||||
self._lib = ctypes.CDLL(library)
|
self._lib = ctypes.CDLL(library)
|
||||||
self._version, self._hexversion, self._cflags = get_version(self._lib)
|
# self._version, self._hexversion, self._cflags = get_version(self._lib)
|
||||||
self._libreSSL = self._version.startswith("LibreSSL")
|
# self._libreSSL = self._version.startswith("LibreSSL")
|
||||||
|
|
||||||
self.pointer = ctypes.pointer
|
self.pointer = ctypes.pointer
|
||||||
self.c_int = ctypes.c_int
|
self.c_int = ctypes.c_int
|
||||||
|
@ -80,148 +80,148 @@ class _OpenSSL:
|
||||||
self.create_string_buffer = ctypes.create_string_buffer
|
self.create_string_buffer = ctypes.create_string_buffer
|
||||||
|
|
||||||
self.BN_new = self._lib.BN_new
|
self.BN_new = self._lib.BN_new
|
||||||
self.BN_new.restype = ctypes.c_void_p
|
# self.BN_new.restype = ctypes.c_void_p
|
||||||
self.BN_new.argtypes = []
|
# self.BN_new.argtypes = []
|
||||||
|
|
||||||
self.BN_free = self._lib.BN_free
|
self.BN_free = self._lib.BN_free
|
||||||
self.BN_free.restype = None
|
# self.BN_free.restype = None
|
||||||
self.BN_free.argtypes = [ctypes.c_void_p]
|
# self.BN_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.BN_num_bits = self._lib.BN_num_bits
|
self.BN_num_bits = self._lib.BN_num_bits
|
||||||
self.BN_num_bits.restype = ctypes.c_int
|
# self.BN_num_bits.restype = ctypes.c_int
|
||||||
self.BN_num_bits.argtypes = [ctypes.c_void_p]
|
# self.BN_num_bits.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.BN_bn2bin = self._lib.BN_bn2bin
|
self.BN_bn2bin = self._lib.BN_bn2bin
|
||||||
self.BN_bn2bin.restype = ctypes.c_int
|
# self.BN_bn2bin.restype = ctypes.c_int
|
||||||
self.BN_bn2bin.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self.BN_bn2bin.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.BN_bin2bn = self._lib.BN_bin2bn
|
self.BN_bin2bn = self._lib.BN_bin2bn
|
||||||
self.BN_bin2bn.restype = ctypes.c_void_p
|
# self.BN_bin2bn.restype = ctypes.c_void_p
|
||||||
self.BN_bin2bn.argtypes = [ctypes.c_void_p, ctypes.c_int,
|
# self.BN_bin2bn.argtypes = [ctypes.c_void_p, ctypes.c_int,
|
||||||
ctypes.c_void_p]
|
# ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_free = self._lib.EC_KEY_free
|
self.EC_KEY_free = self._lib.EC_KEY_free
|
||||||
self.EC_KEY_free.restype = None
|
# self.EC_KEY_free.restype = None
|
||||||
self.EC_KEY_free.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_new_by_curve_name = self._lib.EC_KEY_new_by_curve_name
|
self.EC_KEY_new_by_curve_name = self._lib.EC_KEY_new_by_curve_name
|
||||||
self.EC_KEY_new_by_curve_name.restype = ctypes.c_void_p
|
# self.EC_KEY_new_by_curve_name.restype = ctypes.c_void_p
|
||||||
self.EC_KEY_new_by_curve_name.argtypes = [ctypes.c_int]
|
# self.EC_KEY_new_by_curve_name.argtypes = [ctypes.c_int]
|
||||||
|
|
||||||
self.EC_KEY_generate_key = self._lib.EC_KEY_generate_key
|
self.EC_KEY_generate_key = self._lib.EC_KEY_generate_key
|
||||||
self.EC_KEY_generate_key.restype = ctypes.c_int
|
# self.EC_KEY_generate_key.restype = ctypes.c_int
|
||||||
self.EC_KEY_generate_key.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_generate_key.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_check_key = self._lib.EC_KEY_check_key
|
self.EC_KEY_check_key = self._lib.EC_KEY_check_key
|
||||||
self.EC_KEY_check_key.restype = ctypes.c_int
|
# self.EC_KEY_check_key.restype = ctypes.c_int
|
||||||
self.EC_KEY_check_key.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_check_key.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_get0_private_key = self._lib.EC_KEY_get0_private_key
|
self.EC_KEY_get0_private_key = self._lib.EC_KEY_get0_private_key
|
||||||
self.EC_KEY_get0_private_key.restype = ctypes.c_void_p
|
# self.EC_KEY_get0_private_key.restype = ctypes.c_void_p
|
||||||
self.EC_KEY_get0_private_key.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_get0_private_key.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_get0_public_key = self._lib.EC_KEY_get0_public_key
|
self.EC_KEY_get0_public_key = self._lib.EC_KEY_get0_public_key
|
||||||
self.EC_KEY_get0_public_key.restype = ctypes.c_void_p
|
# self.EC_KEY_get0_public_key.restype = ctypes.c_void_p
|
||||||
self.EC_KEY_get0_public_key.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_get0_public_key.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_get0_group = self._lib.EC_KEY_get0_group
|
self.EC_KEY_get0_group = self._lib.EC_KEY_get0_group
|
||||||
self.EC_KEY_get0_group.restype = ctypes.c_void_p
|
# self.EC_KEY_get0_group.restype = ctypes.c_void_p
|
||||||
self.EC_KEY_get0_group.argtypes = [ctypes.c_void_p]
|
# self.EC_KEY_get0_group.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_get_affine_coordinates_GFp = self._lib.EC_POINT_get_affine_coordinates_GFp
|
self.EC_POINT_get_affine_coordinates_GFp = self._lib.EC_POINT_get_affine_coordinates_GFp
|
||||||
self.EC_POINT_get_affine_coordinates_GFp.restype = ctypes.c_int
|
# self.EC_POINT_get_affine_coordinates_GFp.restype = ctypes.c_int
|
||||||
self.EC_POINT_get_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
# self.EC_POINT_get_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
||||||
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
# self.EC_KEY_set_private_key.restype = ctypes.c_int
|
||||||
self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p,
|
# self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p]
|
# ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_public_key = self._lib.EC_KEY_set_public_key
|
self.EC_KEY_set_public_key = self._lib.EC_KEY_set_public_key
|
||||||
self.EC_KEY_set_public_key.restype = ctypes.c_int
|
# self.EC_KEY_set_public_key.restype = ctypes.c_int
|
||||||
self.EC_KEY_set_public_key.argtypes = [ctypes.c_void_p,
|
# self.EC_KEY_set_public_key.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p]
|
# ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_group = self._lib.EC_KEY_set_group
|
self.EC_KEY_set_group = self._lib.EC_KEY_set_group
|
||||||
self.EC_KEY_set_group.restype = ctypes.c_int
|
# self.EC_KEY_set_group.restype = ctypes.c_int
|
||||||
self.EC_KEY_set_group.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self.EC_KEY_set_group.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_set_affine_coordinates_GFp = self._lib.EC_POINT_set_affine_coordinates_GFp
|
self.EC_POINT_set_affine_coordinates_GFp = self._lib.EC_POINT_set_affine_coordinates_GFp
|
||||||
self.EC_POINT_set_affine_coordinates_GFp.restype = ctypes.c_int
|
# self.EC_POINT_set_affine_coordinates_GFp.restype = ctypes.c_int
|
||||||
self.EC_POINT_set_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
# self.EC_POINT_set_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_new = self._lib.EC_POINT_new
|
self.EC_POINT_new = self._lib.EC_POINT_new
|
||||||
self.EC_POINT_new.restype = ctypes.c_void_p
|
# self.EC_POINT_new.restype = ctypes.c_void_p
|
||||||
self.EC_POINT_new.argtypes = [ctypes.c_void_p]
|
# self.EC_POINT_new.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_free = self._lib.EC_POINT_free
|
self.EC_POINT_free = self._lib.EC_POINT_free
|
||||||
self.EC_POINT_free.restype = None
|
# self.EC_POINT_free.restype = None
|
||||||
self.EC_POINT_free.argtypes = [ctypes.c_void_p]
|
# self.EC_POINT_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.BN_CTX_free = self._lib.BN_CTX_free
|
self.BN_CTX_free = self._lib.BN_CTX_free
|
||||||
self.BN_CTX_free.restype = None
|
# self.BN_CTX_free.restype = None
|
||||||
self.BN_CTX_free.argtypes = [ctypes.c_void_p]
|
# self.BN_CTX_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_mul = self._lib.EC_POINT_mul
|
self.EC_POINT_mul = self._lib.EC_POINT_mul
|
||||||
self.EC_POINT_mul.restype = None
|
# self.EC_POINT_mul.restype = None
|
||||||
self.EC_POINT_mul.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
# self.EC_POINT_mul.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
||||||
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
# self.EC_KEY_set_private_key.restype = ctypes.c_int
|
||||||
self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p,
|
# self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p]
|
# ctypes.c_void_p]
|
||||||
|
|
||||||
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
||||||
self.EC_KEY_OpenSSL = self._lib.EC_KEY_OpenSSL
|
self.EC_KEY_OpenSSL = self._lib.EC_KEY_OpenSSL
|
||||||
self._lib.EC_KEY_OpenSSL.restype = ctypes.c_void_p
|
# self._lib.EC_KEY_OpenSSL.restype = ctypes.c_void_p
|
||||||
self._lib.EC_KEY_OpenSSL.argtypes = []
|
# self._lib.EC_KEY_OpenSSL.argtypes = []
|
||||||
|
|
||||||
self.EC_KEY_set_method = self._lib.EC_KEY_set_method
|
self.EC_KEY_set_method = self._lib.EC_KEY_set_method
|
||||||
self._lib.EC_KEY_set_method.restype = ctypes.c_int
|
# self._lib.EC_KEY_set_method.restype = ctypes.c_int
|
||||||
self._lib.EC_KEY_set_method.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self._lib.EC_KEY_set_method.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
else:
|
else:
|
||||||
self.ECDH_OpenSSL = self._lib.ECDH_OpenSSL
|
self.ECDH_OpenSSL = self._lib.ECDH_OpenSSL
|
||||||
self._lib.ECDH_OpenSSL.restype = ctypes.c_void_p
|
# self._lib.ECDH_OpenSSL.restype = ctypes.c_void_p
|
||||||
self._lib.ECDH_OpenSSL.argtypes = []
|
# self._lib.ECDH_OpenSSL.argtypes = []
|
||||||
|
|
||||||
self.ECDH_set_method = self._lib.ECDH_set_method
|
self.ECDH_set_method = self._lib.ECDH_set_method
|
||||||
self._lib.ECDH_set_method.restype = ctypes.c_int
|
# self._lib.ECDH_set_method.restype = ctypes.c_int
|
||||||
self._lib.ECDH_set_method.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self._lib.ECDH_set_method.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.BN_CTX_new = self._lib.BN_CTX_new
|
self.BN_CTX_new = self._lib.BN_CTX_new
|
||||||
self._lib.BN_CTX_new.restype = ctypes.c_void_p
|
# self._lib.BN_CTX_new.restype = ctypes.c_void_p
|
||||||
self._lib.BN_CTX_new.argtypes = []
|
# self._lib.BN_CTX_new.argtypes = []
|
||||||
|
|
||||||
self.ECDH_compute_key = self._lib.ECDH_compute_key
|
self.ECDH_compute_key = self._lib.ECDH_compute_key
|
||||||
self.ECDH_compute_key.restype = ctypes.c_int
|
# self.ECDH_compute_key.restype = ctypes.c_int
|
||||||
self.ECDH_compute_key.argtypes = [ctypes.c_void_p,
|
# self.ECDH_compute_key.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_CipherInit_ex = self._lib.EVP_CipherInit_ex
|
self.EVP_CipherInit_ex = self._lib.EVP_CipherInit_ex
|
||||||
self.EVP_CipherInit_ex.restype = ctypes.c_int
|
# self.EVP_CipherInit_ex.restype = ctypes.c_int
|
||||||
self.EVP_CipherInit_ex.argtypes = [ctypes.c_void_p,
|
# self.EVP_CipherInit_ex.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_CIPHER_CTX_new = self._lib.EVP_CIPHER_CTX_new
|
self.EVP_CIPHER_CTX_new = self._lib.EVP_CIPHER_CTX_new
|
||||||
self.EVP_CIPHER_CTX_new.restype = ctypes.c_void_p
|
# self.EVP_CIPHER_CTX_new.restype = ctypes.c_void_p
|
||||||
self.EVP_CIPHER_CTX_new.argtypes = []
|
# self.EVP_CIPHER_CTX_new.argtypes = []
|
||||||
|
|
||||||
# Cipher
|
# Cipher
|
||||||
self.EVP_aes_128_cfb128 = self._lib.EVP_aes_128_cfb128
|
self.EVP_aes_128_cfb128 = self._lib.EVP_aes_128_cfb128
|
||||||
self.EVP_aes_128_cfb128.restype = ctypes.c_void_p
|
# self.EVP_aes_128_cfb128.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_128_cfb128.argtypes = []
|
# self.EVP_aes_128_cfb128.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_256_cfb128 = self._lib.EVP_aes_256_cfb128
|
self.EVP_aes_256_cfb128 = self._lib.EVP_aes_256_cfb128
|
||||||
self.EVP_aes_256_cfb128.restype = ctypes.c_void_p
|
# self.EVP_aes_256_cfb128.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_256_cfb128.argtypes = []
|
# self.EVP_aes_256_cfb128.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_128_cbc = self._lib.EVP_aes_128_cbc
|
self.EVP_aes_128_cbc = self._lib.EVP_aes_128_cbc
|
||||||
self.EVP_aes_128_cbc.restype = ctypes.c_void_p
|
# self.EVP_aes_128_cbc.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_128_cbc.argtypes = []
|
# self.EVP_aes_128_cbc.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_256_cbc = self._lib.EVP_aes_256_cbc
|
self.EVP_aes_256_cbc = self._lib.EVP_aes_256_cbc
|
||||||
self.EVP_aes_256_cbc.restype = ctypes.c_void_p
|
# self.EVP_aes_256_cbc.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_256_cbc.argtypes = []
|
# self.EVP_aes_256_cbc.argtypes = []
|
||||||
|
|
||||||
#self.EVP_aes_128_ctr = self._lib.EVP_aes_128_ctr
|
#self.EVP_aes_128_ctr = self._lib.EVP_aes_128_ctr
|
||||||
#self.EVP_aes_128_ctr.restype = ctypes.c_void_p
|
#self.EVP_aes_128_ctr.restype = ctypes.c_void_p
|
||||||
|
@ -232,138 +232,138 @@ class _OpenSSL:
|
||||||
#self.EVP_aes_256_ctr.argtypes = []
|
#self.EVP_aes_256_ctr.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_128_ofb = self._lib.EVP_aes_128_ofb
|
self.EVP_aes_128_ofb = self._lib.EVP_aes_128_ofb
|
||||||
self.EVP_aes_128_ofb.restype = ctypes.c_void_p
|
# self.EVP_aes_128_ofb.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_128_ofb.argtypes = []
|
# self.EVP_aes_128_ofb.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_256_ofb = self._lib.EVP_aes_256_ofb
|
self.EVP_aes_256_ofb = self._lib.EVP_aes_256_ofb
|
||||||
self.EVP_aes_256_ofb.restype = ctypes.c_void_p
|
# self.EVP_aes_256_ofb.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_256_ofb.argtypes = []
|
# self.EVP_aes_256_ofb.argtypes = []
|
||||||
|
|
||||||
self.EVP_bf_cbc = self._lib.EVP_bf_cbc
|
self.EVP_bf_cbc = self._lib.EVP_bf_cbc
|
||||||
self.EVP_bf_cbc.restype = ctypes.c_void_p
|
# self.EVP_bf_cbc.restype = ctypes.c_void_p
|
||||||
self.EVP_bf_cbc.argtypes = []
|
# self.EVP_bf_cbc.argtypes = []
|
||||||
|
|
||||||
self.EVP_bf_cfb64 = self._lib.EVP_bf_cfb64
|
self.EVP_bf_cfb64 = self._lib.EVP_bf_cfb64
|
||||||
self.EVP_bf_cfb64.restype = ctypes.c_void_p
|
# self.EVP_bf_cfb64.restype = ctypes.c_void_p
|
||||||
self.EVP_bf_cfb64.argtypes = []
|
# self.EVP_bf_cfb64.argtypes = []
|
||||||
|
|
||||||
self.EVP_rc4 = self._lib.EVP_rc4
|
self.EVP_rc4 = self._lib.EVP_rc4
|
||||||
self.EVP_rc4.restype = ctypes.c_void_p
|
# self.EVP_rc4.restype = ctypes.c_void_p
|
||||||
self.EVP_rc4.argtypes = []
|
# self.EVP_rc4.argtypes = []
|
||||||
|
|
||||||
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
||||||
self.EVP_CIPHER_CTX_reset = self._lib.EVP_CIPHER_CTX_reset
|
self.EVP_CIPHER_CTX_reset = self._lib.EVP_CIPHER_CTX_reset
|
||||||
self.EVP_CIPHER_CTX_reset.restype = ctypes.c_int
|
# self.EVP_CIPHER_CTX_reset.restype = ctypes.c_int
|
||||||
self.EVP_CIPHER_CTX_reset.argtypes = [ctypes.c_void_p]
|
# self.EVP_CIPHER_CTX_reset.argtypes = [ctypes.c_void_p]
|
||||||
else:
|
else:
|
||||||
self.EVP_CIPHER_CTX_cleanup = self._lib.EVP_CIPHER_CTX_cleanup
|
self.EVP_CIPHER_CTX_cleanup = self._lib.EVP_CIPHER_CTX_cleanup
|
||||||
self.EVP_CIPHER_CTX_cleanup.restype = ctypes.c_int
|
# self.EVP_CIPHER_CTX_cleanup.restype = ctypes.c_int
|
||||||
self.EVP_CIPHER_CTX_cleanup.argtypes = [ctypes.c_void_p]
|
# self.EVP_CIPHER_CTX_cleanup.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_CIPHER_CTX_free = self._lib.EVP_CIPHER_CTX_free
|
self.EVP_CIPHER_CTX_free = self._lib.EVP_CIPHER_CTX_free
|
||||||
self.EVP_CIPHER_CTX_free.restype = None
|
# self.EVP_CIPHER_CTX_free.restype = None
|
||||||
self.EVP_CIPHER_CTX_free.argtypes = [ctypes.c_void_p]
|
# self.EVP_CIPHER_CTX_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_CipherUpdate = self._lib.EVP_CipherUpdate
|
self.EVP_CipherUpdate = self._lib.EVP_CipherUpdate
|
||||||
self.EVP_CipherUpdate.restype = ctypes.c_int
|
# self.EVP_CipherUpdate.restype = ctypes.c_int
|
||||||
self.EVP_CipherUpdate.argtypes = [ctypes.c_void_p,
|
# self.EVP_CipherUpdate.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
|
# ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
|
||||||
|
|
||||||
self.EVP_CipherFinal_ex = self._lib.EVP_CipherFinal_ex
|
self.EVP_CipherFinal_ex = self._lib.EVP_CipherFinal_ex
|
||||||
self.EVP_CipherFinal_ex.restype = ctypes.c_int
|
# self.EVP_CipherFinal_ex.restype = ctypes.c_int
|
||||||
self.EVP_CipherFinal_ex.argtypes = [ctypes.c_void_p,
|
# self.EVP_CipherFinal_ex.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_DigestInit = self._lib.EVP_DigestInit
|
self.EVP_DigestInit = self._lib.EVP_DigestInit
|
||||||
self.EVP_DigestInit.restype = ctypes.c_int
|
# self.EVP_DigestInit.restype = ctypes.c_int
|
||||||
self._lib.EVP_DigestInit.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self._lib.EVP_DigestInit.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_DigestInit_ex = self._lib.EVP_DigestInit_ex
|
self.EVP_DigestInit_ex = self._lib.EVP_DigestInit_ex
|
||||||
self.EVP_DigestInit_ex.restype = ctypes.c_int
|
# self.EVP_DigestInit_ex.restype = ctypes.c_int
|
||||||
self._lib.EVP_DigestInit_ex.argtypes = 3 * [ctypes.c_void_p]
|
# self._lib.EVP_DigestInit_ex.argtypes = 3 * [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_DigestUpdate = self._lib.EVP_DigestUpdate
|
self.EVP_DigestUpdate = self._lib.EVP_DigestUpdate
|
||||||
self.EVP_DigestUpdate.restype = ctypes.c_int
|
# self.EVP_DigestUpdate.restype = ctypes.c_int
|
||||||
self.EVP_DigestUpdate.argtypes = [ctypes.c_void_p,
|
# self.EVP_DigestUpdate.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_int]
|
# ctypes.c_void_p, ctypes.c_int]
|
||||||
|
|
||||||
self.EVP_DigestFinal = self._lib.EVP_DigestFinal
|
self.EVP_DigestFinal = self._lib.EVP_DigestFinal
|
||||||
self.EVP_DigestFinal.restype = ctypes.c_int
|
# self.EVP_DigestFinal.restype = ctypes.c_int
|
||||||
self.EVP_DigestFinal.argtypes = [ctypes.c_void_p,
|
# self.EVP_DigestFinal.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_DigestFinal_ex = self._lib.EVP_DigestFinal_ex
|
self.EVP_DigestFinal_ex = self._lib.EVP_DigestFinal_ex
|
||||||
self.EVP_DigestFinal_ex.restype = ctypes.c_int
|
# self.EVP_DigestFinal_ex.restype = ctypes.c_int
|
||||||
self.EVP_DigestFinal_ex.argtypes = [ctypes.c_void_p,
|
# self.EVP_DigestFinal_ex.argtypes = [ctypes.c_void_p,
|
||||||
ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.ECDSA_sign = self._lib.ECDSA_sign
|
self.ECDSA_sign = self._lib.ECDSA_sign
|
||||||
self.ECDSA_sign.restype = ctypes.c_int
|
# self.ECDSA_sign.restype = ctypes.c_int
|
||||||
self.ECDSA_sign.argtypes = [ctypes.c_int, ctypes.c_void_p,
|
# self.ECDSA_sign.argtypes = [ctypes.c_int, ctypes.c_void_p,
|
||||||
ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.ECDSA_verify = self._lib.ECDSA_verify
|
self.ECDSA_verify = self._lib.ECDSA_verify
|
||||||
self.ECDSA_verify.restype = ctypes.c_int
|
# self.ECDSA_verify.restype = ctypes.c_int
|
||||||
self.ECDSA_verify.argtypes = [ctypes.c_int, ctypes.c_void_p,
|
# self.ECDSA_verify.argtypes = [ctypes.c_int, ctypes.c_void_p,
|
||||||
ctypes.c_int, ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
|
# ctypes.c_int, ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
|
||||||
|
|
||||||
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
if self._hexversion >= 0x10100000 and not self._libreSSL:
|
||||||
self.EVP_MD_CTX_new = self._lib.EVP_MD_CTX_new
|
self.EVP_MD_CTX_new = self._lib.EVP_MD_CTX_new
|
||||||
self.EVP_MD_CTX_new.restype = ctypes.c_void_p
|
# self.EVP_MD_CTX_new.restype = ctypes.c_void_p
|
||||||
self.EVP_MD_CTX_new.argtypes = []
|
# self.EVP_MD_CTX_new.argtypes = []
|
||||||
|
|
||||||
self.EVP_MD_CTX_reset = self._lib.EVP_MD_CTX_reset
|
self.EVP_MD_CTX_reset = self._lib.EVP_MD_CTX_reset
|
||||||
self.EVP_MD_CTX_reset.restype = None
|
# self.EVP_MD_CTX_reset.restype = None
|
||||||
self.EVP_MD_CTX_reset.argtypes = [ctypes.c_void_p]
|
# self.EVP_MD_CTX_reset.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_MD_CTX_free = self._lib.EVP_MD_CTX_free
|
self.EVP_MD_CTX_free = self._lib.EVP_MD_CTX_free
|
||||||
self.EVP_MD_CTX_free.restype = None
|
# self.EVP_MD_CTX_free.restype = None
|
||||||
self.EVP_MD_CTX_free.argtypes = [ctypes.c_void_p]
|
# self.EVP_MD_CTX_free.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_sha1 = self._lib.EVP_sha1
|
self.EVP_sha1 = self._lib.EVP_sha1
|
||||||
self.EVP_sha1.restype = ctypes.c_void_p
|
# self.EVP_sha1.restype = ctypes.c_void_p
|
||||||
self.EVP_sha1.argtypes = []
|
# self.EVP_sha1.argtypes = []
|
||||||
|
|
||||||
self.digest_ecdsa_sha1 = self.EVP_sha1
|
self.digest_ecdsa_sha1 = self.EVP_sha1
|
||||||
else:
|
else:
|
||||||
self.EVP_MD_CTX_create = self._lib.EVP_MD_CTX_create
|
self.EVP_MD_CTX_create = self._lib.EVP_MD_CTX_create
|
||||||
self.EVP_MD_CTX_create.restype = ctypes.c_void_p
|
# self.EVP_MD_CTX_create.restype = ctypes.c_void_p
|
||||||
self.EVP_MD_CTX_create.argtypes = []
|
# self.EVP_MD_CTX_create.argtypes = []
|
||||||
|
|
||||||
self.EVP_MD_CTX_init = self._lib.EVP_MD_CTX_init
|
self.EVP_MD_CTX_init = self._lib.EVP_MD_CTX_init
|
||||||
self.EVP_MD_CTX_init.restype = None
|
# self.EVP_MD_CTX_init.restype = None
|
||||||
self.EVP_MD_CTX_init.argtypes = [ctypes.c_void_p]
|
# self.EVP_MD_CTX_init.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_MD_CTX_destroy = self._lib.EVP_MD_CTX_destroy
|
self.EVP_MD_CTX_destroy = self._lib.EVP_MD_CTX_destroy
|
||||||
self.EVP_MD_CTX_destroy.restype = None
|
# self.EVP_MD_CTX_destroy.restype = None
|
||||||
self.EVP_MD_CTX_destroy.argtypes = [ctypes.c_void_p]
|
# self.EVP_MD_CTX_destroy.argtypes = [ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_ecdsa = self._lib.EVP_ecdsa
|
self.EVP_ecdsa = self._lib.EVP_ecdsa
|
||||||
self._lib.EVP_ecdsa.restype = ctypes.c_void_p
|
# self._lib.EVP_ecdsa.restype = ctypes.c_void_p
|
||||||
self._lib.EVP_ecdsa.argtypes = []
|
# self._lib.EVP_ecdsa.argtypes = []
|
||||||
|
|
||||||
self.digest_ecdsa_sha1 = self.EVP_ecdsa
|
self.digest_ecdsa_sha1 = self.EVP_ecdsa
|
||||||
|
|
||||||
self.RAND_bytes = self._lib.RAND_bytes
|
self.RAND_bytes = self._lib.RAND_bytes
|
||||||
self.RAND_bytes.restype = ctypes.c_int
|
# self.RAND_bytes.restype = ctypes.c_int
|
||||||
self.RAND_bytes.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
# self.RAND_bytes.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
||||||
|
|
||||||
self.EVP_sha256 = self._lib.EVP_sha256
|
self.EVP_sha256 = self._lib.EVP_sha256
|
||||||
self.EVP_sha256.restype = ctypes.c_void_p
|
# self.EVP_sha256.restype = ctypes.c_void_p
|
||||||
self.EVP_sha256.argtypes = []
|
# self.EVP_sha256.argtypes = []
|
||||||
|
|
||||||
self.i2o_ECPublicKey = self._lib.i2o_ECPublicKey
|
self.i2o_ECPublicKey = self._lib.i2o_ECPublicKey
|
||||||
self.i2o_ECPublicKey.restype = ctypes.c_void_p
|
# self.i2o_ECPublicKey.restype = ctypes.c_void_p
|
||||||
self.i2o_ECPublicKey.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
# self.i2o_ECPublicKey.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EVP_sha512 = self._lib.EVP_sha512
|
self.EVP_sha512 = self._lib.EVP_sha512
|
||||||
self.EVP_sha512.restype = ctypes.c_void_p
|
# self.EVP_sha512.restype = ctypes.c_void_p
|
||||||
self.EVP_sha512.argtypes = []
|
# self.EVP_sha512.argtypes = []
|
||||||
|
|
||||||
self.HMAC = self._lib.HMAC
|
self.HMAC = self._lib.HMAC
|
||||||
self.HMAC.restype = ctypes.c_void_p
|
# self.HMAC.restype = ctypes.c_void_p
|
||||||
self.HMAC.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int,
|
# self.HMAC.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int,
|
||||||
ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p]
|
# ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC
|
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC
|
||||||
|
@ -371,11 +371,11 @@ class _OpenSSL:
|
||||||
# The above is not compatible with all versions of OSX.
|
# The above is not compatible with all versions of OSX.
|
||||||
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1
|
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1
|
||||||
|
|
||||||
self.PKCS5_PBKDF2_HMAC.restype = ctypes.c_int
|
# self.PKCS5_PBKDF2_HMAC.restype = ctypes.c_int
|
||||||
self.PKCS5_PBKDF2_HMAC.argtypes = [ctypes.c_void_p, ctypes.c_int,
|
# self.PKCS5_PBKDF2_HMAC.argtypes = [ctypes.c_void_p, ctypes.c_int,
|
||||||
ctypes.c_void_p, ctypes.c_int,
|
# ctypes.c_void_p, ctypes.c_int,
|
||||||
ctypes.c_int, ctypes.c_void_p,
|
# ctypes.c_int, ctypes.c_void_p,
|
||||||
ctypes.c_int, ctypes.c_void_p]
|
# ctypes.c_int, ctypes.c_void_p]
|
||||||
|
|
||||||
self._set_ciphers()
|
self._set_ciphers()
|
||||||
self._set_curves()
|
self._set_curves()
|
||||||
|
|
|
@ -64,11 +64,11 @@ class RandomTrackingDict(object):
|
||||||
del self.dictionary[key]
|
del self.dictionary[key]
|
||||||
self.len -= 1
|
self.len -= 1
|
||||||
|
|
||||||
def setMaxPending(self, maxPending):
|
# def setMaxPending(self, maxPending):
|
||||||
self.maxPending = maxPending
|
# self.maxPending = maxPending
|
||||||
|
|
||||||
def setPendingTimeout(self, pendingTimeout):
|
# def setPendingTimeout(self, pendingTimeout):
|
||||||
self.pendingTimeout = pendingTimeout
|
# self.pendingTimeout = pendingTimeout
|
||||||
|
|
||||||
def randomKeys(self, count=1):
|
def randomKeys(self, count=1):
|
||||||
if self.len == 0 or ((self.pendingLen >= self.maxPending or
|
if self.len == 0 or ((self.pendingLen >= self.maxPending or
|
||||||
|
|
4
src/singleinstance.py
Normal file → Executable file
4
src/singleinstance.py
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import errno
|
import errno
|
||||||
from multiprocessing import Process
|
# from multiprocessing import Process
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import state
|
import state
|
||||||
|
@ -21,7 +21,7 @@ class singleinstance:
|
||||||
"""
|
"""
|
||||||
def __init__(self, flavor_id="", daemon=False):
|
def __init__(self, flavor_id="", daemon=False):
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.counter = 0
|
# self.counter = 0
|
||||||
self.daemon = daemon
|
self.daemon = daemon
|
||||||
self.lockPid = None
|
self.lockPid = None
|
||||||
self.lockfile = os.path.normpath(os.path.join(state.appdata, 'singleton%s.lock' % flavor_id))
|
self.lockfile = os.path.normpath(os.path.join(state.appdata, 'singleton%s.lock' % flavor_id))
|
||||||
|
|
|
@ -92,25 +92,25 @@ _socks4errors = ("request granted",
|
||||||
"request rejected because the client program and identd report different user-ids",
|
"request rejected because the client program and identd report different user-ids",
|
||||||
"unknown error")
|
"unknown error")
|
||||||
|
|
||||||
def setdefaultproxy(proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
|
# def setdefaultproxy(proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
|
||||||
"""setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
|
# """setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
|
||||||
Sets a default proxy which all further socksocket objects will use,
|
# Sets a default proxy which all further socksocket objects will use,
|
||||||
unless explicitly changed.
|
# unless explicitly changed.
|
||||||
"""
|
# """
|
||||||
global _defaultproxy
|
# global _defaultproxy
|
||||||
_defaultproxy = (proxytype, addr, port, rdns, username, password)
|
# _defaultproxy = (proxytype, addr, port, rdns, username, password)
|
||||||
|
|
||||||
def wrapmodule(module):
|
# def wrapmodule(module):
|
||||||
"""wrapmodule(module)
|
# """wrapmodule(module)
|
||||||
Attempts to replace a module's socket library with a SOCKS socket. Must set
|
# Attempts to replace a module's socket library with a SOCKS socket. Must set
|
||||||
a default proxy using setdefaultproxy(...) first.
|
# a default proxy using setdefaultproxy(...) first.
|
||||||
This will only work on modules that import socket directly into the namespace;
|
# This will only work on modules that import socket directly into the namespace;
|
||||||
most of the Python Standard Library falls into this category.
|
# most of the Python Standard Library falls into this category.
|
||||||
"""
|
# """
|
||||||
if _defaultproxy != None:
|
# if _defaultproxy != None:
|
||||||
module.socket.socket = socksocket
|
# module.socket.socket = socksocket
|
||||||
else:
|
# else:
|
||||||
raise GeneralProxyError((4, "no proxy specified"))
|
# raise GeneralProxyError((4, "no proxy specified"))
|
||||||
|
|
||||||
class socksocket(socket.socket):
|
class socksocket(socket.socket):
|
||||||
"""socksocket([family[, type[, proto]]]) -> socket object
|
"""socksocket([family[, type[, proto]]]) -> socket object
|
||||||
|
@ -287,17 +287,17 @@ class socksocket(socket.socket):
|
||||||
boundport = struct.unpack(">H", self.__recvall(2))[0]
|
boundport = struct.unpack(">H", self.__recvall(2))[0]
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
def getproxysockname(self):
|
# def getproxysockname(self):
|
||||||
"""getsockname() -> address info
|
# """getsockname() -> address info
|
||||||
Returns the bound IP address and port number at the proxy.
|
# Returns the bound IP address and port number at the proxy.
|
||||||
"""
|
# """
|
||||||
return self.__proxysockname
|
# return self.__proxysockname
|
||||||
|
|
||||||
def getproxypeername(self):
|
# def getproxypeername(self):
|
||||||
"""getproxypeername() -> address info
|
# """getproxypeername() -> address info
|
||||||
Returns the IP and port number of the proxy.
|
# Returns the IP and port number of the proxy.
|
||||||
"""
|
# """
|
||||||
return _orgsocket.getpeername(self)
|
# return _orgsocket.getpeername(self)
|
||||||
|
|
||||||
def getpeername(self):
|
def getpeername(self):
|
||||||
"""getpeername() -> address info
|
"""getpeername() -> address info
|
||||||
|
@ -306,8 +306,8 @@ class socksocket(socket.socket):
|
||||||
"""
|
"""
|
||||||
return self.__proxypeername
|
return self.__proxypeername
|
||||||
|
|
||||||
def getproxytype(self):
|
# def getproxytype(self):
|
||||||
return self.__proxy[0]
|
# return self.__proxy[0]
|
||||||
|
|
||||||
def __negotiatesocks4(self,destaddr,destport):
|
def __negotiatesocks4(self,destaddr,destport):
|
||||||
"""__negotiatesocks4(self,destaddr,destport)
|
"""__negotiatesocks4(self,destaddr,destport)
|
||||||
|
|
|
@ -114,8 +114,8 @@ class FilesystemInventory(InventoryStorage):
|
||||||
# for i, v in self._inventory.items():
|
# for i, v in self._inventory.items():
|
||||||
# print "loaded stream: %s, %i items" % (i, len(v))
|
# print "loaded stream: %s, %i items" % (i, len(v))
|
||||||
|
|
||||||
def stream_list(self):
|
# def stream_list(self):
|
||||||
return self._inventory.keys()
|
# return self._inventory.keys()
|
||||||
|
|
||||||
def object_list(self):
|
def object_list(self):
|
||||||
return [unhexlify(x) for x in listdir(path.join(self.baseDir, FilesystemInventory.objectDir))]
|
return [unhexlify(x) for x in listdir(path.join(self.baseDir, FilesystemInventory.objectDir))]
|
||||||
|
@ -130,7 +130,7 @@ class FilesystemInventory(InventoryStorage):
|
||||||
def getMetadata(self, hashId):
|
def getMetadata(self, hashId):
|
||||||
try:
|
try:
|
||||||
with open(path.join(self.baseDir, FilesystemInventory.objectDir, hexlify(hashId), FilesystemInventory.metadataFilename), 'r') as f:
|
with open(path.join(self.baseDir, FilesystemInventory.objectDir, hexlify(hashId), FilesystemInventory.metadataFilename), 'r') as f:
|
||||||
objectType, streamNumber, expiresTime, tag, undef = string.split(f.read(), ",", 4)
|
objectType, streamNumber, expiresTime, tag, _ = string.split(f.read(), ",", 4)
|
||||||
return [int(objectType), int(streamNumber), int(expiresTime), unhexlify(tag)]
|
return [int(objectType), int(streamNumber), int(expiresTime), unhexlify(tag)]
|
||||||
except IOError:
|
except IOError:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
|
|
@ -42,7 +42,7 @@ class InventoryStorage(Storage, collections.MutableMapping):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
class MailboxStorage(Storage, collections.MutableMapping):
|
# class MailboxStorage(Storage, collections.MutableMapping):
|
||||||
def __init__(self):
|
# def __init__(self):
|
||||||
# super(self.__class__, self).__init__()
|
# super(self.__class__, self).__init__()
|
||||||
pass
|
# pass
|
||||||
|
|
|
@ -12,11 +12,10 @@ class Throttle(object):
|
||||||
|
|
||||||
def __init__(self, limit=0):
|
def __init__(self, limit=0):
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
self.speed = 0
|
# self.speed = 0
|
||||||
self.chunkSize = Throttle.maxChunkSize
|
self.chunkSize = Throttle.maxChunkSize
|
||||||
self.txTime = int(time.time())
|
self.txTime = int(time.time())
|
||||||
self.txLen = 0
|
self.txLen = 0
|
||||||
self.total = 0
|
|
||||||
self.timer = threading.Event()
|
self.timer = threading.Event()
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
self.resetChunkSize()
|
self.resetChunkSize()
|
||||||
|
@ -25,7 +24,7 @@ class Throttle(object):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
if now > self.txTime:
|
if now > self.txTime:
|
||||||
self.speed = self.txLen / (now - self.txTime)
|
# self.speed = self.txLen / (now - self.txTime)
|
||||||
self.txLen -= self.limit * (now - self.txTime)
|
self.txLen -= self.limit * (now - self.txTime)
|
||||||
self.txTime = now
|
self.txTime = now
|
||||||
if self.txLen < 0 or self.limit == 0:
|
if self.txLen < 0 or self.limit == 0:
|
||||||
|
@ -34,7 +33,6 @@ class Throttle(object):
|
||||||
def wait(self, dataLen):
|
def wait(self, dataLen):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.txLen += dataLen
|
self.txLen += dataLen
|
||||||
self.total += dataLen
|
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
self.recalculate()
|
self.recalculate()
|
||||||
if self.limit == 0:
|
if self.limit == 0:
|
||||||
|
@ -43,9 +41,9 @@ class Throttle(object):
|
||||||
break
|
break
|
||||||
self.timer.wait(0.2)
|
self.timer.wait(0.2)
|
||||||
|
|
||||||
def getSpeed(self):
|
# def getSpeed(self):
|
||||||
self.recalculate()
|
# self.recalculate()
|
||||||
return self.speed
|
# return self.speed
|
||||||
|
|
||||||
def resetChunkSize(self):
|
def resetChunkSize(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -65,17 +63,17 @@ class SendThrottle(Throttle):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Throttle.__init__(self, BMConfigParser().safeGetInt('bitmessagesettings', 'maxuploadrate')*1024)
|
Throttle.__init__(self, BMConfigParser().safeGetInt('bitmessagesettings', 'maxuploadrate')*1024)
|
||||||
|
|
||||||
def resetLimit(self):
|
# def resetLimit(self):
|
||||||
with self.lock:
|
# with self.lock:
|
||||||
self.limit = BMConfigParser().safeGetInt('bitmessagesettings', 'maxuploadrate')*1024
|
# self.limit = BMConfigParser().safeGetInt('bitmessagesettings', 'maxuploadrate')*1024
|
||||||
Throttle.resetChunkSize(self)
|
# Throttle.resetChunkSize(self)
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ReceiveThrottle(Throttle):
|
class ReceiveThrottle(Throttle):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Throttle.__init__(self, BMConfigParser().safeGetInt('bitmessagesettings', 'maxdownloadrate')*1024)
|
Throttle.__init__(self, BMConfigParser().safeGetInt('bitmessagesettings', 'maxdownloadrate')*1024)
|
||||||
|
|
||||||
def resetLimit(self):
|
# def resetLimit(self):
|
||||||
with self.lock:
|
# with self.lock:
|
||||||
self.limit = BMConfigParser().safeGetInt('bitmessagesettings', 'maxdownloadrate')*1024
|
# self.limit = BMConfigParser().safeGetInt('bitmessagesettings', 'maxdownloadrate')*1024
|
||||||
Throttle.resetChunkSize(self)
|
# Throttle.resetChunkSize(self)
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
softwareName = 'PyBitmessage'
|
|
||||||
softwareVersion = '0.6.3.2'
|
softwareVersion = '0.6.3.2'
|
||||||
|
|
Reference in New Issue
Block a user