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 0e3102f
Show file tree
Hide file tree
Showing 17 changed files with 1,870 additions and 14 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
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ install_requires =
# Required to fix a dependency issue with parsimonious and Python3.11
eth_abi==4.0.0b2; python_version>="3.11"
python-magic
peewee
# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
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",
]
8 changes: 8 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,11 @@ 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 0e3102f

Please sign in to comment.