Ejemplo n.º 1
0
 def populate(self):
     self.languages = []
     self.clear()
     localesPath = os.path.join (codePath(), 'translations')
     configuredLocale = "system"
     try:
         configuredLocale = config.get('bitmessagesettings', 'userlocale', "system")
     except:
         pass
     self.addItem(QtGui.QApplication.translate("settingsDialog", "System Settings", "system"), "system")
     self.setCurrentIndex(0)
     self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
     for translationFile in sorted(glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))):
         localeShort = os.path.split(translationFile)[1].split("_", 1)[1][:-3]
         locale = QtCore.QLocale(QtCore.QString(localeShort))
         if localeShort in LanguageBox.languageName:
             self.addItem(LanguageBox.languageName[localeShort], localeShort)
         elif locale.nativeLanguageName() == "":
             self.addItem(localeShort, localeShort)
         else:
             self.addItem(locale.nativeLanguageName(), localeShort)
     for i in range(self.count()):
         if self.itemData(i) == configuredLocale:
             self.setCurrentIndex(i)
             break
    def connectionFullyEstablished(self):
        if self.connectionIsOrWasFullyEstablished:
            # there is no reason to run this function a second time
            return
        self.connectionIsOrWasFullyEstablished = True

        self.sslSock = self.sock
        if ((self.services & shared.NODE_SSL == shared.NODE_SSL) and
            shared.haveSSL(not self.initiatedConnection)):
            logger.debug("Initialising TLS")
            self.sslSock = ssl.wrap_socket(self.sock, keyfile = os.path.join(shared.codePath(), 'sslkeys', 'key.pem'), certfile = os.path.join(shared.codePath(), 'sslkeys', 'cert.pem'), server_side = not self.initiatedConnection, ssl_version=ssl.PROTOCOL_TLSv1, do_handshake_on_connect=False, ciphers='AECDH-AES256-SHA')
            if hasattr(self.sslSock, "context"):
                self.sslSock.context.set_ecdh_curve("secp256k1")
            while True:
                try:
                    self.sslSock.do_handshake()
                    break
                except ssl.SSLError as e:
                    if e.errno == 2:
                        select.select([self.sslSock], [self.sslSock], [])
                    else:
                        break
                except:
                    break
        # Command the corresponding sendDataThread to set its own connectionIsOrWasFullyEstablished variable to True also
        self.sendDataThreadQueue.put((0, 'connectionIsOrWasFullyEstablished', (self.services, self.sslSock)))

        if not self.initiatedConnection:
            shared.clientHasReceivedIncomingConnections = True
            shared.UISignalQueue.put(('setStatusIcon', 'green'))
        self.sock.settimeout(
            600)  # We'll send out a pong every 5 minutes to make sure the connection stays alive if there has been no other traffic to send lately.
        shared.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
        logger.debug('Connection fully established with ' + str(self.peer) + "\n" + \
            'The size of the connectedHostsList is now ' + str(len(shared.connectedHostsList)) + "\n" + \
            'The length of sendDataQueues is now: ' + str(len(shared.sendDataQueues)) + "\n" + \
            'broadcasting addr from within connectionFullyEstablished function.')

        # Let all of our peers know about this new node.
        dataToSend = (int(time.time()), self.streamNumber, 1, self.peer.host, self.remoteNodeIncomingPort)
        shared.broadcastToSendDataQueues((
            self.streamNumber, 'advertisepeer', dataToSend))

        self.sendaddr()  # This is one large addr message to this one peer.
        if not self.initiatedConnection and len(shared.connectedHostsList) > 200:
            logger.info ('We are connected to too many people. Closing connection.')

            self.sendDataThreadQueue.put((0, 'shutdown','no data'))
            return
        self.sendBigInv()
Ejemplo n.º 3
0
    def connectionFullyEstablished(self):
        if self.connectionIsOrWasFullyEstablished:
            # there is no reason to run this function a second time
            return
        self.connectionIsOrWasFullyEstablished = True

        self.sslSock = self.sock
        if ((self.services & shared.NODE_SSL == shared.NODE_SSL) and
            shared.haveSSL(not self.initiatedConnection)):
            logger.debug("Initialising TLS")
            self.sslSock = ssl.wrap_socket(self.sock, keyfile = os.path.join(shared.codePath(), 'sslkeys', 'key.pem'), certfile = os.path.join(shared.codePath(), 'sslkeys', 'cert.pem'), server_side = not self.initiatedConnection, ssl_version=ssl.PROTOCOL_TLSv1, do_handshake_on_connect=False, ciphers='AECDH-AES256-SHA')
            if hasattr(self.sslSock, "context"):
                self.sslSock.context.set_ecdh_curve("secp256k1")
            while True:
                try:
                    self.sslSock.do_handshake()
                    break
                except ssl.SSLError as e:
                    if e.errno == 2:
                        select.select([self.sslSock], [self.sslSock], [])
                    else:
                        break
                except:
                    break
        # Command the corresponding sendDataThread to set its own connectionIsOrWasFullyEstablished variable to True also
        self.sendDataThreadQueue.put((0, 'connectionIsOrWasFullyEstablished', (self.services, self.sslSock)))

        if not self.initiatedConnection:
            shared.clientHasReceivedIncomingConnections = True
            shared.UISignalQueue.put(('setStatusIcon', 'green'))
        self.sock.settimeout(
            600)  # We'll send out a pong every 5 minutes to make sure the connection stays alive if there has been no other traffic to send lately.
        shared.UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
        logger.debug('Connection fully established with ' + str(self.peer) + "\n" + \
            'The size of the connectedHostsList is now ' + str(len(shared.connectedHostsList)) + "\n" + \
            'The length of sendDataQueues is now: ' + str(len(shared.sendDataQueues)) + "\n" + \
            'broadcasting addr from within connectionFullyEstablished function.')

        # Let all of our peers know about this new node.
        dataToSend = (int(time.time()), self.streamNumber, 1, self.peer.host, self.remoteNodeIncomingPort)
        shared.broadcastToSendDataQueues((
            self.streamNumber, 'advertisepeer', dataToSend))

        self.sendaddr()  # This is one large addr message to this one peer.
        if not self.initiatedConnection and len(shared.connectedHostsList) > 200:
            logger.info ('We are connected to too many people. Closing connection.')

            self.sendDataThreadQueue.put((0, 'shutdown','no data'))
            return
        self.sendBigInv()
Ejemplo n.º 4
0
def initCL():
    global ctx, queue, program, gpus, hash_dt
    try:
        hash_dt = numpy.dtype([("target", numpy.uint64), ("v", numpy.str_, 73)])
        for platform in cl.get_platforms():
            gpus.extend(platform.get_devices(device_type=cl.device_type.GPU))
        if len(gpus) > 0:
            ctx = cl.Context(devices=gpus)
            queue = cl.CommandQueue(ctx)
            f = open(os.path.join(codePath(), "bitmsghash", "bitmsghash.cl"), "r")
            fstr = "".join(f.readlines())
            program = cl.Program(ctx, fstr).build(options="")
            logger.info("Loaded OpenCL kernel")
        else:
            logger.info("No OpenCL GPUs found")
            ctx = False
    except Exception as e:
        logger.error("OpenCL fail: ", exc_info=True)
        ctx = False
Ejemplo n.º 5
0
def initCL():
    global ctx, queue, program, gpus, hash_dt
    try:
        hash_dt = numpy.dtype([('target', numpy.uint64),
                               ('v', numpy.str_, 73)])
        for platform in cl.get_platforms():
            gpus.extend(platform.get_devices(device_type=cl.device_type.GPU))
        if (len(gpus) > 0):
            ctx = cl.Context(devices=gpus)
            queue = cl.CommandQueue(ctx)
            f = open(os.path.join(codePath(), "bitmsghash", 'bitmsghash.cl'),
                     'r')
            fstr = ''.join(f.readlines())
            program = cl.Program(ctx, fstr).build(options="")
            logger.info("Loaded OpenCL kernel")
        else:
            logger.info("No OpenCL GPUs found")
            ctx = False
    except Exception as e:
        logger.error("OpenCL fail: ", exc_info=True)
        ctx = False
Ejemplo n.º 6
0
        return _doSafePoW(target, initialHash)
    except:
        if shutdown != 0:
            raise
        pass #fallback

# init
bitmsglib = 'bitmsghash.so'
if "win32" == sys.platform:
    if ctypes.sizeof(ctypes.c_voidp) == 4:
        bitmsglib = 'bitmsghash32.dll'
    else:
        bitmsglib = 'bitmsghash64.dll'
    try:
        # MSVS
        bso = ctypes.WinDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
        logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib)
        bmpow = bso.BitmessagePOW
        bmpow.restype = ctypes.c_ulonglong
        _doCPoW(2**63, "")
        logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib)
    except:
        logger.error("C PoW test fail.", exc_info=True)
        try:
            # MinGW
            bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
            logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib)
            bmpow = bso.BitmessagePOW
            bmpow.restype = ctypes.c_ulonglong
            _doCPoW(2**63, "")
            logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib)
Ejemplo n.º 7
0
from debug import logger
from shared import config, frozen, codePath, shutdown, safeConfigGetBoolean, UISignalQueue
import openclpow
import tr
import os
import ctypes

bitmsglib = 'bitmsghash.so'
if "win32" == sys.platform:
    if ctypes.sizeof(ctypes.c_voidp) == 4:
        bitmsglib = 'bitmsghash32.dll'
    else:
        bitmsglib = 'bitmsghash64.dll'
    try:
        # MSVS
        bso = ctypes.WinDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
        logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib)
    except:
        try:
            # MinGW
            bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash",
                                           bitmsglib))
            logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib)
        except:
            bso = None
else:
    try:
        bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
        logger.info("Loaded C PoW DLL %s", bitmsglib)
    except:
        bso = None
Ejemplo n.º 8
0
def resource_path(resFile):
    baseDir = codePath()
    for subDir in ["ui", "bitmessageqt"]:
        if os.path.isdir(os.path.join(baseDir, subDir)) and os.path.isfile(
                os.path.join(baseDir, subDir, resFile)):
            return os.path.join(baseDir, subDir, resFile)
Ejemplo n.º 9
0
def resource_path(resFile):
    baseDir = codePath()
    for subDir in ["ui", "bitmessageqt"]:
        if os.path.isdir(os.path.join(baseDir, subDir)) and os.path.isfile(os.path.join(baseDir, subDir, resFile)):
            return os.path.join(baseDir, subDir, resFile)