bittensor.utils.networking#

Utils for handling local network with ip and ports.

Exceptions#

ExternalIPNotFound

Raised if we cannot attain your external ip from CURL/URLLIB/IPIFY/AWS

Functions#

int_to_ip(int_val)

Maps an integer to a unique ip-string

ip_to_int(str_val)

Maps an ip-string to a unique integer.

ip_version(str_val)

Returns the ip version (IPV4 or IPV6).

ip__str__(ip_type, ip_str, port)

Return a formatted ip string

get_external_ip()

Checks CURL/URLLIB/IPIFY/AWS for your external ip.

get_formatted_ws_endpoint_url(endpoint_url)

Returns a formatted websocket endpoint url.

ensure_connected(func)

Decorator ensuring the function executes with an active substrate connection.

Module Contents#

bittensor.utils.networking.int_to_ip(int_val)[source]#

Maps an integer to a unique ip-string :param int_val: The integer representation of an ip. Must be in the range (0, 3.4028237e+38). :type int_val: int128, required

Returns:

The string representation of an ip. Of form ..*.* for ipv4 or :::::* for ipv6

Return type:

str_val (:tyep:`str`, `required)

Raises:

netaddr.core.AddrFormatError (Exception) – Raised when the passed int_vals is not a valid ip int value.

Parameters:

int_val (int)

bittensor.utils.networking.ip_to_int(str_val)[source]#

Maps an ip-string to a unique integer. arg:

str_val (:tyep:`str`, `required):

The string representation of an ip. Of form ..*.* for ipv4 or :::::* for ipv6

Returns:

The integer representation of an ip. Must be in the range (0, 3.4028237e+38).

Return type:

int_val (int128, required)

Raises:

netaddr.core.AddrFormatError (Exception) – Raised when the passed str_val is not a valid ip string value.

Parameters:

str_val (str)

bittensor.utils.networking.ip_version(str_val)[source]#

Returns the ip version (IPV4 or IPV6). arg:

str_val (:tyep:`str`, `required):

The string representation of an ip. Of form ..*.* for ipv4 or :::::* for ipv6

Returns:

The ip version (Either 4 or 6 for IPv4/IPv6)

Return type:

int_val (int128, required)

Raises:

netaddr.core.AddrFormatError (Exception) – Raised when the passed str_val is not a valid ip string value.

Parameters:

str_val (str)

bittensor.utils.networking.ip__str__(ip_type, ip_str, port)[source]#

Return a formatted ip string

Parameters:
exception bittensor.utils.networking.ExternalIPNotFound[source]#

Bases: Exception

Raised if we cannot attain your external ip from CURL/URLLIB/IPIFY/AWS

Initialize self. See help(type(self)) for accurate signature.

bittensor.utils.networking.get_external_ip()[source]#

Checks CURL/URLLIB/IPIFY/AWS for your external ip. :returns: Your routers external facing ip as a string. :rtype: external_ip (str required)

Raises:

ExternalIPNotFound (Exception) – Raised if all external ip attempts fail.

Return type:

str

bittensor.utils.networking.get_formatted_ws_endpoint_url(endpoint_url)[source]#

Returns a formatted websocket endpoint url. Note: The port (or lack thereof) is left unchanged :param endpoint_url: The endpoint url to format. :type endpoint_url: str, required

Returns:

The formatted endpoint url. In the form of ws://<endpoint_url> or wss://<endpoint_url>

Return type:

formatted_endpoint_url (str, required)

Parameters:

endpoint_url (str)

bittensor.utils.networking.ensure_connected(func)[source]#

Decorator ensuring the function executes with an active substrate connection.