Local encrypted p2p communication
Project description
pnet
Continuation of previous p2p network projects
Packet Format
{network id}|{packet type (any of [adv, msg, rsp, err])}|{message content}|{public key}|END
Node Types
Basic Node
Node(
:name Unique name within network - Should not use | or @
:network_id ID of network to listen to - Should not use |
:onmessage Callback to run when a message is recieved. Takes one argument
:crypt Crypt object or None. If None, auto-generates object.
:network_key Fernet encryption key of network. Leaving as None will disable network-level encryption
:server_port Port to listen on
:advertise_port Port to advertise on. Should be shared across a network
:broadcast_interval Time between UDP advertisements
:bind_ip IP to bind to
)
Methods:
.serve()
- Starts server in another thread.shutdown()
- Stops server.send(target: name of target peer, data: arbitrary data)
- Send data to node
Notes:
- Probably don't use this, it's extremely raw
- Make sure you use encryption
onmessage
should be a function that takes 1 argument
Advanced Node
Node(
:name Unique name within network - Should not use | or @
:network_id ID of network to listen to - Should not use |
:crypt Crypt object or None. If None, auto-generates object.
:network_key Fernet encryption key of network. Leaving as None will disable network-level encryption
:server_port Port to listen on
:advertise_port Port to advertise on. Should be shared across a network
:broadcast_interval Time between UDP advertisements
:bind_ip IP to bind to
:chunk_size Size of chunks in transmissions. Default 16KB should be fine
:functions Dictionary of function name: function
)
Methods:
@.register(function_name: name of function)
- Decorate functions with this to register them in the node. They should take 3 arguments:- Node instance
- Originator node name
- A readable stream
The function should then return a readable stream.
.send()
- ReplacesNode.send
.send(
target: either a target peer name, "*" for all known peers, or a list of peer names)
command: command name
data: An open file object, readable stream, or bytes
- All other
Node
methods
CommandNode
Node(
:name Unique name within network - Should not use | or @
:network_id ID of network to listen to - Should not use |
:crypt Crypt object or None. If None, auto-generates object.
:network_key Fernet encryption key of network. Leaving as None will disable network-level encryption
:server_port Port to listen on
:advertise_port Port to advertise on. Should be shared across a network
:broadcast_interval Time between UDP advertisements
:bind_ip IP to bind to
:chunk_size Size of chunks in transmissions. Default 16KB should be fine
:functions Dictionary of function name: function
)
Methods:
-
@.register(function_name: name of function)
- Decorate functions with this to register them in the node. They should be of the following form:function(node: CommandNode, originator: str, *args, **kwargs) -> Any JSON Encodable
-
Sending commands:
node.target("target or * or [targets]").<function name>(*args, **kwargs)
Notes:
- Nodes implement
get_funcs
andget_peers
calls automatically. Good for determining network topology.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
peernet-0.1.1.tar.gz
(11.1 kB
view details)
File details
Details for the file peernet-0.1.1.tar.gz
.
File metadata
- Download URL: peernet-0.1.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0626159846a8cd8c51b38da1ba9415f7e7375a87adb784b875c14fa500ef7739 |
|
MD5 | d44fab1e7921b7839a54e19d2250765e |
|
BLAKE2b-256 | dfba93c19445c86811d17049874eeba4e38a2ccc37c35fdb1af89cf467238321 |