Exemplo n.º 1
0
def IDchanged(changes):
    s = set(changes)
    if s.intersection([
        'transport.transport-tcp.transport-tcp-enable',
        'transport.transport-tcp.transport-tcp-receiving-enable',
        'transport.transport-udp.transport-udp-enable',
        'transport.transport-udp.transport-udp-receiving-enable',
        'transport.transport-cspace.transport-cspace-enable',
        'transport.transport-cspace.transport-cspace-receiving-enable',
        # 'transport.transport-ssh.transport-ssh-enable',
        # 'transport.transport-http.transport-http-enable',
        # 'transport.transport-email.transport-email-enable',
        # 'transport.transport-q2q.transport-q2q-enable',
        # 'transport.transport-skype.transport-skype-enable',
        ]):
        return True
    if 'transport.transport-tcp.transport-tcp-port' in s and settings.enableTCP():
        return True
    if 'transport.transport-udp.transport-udp-port' in s and settings.enableUDP():
        return True
    if 'transport.transport-ssh.transport-ssh-port' in s and settings.enableSSH():
        return True
    if 'transport.transport-q2q.transport-q2q-username' in s and settings.enableQ2Q():
        return True
    if 'transport.transport-cspace.transport-cspace-key-id' in s and settings.enableCSpace():
        return True
    if 'transport.transport-http.transport-http-server-port' in s and settings.enableHTTP():
        return True
    if 'transport.transport-tcp.transport-tcp-port' in s and settings.enableTCP():
        return True
    return False
Exemplo n.º 2
0
 def isCSpaceOnline(self, arg):
     if not transport_control._TransportCSpaceEnable:
         return False
     if not settings.enableCSpace():
         return False
     if not transport_cspace.registered():
         return False
     return transport_cspace.A().state == 'ONLINE'
Exemplo n.º 3
0
def CreateNewIdentity():
    global _NewIdentity
    
    dhncrypto.InitMyKey()
    misc.loadLocalIdentity()
    if misc.isLocalIdentityReady():
        try:
            lid = misc.getLocalIdentity()
            lid.sign()
            # misc.setLocalIdentity(lid)
            # misc.saveLocalIdentity()
            valid = lid.Valid()
        except:
            valid = False
            dhnio.DprintException()
        if valid:
            _NewIdentity = lid
            return
        dhnio.Dprint(2, 'identity_registrator.CreateNewIdentity existing local identity is not VALID')

    login = dhnio.ReadTextFile(settings.UserNameFilename())
    externalIP = dhnio.ReadTextFile(settings.ExternalIPFilename())
    localIP = dhnio.ReadTextFile(settings.LocalIPFilename())

    dhnio.Dprint(4, 'identity_registrator.CreateNewIdentity %s %s ' % (login, externalIP))
    
    idurl = 'http://'+settings.IdentityServerName()+'/'+login.lower()+'.xml'
    ident = identity.identity( )
    ident.sources.append(idurl)

    cdict = {}
    if settings.enableTCP():
        cdict['tcp'] = 'tcp://'+externalIP+':'+settings.getTCPPort()
    if settings.enableCSpace() and transport_control._TransportCSpaceEnable:
        cdict['cspace'] = 'cspace://'
        if settings.getCSpaceKeyID() != '':
            cdict['cspace'] += settings.getCSpaceKeyID()
    if settings.enableUDP() and transport_control._TransportUDPEnable:
        if stun.getUDPClient() is not None:
            if stun.getUDPClient().externalAddress is not None: # _altStunAddress
                cdict['udp'] = 'udp://'+stun.getUDPClient().externalAddress[0]+':'+str(stun.getUDPClient().externalAddress[1])
        
    for c in misc.validTransports:
        if cdict.has_key(c):
            ident.contacts.append(cdict[c])

    ident.publickey = dhncrypto.MyPublicKey()
    ident.date = time.ctime() #time.strftime('%b %d, %Y')

    revnum = dhnio.ReadTextFile(settings.RevisionNumberFile()).strip()
    repo, location = misc.ReadRepoLocation()
    ident.version = (revnum.strip() + ' ' + repo.strip() + ' ' + dhnio.osinfo().strip()).strip()

    ident.sign()
    
    dhnio.WriteFile(settings.LocalIdentityFilename()+'.new', ident.serialize())
    
    _NewIdentity = ident
Exemplo n.º 4
0
 def doCSpaceInit(self, arg):
     if transport_control._TransportCSpaceEnable and settings.enableCSpace():
         def _cspace_done(x):
             if transport_cspace.registered():
                 settings.setCSpaceKeyID(transport_cspace.keyID())
             self.automat('cspace-done', transport_cspace.A().state)
         transport_cspace.init().addBoth(_cspace_done)
     else:
         self.automat('cspace-done', None)
Exemplo n.º 5
0
 def doCSpaceInit(self, arg):
     if transport_control._TransportCSpaceEnable and settings.enableCSpace():
         def _cspace_done(x):
             reactor.addSystemEventTrigger('before', 'shutdown', transport_cspace.shutdown_final)
             if transport_cspace.registered():
                 settings.setCSpaceKeyID(transport_cspace.keyID())
             self.automat('cspace-done', transport_cspace.A().state)
         transport_cspace.init().addBoth(_cspace_done)
     else:
         self.automat('cspace-done', None)