예제 #1
0
from twisted.python.log import msg

# TODO(emilon): Fix this crap
pythonpath.append(path.abspath(path.join(path.dirname(__file__), '..', '..', '..', "./tribler")))


class DemersClient(DispersyExperimentScriptClient):

    def __init__(self, *argv, **kwargs):
        from Tribler.community.demers.community import DemersTest
        DispersyExperimentScriptClient.__init__(self, *argv, **kwargs)
        self.community_class = DemersTest

    def registerCallbacks(self):
        self.scenario_runner.register(self.publish, 'publish')

    @call_on_dispersy_thread
    def publish(self, amount=1):
        amount = int(amount)
        for _ in xrange(amount):
            msg('creating-text')
            text = u''.join(choice(letters) for _ in xrange(100))
            self._community.create_text(text)

if __name__ == '__main__':
    DemersClient.scenario_file = "demers.scenario"
    main(DemersClient)

#
# demers_client.py ends here
예제 #2
0
        if self.foafs:
            bootstrapped_foafs = connected_foafs / float(len(self.foafs))
        else:
            bootstrapped_foafs = 0

        self.prev_scenario_statistics = self.print_on_change(
            "scenario-statistics", self.prev_scenario_statistics, {
                'bootstrapped': bootstrapped,
                'bootstrapped_foafs': bootstrapped_foafs,
                'indirect_bootstrapped': indirect_bootstrapped
            })
        if self._community:
            self.prev_scenario_debug = self.print_on_change(
                "scenario-debug", self.prev_scenario_debug, {
                    'create_time_encryption':
                    self._community.create_time_encryption,
                    'create_time_decryption':
                    self._community.create_time_decryption,
                    'receive_time_encryption':
                    self._community.receive_time_encryption
                })


if __name__ == '__main__':
    SocialClient.scenario_file = environ.get('SCENARIO_FILE',
                                             'social.scenario')
    main(SocialClient)

#
# social_client.py ends here
예제 #3
0
# TODO(emilon): Fix this crap
pythonpath.append(
    path.abspath(
        path.join(path.dirname(__file__), '..', '..', '..', "./tribler")))


class DemersClient(DispersyExperimentScriptClient):
    def __init__(self, *argv, **kwargs):
        from Tribler.community.demers.community import DemersTest
        DispersyExperimentScriptClient.__init__(self, *argv, **kwargs)
        self.community_class = DemersTest

    def registerCallbacks(self):
        self.scenario_runner.register(self.publish, 'publish')

    def publish(self, amount=1):
        amount = int(amount)
        for _ in xrange(amount):
            msg('creating-text')
            text = u''.join(choice(letters) for _ in xrange(100))
            self._community.create_text(text)


if __name__ == '__main__':
    DemersClient.scenario_file = "demers.scenario"
    main(DemersClient)

#
# demers_client.py ends here
예제 #4
0
                            len(self.taste_buddies))
        if max_connected:
            bootstrapped = connected_friends / float(max_connected)
        else:
            bootstrapped = 0

        self.print_on_change("scenario-statistics",
                             self.prev_scenario_statistics,
                             {'bootstrapped': bootstrapped})
        self.print_on_change(
            "scenario-debug", self.prev_scenario_debug, {
                'not_connected': list(self.not_connected_taste_buddies),
                'create_time_encryption':
                self._community.create_time_encryption,
                'create_time_decryption':
                self._community.create_time_decryption,
                'receive_time_encryption':
                self._community.receive_time_encryption,
                'send_packet_size': self._community.send_packet_size,
                'reply_packet_size': self._community.reply_packet_size,
                'forward_packet_size': self._community.forward_packet_size
            })


if __name__ == '__main__':
    PrivateSemanticClient.scenario_file = 'privatesemantic_1000.scenario'
    main(PrivateSemanticClient)

#
# privatesemantic_client.py ends here
예제 #5
0
                connected_friends += 1
            if self._community and self._community.is_overlapping_taste_buddy_mid(mid):
                indirectly_connected_friends += 1

        connected_foafs = 0
        for mid in self.foafs:
            if self._community and self._community.is_taste_buddy_mid(mid):
                connected_foafs += 1

        if self.friends:
            bootstrapped = connected_friends / float(len(self.friends))
            indirect_bootstrapped = indirectly_connected_friends / float(len(self.friends))
        else:
            bootstrapped = 0

        if self.foafs:
            bootstrapped_foafs = connected_foafs / float(len(self.foafs))
        else:
            bootstrapped_foafs = 0

        self.prev_scenario_statistics = self.print_on_change("scenario-statistics", self.prev_scenario_statistics, {'bootstrapped': bootstrapped, 'bootstrapped_foafs': bootstrapped_foafs, 'indirect_bootstrapped':indirect_bootstrapped})
        if self._community:
            self.prev_scenario_debug = self.print_on_change("scenario-debug", self.prev_scenario_debug, {'create_time_encryption':self._community.create_time_encryption, 'create_time_decryption':self._community.create_time_decryption, 'receive_time_encryption':self._community.receive_time_encryption})

if __name__ == '__main__':
    SocialClient.scenario_file = environ.get('SCENARIO_FILE', 'social.scenario')
    main(SocialClient)

#
# social_client.py ends here
예제 #6
0
    def log_search_response(self, keywords, results, candidate):
        for result in results:
            if result[0] in self.test_set:
                ip, port = result[1].split()
                peer = self.get_peer_id(ip, port)
                self.test_reply[result[0]].append(peer)

        recall = len(self.test_reply) / float(len(self.test_set))
        paths_found = sum(len(paths) for paths in self.test_reply.itervalues())
        sources_found = 0
        for infohash, peers in self.test_reply.iteritems():
            sources_found += sum(peer in self.file_availability[infohash] for peer in set(peers))

        unique_sources = float(sum([len(self.file_availability[infohash]) for infohash in self.test_reply.iterkeys()]))
        if unique_sources:
            sources_found = sources_found / unique_sources
            paths_found = paths_found / unique_sources

        from Tribler.dispersy.tool.lencoder import log
        if results:
            log("dispersy.log", "results", recall=recall, paths_found=paths_found, sources_found=sources_found, keywords=keywords, candidate=str(candidate), results=results, unique_sources=unique_sources)
        else:
            log("dispersy.log", "no results", recall=recall, paths_found=paths_found, sources_found=sources_found, keywords=keywords, candidate=str(candidate), unique_sources=unique_sources)

if __name__ == '__main__':
    PrivateSearchClient.scenario_file = 'privatesearch_1000.scenario'
    main(PrivateSearchClient)

#
# privatesearch_client.py ends here
예제 #7
0
        DispersyExperimentScriptClient.online(self)

        if not self.log_statistics_lc:
            self.log_statistics_lc = lc = LoopingCall(self.log_statistics)
            lc.start(5.0, now=True)

    def insert_metadata(self, infohash_data="", roothash_data="", amount=1):
        amount = int(amount)
        for _ in xrange(amount):
            msg('creating-metadata')

            infohash = sha1(infohash_data).digest()
            roothash = sha1(roothash_data).digest()
            data_list = [(u"name", u"test-metadata"), (u"category", u"test")]

            self._community.create_metadata_message(infohash, roothash, data_list)

    def log_statistics(self):
        all_metadata_msg = self._community._metadata_db.getAllMetadataMessage()
        metadata_msg_count = len(all_metadata_msg)

        self.prev_scenario_statistics = self.print_on_change("scenario-statistics", self.prev_scenario_statistics, {"metadata_msg_count": metadata_msg_count})


if __name__ == '__main__':
    MetadataClient.scenario_file = environ.get('SCENARIO_FILE', 'metadata.scenario')
    main(MetadataClient)

#
# metadata_client.py ends here
예제 #8
0
                                  for _ in xrange(30)), 123455))

                trackers = []
                for _ in range(10):
                    trackers.append(''.join(
                        choice(letters) for _ in xrange(30)))

                files = tuple(files)
                trackers = tuple(trackers)

                self.torrentindex += 1
                torrents.append((infohash, int(time()), name, files, trackers))
        if torrents:
            self.my_channel._disp_create_torrents(torrents)

    def post(self, amount=1):
        amount = int(amount)
        if self.joined_community:
            for _ in xrange(amount):
                text = ''.join(choice(letters) for i in xrange(160))
                self.joined_community._disp_create_comment(
                    text, int(time()), None, None, None, None)


if __name__ == '__main__':
    AllChannelClient.scenario_file = 'allchannel_1000.scenario'
    main(AllChannelClient)

#
# allchannel_client.py ends here
예제 #9
0
                for _ in range(10):
                    files.append((u''.join(choice(letters) for _ in xrange(30)), 123455))

                trackers = []
                for _ in range(10):
                    trackers.append(''.join(choice(letters) for _ in xrange(30)))

                files = tuple(files)
                trackers = tuple(trackers)

                self.torrentindex += 1
                torrents.append((infohash, int(time()), name, files, trackers))
        if torrents:
            self.my_channel._disp_create_torrents(torrents)

    @call_on_dispersy_thread
    def post(self, amount=1):
        amount = int(amount)
        if self.joined_community:
            for _ in xrange(amount):
                text = ''.join(choice(letters) for i in xrange(160))
                self.joined_community._disp_create_comment(text, int(time()), None, None, None, None)


if __name__ == '__main__':
    AllChannelClient.scenario_file = 'allchannel_1000.scenario'
    main(AllChannelClient)

#
# allchannel_client.py ends here
예제 #10
0
                    print >> sys.stderr, "No ip/port or key", peer_id
        except:
            from traceback import print_exc
            print_exc()

    def download(self, infohash):
        self.preferences.add(sha1(str(infohash)).digest())

    def ignore_call(self, *args):
        pass

    def monitor_friends(self):
        connected_friends = 0
        for mid in self.friends:
            if self._community and self._community.is_taste_buddy_mid(mid):
                connected_friends += 1

        if self.friends:
            bootstrapped = connected_friends / float(len(self.friends))
        else:
            bootstrapped = 0

        self._prev_scenario_statistics = self.print_on_change("scenario-statistics", self._prev_scenario_statistics, {'bootstrapped': bootstrapped})
        if self._community:
            self._prev_scenario_debug = self.print_on_change("scenario-debug", self._prev_scenario_debug, {'nr_friends':len(self.friends) if self.friends else 0})

if __name__ == '__main__':
    DiscoveryClient.scenario_file = environ.get('SCENARIO_FILE', 'social.scenario')
    main(DiscoveryClient)