atomic_p2p.mixin.topology package¶
Subpackages¶
- atomic_p2p.mixin.topology.lan package
- Subpackages
- atomic_p2p.mixin.topology.lan.handler package
- Submodules
- atomic_p2p.mixin.topology.lan.handler.ack_new_member module
- atomic_p2p.mixin.topology.lan.handler.check_join module
- atomic_p2p.mixin.topology.lan.handler.disconnect module
- atomic_p2p.mixin.topology.lan.handler.join module
- atomic_p2p.mixin.topology.lan.handler.new_member module
- Module contents
- atomic_p2p.mixin.topology.lan.handler package
- Module contents
- Subpackages
Module contents¶
-
class
atomic_p2p.mixin.topology.
LanTopologyMixin
¶ Bases:
atomic_p2p.abc.topology.TopologyABC
-
add_peer_in_net
(peer_info, **kwargs)¶ Add given PeerInfo into current net’s peer_pool.
- Parameters
peer_info (
PeerInfo
) – A PeerInfo object to be add.- Raises
AssertionError – If given peer_info variable is not in proper PeerInfo type.
- Return type
None
-
del_peer_in_net
(peer_info, **kwargs)¶ Delete given PeerInfo if exists in current net’s peer_pool
- Parameters
peer_info (
PeerInfo
) – A PeerInfo object to be delete.- Return type
bool
- Returns
True is success, or False.
- Raises
ValueError – If peer_info object type is not PeerInfo.
-
get_peer_info_by_conn
(conn, **kwargs)¶ The function get peer info by given socket.
- Return type
Union
[None
,_Forwardref
]
-
get_peer_info_by_host
(host, **kwargs)¶ Get PeerInfo object from current net’s peer_pool if exists.
- Parameters
host (
Tuple
[str
,int
]) – A tuple(str, int) object represents host in net.- Return type
Union
[None
,PeerInfo
]- Returns
A PeerInfo object get from peer_pool if exists or None.
- Raises
ValueError – If a given host is not tuple(str, int) object.
-
handler_broadcast_packet
(host, pkt_type, **kwargs)¶ Exported function for pending broadcast pkt to specific peers. This function is for anyother instance to make a safer packet send with given role currently in peer_pool to broadcast.
Args:from atomic_p2p.utils.logging import getLogger
- host: First argument in tuple will not be used. Only use second one
which represents target role to recive the pkt.
pkt_type: Packet’s unique identity str. kwargs: Any addtional arguments need by Handler.
- Return type
None
-
handler_unicast_packet
(host, pkt_type, **kwargs)¶ Exported function for pending unicast pkt with specific host. This function is for anyother instance to make a safer packet send with specific host currently in peer_pool.
- Parameters
host (
Tuple
[str
,int
]) – Destination to recieve packet. This host should be currently in .pkt_type (
str
) – Packet’s unique identity str.kwargs – Any addtional arguments need by Handler.
- Raises
AssertionError – If given host variable is not in proper Tuple[str, int] type.
- Return type
None
-
is_peer_in_net
(info, **kwargs)¶ Return if in current net pool
- Parameters
peer_info – A PeerInfo object or a tuple with (str, int) type represents host.
- Return type
bool
- Returns
true if in net, or False.
- Raises
ValueError – If peer_info’s type is not PeerInfo or tuple (str, int)
-
join_net
(host, **kwargs)¶ Join into a net with known host. This method is use to join a net with known host while current peer is
not in any net yet.
- Parameters
host (
Tuple
[str
,int
]) – A tuple with address in str at position 0 and port in int at positon 1.- Return type
None
-
join_net_by_DNS
(domain, ns=None, **kwargs)¶ Join into a net with known domain. This method is use to join a net with known domain while current peer
is not in any net yet.
The domain can point to single or multiple exists host in net.
- Parameters
domain (
str
) – The domain point to any host currently in net.ns (
Optional
[List
[str
]]) – A list with str, specified which DNS server to query.
- Raises
ValueError – No any valid record after given domain.
- Return type
None
-
leave_net
(**kwargs)¶ - Return type
None
-
on_packet_to_route
(sock, pkt, **kwargs)¶ Call by AuthenticatorABC after a packet passed the authentication. The content should be like:
handler = self.select_handler(pkt_type=pkt._type) if handler is None:
self.logger.info(“Unknown packet type: {}”.format(pkt._type))
- else:
return handler.on_recv(src=pkt.src, pkt=pkt, sock=sock)
Notice that select_handler method is from HandleableMixin.
- Return type
None
-
topology_register_handler
()¶ Call by a peer class to register essentials handlers. The content should be like:
- installing_handlers = [
… AnyHandlerYouNeed, …
] for each in installing_handlers:
self.register_handler(handler=each)
Notice that register_handler method is from HandleableMixin & each element inside installing_handlers should be a Handler object.
-