本文整理汇总了Python中twisted.internet.reactor.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startAudio
def startAudio(self, sdp):
md = sdp.getMediaDescription('audio')
addr = md.ipaddr or sdp.ipaddr
def go(ipaddr):
remoteAddr = (ipaddr, md.port)
return RTPStart(cookie=self.cookie, targethost=remoteAddr[0], targetport=remoteAddr[1]).do(self.rtp)
reactor.resolve(addr).addCallback(go)
示例2: startProtocol
def startProtocol(self):
print "1. Start protocol"
# Come prima cosa risolvo il nome
# TODO: devo unserire una cache nella risoluzione
reactor.resolve(self.server_address).addCallbacks(self.got_ip, self.no_ip)
self.start_tout(CtrlUnitDatagramProtocol.ERR_NO_DNS_RESOLUTION, "IP resolution")
示例3: startProtocol
def startProtocol(self):
#==============================
def _start_protocol(ip):
"""This is called once the host is resolved."""
self.host = ip
self.transport.connect(self.host, self.port)
self.authenticate()
reactor.resolve(self.host).addCallback(_start_protocol)
示例4: __init__
def __init__(self, host):
self.clientFactory = SnarlNetworkProtocolClientFactory()
self.serverFactory = SnarlNetworkProtocolServerFactory()
if host.enable_outgoing.value:
reactor.resolve(host.address.value).addCallback(self.gotIP).addErrback(self.noIP)
if host.enable_incoming.value:
self.serverPort = reactor.listenTCP(SNP_TCP_PORT, self.serverFactory)
self.pending += 1
示例5: add_device
def add_device(self, device):
""" Add a single device to the list of devices that we have
"""
def really_add_device(addr):
device.host = addr
reactor.connectTCP(device.host, device.port, self.client_factory)
self.devices[device.name] = device
self.addr_mapping[(device.host, device.port)] = device
device.add_proxy(self)
reactor.resolve(device.host).addCallback(really_add_device)
示例6: get
def get(self):
host = self.config.get('destination', self.hostname)
try:
ip = yield reactor.resolve(host)
except:
ip = None
if ip:
try:
loss, latency = yield icmp.ping(ip, 5)
except:
loss, latency = 100, None
event = [self.createEvent('ok', '%s%% loss to %s' % (loss,host), loss,
prefix="loss")]
if latency:
event.append(self.createEvent('ok', 'Latency to %s' % host, latency,
prefix="latency"))
else:
event = [self.createEvent('critical', 'Unable to resolve %s' % host, 100,
prefix="loss")]
defer.returnValue(event)
示例7: resolve
def resolve(parsedPath):
arguments = urlparse.parse_qs(parsedPath.query)
hostname = arguments["hostname"][0]
try:
ip = yield reactor.resolve(hostname)
except Exception, e:
message = str(e)
示例8: initialize
def initialize(self):
self.clean()
def resolveCb(result):
self.mangle.createChain(chain="cattivo")
entry = self._createAuthenticatorEntry(result)
self.mangle.appendEntry(entry, chain="cattivo")
entry = self._createLocalTrafficEntry()
self.mangle.appendEntry(entry, chain="cattivo")
entry = self._createDefaultTproxyEntry()
self.mangle.appendEntry(entry, chain="cattivo")
self.mangle.commit()
entry = self._createJumpInCattivoEntry()
self.mangle.appendEntry(entry, chain="PREROUTING")
self.mangle.commit()
authenticator = cattivo.config.get("authenticator", "host")
url = URLPath.fromString(authenticator)
address = url.netloc
dfr = reactor.resolve(address)
dfr.addCallback(resolveCb)
return dfr
示例9: __init__
def __init__(self, torrent, url, verbose=None):
self._torrent = torrent
self._verbose = verbose
self.status = "Connecting..."
self._connection_id = None
self._msngr = None
self.seeders = -1 #negative means not connected yet
self.leechers = -1
if not url.startswith('udp://'):
raise ValueError("URL should be udp")
else:
u, p = url.split('/')[2].split(':')
if self._verbose > 10: print("Trying to resolve ip for %s"%u)
self._url = url
self._port = int(p)
reactor.resolve(u).addCallbacks(self._ip_resolved, self._ip_failed)
示例10: get_deferred_host_ip
def get_deferred_host_ip():
global _host_ip
global _host_ip_callbacks
global _host_ip_cachetime
assert reactor.ident == thread.get_ident()
if _host_ip is not "unknown" and _host_ip_cachetime + CACHE_TIME > bttime():
return defer.succeed(_host_ip)
df = defer.Deferred()
if not _host_ip_callbacks:
def connect(ip):
factory = RecorderFactory()
factory.protocol = RecorderProtocol
if hasattr(reactor, "limiter"):
reactor.connectTCP(ip, 80, factory, urgent=True)
else:
reactor.connectTCP(ip, 80, factory)
rdf = reactor.resolve("ip.bittorrent.com")
rdf.addCallback(connect)
rdf.addErrback(lambda e: _got_result(None))
_host_ip_callbacks.append(df)
return df
示例11: get_local_ip
def get_local_ip():
"""
Returns a deferred which will be called with a
2-uple (lan_flag, ip_address) :
- lan_flag:
- True if it's a local network (RFC1918)
- False if it's a WAN address
- ip_address is the actual ip address
@return: A deferred called with the above defined tuple
@rtype: L{twisted.internet.defer.Deferred}
"""
# first we try a connected udp socket, then via multicast
logging.debug("Resolving dns to get udp ip")
try:
ipaddr = yield reactor.resolve('A.ROOT-SERVERS.NET')
except:
pass
else:
udpprot = DatagramProtocol()
port = reactor.listenUDP(0, udpprot)
udpprot.transport.connect(ipaddr, 7)
localip = udpprot.transport.getHost().host
port.stopListening()
if is_bogus_ip(localip):
raise RuntimeError("Invalid IP address returned")
else:
defer.returnValue((is_rfc1918_ip(localip), localip))
logging.debug("Multicast ping to retrieve local IP")
ipaddr = yield _discover_multicast()
defer.returnValue((is_rfc1918_ip(ipaddr), ipaddr))
示例12: announce
def announce(self, torrent):
self.torrent = torrent
host = yield reactor.resolve(self.host, timeout=(1, 3))
self.host = host
reactor.listenUDP(self.factory.track_port, self)
peers = yield self.deferred
defer.returnValue(peers)
示例13: create
def create(host, port, connect_callback=None, disconnect_callback=None,
resolver_errback=None):
"""Create an instance that resolves the host to an IP asynchronously.
Will queue all messages while the host is not yet resolved.
Build a connection that reports to the endpoint (on C{host} and
C{port}) using UDP.
@param host: The StatsD server host.
@param port: The StatsD server port.
@param resolver_errback: The errback to invoke should
issues occur resolving the supplied C{host}.
@param connect_callback: The callback to invoke on connection.
@param disconnect_callback: The callback to invoke on disconnection."""
from twisted.internet import reactor
instance = TwistedStatsDClient(
host=host, port=port, connect_callback=connect_callback,
disconnect_callback=disconnect_callback)
if resolver_errback is None:
resolver_errback = log.err
instance.resolve_later = reactor.resolve(host)
instance.resolve_later.addCallbacks(instance.host_resolved,
resolver_errback)
return instance
示例14: _resolveStunServers
def _resolveStunServers(self, localAddress):
self.localAddress = localAddress
# reactor.resolve the hosts!
for host, port in self.servers:
d = reactor.resolve(host)
#添加向stun server发送消息的函数
d.addCallback(lambda x,p=port: self.initialStunRequest((x, p)))
示例15: resolve
def resolve(self, hostname):
"""Asynchronously resolve a hostname, with caching."""
ip = self.dns_cache.get(hostname, None)
if ip is None:
ip = yield reactor.resolve(hostname)
self.dns_cache[hostname] = ip
defer.returnValue(ip)