-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Written tutorials. - Updated existing documentation.
- Loading branch information
Showing
27 changed files
with
601 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,6 @@ output/ | |
.idea | ||
|
||
.DS_Store | ||
|
||
# docs | ||
docs/_build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,26 @@ | ||
*********************** | ||
Isolating IPv8 overlays | ||
*********************** | ||
|
||
The purpose of this document is to show a means of isolating IPv8 overlays from outside interference in Gumby experiments. | ||
This document assumes the reader has a basic understanding of running Gumby experiments, creating IPv8 overlays and running them through the ``TriblerExperimentScriptClient`` class. | ||
This document assumes the reader has a basic understanding of running Gumby experiments, creating IPv8 overlays and running them. | ||
|
||
************************************* | ||
Isolating and replacing IPv8 overlays | ||
************************************* | ||
As you may have noticed, the overlays loaded by the ``TriblerExperimentScriptClient`` are the live overlays as loaded by Tribler (which you can toggle by setting the correct flags in the ``SessionConfig``). | ||
As you may have noticed, some of the overlays loaded through Gumby are the actual overlays that are also re-used in production. | ||
In some cases this may be desirable functionality, in other cases one would like to isolate these overlays as such that they do not communicate with third parties. | ||
|
||
How have we solved this in the past? | ||
As you may know, part of the unique identification of a IPv8 overlay is its master peer definition. | ||
Previously, one was required to create a subclass of the overlay under test in Gumby which had a different master peer definition. | ||
Even though this is still possible, a system has been implemented in Gumby which allows you to easily isolate and/or replace these existing Tribler overlays or add your own. | ||
As you may know, part of the unique identification of a IPv8 overlay is its community ID. | ||
Previously, one was required to create a subclass of the overlay under test in Gumby which had a different overlay ID. | ||
Even though this is still possible, a system has been implemented in Gumby which allows you to easily isolate and/or replace these existing overlays or add your own. | ||
|
||
Isolation | ||
--------- | ||
To demonstrate the use of overlay isolation we will use the following subclass of ``TriblerExperimentScriptClient``: | ||
|
||
.. code-block:: python | ||
class MyTriblerExperimentScriptClientSubclass(TriblerExperimentScriptClient): | ||
def create_overlay_loader(self): | ||
loader = super(MyTriblerExperimentScriptClientSubclass, self).create_community_loader() | ||
loader.isolate("HiddenTunnelCommunity") | ||
return loader | ||
What we are doing here is overwriting the ``TriblerExperimentScriptClient.create_community_loader`` method and modifying the default ``IsolatedCommunityLoader`` it returns. | ||
Specifically, we are asking the ``IsolatedCommunityLoader`` to isolate a community with the name ``"HiddenTunnelCommunity"``, which happens to be one of the communities loaded by default (if we don't modify the ``SessionConfig``). | ||
|
||
You can also perform isolation with your own communities. | ||
To do this, you will have to write your own launcher. | ||
We will go over the basics of this in the following section. | ||
|
||
My First CommunityLauncher | ||
-------------------------- | ||
Now that you know how to isolate existing communities, let's go over adding your own communities to ``TriblerExperimentScriptClient``. | ||
In this example we will create a custom ``CommunityLauncher``, in the next section we will discuss more advanced functionality which the ``CommunityLauncher`` offers. | ||
Consider the following minimal example, which sets up a launcher for some community class ``MyFirstCommunity``: | ||
|
||
.. code-block:: python | ||
class MyFirstCommunityLauncher(CommunityLauncher): | ||
def get_name(self): | ||
return "MyFirstCommunity" | ||
def get_community_class(self): | ||
return MyFirstCommunity | ||
class MyTriblerExperimentScriptClientSubclass(TriblerExperimentScriptClient): | ||
def create_community_loader(self): | ||
loader = super(MyTriblerExperimentScriptClientSubclass, self).create_community_loader() | ||
# Register our custom community | ||
loader.set_launcher(MyFirstCommunityLauncher()) | ||
# Which we can isolate as well | ||
loader.isolate("MyFirstCommunity") | ||
return loader | ||
Isolating a particular community is as simple as adding the following line to a scenario file (before the IPv8 session starts): | ||
|
||
As you can see, a minimal ``CommunityLauncher`` implementation requires a name and a community class to be defined. | ||
A launcher is uniquely identified by its name. | ||
**If you use ``set_launcher`` with an existing name, the current launcher will be overwritten.** | ||
In some cases overwriting a default community entirely may be desired though. | ||
.. code-block:: none | ||
CommunityLauncher Interface | ||
--------------------------- | ||
The reference for the methods of the ``CommunityLauncher`` is as follows: | ||
@0:0 isolate_ipv8_overlay PingPongCommunity | ||
========================================== =========== =========== | ||
Method Type Description | ||
========================================== =========== =========== | ||
``get_name()`` *str* The unique name of this launcher. | ||
``not_before()`` *list(str)* The names of launchers which should be loaded before this launcher is launched. Use in combination with ``prepare()`` to retrieve runtime information from other communities. | ||
``should_launch(session)`` *bool* Checks the Session parameters to see if this community should be loaded. | ||
``prepare(ipv8, session)`` *None* Prepare this launcher with information from the current ``Session``. | ||
``finalize(ipv8, session, community)`` *None* Called after the overlay has been loaded. | ||
``get_overlay_class()`` *Overlay* The class of the overlay to be loaded by IPv8. | ||
``get_my_peer(ipv8, session)`` *Member* The IPv8 member to use for this community. | ||
``should_load_now(session)`` *bool* Load this overlay right now, should be ``True`` in most cases. The ``IsolatedCommunityWrapper`` uses this mechanism to provide a custom master member. | ||
``get_args(session)`` *tuple* The arguments to supply to the ``__init__`` method of the loaded overlay class. | ||
``get_kwargs(session)`` *dict* The named arguments to supply to the ``__init__`` method of the loaded overlay class. | ||
========================================== =========== =========== | ||
In this case, Gumby will automatically search for the launcher associated with the ``PingPongCommunity`` and replace the existing launcher with an instance of ``IsolatedIPv8LauncherWrapper``. | ||
All information in the existing launcher will be copied to the instance of ``IsolatedIPv8LauncherWrapper``. | ||
The community ID will be randomized such that it becomes more difficult for the Gumby experiment to interfere with deployed communities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# list see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath('.')) | ||
|
||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
project = 'Gumby' | ||
copyright = '2021, Tribler Team' # pylint: disable=redefined-builtin | ||
author = 'Tribler Team' | ||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = [ | ||
] | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ['_templates'] | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path. | ||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = 'alabaster' | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ['_static'] |
Oops, something went wrong.