atomic_p2p.peer package¶
Subpackages¶
Submodules¶
atomic_p2p.peer.command module¶
-
class
atomic_p2p.peer.command.
HelpCmd
(peer)¶ Bases:
atomic_p2p.communication.command.Command
show the help for peers. Usage in prompt: peer help [cmd]
-
class
atomic_p2p.peer.command.
JoinCmd
(peer)¶ Bases:
atomic_p2p.communication.command.Command
send a join request to a peer. Usage in prompt:
peer join IP:PORT peer join DOMAIN [NS1,NS2,NS3]
-
class
atomic_p2p.peer.command.
LeaveNetCmd
(peer)¶ Bases:
atomic_p2p.communication.command.Command
leave the current net, this will clear monitor list and peer list. Usage in prompt: peer leavenet
-
class
atomic_p2p.peer.command.
ListCmd
(peer)¶ Bases:
atomic_p2p.communication.command.Command
list every linked peer’s host message in prompt. Usage in prompt: peer list
-
class
atomic_p2p.peer.command.
SendCmd
(peer)¶ Bases:
atomic_p2p.communication.command.Command
send a message to a specific peer or broadcast in prompt. Usage in prompt: peer send [ip:port/broadcast:all] [msg]
atomic_p2p.peer.communication module¶
-
class
atomic_p2p.peer.communication.
MessageHandler
(peer)¶ Bases:
atomic_p2p.communication.handler.Handler
-
on_recv_pkt
(src, pkt, conn)¶
-
on_send_pkt
(target, msg)¶
-
pkt_type
= 'message'¶
-
atomic_p2p.peer.peer module¶
-
class
atomic_p2p.peer.peer.
Peer
(host, name, role, cert, program_hash, ns, auto_register=False, logger=<Logger atomic_p2p.peer.peer (DEBUG)>)¶ Bases:
atomic_p2p.mixin.handleable.HandleableMixin
,atomic_p2p.mixin.commandable.CommandableMixin
,atomic_p2p.mixin.topology.lan.LanTopologyMixin
,atomic_p2p.mixin.authenticator.default_authenticator.DefaultAuthenticatorMixin
-
_Peer__on_accept
(sock, mask, **kwargs)¶ Call when a new socket is connection by waiter socket. This will accept all sockets from outside, but it doesn’t mean every socket’s
packet be process by higher layer.
This is the 1st layer to process sockets.
-
_Peer__on_handle
(sock, mask, **kwargs)¶ Decide whether send or recv.
-
_Peer__on_recv
(sock, mask, **kwargs)¶ Method use when recieve socket data. This is 2th layer to process Packets.
-
_Peer__on_send
(sock, mask, **kwargs)¶ Method use when sending data to socket.
-
__init__
(host, name, role, cert, program_hash, ns, auto_register=False, logger=<Logger atomic_p2p.peer.peer (DEBUG)>)¶ Init of PeerManager
- Parameters
host (
Tuple
[str
,int
]) – Binding host.name (
str
) – Peer’s name in net.role (
str
) – Peer’s role in net.cert (
Tuple
[str
,str
]) – Cert file’s path.program_hash (
str
) – Program self hash to send in packet.ns (
str
) – Nameserver address for resolve DNS.logger (logging.Logger) – Logger for logging.
- Return type
None
-
_loop
()¶ Called inside infinite loop from outside inherited class. It’s use to call the method which given event is triggered.
-
_on_packet
(sock, pkt, handler)¶ Method use to process passed packet to higher application layer. This method will call by AuthenticatorMixin when a packet is passed examination.
This is 3rd layer to process packet to handler. This is last layer to application layer.
- Return type
None
-
connectlist
¶ - Return type
List
[~T]
-
loop
()¶
-
loop_start
()¶
-
loop_stop
()¶
-
loop_stop_post
()¶
-
new_tcp_long_conn
(dst)¶ Create a ssl-wrapped TCP socket with given destination host
- Parameters
dst (
Tuple
[str
,int
]) – Specified socket destination.- Return type
SSLSocket
- Returns
- A SSLSocket object which connected to destination host with
non-blocking.
- Raises
AssertionError – If given dst variable is not in proper Tuple[str, int] type.
-
pend_packet
(sock, pkt, **kwargs)¶ Pending pkt’s raw_data to queue’s with sepecific sock. Any exception when wrapping handler to packet whould cause this connec- tion been close and thread maintaining loop terminate.
- Parameters
sock (Socket) – A Socket which wants to pend on its queue.
pkt (Packet) – A Packet ready to be pend.
**kwargs – Any additional arguments needs by handler object.
- Raises
AssertionError – If given pkt variable is not in proper Packet type.
- Return type
None
-
program_hash
¶
-
register_socket
(sock)¶ Register a new socket with packet queue & selector. Init a packet queue and put into dict for further handling of packets. And the given socket will be register in selector for IO process.
- Parameters
sock (Socket) – A Socket object which wants to be register.
- Return type
None
-
send_queue
¶
-
server_info
-
unregister_socket
(sock)¶ - Return type
None
-
atomic_p2p.peer.process_peer module¶
-
class
atomic_p2p.peer.process_peer.
ProcessPeer
(host, name, role, cert, program_hash, ns=None, loop_delay=1, auto_register=False, logger=<Logger atomic_p2p.peer.process_peer (DEBUG)>)¶ Bases:
atomic_p2p.peer.peer.Peer
,multiprocessing.context.Process
-
is_start
()¶ - Return type
bool
-
run
()¶ Method to be run in sub-process; can be overridden in sub-class
- Return type
None
-
start
()¶ Start child process
- Return type
None
-
stop
()¶ - Return type
None
-
atomic_p2p.peer.thread_peer module¶
-
class
atomic_p2p.peer.thread_peer.
ThreadPeer
(host, name, role, cert, program_hash, ns=None, loop_delay=1, auto_register=False, logger=<Logger atomic_p2p.peer.thread_peer (DEBUG)>)¶ Bases:
atomic_p2p.peer.peer.Peer
,threading.Thread
-
is_start
()¶ - Return type
bool
-
run
()¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- Return type
None
-
start
()¶ Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
- Return type
None
-
stop
()¶ - Return type
None
-
Module contents¶
-
class
atomic_p2p.peer.
Peer
(host, name, role, cert, program_hash, ns, auto_register=False, logger=<Logger atomic_p2p.peer.peer (DEBUG)>)¶ Bases:
atomic_p2p.mixin.handleable.HandleableMixin
,atomic_p2p.mixin.commandable.CommandableMixin
,atomic_p2p.mixin.topology.lan.LanTopologyMixin
,atomic_p2p.mixin.authenticator.default_authenticator.DefaultAuthenticatorMixin
-
_Peer__on_accept
(sock, mask, **kwargs)¶ Call when a new socket is connection by waiter socket. This will accept all sockets from outside, but it doesn’t mean every socket’s
packet be process by higher layer.
This is the 1st layer to process sockets.
-
_Peer__on_handle
(sock, mask, **kwargs)¶ Decide whether send or recv.
-
_Peer__on_recv
(sock, mask, **kwargs)¶ Method use when recieve socket data. This is 2th layer to process Packets.
-
_Peer__on_send
(sock, mask, **kwargs)¶ Method use when sending data to socket.
-
__init__
(host, name, role, cert, program_hash, ns, auto_register=False, logger=<Logger atomic_p2p.peer.peer (DEBUG)>)¶ Init of PeerManager
- Parameters
host (
Tuple
[str
,int
]) – Binding host.name (
str
) – Peer’s name in net.role (
str
) – Peer’s role in net.cert (
Tuple
[str
,str
]) – Cert file’s path.program_hash (
str
) – Program self hash to send in packet.ns (
str
) – Nameserver address for resolve DNS.logger (logging.Logger) – Logger for logging.
- Return type
None
-
_loop
()¶ Called inside infinite loop from outside inherited class. It’s use to call the method which given event is triggered.
-
_on_packet
(sock, pkt, handler)¶ Method use to process passed packet to higher application layer. This method will call by AuthenticatorMixin when a packet is passed examination.
This is 3rd layer to process packet to handler. This is last layer to application layer.
- Return type
None
-
connectlist
¶ - Return type
List
[~T]
-
loop
()¶
-
loop_start
()¶
-
loop_stop
()¶
-
loop_stop_post
()¶
-
new_tcp_long_conn
(dst)¶ Create a ssl-wrapped TCP socket with given destination host
- Parameters
dst (
Tuple
[str
,int
]) – Specified socket destination.- Return type
SSLSocket
- Returns
- A SSLSocket object which connected to destination host with
non-blocking.
- Raises
AssertionError – If given dst variable is not in proper Tuple[str, int] type.
-
pend_packet
(sock, pkt, **kwargs)¶ Pending pkt’s raw_data to queue’s with sepecific sock. Any exception when wrapping handler to packet whould cause this connec- tion been close and thread maintaining loop terminate.
- Parameters
sock (Socket) – A Socket which wants to pend on its queue.
pkt (Packet) – A Packet ready to be pend.
**kwargs – Any additional arguments needs by handler object.
- Raises
AssertionError – If given pkt variable is not in proper Packet type.
- Return type
None
-
program_hash
¶
-
register_socket
(sock)¶ Register a new socket with packet queue & selector. Init a packet queue and put into dict for further handling of packets. And the given socket will be register in selector for IO process.
- Parameters
sock (Socket) – A Socket object which wants to be register.
- Return type
None
-
send_queue
¶
-
server_info
-
unregister_socket
(sock)¶ - Return type
None
-
-
class
atomic_p2p.peer.
ThreadPeer
(host, name, role, cert, program_hash, ns=None, loop_delay=1, auto_register=False, logger=<Logger atomic_p2p.peer.thread_peer (DEBUG)>)¶ Bases:
atomic_p2p.peer.peer.Peer
,threading.Thread
-
is_start
()¶ - Return type
bool
-
run
()¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- Return type
None
-
start
()¶ Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
- Return type
None
-
stop
()¶ - Return type
None
-
-
class
atomic_p2p.peer.
ProcessPeer
(host, name, role, cert, program_hash, ns=None, loop_delay=1, auto_register=False, logger=<Logger atomic_p2p.peer.process_peer (DEBUG)>)¶ Bases:
atomic_p2p.peer.peer.Peer
,multiprocessing.context.Process
-
is_start
()¶ - Return type
bool
-
run
()¶ Method to be run in sub-process; can be overridden in sub-class
- Return type
None
-
start
()¶ Start child process
- Return type
None
-
stop
()¶ - Return type
None
-