Skip to main content

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() - Replaces Node.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 and get_peers calls automatically. Good for determining network topology.

Metadata

Release files for peernet 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for peernet 0.1.1
File Size Uploaded Provenance
peernet-0.1.1.tar.gz 11.1 kB Without provenance Details

Release files / peernet-0.1.1.tar.gz

Download URL peernet-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0626159846a8cd8c51b38da1ba9415f7e7375a87adb784b875c14fa500ef7739
BLAKE2b-256 checksum
How to use checksums
dfba93c19445c86811d17049874eeba4e38a2ccc37c35fdb1af89cf467238321
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for peernet 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page