atomic_p2p.utils package

Submodules

atomic_p2p.utils.dns_resolver module

class atomic_p2p.utils.dns_resolver.DNSResolver(ns, role)

Bases: object

A object responsible for keep updating peer info pool from DNS This object will maintain every records in DNS such as global and self- service pool.

__init__(ns, role)

Init of DNSResolver

Parameters
  • ns (Union[str, List[str]]) – All avaiable nameservers.

  • role (str) – Current peer’s service type.

  • loopDelay – Update period, default is 300 secs.

Return type

None

change_ns(ns)

Change resolver’s namserver host.

Parameters

ns (List[str]) – nameservers to change to.

Return type

None

forward(fqdn)

Wraped function to query A records.

Parameters

fqdn (str) – fqdn to be query.

Return type

List[str]

Returns

A records of given fqdn in list with str. Exceptions occurr will return a empty list.

reverse(address)

Wrapped function to query PTR records.

Parameters

address (str) – address to be query.

Return type

List[str]

Returns

PTR records of give address in list with str. Exceptions occurr will return a empty list

srv(fqdn)

Wrapped function to query SRV records.

Parameters

fqdn (str) – fqdn to be query.

Returns

priority, weight, port, and srv_fqdn Exceptions occurr will return with (0, 0, -1, None)

Return type

Give a tuple with four varialbe with

sync_from_DNS(current_host, domain)

Query from DNS fetch all records and put in pool Hard-code with global.[domain] will send to DNS for query. Durring pro- cessing each record, if any error occured, then it will be skip. The fianl result would be all DNS record been parse to PeerInfo and put at each peer pool in class variable.

Parameters

domain (str) – Whole net’s domain.

Return type

List[PeerInfo]

Returns

Query results in list with PeerInfo from DNS.

atomic_p2p.utils.security module

atomic_p2p.utils.security.create_self_signed_cert(cert_dir, cert_file='myapp.crt', key_file='myapp.key')

If datacard.crt and datacard.key don’t exist in cert_dir, create a new self-signed cert and keypair and write them into that directory.

Return type

Tuple[str, str]

atomic_p2p.utils.security.self_hash(path)
Return type

str

Module contents

atomic_p2p.utils.create_self_signed_cert(cert_dir, cert_file='myapp.crt', key_file='myapp.key')

If datacard.crt and datacard.key don’t exist in cert_dir, create a new self-signed cert and keypair and write them into that directory.

Return type

Tuple[str, str]

atomic_p2p.utils.self_hash(path)
Return type

str

atomic_p2p.utils.host_valid(host)
class atomic_p2p.utils.DNSResolver(ns, role)

Bases: object

A object responsible for keep updating peer info pool from DNS This object will maintain every records in DNS such as global and self- service pool.

__init__(ns, role)

Init of DNSResolver

Parameters
  • ns (Union[str, List[str]]) – All avaiable nameservers.

  • role (str) – Current peer’s service type.

  • loopDelay – Update period, default is 300 secs.

Return type

None

change_ns(ns)

Change resolver’s namserver host.

Parameters

ns (List[str]) – nameservers to change to.

Return type

None

forward(fqdn)

Wraped function to query A records.

Parameters

fqdn (str) – fqdn to be query.

Return type

List[str]

Returns

A records of given fqdn in list with str. Exceptions occurr will return a empty list.

reverse(address)

Wrapped function to query PTR records.

Parameters

address (str) – address to be query.

Return type

List[str]

Returns

PTR records of give address in list with str. Exceptions occurr will return a empty list

srv(fqdn)

Wrapped function to query SRV records.

Parameters

fqdn (str) – fqdn to be query.

Returns

priority, weight, port, and srv_fqdn Exceptions occurr will return with (0, 0, -1, None)

Return type

Give a tuple with four varialbe with

sync_from_DNS(current_host, domain)

Query from DNS fetch all records and put in pool Hard-code with global.[domain] will send to DNS for query. Durring pro- cessing each record, if any error occured, then it will be skip. The fianl result would be all DNS record been parse to PeerInfo and put at each peer pool in class variable.

Parameters

domain (str) – Whole net’s domain.

Return type

List[PeerInfo]

Returns

Query results in list with PeerInfo from DNS.