コード例 #1
0
ファイル: main.py プロジェクト: gyver/p2pool
 def upnp_thread():
     while True:
         try:
             is_lan, lan_ip = yield ipdiscover.get_local_ip()
             if not is_lan:
                 continue
             pm = yield portmapper.get_port_mapper()
             yield pm._upnp.add_port_mapping(lan_ip, args.net.P2P_PORT, args.net.P2P_PORT, 'p2pool', 'TCP')
         except:
             if p2pool_init.DEBUG:
                 log.err()
         yield deferral.sleep(random.expovariate(1/120))
コード例 #2
0
 def upnp_thread():
     while True:
         try:
             is_lan, lan_ip = yield ipdiscover.get_local_ip()
             if is_lan:
                 pm = yield portmapper.get_port_mapper()
                 yield pm._upnp.add_port_mapping(lan_ip, args.p2pool_port, args.p2pool_port, 'p2pool', 'TCP')
         except defer.TimeoutError:
             pass
         except:
             if p2pool.DEBUG:
                 log.err(None, 'UPnP error:')
         yield deferral.sleep(random.expovariate(1/120))
コード例 #3
0
ファイル: main.py プロジェクト: and-then/p2pool-rav
 def upnp_thread():
     while True:
         try:
             is_lan, lan_ip = yield ipdiscover.get_local_ip()
             if is_lan:
                 pm = yield portmapper.get_port_mapper()
                 yield pm._upnp.add_port_mapping(lan_ip, args.p2pool_port, args.p2pool_port, 'p2pool', 'TCP')
         except defer.TimeoutError:
             pass
         except:
             if p2pool.DEBUG:
                 log.err(None, 'UPnP error:')
         yield deferral.sleep(random.expovariate(1/120))
コード例 #4
0
		
def remove_mapping(mapper, port):
	print 'Removing mapping for port', port
	return mapper.unmap(port).addCallback(on_mapping_removed, mapper).addErrback(error_occured)
	
def on_mapping_done(result, mapper, port):
	print '\tNew mapping added for:', port
	return mapper.get_port_mappings().addCallback(
		got_mappings).addCallback(lambda x:remove_mapping(mapper, port)).addErrback(error_occured)
	
def add_mapping(mapper):
	print 'Adding new mapping, faking an http server on port 10333 on this host'
	from twisted.web import server, resource as web_resource
	port = reactor.listenTCP(10333, server.Site(resource=web_resource.Resource()))
	return mapper.map(port).addCallback(on_mapping_done, mapper, port).addErrback(error_occured)
	
def got_port_mapper(mapper):
	print "\tGot port mapper:", mapper
	print "Retreiving existing mappings"
	return mapper.get_port_mappings().addCallback(
		got_mappings).addCallback(lambda x:add_mapping(mapper)).addErrback(error_occured)
	
def error_occured(err):
	print "\tError occured:", err


get_port_mapper().addCallbacks(got_port_mapper,error_occured).addCallback(lambda x:reactor.stop())

print 'Attempting to get_port_mapper()'
reactor.run()