latest.ipv8.configuration

Module Contents

Classes

Strategy

ConfigBuilder enum to request default DiscoveryStrategies to be instantiated.

WalkerDefinition

ConfigBuilder directive to request a given strategy to run below a given peer count.

Bootstrapper

ConfigBuilder enum to request a community to use a given bootstrapping method.

BootstrapperDefinition

ConfigBuilder directive to specify how Bootstrapper instances should be instantiated.

ConfigBuilder

Factory class to create IPv8 configurations.

Functions

get_default_configuration(→ dict[Any, Any])

Get a COPY of the default configuration.

Attributes

DISPERSY_BOOTSTRAPPER

default_bootstrap_defs

Shortcut for the most common ConfigBuilder default bootstrapper settings.

latest.ipv8.configuration.DISPERSY_BOOTSTRAPPER: dict[Any, Any]
latest.ipv8.configuration.get_default_configuration() dict[Any, Any]

Get a COPY of the default configuration.

You should always use this method instead of accesesing the global default directly.

class latest.ipv8.configuration.Strategy(*args, **kwds)

Bases: enum.Enum

ConfigBuilder enum to request default DiscoveryStrategies to be instantiated.

RandomWalk = 'RandomWalk'
RandomChurn = 'RandomChurn'
PeriodicSimilarity = 'PeriodicSimilarity'
EdgeWalk = 'EdgeWalk'
PingChurn = 'PingChurn'
classmethod values() list[str]

Get the known default DiscoveryStrategy names.

class latest.ipv8.configuration.WalkerDefinition

Bases: NamedTuple

ConfigBuilder directive to request a given strategy to run below a given peer count.

The strategy instance is created with the keyword arguments given in init. If the peers are set to -1, the strategy will always be invoked, regardless of the number of peers.

strategy: Strategy
peers: int
init: dict
class latest.ipv8.configuration.Bootstrapper(*args, **kwds)

Bases: enum.Enum

ConfigBuilder enum to request a community to use a given bootstrapping method.

DispersyBootstrapper = 'DispersyBootstrapper'
UDPBroadcastBootstrapper = 'UDPBroadcastBootstrapper'
classmethod values() list[str]

Get the known default Bootstrapper names.

class latest.ipv8.configuration.BootstrapperDefinition

Bases: NamedTuple

ConfigBuilder directive to specify how Bootstrapper instances should be instantiated.

The bootstrapper instance is created with the keyword arguments given in init.

bootstrapper: Bootstrapper
init: dict
latest.ipv8.configuration.default_bootstrap_defs

Shortcut for the most common ConfigBuilder default bootstrapper settings.

class latest.ipv8.configuration.ConfigBuilder(clean: bool = False)

Factory class to create IPv8 configurations.

finalize() dict

Process the builder input and check for errors, this produces a configuration dictionary suitable for IPv8.

Essentially this only checks the config variable for errors, use that instead if you’re confident you never make any errors.

clear_keys() ConfigBuilder

Remove all keys in the current configuration.

clear_overlays() ConfigBuilder

Remove all overlays in the current configuration.

set_address(address: str, interface: str = 'UDPIPv4') ConfigBuilder

Set the address IPv8 is to try and bind to.

For IPv4 localhost only use 127.0.0.1
For IPv4 Internet communication use 0.0.0.0
For IPv6 localhost only use ::1
For IPv6 Internet communication use ::
Parameters:
  • address – the address to attempt to bind to.

  • interface – the interface to use (currently “UDPIPv4” or “UDPIPv6”).

set_port(port: int, interface: str = 'UDPIPv4') ConfigBuilder

Set the port that IPv8 should TRY to bind to. If your port is not available, IPv8 will try and find another one.

Parameters:
  • port – the port to attempt to bind to.

  • interface – the interface to use (currently “UDPIPv4” or “UDPIPv6”).

set_log_level(log_level: str) ConfigBuilder

Set the log level for all of IPv8’s loggers. Choose from ‘CRITICAL’, ‘ERROR’, ‘WARNING’, ‘INFO’, ‘DEBUG’ or ‘NOTSET’.

set_working_directory(folder_path: str) ConfigBuilder

Set the common working directory for overlays.

Individual settings may override this working directory, but it serves as the base working directory.

set_walker_interval(interval: float) ConfigBuilder

Set the interval, in seconds, at which IPv8 schedules its strategies.

An interval of 3.14 would mean that each walker attempts to walk every 3.14 seconds. Setting this interval too low will choke the event thread and decrease the QoS of IPv8 overlays. Setting this interval too high will decrease the QoS of IPv8 overlays due to lack of content.

add_key(alias: str, generation: str, file_path: str) ConfigBuilder

Add a key by alias and mode of generation, to be stored at a certain file path.

If a key already exists at the given file path, that will be loaded instead of generating a new key.

add_key_from_bin(alias: str, key_bin_b64: str, file_path: str | None = None) ConfigBuilder

Add a key by alias and its raw key material, possibly stored at a certain file path.

If a key already exists at the given file path, that will be loaded instead of the given key material.

Parameters:
  • alias – the alias used to reference this key

  • key_bin_b64 – the base64 encoded private key material

  • file_path – the optional file path to save the key to

add_ephemeral_key(alias: str) ConfigBuilder

Add an ephemeral key, which is only stored in memory (i.e., not associated with a file).

Parameters:

alias – the alias used to reference this key

add_overlay(overlay_class: str, key_alias: str, walkers: list[WalkerDefinition], bootstrappers: list[BootstrapperDefinition], initialize: dict[str, Any], on_start: list[tuple], allow_duplicate: bool = False) ConfigBuilder

Add an overlay by its class name. You can choose from the default communities or register your own (see IPv8’s extra_communities for the latter). Whatever key alias you choose for this overlay should be registered through add_key.

The default communities include:

  • ‘AttestationCommunity’

  • ‘DiscoveryCommunity’

  • ‘HiddenTunnelCommunity’

  • ‘IdentityCommunity’

  • ‘TunnelCommunity’

  • ‘DHTDiscoveryCommunity’

The initialize argument is a key-value mapping passed to the constructor (__init__) of the overlay.

The on_start contains a list of tuples that specify the method to call on the overlay when IPv8 has initialized, coupled to the positional arguments to pass to the method, for example to call some_method(1, 2):

[(“some_method”, 1, 2)]

Lastly, IPv8 is capable of loading two distinct instances of the same overlay class. Set allow_duplicate to explicitly allow this (usually this is programmer error).