I2P Proxy

The darc.proxy.i2p module contains the auxiliary functions around managing and processing the I2P proxy.

darc.proxy.i2p._i2p_bootstrap()[source]

I2P bootstrap.

The bootstrap arguments are defined as _I2P_ARGS.

Raises

subprocess.CalledProcessError – If the return code of _I2P_PROC is non-zero.

Return type

None

Return type

None

darc.proxy.i2p.fetch_hosts(link, force=False)[source]

Fetch hosts.txt.

Parameters
  • link (darc_link.Link) – Link object to fetch for its hosts.txt.

  • force (bool) – Force refetch hosts.txt.

Return type

None

Returns

Content of the hosts.txt file.

darc.proxy.i2p.get_hosts(link)[source]

Read hosts.txt.

Parameters

link (darc_link.Link) – Link object to read hosts.txt.

Return type

Optional[File]

Returns

  • If hosts.txt exists, return the data from hosts.txt.

    • path – relative path from hosts.txt to root of data storage PATH_DB, <proxy>/<scheme>/<hostname>/hosts.txt

    • database64 encoded content of hosts.txt

  • If not, return None.

darc.proxy.i2p.have_hosts(link)[source]

Check if hosts.txt already exists.

Parameters

link (darc_link.Link) – Link object to check if hosts.txt already exists.

Return type

Optional[str]

Returns

  • If hosts.txt exists, return the path to hosts.txt, i.e. <root>/<proxy>/<scheme>/<hostname>/hosts.txt.

  • If not, return None.

darc.proxy.i2p.i2p_bootstrap()[source]

Bootstrap wrapper for I2P.

The function will bootstrap the I2P proxy. It will retry for I2P_RETRY times in case of failure.

Also, it will NOT re-bootstrap the proxy as is guaranteed by _I2P_BS_FLAG.

Warns

I2PBootstrapFailed – If failed to bootstrap I2P proxy.

Raises

UnsupportedPlatform – If the system is not supported, i.e. not macOS or Linux.

Return type

None

Return type

None

darc.proxy.i2p.launch_i2p()[source]

Launch I2P process.

See also

This function mocks the behaviour of stem.process.launch_tor().

Return type

Popen[bytes]

darc.proxy.i2p.read_hosts(link, text, check=False)[source]

Read hosts.txt.

Parameters
  • link (darc_link.Link) – Link object to fetch for its hosts.txt.

  • text (str) – Content of hosts.txt.

  • check (bool) – If perform checks on extracted links, default to CHECK.

Return type

List[darc_link.Link]

Returns

List of links extracted.

darc.proxy.i2p.save_hosts(link, text)[source]

Save hosts.txt.

Parameters
  • link (darc_link.Link) – Link object of hosts.txt.

  • text (str) – Content of hosts.txt.

Return type

str

Returns

Saved path to hosts.txt, i.e. <root>/<proxy>/<scheme>/<hostname>/hosts.txt.

darc.proxy.i2p.I2P_REQUESTS_PROXY: Dict[str, Any]

Proxy for I2P sessions.

darc.proxy.i2p.I2P_SELENIUM_PROXY: selenium.webdriver.common.proxy.Proxy

Proxy for I2P web drivers.

The following constants are configuration through environment variables:

darc.proxy.i2p.I2P_PORT: int

Port for I2P proxy connection.

Default

4444

Environ

I2P_PORT

darc.proxy.i2p.I2P_RETRY: int

Retry times for I2P bootstrap when failure.

Default

3

Environ

I2P_RETRY

darc.proxy.i2p.BS_WAIT: float

Time after which the attempt to start I2P is aborted.

Default

90

Environ

I2P_WAIT

Note

If not provided, there will be NO timeouts.

darc.proxy.i2p.I2P_ARGS: List[str]

I2P bootstrap arguments for i2prouter start.

If provided, it should be parsed as command line arguments (c.f. shlex.split()).

Default

''

Environ

I2P_ARGS

Note

The command will be run as DARC_USER, if current user (c.f. getpass.getuser()) is root.

The following constants are defined for internal usage:

darc.proxy.i2p._MNG_I2P: bool

If manage I2P proxy through darc.

Default

True

Environ

DARC_I2P

darc.proxy.i2p._I2P_BS_FLAG: bool

If the I2P proxy is bootstrapped.

darc.proxy.i2p._I2P_PROC: subprocess.Popen

I2P proxy process running in the background.

darc.proxy.i2p._I2P_ARGS: List[str]

I2P proxy bootstrap arguments.