コード例 #1
0
def register_task(*args, **kwargs):
    global _register_task
    if not _register_task:
        # 21/11/11 Boudewijn: there are conditions where the Dispersy instance has not yet been
        # created.  In this case we must wait.

        dispersy = Dispersy.has_instance()
        while not dispersy:
            sleep(0.1)
            dispersy = Dispersy.has_instance()
        _register_task = dispersy.callback.register
    return _register_task(*args, **kwargs)
コード例 #2
0
ファイル: __init__.py プロジェクト: jettan/swiftarm
def register_task(*args, **kwargs):
    global _register_task
    if not _register_task:
        # 21/11/11 Boudewijn: there are conditions where the Dispersy instance has not yet been
        # created.  In this case we must wait.

        dispersy = Dispersy.has_instance()
        while not dispersy:
            sleep(0.1)
            dispersy = Dispersy.has_instance()
        _register_task = dispersy.callback.register
    return _register_task(*args, **kwargs)
コード例 #3
0
def main():
    sscfg = SessionStartupConfig()
    sscfg.set_state_dir(unicode(os.path.realpath("/tmp")))
    sscfg.set_dispersy_port(6421)
    sscfg.set_nickname("dispersy")

    # The only modules needed by dispersy and DHT.
    sscfg.set_dispersy(True)
    sscfg.set_megacache(True)

    # Disable all other tribler modules.
    sscfg.set_swift_proc(False)
    sscfg.set_buddycast(False)
    sscfg.set_social_networking(False)
    sscfg.set_remote_query(False)
    sscfg.set_bartercast(False)
    sscfg.set_overlay(False)
    sscfg.set_torrent_collecting(False)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    # Create the session and wait for it to be created.
    session = Session(sscfg)
    time.sleep(5)

    # Create the dispersy instance and make it accessible out of the main().
    dispersy.append(Dispersy.has_instance())

    # Create the NetworkBuzzDBHandler that should be made in the tribler GUI.
    NetworkBuzzDBHandler.getInstance()

    #def on_torrent(messages):
    #pass

    # Find the search community from the dispersy instance.
    def findSearchCommunity():
        for community in dispersy[0].get_communities():
            if isinstance(community, SearchCommunity):
                 search_community.append(community)
                 #searchCommunity.on_torrent = on_torrent
                 break

    # Let the dispersy thread find the search community.
    # MUST be called on the dispersy thread.
    dispersy[0].callback.register(findSearchCommunity)

    # Any search request before this point will create a segfault!
    print >> sys.stderr, "Ready to search!"

    # Keep the main function spinning to keep the session alive and dispersy and DHT running.
    try:
        while True:
            sys.stdin.read()
    except:
        print_exc()

    # Shutdown everything.
    session.shutdown()
    print "Shutting down..."
    time.sleep(5)
コード例 #4
0
def main():
    sscfg = SessionStartupConfig()
    sscfg.set_state_dir(unicode(os.path.realpath("/tmp")))
    sscfg.set_dispersy_port(6421)
    sscfg.set_nickname("dispersy")

    # The only modules needed by dispersy and DHT.
    sscfg.set_dispersy(True)
    sscfg.set_megacache(True)

    # Disable all other tribler modules.
    sscfg.set_swift_proc(False)
    sscfg.set_buddycast(False)
    sscfg.set_social_networking(False)
    sscfg.set_remote_query(False)
    sscfg.set_bartercast(False)
    sscfg.set_overlay(False)
    sscfg.set_torrent_collecting(False)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    # Create the session and wait for it to be created.
    session = Session(sscfg)
    time.sleep(5)

    # Create the dispersy instance and make it accessible out of the main().
    dispersy.append(Dispersy.has_instance())

    # Create the NetworkBuzzDBHandler that should be made in the tribler GUI.
    NetworkBuzzDBHandler.getInstance()

    #def on_torrent(messages):
    #pass

    # Find the search community from the dispersy instance.
    def findSearchCommunity():
        for community in dispersy[0].get_communities():
            if isinstance(community, SearchCommunity):
                search_community.append(community)
                #searchCommunity.on_torrent = on_torrent
                break

    # Let the dispersy thread find the search community.
    # MUST be called on the dispersy thread.
    dispersy[0].callback.register(findSearchCommunity)

    # Any search request before this point will create a segfault!
    print >> sys.stderr, "Ready to search!"

    # Keep the main function spinning to keep the session alive and dispersy and DHT running.
    try:
        while True:
            sys.stdin.read()
    except:
        print_exc()

    # Shutdown everything.
    session.shutdown()
    print "Shutting down..."
    time.sleep(5)
コード例 #5
0
ファイル: home.py プロジェクト: duy/tribler
    def __init__(self, parent):
        self.buildColumns = False
        self.dispersy = Dispersy.has_instance()
        if not self.dispersy:
            raise RuntimeError("Dispersy has not started yet")

        HomePanel.__init__(self, parent, 'Dispersy info' , SEPARATOR_GREY)

        self.SetMinSize((-1, 200))

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._onTimer, self.timer)
        self.timer.Start(5000, False)
        self.UpdateStats()

        def ratio(i, j):
            return "%d / %d ~%.1f%%" % (i, j, (100.0 * i / j) if j else 0.0)

        self.mapping = [
            ("WAN Address", '', lambda stats: "%s:%d" % stats.wan_address),
            ("LAN Address", '', lambda stats: "%s:%d" % stats.lan_address),
            ("Connection", '', lambda stats: str(stats.connection_type)),
            ("Runtime", '', lambda stats: self.utility.eta_value(stats.timestamp - stats.start)),
            ("Download", '', lambda stats: self.utility.size_format(stats.total_down) + " or " + self.utility.size_format(int(stats.total_down / (stats.timestamp - stats.start))) + "/s"),
            ("Upload", '', lambda stats: self.utility.size_format(stats.total_up) + " or " + self.utility.size_format(int(stats.total_up / (stats.timestamp - stats.start))) + "/s"),
            
            ("Packets send", 'Packets send vs Packets handled', lambda stats: ratio(stats.total_send, stats.received_count+stats.total_send)),
            ("Packets received", 'Packets received vs Packets handled', lambda stats: ratio(stats.received_count, stats.received_count+stats.total_send)),
            ("Packets dropped", 'Packets dropped vs Packets received', lambda stats: ratio(stats.drop_count, stats.received_count)),
            ("Packets success", 'Messages successfully handled vs Packets received', lambda stats: ratio(stats.success_count, stats.received_count)),
            ("Packets delayed", 'Packets being delayed vs Packets reveived', lambda stats: ratio(stats.delay_count, stats.received_count)),
            ("Sync-Messages created", 'Total number of sync messages created by us in this session', lambda stats: str(stats.created_count)),
            
            ("Candidates reuse", 'Candidates discovered (intro or stumbled) vs Candidates active in more than one community', lambda stats: ratio(stats.total_candidates_overlapped, stats.total_candidates_discovered)),
            
            ("Packets delayed send", 'Total number of delaymessages or delaypacket messages being send', lambda stats: ratio(stats.delay_send, stats.delay_count)),
            ("Packets delayed success", 'Total number of packets which were delayed, and did not timeout', lambda stats: ratio(stats.delay_success, stats.delay_count)),
            ("Packets delayed timeout", 'Total number of packets which were delayed, but got a timeout', lambda stats: ratio(stats.delay_timeout, stats.delay_count)),
            
            ("Walker success", '', lambda stats: ratio(stats.walk_success, stats.walk_attempt)),
            ("Walker success (from trackers)", 'Comparing the successes to tracker to overall successes.', lambda stats: ratio(stats.walk_bootstrap_success, stats.walk_bootstrap_attempt)),
            ("Walker resets", '', lambda stats: str(stats.walk_reset)),
            ("Bloom reuse", '', lambda stats: ratio(sum(c.sync_bloom_reuse for c in stats.communities), sum(c.sync_bloom_new for c in stats.communities))),
            ("Revision", '', lambda stats: str(max(stats.revision.itervalues()))),
            ("Debug mode", '', lambda stats: "yes" if __debug__ else "no"),
            ]
コード例 #6
0
ファイル: metadata-injector.py プロジェクト: Devristo/tribler
def main():
    command_line_parser = optparse.OptionParser()
    command_line_parser.add_option("--statedir", action="store", type="string", help="Use an alternate statedir")
    command_line_parser.add_option("--port", action="store", type="int", help="Listen at this port")
    command_line_parser.add_option("--rss", action="store", type="string", help="Url where to fetch rss feed, or several seperated with ';'")
    command_line_parser.add_option("--dir", action="store", type="string", help="Directory to watch for .torrent files, or several seperated with ';'")
    command_line_parser.add_option("--file", action="store", type="string", help="JSON file which has a community")
    command_line_parser.add_option("--nickname", action="store", type="string", help="The moderator name")
    command_line_parser.add_option("--channelname", action="store", type="string", help="The channel name")

    # parse command-line arguments
    opt, args = command_line_parser.parse_args()

    if not (opt.rss or opt.dir or opt.file):
        command_line_parser.print_help()
        print "\nExample: python Tribler/Main/metadata-injector.py --rss http://frayja.com/rss.php --nickname frayja --channelname goldenoldies"
        sys.exit()

    print "Type 'Q' to stop the metadata-injector"

    sscfg = SessionStartupConfig()
    if opt.statedir: sscfg.set_state_dir(unicode(os.path.realpath(opt.statedir)))
    if opt.port: sscfg.set_dispersy_port(opt.port)
    if opt.nickname: sscfg.set_nickname(opt.nickname)

    sscfg.set_megacache(True)
    sscfg.set_overlay(True)
    # turn torrent collecting on. this will cause torrents to be distributed
    sscfg.set_torrent_collecting(True)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    session = Session(sscfg)

    #Wait for Dispersy
    if Dispersy.has_instance():
        dispersy_started(session, opt)
    else:
        def notify(*args):
            dispersy_started(session, opt)
        session.add_observer(notify,NTFY_DISPERSY,[NTFY_STARTED])

    # condition variable would be prettier, but that don't listen to
    # KeyboardInterrupt
    try:
        while True:
            x = sys.stdin.readline()
            print >> sys.stderr, x
            if x.strip() == 'Q':
                break
    except:
        print_exc()


    torrentfeed = RssParser.getInstance()
    torrentfeed.shutdown()

    dirfeed = DirectoryFeedThread.getInstance()
    dirfeed.shutdown()

    session.shutdown()
    print "Shutting down..."
    time.sleep(5)
コード例 #7
0
    def __init__(self, parent):
        self.buildColumns = False
        self.dispersy = Dispersy.has_instance()
        if not self.dispersy:
            raise RuntimeError("Dispersy has not started yet")

        HomePanel.__init__(self, parent, 'Dispersy info', SEPARATOR_GREY)

        self.SetMinSize((-1, 200))

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._onTimer, self.timer)
        self.timer.Start(5000, False)
        self.UpdateStats()

        def ratio(i, j):
            return "%d / %d ~%.1f%%" % (i, j, (100.0 * i / j) if j else 0.0)

        self.mapping = [
            ("WAN Address", '', lambda stats: "%s:%d" % stats.wan_address),
            ("LAN Address", '', lambda stats: "%s:%d" % stats.lan_address),
            ("Connection", '', lambda stats: str(stats.connection_type)),
            ("Runtime", '', lambda stats: self.utility.eta_value(
                stats.timestamp - stats.start)),
            ("Download", '', lambda stats: self.utility.size_format(
                stats.total_down) + " or " + self.utility.size_format(
                    int(stats.total_down /
                        (stats.timestamp - stats.start))) + "/s"),
            ("Upload", '', lambda stats: self.utility.size_format(
                stats.total_up) + " or " + self.utility.size_format(
                    int(stats.total_up /
                        (stats.timestamp - stats.start))) + "/s"),
            ("Packets send", 'Packets send vs Packets handled', lambda stats:
             ratio(stats.total_send, stats.received_count + stats.total_send)),
            ("Packets received", 'Packets received vs Packets handled',
             lambda stats: ratio(stats.received_count, stats.received_count +
                                 stats.total_send)),
            ("Packets dropped", 'Packets dropped vs Packets received',
             lambda stats: ratio(stats.drop_count, stats.received_count)),
            ("Packets success",
             'Messages successfully handled vs Packets received',
             lambda stats: ratio(stats.success_count, stats.received_count)),
            ("Packets delayed", 'Packets being delayed vs Packets reveived',
             lambda stats: ratio(stats.delay_count, stats.received_count)),
            ("Sync-Messages created",
             'Total number of sync messages created by us in this session',
             lambda stats: str(stats.created_count)),
            ("Candidates reuse",
             'Candidates discovered (intro or stumbled) vs Candidates active in more than one community',
             lambda stats: ratio(stats.total_candidates_overlapped, stats.
                                 total_candidates_discovered)),
            ("Packets delayed send",
             'Total number of delaymessages or delaypacket messages being sent',
             lambda stats: ratio(stats.delay_send, stats.delay_count)),
            ("Packets delayed success",
             'Total number of packets which were delayed, and did not timeout',
             lambda stats: ratio(stats.delay_success, stats.delay_count)),
            ("Packets delayed timeout",
             'Total number of packets which were delayed, but got a timeout',
             lambda stats: ratio(stats.delay_timeout, stats.delay_count)),
            ("Walker success", '',
             lambda stats: ratio(stats.walk_success, stats.walk_attempt)),
            ("Walker success (from trackers)",
             'Comparing the successes to tracker to overall successes.',
             lambda stats: ratio(stats.walk_bootstrap_success, stats.
                                 walk_bootstrap_attempt)),
            ("Walker resets", '', lambda stats: str(stats.walk_reset)),
            ("Bloom reuse",
             'Total number of bloomfilters reused vs bloomfilters sent in this session',
             lambda stats: ratio(
                 sum(c.sync_bloom_reuse for c in stats.communities),
                 sum(c.sync_bloom_send for c in stats.communities))),
            ("Revision", '',
             lambda stats: str(max(stats.revision.itervalues()))),
            ("Debug mode", '', lambda stats: "yes" if __debug__ else "no"),
        ]
def main():
    command_line_parser = optparse.OptionParser()
    command_line_parser.add_option("--statedir",
                                   action="store",
                                   type="string",
                                   help="Use an alternate statedir")
    command_line_parser.add_option("--port",
                                   action="store",
                                   type="int",
                                   help="Listen at this port")
    command_line_parser.add_option(
        "--rss",
        action="store",
        type="string",
        help="Url where to fetch rss feed, or several seperated with ';'")
    command_line_parser.add_option(
        "--dir",
        action="store",
        type="string",
        help=
        "Directory to watch for .torrent files, or several seperated with ';'")
    command_line_parser.add_option("--file",
                                   action="store",
                                   type="string",
                                   help="JSON file which has a community")
    command_line_parser.add_option("--nickname",
                                   action="store",
                                   type="string",
                                   help="The moderator name")
    command_line_parser.add_option("--channelname",
                                   action="store",
                                   type="string",
                                   help="The channel name")

    # parse command-line arguments
    opt, args = command_line_parser.parse_args()

    if not (opt.rss or opt.dir or opt.file):
        command_line_parser.print_help()
        print "\nExample: python Tribler/Main/metadata-injector.py --rss http://frayja.com/rss.php --nickname frayja --channelname goldenoldies"
        sys.exit()

    print "Type 'Q' to stop the metadata-injector"

    sscfg = SessionStartupConfig()
    if opt.statedir:
        sscfg.set_state_dir(unicode(os.path.realpath(opt.statedir)))
    if opt.port: sscfg.set_dispersy_port(opt.port)
    if opt.nickname: sscfg.set_nickname(opt.nickname)

    sscfg.set_megacache(True)
    sscfg.set_overlay(True)
    # turn torrent collecting on. this will cause torrents to be distributed
    sscfg.set_torrent_collecting(True)
    sscfg.set_dialback(False)
    sscfg.set_internal_tracker(False)

    session = Session(sscfg)

    #Wait for Dispersy
    if Dispersy.has_instance():
        dispersy_started(session, opt)
    else:

        def notify(*args):
            dispersy_started(session, opt)

        session.add_observer(notify, NTFY_DISPERSY, [NTFY_STARTED])

    # condition variable would be prettier, but that don't listen to
    # KeyboardInterrupt
    try:
        while True:
            x = sys.stdin.readline()
            print >> sys.stderr, x
            if x.strip() == 'Q':
                break
    except:
        print_exc()

    torrentfeed = RssParser.getInstance()
    torrentfeed.shutdown()

    dirfeed = DirectoryFeedThread.getInstance()
    dirfeed.shutdown()

    session.shutdown()
    print "Shutting down..."
    time.sleep(5)