示例#1
0
def addPortMapping(port):
    with open("recip/network/messages/upnp/AddPortMapping.xml", "r") as upnp:
        payload = upnp.read()
        payload = payload % (port, port, Network.getIpAddress(False),
                             Config.getValue('NODE_VERSION'))
        headers = {
            'SOAPAction':
            '"urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"',
            'Content-Type': 'text/xml'
        }
        for igd in INTERNET_GATEWAY_DEVICES:
            xml = Http.send(igd, payload, False, headers)
            return xmlFindText(xml, 'AddPortMappingResponse')
示例#2
0
class Peers:
    db = Config.getValue("PEERS_DB")
    subDb = Config.getValue("PEERS_SUB_DB")
    peers = Storage(db, subDb)

    hostname = Network.getHostname()
    ipAddress = Network.getIpAddress()

    if Config.getBoolValue('PEERS_ENABLE_SEEDS'):
        with open(Config.getValue('SEEDS_DIR')) as seeds:
            hosts = json.load(seeds)
            for host in hosts:
                if host != hostname and host != ipAddress:
                    hostBytes = DataType.serialize(host)
                    if peers.get(hostBytes) == None:
                        peer = Peer()
                        peer.host = host
                        peer.lastUpdate = DataType.asTime()
                        peers.set(hostBytes, peer.serialize())