コード例 #1
0
ファイル: Site.py プロジェクト: nbdarling/ZeroNet
    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
コード例 #2
0
    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 helper.getIpType(ip) 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
コード例 #3
0
ファイル: SiteAnnouncer.py プロジェクト: 0-vortex/ZeroNet
    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(":")
        tracker = UdpTrackerClient(ip, int(port))
        if "ip4" in self.getOpenedServiceTypes():
            tracker.peer_port = self.fileserver_port
        else:
            tracker.peer_port = 0
        tracker.connect()
        tracker.poll_once()
        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
コード例 #4
0
ファイル: test.py プロジェクト: Mrkebubun/ZeroNet
    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
コード例 #5
0
ファイル: Site.py プロジェクト: davinirjr/ZeroNet
	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
コード例 #6
0
	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

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

		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
コード例 #7
0
ファイル: Site.py プロジェクト: meergod/ZeroNet
	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
コード例 #8
0
 def announceTracker(self, protocol, address, fileserver_port, address_hash, my_peer_id):
     s = time.time()
     if protocol == "udp":  # Udp tracker
         if config.disable_udp:
             return False  # No udp supported
         ip, port = address.split(":")
         tracker = UdpTrackerClient(ip, int(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
コード例 #9
0
	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
コード例 #10
0
    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
コード例 #11
0
ファイル: Site.py プロジェクト: 7uk0n/ZeroNet
    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
コード例 #12
0
ファイル: test.py プロジェクト: Donno191/ZeroNet
	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