Skip to content

Commit

Permalink
Merge pull request #312 from qstokkink/stolen_base_refactor
Browse files Browse the repository at this point in the history
Refactored gumby for future proofness
  • Loading branch information
devos50 authored May 8, 2017
2 parents aae372b + fbb04d3 commit 5c1ab4b
Show file tree
Hide file tree
Showing 98 changed files with 1,807 additions and 1,161,744 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ output/
\#*\#
.\#*
/TAGS

#IDEs
.idea
4 changes: 4 additions & 0 deletions experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This python module contains all experiments that can be run in gumby.
Specifically it contains the various Experiment Modules that can be loaded by scenario files.
"""
3 changes: 3 additions & 0 deletions experiments/dispersy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
This python module contains experiment modules that deal with dispersy communities.
"""
3 changes: 2 additions & 1 deletion experiments/dispersy/allchannel.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tracker_cmd = 'run_tracker.sh'
tracker_profile = 'true'

local_instance_cmd = 'das4_reserve_and_run.sh'
scenario_file = 'allchannel_1000.scenario'

post_process_cmd = 'post_process_dispersy_experiment.sh'

Expand All @@ -31,7 +32,7 @@ das4_node_timeout = 350
das4_instances_to_run = 1000

# What command do we want to run?
das4_node_command = "allchannel_client.py"
das4_node_command = "launch_scenario.py"

messages_to_plot= 'torrent'

Expand Down
26 changes: 14 additions & 12 deletions experiments/dispersy/allchannel_1000.scenario
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@0:0 set_master_member 3081a7301006072a8648ce3d020106052b81040027038192000403cbbfd2dfb67a7db66c88988df56f93fa6e7f982f9a6a0fa8898492c8b8cae23e10b159ace60b7047012082a5aa4c6e221d7e58107bb550436d57e046c11ab4f51f0ab18fa8f58d0346cc12d1cc2b61fc86fe5ed192309152e11e3f02489e30c7c971dd989e1ce5030ea0fb77d5220a92cceb567cbc94bc39ba246a42e215b55e9315b543ddeff0209e916f77c0d747
@0:0 start_dispersy
@0:1 online {1-980,990-1000}
&module gumby.modules.dispersy_module.DispersyModule
&module experiments.dispersy.allchannel_module.AllChannelModule

@0:0 isolate_community AllChannelCommunity
@0:1 start_session {1-980,990-1000}
@0:110 reset_dispersy_statistics
@0:120 annotate start-experiment
@0:121 join {272,309,310,687,728,922}
Expand Down Expand Up @@ -1415,7 +1417,7 @@
@0:1677 publish 2 {1}
@0:1678 publish 2 {1}
@0:1679 publish 2 {1}
@0:1680 online {982}
@0:1680 start_session {982}
@0:1680 join {982}
@0:1680 publish 2 {1}
@0:1681 publish 2 {1}
Expand All @@ -1427,11 +1429,11 @@
@0:1687 publish 2 {1}
@0:1688 publish 2 {1}
@0:1689 publish 2 {1}
@0:1690 online {985,989}
@0:1690 start_session {985,989}
@0:1690 join {985,989,990}
@0:1690 publish 2 {1}
@0:1691 publish 2 {1}
@0:1692 online {987}
@0:1692 start_session {987}
@0:1692 join {987}
@0:1692 publish 2 {1}
@0:1693 publish 2 {1}
Expand All @@ -1448,7 +1450,7 @@
@0:1704 publish 2 {1}
@0:1705 publish 2 {1}
@0:1706 publish 2 {1}
@0:1707 online {981}
@0:1707 start_session {981}
@0:1707 join {981}
@0:1707 publish 2 {1}
@0:1708 publish 2 {1}
Expand Down Expand Up @@ -1477,7 +1479,7 @@
@0:1731 publish 2 {1}
@0:1732 publish 2 {1}
@0:1733 publish 2 {1}
@0:1734 online {986}
@0:1734 start_session {986}
@0:1734 join {986}
@0:1734 publish 2 {1}
@0:1735 publish 2 {1}
Expand All @@ -1489,7 +1491,7 @@
@0:1741 publish 2 {1}
@0:1742 publish 2 {1}
@0:1743 publish 2 {1}
@0:1744 online {988}
@0:1744 start_session {988}
@0:1744 join {988}
@0:1744 publish 2 {1}
@0:1745 publish 2 {1}
Expand All @@ -1509,11 +1511,11 @@
@0:1759 publish 2 {1}
@0:1760 publish 2 {1}
@0:1761 publish 2 {1}
@0:1762 online {983}
@0:1762 start_session {983}
@0:1762 join {983}
@0:1762 publish 2 {1}
@0:1763 publish 2 {1}
@0:1764 online {984}
@0:1764 start_session {984}
@0:1764 join {984}
@0:1764 publish 2 {1}
@0:1765 publish 2 {1}
Expand Down Expand Up @@ -2287,5 +2289,5 @@
@0:2633 publish 2 {1}
@0:2634 publish 2 {1}
@0:2635 publish 2 {1}
@0:3135 stop_dispersy
@0:3135 stop_session
@0:3145 stop
37 changes: 0 additions & 37 deletions experiments/dispersy/allchannel_local.conf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# dummy_scenario_experiment_client.py ---
#
# Filename: allchannel_client.py
# Filename: allchannel_module.py
# Description:
# Author: Elric Milon
# Maintainer:
Expand Down Expand Up @@ -36,72 +36,62 @@
#

# Code:
from os import path
from random import choice
from string import letters
from sys import path as pythonpath
from time import time

from twisted.internet.task import LoopingCall

from gumby.experiments.dispersyclient import DispersyExperimentScriptClient, main


# TODO(emilon): Fix this crap
pythonpath.append(path.abspath(path.join(path.dirname(__file__), '..', '..', '..', "./tribler")))
from gumby.experiment import experiment_callback
from gumby.modules.experiment_module import static_module
from gumby.modules.community_experiment_module import CommunityExperimentModule

from Tribler.community.allchannel.community import AllChannelCommunity
from Tribler.community.channel.community import ChannelCommunity


class AllChannelClient(DispersyExperimentScriptClient):
@static_module
class AllChannelModule(CommunityExperimentModule):

def __init__(self, *argv, **kwargs):
from Tribler.community.allchannel.community import AllChannelCommunity
super(AllChannelClient, self).__init__(*argv, **kwargs)
self.community_class = AllChannelCommunity
def __init__(self, experiment):
super(AllChannelModule, self).__init__(experiment, AllChannelCommunity)
# by default the dispersy providers will not load this one
self.my_channel = None
self.joined_community = None
self.torrentindex = 1

self.join_lc = None
self.set_community_kwarg('tribler_session', None)

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

def start_dispersy(self):
from Tribler.community.channel.preview import PreviewChannelCommunity

super(AllChannelClient, self).start_dispersy()
self._dispersy.define_auto_load(ChannelCommunity, self._my_member, (), {"tribler_session": None})
self._dispersy.define_auto_load(PreviewChannelCommunity, self._my_member, (), {"tribler_session": None})
def on_id_received(self):
super(AllChannelModule, self).on_id_received()
self.session_config.set_enable_channel_search(True)
self.community_launcher.community_kwargs["tribler_session"] = None
self.community_loader.get_launcher("ChannelCommunity").community_kwargs["tribler_session"] = None

@experiment_callback
def create(self):
self._logger.info("creating-community")
self.my_channel = ChannelCommunity.create_community(self._dispersy, self._my_member, tribler_session=None)
self.my_channel = ChannelCommunity.create_community(self.dispersy, self.community.my_member,
tribler_session=None)
self.my_channel.set_channel_mode(ChannelCommunity.CHANNEL_OPEN)

self._logger.info("Community created with member: %s", self.my_channel._master_member)
self.my_channel._disp_create_channel(u'', u'')

@experiment_callback
def join(self):
if not self.join_lc:
self.join_lc = lc = LoopingCall(self.join)
lc.start(1.0, now=False)
self.join_lc = LoopingCall(self.join)
self.join_lc.start(1.0, now=False)

self._logger.info("trying-to-join-community")

cid = self._community._channelcast_db.getChannelIdFromDispersyCID(None)
cid = self.community._channelcast_db.getChannelIdFromDispersyCID(None)
if cid:
community = self._community._get_channel_community(cid)
community = self.community._get_channel_community(cid)
if community._channel_id:
self._community.disp_create_votecast(community.cid, 2, int(time()))
self.community.disp_create_votecast(community.cid, 2, int(time()))

self._logger.info("joining-community")
for c in self._dispersy.get_communities():
for c in self.dispersy.get_communities():
if isinstance(c, ChannelCommunity):
self.joined_community = c
if self.joined_community is None:
Expand All @@ -110,6 +100,7 @@ def join(self):
self.join_lc.stop()
return

@experiment_callback
def publish(self, amount=1):
amount = int(amount)
torrents = []
Expand Down Expand Up @@ -138,16 +129,20 @@ def publish(self, amount=1):
elif self.joined_community:
self.joined_community._disp_create_torrents(torrents)

@experiment_callback
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
@experiment_callback
def close(self):
self._logger.info('close command received')
if self.my_channel:
self._logger.info('close-channel: %s ', self.my_channel)
self.my_channel.unload_community()
if self.joined_community:
self._logger.info('close-community %s ', self.joined_community)
self.joined_community.unload_community()
18 changes: 18 additions & 0 deletions experiments/dispersy/allchannel_small.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
experiment_name = "dispersy_small_allchannel"
experiment_time = 90

tracker_cmd = 'run_tracker.sh'
tracker_port = __unique_port__

experiment_server_cmd = 'experiment_server.py'
sync_host = 127.0.0.1
sync_port = __unique_port__
sync_experiment_start_delay = 1
sync_subscribers_amount = 5

local_instance_cmd = "process_guard.py -c launch_scenario.py -c launch_scenario.py -c launch_scenario.py -c launch_scenario.py -c launch_scenario.py -t $EXPERIMENT_TIME -m $OUTPUT_DIR -o $OUTPUT_DIR "
scenario_file = 'allchannel_small.scenario'

post_process_cmd = 'post_process_dispersy_experiment.sh'

use_local_venv = FALSE
16 changes: 16 additions & 0 deletions experiments/dispersy/allchannel_small.scenario
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
&module gumby.modules.dispersy_module.DispersyModule
&module experiments.dispersy.allchannel_module.AllChannelModule

@0:0 isolate_community AllChannelCommunity
@0:1 start_session {1-4}
@0:14 reset_dispersy_statistics {1-4}
@0:15 annotate start-experiment
@0:17 create {1}
@0:20 join {3,4}
@0:20 publish 2 {1}
@0:25 start_session {5}
@0:29 reset_dispersy_statistics {5}
@0:30 join {5}
@0:30 publish 2 {1}
@0:50 stop_session
@0:55 stop
23 changes: 0 additions & 23 deletions experiments/dispersy/barter.scenario

This file was deleted.

33 changes: 0 additions & 33 deletions experiments/dispersy/barter10.scenario

This file was deleted.

Loading

0 comments on commit 5c1ab4b

Please sign in to comment.