コード例 #1
0
    def __init__(self, rawserver, check_crawler, port = 0):
        # initialise connections now because it is used in shutdown which will
        # be called for Crawler instances as well
        self.connections = {}
        if check_crawler:
            from Tribler.Core.Statistics.Crawler import Crawler
            crawler = Crawler.get_instance()
            if crawler.am_crawler():
                return

        # initialise connections now because it is used in shutdown which will
        # be called for Crawler instances as well
        self.connections = {}

        # 17/03/10 Boudewijn: obsolete code, see the same code a few
        # lines above that include the check_crawler if/else check
        # from Tribler.Core.Statistics.Crawler import Crawler
        # crawler = Crawler.get_instance()
        # if crawler.am_crawler():
        #     return
        
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, "0.0.0.0")
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        self.max_connections = 100
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None
        self.last_sends = {}

        rawserver.start_listening_udp(self.socket, self)

        # Contact NATSwarm tracker peer after 5 seconds
        if port == 9473:
            self.tracker = True

            # Tracker needs a known ID, so set it to all zero
            self.id = "\0\0\0\0"
            # Tracker should accept many more connections than other nodes
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False

            # Create a 4 byte random ID
            self.id = (chr(random.getrandbits(8)) + chr(random.getrandbits(8)) +
                chr(random.getrandbits(8)) + chr(random.getrandbits(8)))
            if DEBUG:
                debug("My ID: %s" % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)

            if not DEBUG:
                if check_crawler:
                    #~ from Tribler.Core.Statistics.StatusReporter import get_reporter_instance
                    from Tribler.Core.Statistics.PunctureCrawler import get_reporter_instance
                    self.reporter = get_reporter_instance()

        if self.reporter:
            my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None and sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen("netstat -nr").readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break
                except:
                    pass
            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event("UDPPuncture", "ID:%s;IP:%s" % (self.id.encode('hex'), my_wan_ip))
コード例 #2
0
ファイル: UDPPuncture.py プロジェクト: Anaconda84/Anaconda
    def __init__(self, rawserver, port = 0):
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, "0.0.0.0")
        self.connections = {}
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        self.max_connections = 100
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None

        rawserver.start_listening_udp(self.socket, self)

        # Contact NATSwarm tracker peer after 5 seconds
        if port == 9473:
            self.tracker = True

            # Tracker needs a known ID, so set it to all zero
            self.id = "\0\0\0\0"
            # Tracker should accept many more connections than other nodes
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False

            # Create a 4 byte random ID
            self.id = (chr(random.getrandbits(8)) + chr(random.getrandbits(8)) +
                chr(random.getrandbits(8)) + chr(random.getrandbits(8)))
            if DEBUG:
                debug("My ID: %s" % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)

            from Tribler.Core.Statistics.StatusReporter import get_reporter_instance
            if not DEBUG:
                self.reporter = get_reporter_instance()

        if self.reporter:
            my_wan_ip = None
            if sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen("netstat -nr").readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break
                except:
                    pass
            else:
                my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event("UDPPuncture", "ID:%s;IP:%s" % (self.id.encode('hex'), my_wan_ip))
コード例 #3
0
    def __init__(self, rawserver, port=0):
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, "0.0.0.0")
        self.connections = {}
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        self.max_connections = 100
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None

        rawserver.start_listening_udp(self.socket, self)

        # Contact NATSwarm tracker peer after 5 seconds
        if port == 9473:
            self.tracker = True

            # Tracker needs a known ID, so set it to all zero
            self.id = "\0\0\0\0"
            # Tracker should accept many more connections than other nodes
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False

            # Create a 4 byte random ID
            self.id = (chr(random.getrandbits(8)) +
                       chr(random.getrandbits(8)) +
                       chr(random.getrandbits(8)) + chr(random.getrandbits(8)))
            if DEBUG:
                debug("My ID: %s" % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)

            from BaseLib.Core.Statistics.StatusReporter import get_reporter_instance
            if not DEBUG:
                self.reporter = get_reporter_instance()

        if self.reporter:
            my_wan_ip = None
            if sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen("netstat -nr").readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break
                except:
                    pass
            else:
                my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event(
                "UDPPuncture",
                "ID:%s;IP:%s" % (self.id.encode('hex'), my_wan_ip))
コード例 #4
0
    def __init__(self, rawserver, check_crawler, port=0):
        self.connections = {}
        if check_crawler:
            from ACEStream.Core.Statistics.Crawler import Crawler
            crawler = Crawler.get_instance()
            if crawler.am_crawler():
                return
        self.connections = {}
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, '0.0.0.0')
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        current_file_path = os.path.dirname(os.path.realpath(__file__))
        maxconnections_file = os.path.join(
            os.path.split(os.path.split(current_file_path)[0])[0], "values",
            "maxconnections.txt")
        f = open(maxconnections_file, "r")
        string = f.read()
        self.max_connections = int(string)
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None
        self.last_sends = {}
        rawserver.start_listening_udp(self.socket, self)
        if port == 9473:
            self.tracker = True
            self.id = '\x00\x00\x00\x00'
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False
            self.id = chr(random.getrandbits(8)) + chr(
                random.getrandbits(8)) + chr(random.getrandbits(8)) + chr(
                    random.getrandbits(8))
            if DEBUG:
                debug('My ID: %s' % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)
            if not DEBUG:
                if check_crawler:
                    from ACEStream.Core.Statistics.PunctureCrawler import get_reporter_instance
                self.reporter = get_reporter_instance()
        if self.reporter:
            my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None and sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen('netstat -nr').readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break

                except:
                    pass

            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event(
                'UDPPuncture',
                'ID:%s;IP:%s' % (self.id.encode('hex'), my_wan_ip))
コード例 #5
0
ファイル: UDPPuncture.py プロジェクト: salekseev/freestream
    def __init__(self, rawserver, check_crawler, port=0):
        self.connections = {}
        if check_crawler:
            from freestream.Core.Statistics.Crawler import Crawler

            crawler = Crawler.get_instance()
            if crawler.am_crawler():
                return
        self.connections = {}
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, "0.0.0.0")
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        self.max_connections = 100
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None
        self.last_sends = {}
        rawserver.start_listening_udp(self.socket, self)
        if port == 9473:
            self.tracker = True
            self.id = "\x00\x00\x00\x00"
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False
            self.id = (
                chr(random.getrandbits(8))
                + chr(random.getrandbits(8))
                + chr(random.getrandbits(8))
                + chr(random.getrandbits(8))
            )
            if DEBUG:
                debug("My ID: %s" % self.id.encode("hex"))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)
            if not DEBUG:
                if check_crawler:
                    from freestream.Core.Statistics.PunctureCrawler import get_reporter_instance
                self.reporter = get_reporter_instance()
        if self.reporter:
            my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None and sys.platform == "win32":
                try:
                    import os

                    for line in os.popen("netstat -nr").readlines():
                        words = line.split()
                        if words[0] == "0.0.0.0":
                            my_wan_ip = words[3]
                            break

                except:
                    pass

            if my_wan_ip == None:
                my_wan_ip = "Unknown"
            self.reporter.add_event("UDPPuncture", "ID:%s;IP:%s" % (self.id.encode("hex"), my_wan_ip))
コード例 #6
0
ファイル: UDPPuncture.py プロジェクト: Anaconda84/Anaconda
    def __init__(self, rawserver, check_crawler, port = 0):
        # initialise connections now because it is used in shutdown which will
        # be called for Crawler instances as well
        self.connections = {}
        if check_crawler:
            from BaseLib.Core.Statistics.Crawler import Crawler
            crawler = Crawler.get_instance()
            if crawler.am_crawler():
                return

        # initialise connections now because it is used in shutdown which will
        # be called for Crawler instances as well
        self.connections = {}

        # 17/03/10 Boudewijn: obsolete code, see the same code a few
        # lines above that include the check_crawler if/else check
        # from BaseLib.Core.Statistics.Crawler import Crawler
        # crawler = Crawler.get_instance()
        # if crawler.am_crawler():
        #     return
        
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, "0.0.0.0")
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
        self.max_connections = 100
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None
        self.last_sends = {}

        rawserver.start_listening_udp(self.socket, self)

        # Contact NATSwarm tracker peer after 5 seconds
        if port == 9473:
            self.tracker = True

            # Tracker needs a known ID, so set it to all zero
            self.id = "\0\0\0\0"
            # Tracker should accept many more connections than other nodes
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False

            # Create a 4 byte random ID
            self.id = (chr(random.getrandbits(8)) + chr(random.getrandbits(8)) +
                chr(random.getrandbits(8)) + chr(random.getrandbits(8)))
            if DEBUG:
                debug("My ID: %s" % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)

            if not DEBUG:
                if check_crawler:
                    #~ from BaseLib.Core.Statistics.StatusReporter import get_reporter_instance
                    from BaseLib.Core.Statistics.PunctureCrawler import get_reporter_instance
                    self.reporter = get_reporter_instance()

        if self.reporter:
            my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None and sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen("netstat -nr").readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break
                except:
                    pass
            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event("UDPPuncture", "ID:%s;IP:%s" % (self.id.encode('hex'), my_wan_ip))
コード例 #7
0
    def __init__(self, rawserver, check_crawler, port = 0):
        self.connections = {}
        if check_crawler:
            from ACEStream.Core.Statistics.Crawler import Crawler
            crawler = Crawler.get_instance()
            if crawler.am_crawler():
                return
        self.connections = {}
        self.rawserver = rawserver
        self.socket = rawserver.create_udpsocket(port, '0.0.0.0')
        self.known_peers = {}
        self.nat_type = UDPHandler.NAT_UNKNOWN
        self.filter_type = UDPHandler.FILTER_UNKNOWN
	current_file_path = os.path.dirname(os.path.realpath(__file__))
	maxconnections_file = os.path.join(os.path.split(os.path.split(current_file_path)[0])[0],"values","maxconnections.txt")
	f = open(maxconnections_file, "r")
	string = f.read()
        self.max_connections = int(string)
        self.connect_threshold = 75
        self.recv_unsolicited = 0
        self.recv_connect_total = 0
        self.recv_address = 0
        self.recv_different_address = 0
        self.sendqueue = deque([])
        self.last_connect = 0
        self.last_info_dump = time.time()
        self.natfw_version = 1
        self.keepalive_intvl = 100
        self.done = False
        self.reporter = None
        self.last_sends = {}
        rawserver.start_listening_udp(self.socket, self)
        if port == 9473:
            self.tracker = True
            self.id = '\x00\x00\x00\x00'
            self.max_connections = 1000
            rawserver.add_task(self.check_for_timeouts, 10)
        else:
            self.tracker = False
            self.id = chr(random.getrandbits(8)) + chr(random.getrandbits(8)) + chr(random.getrandbits(8)) + chr(random.getrandbits(8))
            if DEBUG:
                debug('My ID: %s' % self.id.encode('hex'))
            rawserver.add_task(self.bootstrap, 5)
            TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report)
            TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report)
            if not DEBUG:
                if check_crawler:
                    from ACEStream.Core.Statistics.PunctureCrawler import get_reporter_instance
                self.reporter = get_reporter_instance()
        if self.reporter:
            my_wan_ip = guessip.get_my_wan_ip()
            if my_wan_ip == None and sys.platform == 'win32':
                try:
                    import os
                    for line in os.popen('netstat -nr').readlines():
                        words = line.split()
                        if words[0] == '0.0.0.0':
                            my_wan_ip = words[3]
                            break

                except:
                    pass

            if my_wan_ip == None:
                my_wan_ip = 'Unknown'
            self.reporter.add_event('UDPPuncture', 'ID:%s;IP:%s' % (self.id.encode('hex'), my_wan_ip))