Skip to content

Commit

Permalink
Feature: Add LightNode and MessageCache
Browse files Browse the repository at this point in the history
A LightNode can synchronize on a subset, or domain, of aleph.im messages. It relies on the MessageCache, which manages a message database with peewee.
  • Loading branch information
MHHukiewitz committed Oct 25, 2023
1 parent 00592c2 commit 06fb6f9
Show file tree
Hide file tree
Showing 19 changed files with 1,862 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.pot
__pycache__/*
.cache/*
cache/**/*
.*.swp
*/.ipynb_checkpoints/*

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ testing =
substrate-interface
py-sr25519-bindings
ledgereth==0.9.0
peewee
mqtt =
aiomqtt<=0.1.3
certifi
Expand All @@ -107,6 +108,8 @@ ledger =
ledgereth==0.9.0
docs =
sphinxcontrib-plantuml
cache =
peewee

[options.entry_points]
# Add here console scripts like:
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pkg_resources import DistributionNotFound, get_distribution

from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient, LightNode

try:
# Change here if project is renamed and does not equal the package name
Expand All @@ -11,4 +11,4 @@
finally:
del get_distribution, DistributionNotFound

__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient"]
__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient", "LightNode"]
4 changes: 4 additions & 0 deletions src/aleph/sdk/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from .abstract import AlephClient, AuthenticatedAlephClient
from .authenticated_http import AuthenticatedAlephHttpClient
from .http import AlephHttpClient
from .light_node import LightNode
from .message_cache import MessageCache

__all__ = [
"AlephClient",
"AuthenticatedAlephClient",
"AlephHttpClient",
"AuthenticatedAlephHttpClient",
"MessageCache",
"LightNode",
]
10 changes: 10 additions & 0 deletions src/aleph/sdk/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import aiohttp
from aleph_message import parse_message
from aleph_message.models import AlephMessage, ItemHash, ItemType
from aleph_message.status import MessageStatus
from pydantic import ValidationError

from ..conf import settings
Expand Down Expand Up @@ -171,6 +172,8 @@ async def download_file_to_buffer(
)
else:
raise FileTooLarge(f"The file from {file_hash} is too large")
else:
response.raise_for_status()

async def download_file_ipfs_to_buffer(
self,
Expand Down Expand Up @@ -314,6 +317,13 @@ async def get_message(
)
return message

async def get_message_status(self, item_hash: str) -> MessageStatus:
async with self.http_session.get(
f"/api/v0/messages/{item_hash}"
) as resp:
resp.raise_for_status()
return MessageStatus((await resp.json())["status"])

async def watch_messages(
self,
message_filter: Optional[MessageFilter] = None,
Expand Down
Loading

0 comments on commit 06fb6f9

Please sign in to comment.