Skip to content

lightningstorm-project/python-lightningstorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightning Storm Python Implementation

Official python implementation of the LightningStorm peer-to-peer meta-protocol.

Internal Python API

from uuid import UUID

from lightningstorm.core.cloud import Cloud
from lightningstorm.core.cloud import Node
from lightningstorm.core.raindrop import MemoryRaindrop


# peer1
peer1_node1 = Node(uuid=UUID("889e2473-9552-4643-80c8-502335fc5b62"))
peer1_cloud1 = Cloud(
    uuid=UUID("646f6476-9b81-4e47-9e3d-daeb5e8a8599"), nodes=[peer1_node1]
)

# peer2
peer2_node1 = Node(uuid=UUID("41497db1-e0e8-470c-9ffe-c18ff49e1bcf"))
peer2_cloud2 = Cloud(
    uuid=UUID("c6a2455d-0e36-4fcf-8945-2351ec3415d4"), nodes=[peer2_node1]
)

# raindrop from peer1 to peer2
raindrop_1to2 = MemoryRaindrop(
    uuid=UUID("e96e58c7-0df4-4bb0-9b28-c90e5de940bb"), payload=b"any binary payload\xF0\xFE"
)

# load raindrop
peer1_node1.load_raindrop(raindrop_1to2)

# share raindrop with peer2
peer1_node1.share_raindrop(
    raindrop_uuid=raindrop_1to2.uuid, peers_cloud_uuid=[peer2_cloud2.uuid]
)

# list raindrops from peer1 to peer2
peer1_node1.list_raindrops_to_peer(peer2_cloud2.uuid)

Raindrop Headers

>>> raindrop_1to2.get_headers()
{
    'UUID': 'e96e58c7-0df4-4bb0-9b28-c90e5de940bb',
    'Created-Date': '2020-03-22T02:57:42.965815+00:00',
    'Content-Type': 'application/octet-stream',
    'Content-Lenght': '20'
}

Raindrop payload

>>> raindrop_1to2.payload
b'any binary payload\xf0\xfe'

Raindrop serialization

MIME - Multipurpose Internet Mail Extensions / "HTTP-like" message format

>>> raindrop_1to2.to_mime()
b'MIME-Version: 1.0\r\nUUID: e96e58c7-0df4-4bb0-9b28-c90e5de940bb\r\nCreated-Date: 2020-03-22T18:28:04.137772+00:00\r\nContent-Type: application/octet-stream\r\nContent-Lenght: 20\r\n\r\nany binary payload\xf0\xfe'
MIME-Version: 1.0
UUID: e96e58c7-0df4-4bb0-9b28-c90e5de940bb
Created-Date: 2020-03-22T18:15:39.542778+00:00
Content-Type: application/octet-stream
Content-Lenght: 20

any binary payload\xf0\xfe

About

Lightning Storm Python Implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages