This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Basic Usage

To connect to a mesh network, you will use the MeshSocket object. You can instantiate this as follows:

>>> import py2p
>>> sock = py2p.MeshSocket('0.0.0.0', 4444)

Using '0.0.0.0' will automatically grab you LAN address. If you want to use an outward-facing internet connection, you will need to specify this address as follows:

>>> import py2p
>>> sock = py2p.MeshSocket('0.0.0.0', 4444, out_addr=('8.8.8.8', 8888))

In addition, you can enable SSL encryption if you have PyOpenSSL or cryptography installed. This works by specifying a custom protocol object, like so:

>>> import py2p
>>> sock = py2p.MeshSocket('0.0.0.0', 4444, prot=py2p.Protocol('mesh', 'SSL'))

Eventually that will be the default, but while things are being tested it will default to plaintext. Specifying a different protocol object will ensure that you only can connect to people who share your object structure. So if someone has 'mesh2' instead of 'mesh', you will fail to connect.

Unfortunately, this failure is currently silent. Because this is asynchronous in nature, raising an Exception is not possible. Because of this, it’s good to perform the following check after connecting:

>>> import py2p, time
>>> sock = py2p.MeshSocket('0.0.0.0', 4444)
>>> sock.connect('192.168.1.14', 4567)
>>> time.sleep(1)
>>> assert sock.routing_table

To send a message, you should use the send method. Each argument you supply will correspond to a packet that your peer receives. In addition, there are two keyed arguments you can use. flag will specify how other nodes relay this. b'broadcast' will indicate that other nodes are supposed to relay it. b'whisper' will indicate that your peers are not supposed to relay it. There are other technically valid options, but they are not recommended. type will specify what actions other nodes are supposed to take on it. It defaults to b'broadcast', which indicates no change from the norm. There are other valid options, but they should normally be left alone, unless you’ve written a handler (see below) to act on this.

>>> sock.send('this is', 'a test')
>>> sock.send('you can also', 'send other things')
>>> sock.send({
...     'for example': True,
...     'how about': None,
...     'or even': float('inf')
... })

Receiving is a bit simpler. When you call the recv method, you receive a Message object. This has a number of methods outlined here. Most notably, you can get the packets in a message with Message.packets, and reply directly with Message.reply().

>>> sock.send('Did you get this?')
>>> msg = sock.recv()
>>> print(msg)
Message(type=2, packets=[b'yes', b'I did'], sender=b'6VnYj9LjoVLTvU3uPhy4nxm6yv2wEvhaRtGHeV9wwFngWGGqKAzuZ8jK6gFuvq737V')
>>> print(msg.packets)
[2, b'yes', b'I did']
>>> for msg in sock.recv(10):
...     msg.reply("Replying to a list")

Events

These also follow the EventEmitter API. These are described in detail in the API docs.

Advanced Usage

In addition to this, you can register a custom handler for incoming messages. This is appended to the end of the included ones. When writing your handler, you must keep in mind that you are only passed a Message object and a link to the receiving connection. Fortunately you can get access to everything you need from these objects. To see what methods each has, see the API docs. An example service would look like this:

>>> import py2p
>>> sock = py2p.MeshSocket('0.0.0.0', 4444)
>>> @sock.register_handler
>>> def relay_tx(msg, handler):
...     """Relays bitcoin transactions to various services"""
...     packets = msg.packets  # Gives a list of the non-metadata packets
...     server = msg.server    # Returns your MeshSocket object
...     if packets[0] == b'tx_relay':  # It's important that this flag is bytes
...         from pycoin import tx, services
...         relay = tx.Tx.from_bin(packets[1])
...         services.blockchain_info.send_tx(relay)
...         services.insight.InsightProvider().send_tx(relay)
...         return True        # This tells the daemon to stop calling handlers
...
>>> # sock.register_handler(relay_tx)
>>> # This syntax also works

If this does not take two arguments, register_handler will raise a ValueError. To help debug these services, you can specify a debug_level in the constructor. Using a value of 5, you can see when it enters into each handler, as well as every message which goes in or out.

Release History

Release History

0.6.757

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.607

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.516

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.213

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.186

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.136

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
py2p-0.6.757-cp27-cp27m-macosx_10_6_intel.whl (101.6 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Feb 23, 2017
py2p-0.6.757-cp27-cp27m-win32.whl (71.5 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Feb 23, 2017
py2p-0.6.757-cp27-cp27m-win_amd64.whl (73.4 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Feb 23, 2017
py2p-0.6.757-cp33-cp33m-win32.whl (72.0 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Feb 23, 2017
py2p-0.6.757-cp33-cp33m-win_amd64.whl (73.3 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Feb 23, 2017
py2p-0.6.757-cp34-cp34m-macosx_10_6_intel.whl (101.4 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Feb 23, 2017
py2p-0.6.757-cp34-cp34m-win32.whl (72.0 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Feb 23, 2017
py2p-0.6.757-cp34-cp34m-win_amd64.whl (73.3 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Feb 23, 2017
py2p-0.6.757-cp35-cp35m-macosx_10_6_intel.whl (101.5 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Feb 23, 2017
py2p-0.6.757-cp35-cp35m-win32.whl (71.0 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Feb 23, 2017
py2p-0.6.757-cp35-cp35m-win_amd64.whl (74.3 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Feb 23, 2017
py2p-0.6.757-cp36-cp36m-macosx_10_6_intel.whl (101.5 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Feb 23, 2017
py2p-0.6.757-cp36-cp36m-win32.whl (71.0 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Feb 23, 2017
py2p-0.6.757-cp36-cp36m-win_amd64.whl (74.3 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Feb 23, 2017
py2p-0.6.757-py2.py3-none-any.whl (47.2 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Feb 23, 2017
py2p-0.6.757.tar.gz (75.6 kB) Copy SHA256 Checksum SHA256 Source Feb 23, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting