def _update_next_proto(): if len(protos_need_upnp) == 0: #dhnio.Dprint(4, 'network_connector.update_upnp done: ' + str(_UpnpResult)) A('upnp-done') return dhnio.Dprint(14, 'network_connector.UpdateUPNP._update_next_proto ' + str(protos_need_upnp)) proto = protos_need_upnp.pop() protos_need_upnp.add(proto) if proto == 'tcp': port = settings.getTCPPort() elif proto == 'ssh': port = settings.getSSHPort() elif proto == 'http': port = settings.getHTTPPort() d = threads.deferToThread(_call_upnp, port) d.addCallback(_upnp_proto_done, proto)
def UpdateIdentity(): global _RevisionNumber global _WorkingProtocols #getting local identity lid = misc.getLocalIdentity() nowip = misc.readExternalIP() order = lid.getProtoOrder() lid.clearContacts() #prepare contacts data cdict = {} cdict['tcp'] = 'tcp://'+nowip+':'+settings.getTCPPort() if transport_control._TransportSSHEnable: cdict['ssh'] = 'ssh://'+nowip+':'+settings.getSSHPort() if transport_control._TransportHTTPEnable: cdict['http'] = 'http://'+nowip+':'+settings.getHTTPPort() if transport_control._TransportQ2QEnable: cdict['q2q'] = 'q2q://'+settings.getQ2Quserathost() if transport_control._TransportEmailEnable: cdict['email'] = 'email://'+settings.getEmailAddress() if transport_control._TransportCSpaceEnable: cdict['cspace'] = 'cspace://'+settings.getCSpaceKeyID() if transport_control._TransportUDPEnable: if stun.getUDPClient() is None or stun.getUDPClient().externalAddress is None: cdict['udp'] = 'udp://'+nowip+':'+settings.getUDPPort() else: cdict['udp'] = 'udp://'+stun.getUDPClient().externalAddress[0]+':'+str(stun.getUDPClient().externalAddress[1]) #making full order list for proto in cdict.keys(): if proto not in order: order.append(proto) #add contacts data to the local identity #check if some transport is not installed for proto in order: if settings.transportIsEnabled(proto) and settings.transportReceivingIsEnabled(proto): contact = cdict.get(proto, None) if contact is not None: lid.setProtoContact(proto, contact) else: # if protocol is disabled - mark this # because we may want to turn it on in the future _WorkingProtocols.discard(proto) #misc.setLocalIdentity(lid) del order # #if IP is not external and upnp configuration was failed for some reasons # #we want to use another contact methods, NOT tcp or ssh # if IPisLocal() and run_upnpc.last_result('tcp') != 'upnp-done': # dhnio.Dprint(4, 'p2p_connector.update_identity want to push tcp contact: local IP, no upnp ...') # lid.pushProtoContact('tcp') # misc.setLocalIdentity(lid) #update software version number revnum = _RevisionNumber.strip() repo, location = misc.ReadRepoLocation() lid.version = (revnum.strip() + ' ' + repo.strip() + ' ' + dhnio.osinfo().strip()).strip() #generate signature with changed content lid.sign() #remember the identity misc.setLocalIdentity(lid) #finally saving local identity misc.saveLocalIdentity() dhnio.Dprint(4, 'p2p_connector.UpdateIdentity') dhnio.Dprint(4, ' version: %s' % str(lid.version)) dhnio.Dprint(4, ' contacts: %s' % str(lid.contacts))