当前位置: 首页>>代码示例>>Python>>正文


Python UdpTrackerClient.announce方法代码示例

本文整理汇总了Python中lib.subtl.subtl.UdpTrackerClient.announce方法的典型用法代码示例。如果您正苦于以下问题:Python UdpTrackerClient.announce方法的具体用法?Python UdpTrackerClient.announce怎么用?Python UdpTrackerClient.announce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.subtl.subtl.UdpTrackerClient的用法示例。


在下文中一共展示了UdpTrackerClient.announce方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: announceTrackerUdp

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
    def announceTrackerUdp(self, tracker_address, mode="start", num_want=10):
        s = time.time()
        if config.disable_udp:
            raise AnnounceError("Udp disabled by config")
        if config.trackers_proxy != "disable":
            raise AnnounceError("Udp trackers not available with proxies")

        ip, port = tracker_address.split("/")[0].split(":")
        tracker = UdpTrackerClient(ip, int(port))
        if "ip4" in self.getOpenedServiceTypes():
            tracker.peer_port = self.fileserver_port
        else:
            tracker.peer_port = 0
        tracker.connect()
        if not tracker.poll_once():
            raise AnnounceError("Could not connect")
        tracker.announce(info_hash=hashlib.sha1(self.site.address).hexdigest(), num_want=num_want, left=431102370)
        back = tracker.poll_once()
        if not back:
            raise AnnounceError("No response after %.0fs" % (time.time() - s))
        elif type(back) is dict and "response" in back:
            peers = back["response"]["peers"]
        else:
            raise AnnounceError("Invalid response: %r" % back)

        return peers
开发者ID:binerf,项目名称:zeronet_tor,代码行数:28,代码来源:SiteAnnouncer.py

示例2: announce

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
	def announce(self, force=False):
		if time.time() < self.last_announce+15 and not force: return # No reannouncing within 15 secs
		self.last_announce = time.time()
		errors = []

		for protocol, ip, port in SiteManager.TRACKERS:
			if protocol == "udp":
				# self.log.debug("Announcing to %s://%s:%s..." % (protocol, ip, port))
				tracker = UdpTrackerClient(ip, port)
				tracker.peer_port = config.fileserver_port
				try:
					tracker.connect()
					tracker.poll_once()
					tracker.announce(info_hash=hashlib.sha1(self.address).hexdigest(), num_want=50)
					back = tracker.poll_once()
					peers = back["response"]["peers"]
				except Exception, err:
					errors.append("%s://%s:%s" % (protocol, ip, port))
					continue
			
				added = 0
				for peer in peers:
					if (peer["addr"], peer["port"]) in self.peer_blacklist: # Ignore blacklist (eg. myself)
						continue
					if self.addPeer(peer["addr"], peer["port"]): added += 1
				if added:
					self.worker_manager.onPeers()
					self.updateWebsocket(peers_added=added)
					self.settings["peers"] = len(peers)
					self.saveSettings()
					self.log.debug("Found %s peers, new: %s" % (len(peers), added))
			else:
				pass # TODO: http tracker support
开发者ID:davinirjr,项目名称:ZeroNet,代码行数:35,代码来源:Site.py

示例3: announce

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
	def announce(self, force=False):
		if time.time() < self.last_announce+60 and not force: return # No reannouncing within 60 secs
		self.last_announce = time.time()
		errors = []
		address_hash = hashlib.sha1(self.address).hexdigest()
		my_peer_id = sys.modules["main"].file_server.peer_id

		# Later, if we have peer exchange
		"""if sys.modules["main"].file_server.port_opened:
			fileserver_port = config.fileserver_port
		else: # Port not opened, report port 0
			fileserver_port = 0"""

		fileserver_port = config.fileserver_port
		s = time.time()
		announced = 0

		for protocol, ip, port in SiteManager.TRACKERS:
			if protocol == "udp": # Udp tracker
				if config.disable_udp: continue # No udp supported
				tracker = UdpTrackerClient(ip, port)
				tracker.peer_port = fileserver_port
				try:
					tracker.connect()
					tracker.poll_once()
					tracker.announce(info_hash=address_hash, num_want=50)
					back = tracker.poll_once()
					peers = back["response"]["peers"]
				except Exception, err:
					errors.append("%s://%s:%s" % (protocol, ip, port))
					continue

			else: # Http tracker
				params = {
					'info_hash': binascii.a2b_hex(address_hash),
					'peer_id': my_peer_id, 'port': fileserver_port,
					'uploaded': 0, 'downloaded': 0, 'left': 0, 'compact': 1, 'numwant': 30,
					'event': 'started'
				}
				try:
					url = "http://"+ip+"?"+urllib.urlencode(params)
					# Load url
					opener = urllib2.build_opener()
					response = opener.open(url, timeout=10).read()
					# Decode peers
					peer_data = bencode.decode(response)["peers"]
					peer_count = len(peer_data) / 6
					peers = []
					for peer_offset in xrange(peer_count):
						off = 6 * peer_offset
						peer = peer_data[off:off + 6]
						addr, port = struct.unpack('!LH', peer)
						peers.append({"addr": socket.inet_ntoa(struct.pack('!L', addr)), "port": port})
				except Exception, err:
					self.log.debug("Http tracker %s error: %s" % (url, err))
					errors.append("%s://%s" % (protocol, ip))
					continue
开发者ID:meergod,项目名称:ZeroNet,代码行数:59,代码来源:Site.py

示例4: announceTracker

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
	def announceTracker(self, protocol, ip, port, fileserver_port, address_hash, my_peer_id):
		s = time.time()
		if protocol == "udp": # Udp tracker
			if config.disable_udp: return False # No udp supported
			tracker = UdpTrackerClient(ip, port)
			tracker.peer_port = fileserver_port
			try:
				tracker.connect()
				tracker.poll_once()
				tracker.announce(info_hash=address_hash, num_want=50)
				back = tracker.poll_once()
				peers = back["response"]["peers"]
			except Exception, err:
				return False
开发者ID:S466531257BOSS,项目名称:ZeroNet--ZeroNet,代码行数:16,代码来源:Site.py

示例5: announceTracker

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
    def announceTracker(self, tracker_protocol, tracker_address, fileserver_port=0, add_types=[], my_peer_id="", mode="start"):
        s = time.time()
        if "ip4" not in add_types:
            fileserver_port = 0

        if tracker_protocol == "udp":  # Udp tracker
            if config.disable_udp:
                return False  # No udp supported
            ip, port = tracker_address.split(":")
            tracker = UdpTrackerClient(ip, int(port))
            tracker.peer_port = fileserver_port
            try:
                tracker.connect()
                tracker.poll_once()
                tracker.announce(info_hash=hashlib.sha1(self.address).hexdigest(), num_want=50)
                back = tracker.poll_once()
                peers = back["response"]["peers"]
            except Exception, err:
                return False
开发者ID:7uk0n,项目名称:ZeroNet,代码行数:21,代码来源:Site.py

示例6: testTrackers

# 需要导入模块: from lib.subtl.subtl import UdpTrackerClient [as 别名]
# 或者: from lib.subtl.subtl.UdpTrackerClient import announce [as 别名]
	def testTrackers(self):
		raise unittest.SkipTest("Notyet")
		from Site import SiteManager
		from lib.subtl.subtl import UdpTrackerClient
		import hashlib

		ok = 0
		for protocol, ip, port in SiteManager.TRACKERS:
			address = "test"
			if protocol == "udp":
				tracker = UdpTrackerClient(ip, port)
				peers = None
				try:
					tracker.connect()
					tracker.poll_once()
					tracker.announce(info_hash=hashlib.sha1(address).hexdigest(), num_want=5)
					back = tracker.poll_once()
					peers = back["response"]["peers"]
				except Exception, err:
					peers = None
					print "Tracker error: %s://%s:%s %s" % (protocol, ip, port, err)
				if peers != None:
					ok += 1
开发者ID:Donno191,项目名称:ZeroNet,代码行数:25,代码来源:test.py


注:本文中的lib.subtl.subtl.UdpTrackerClient.announce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。