Decentralized Instant Messaging Protocol
Project description
Decentralized Instant Messaging Protocol (Python)
Talk is cheap, show you the codes!
Dependencies
pip3 install dimp
Common Extensions
facebook.py
class Facebook(Barrack):
""" Access database to load/save user's private key, meta and profiles """
def save_private_key(self, private_key: PrivateKey, identifier: ID) -> bool:
pass
#
# singleton
#
facebook = Facebook()
keystore.py
class KeyStore(KeyCache):
""" For reuse symmetric key """
def save_keys(self, key_map: dict) -> bool:
pass
def load_keys(self) -> dict:
pass
#
# singleton
#
keystore = KeyStore()
messanger.py
class Messanger(Transceiver, ITransceiverDelegate):
""" Transform and send message """
def __init__(self):
super().__init__()
self.delegate = self
#
# ITransceiverDelegate
#
def send_package(self, data: bytes, handler: ICompletionHandler) -> bool:
pass
def upload_data(self, data: bytes, msg: InstantMessage) -> str:
pass
def download_data(self, url: str, msg: InstantMessage) -> bytes:
pass
#
# singleton
#
messanger = Messanger()
messanger.barrack = facebook
messanger.key_cache = keystore
User Account
register.py
def register(username: str) -> User:
# 1. generate private key
sk = PrivateKey({'algorithm': 'RSA'})
# 2. generate meta with username(as seed) and private key
meta = Meta.generate(private_key=sk, seed=username)
# 3. generate ID with network type by meta
identifier = meta.generate_identifier(network=network)
# 4. save private key and meta info
facebook.save_private_key(private_key=sk, identifier=identifier)
facebook.save_meta(meta=meta, identifier=identifier)
# 5. create user with ID
user = User(identifier)
facebook.cache_user(user)
return user
Messaging
send.py
def pack(content: Content, sender: ID, receiver: ID) -> ReliableMessage:
msg = InstantMessage.new(content=content, sender=sender, receiver=receiver)
return messanger.encrypt_sign(msg)
if __name__ == '__main__':
moki = ID("moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk");
hulk = ID("hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj");
content = TextContent.new(text='Hello world!')
msg = pack(content=content, sender=moki, receiver=hulk)
# TODO: send out the request data
request = json.dumps(msg) + '\n'
data = request.encode('utf-8')
Copyright © 2019 Albert Moky
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
dimp-0.3.11.tar.gz
(17.8 kB
view details)
Built Distribution
dimp-0.3.11-py3-none-any.whl
(37.1 kB
view details)
File details
Details for the file dimp-0.3.11.tar.gz
.
File metadata
- Download URL: dimp-0.3.11.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0b3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 996fafe7d89945045bcc0e7fb172133c33c50013fb8ae5e84a92c774db6c0275 |
|
MD5 | ab5355efe11a418992164a11cf4cea03 |
|
BLAKE2b-256 | a23a6e399b64a8bd47560e0f5d10457839277eca1787f3116362232d0e753cf9 |
File details
Details for the file dimp-0.3.11-py3-none-any.whl
.
File metadata
- Download URL: dimp-0.3.11-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0b3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112c034a21ed258d08168631a17f4cc7edbbaa32a5d542f8507b5f3d13cd5bc5 |
|
MD5 | 3bb73d783349200e6f74905588e6f541 |
|
BLAKE2b-256 | f24a335a92385ead86cdc0bafc7ffcca10d1bb936b7ae91b8025f1b0b3c33272 |