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
def init_contacts(callback=None, errback=None): """ Initialize `contacts` and `identitycache`. """ dhnio.Dprint(2, "dhninit.init_contacts") import lib.misc as misc misc.loadLocalIdentity() if misc._LocalIdentity is None: if errback is not None: errback(1) return import lib.contacts as contacts contacts.init() import lib.identitycache as identitycache identitycache.init(callback, errback)