uploader-bot/app/core/models/my_network.py

48 lines
2.8 KiB
Python

from .base import AlchemyBase
from sqlalchemy import Column, BigInteger, Integer, String, ForeignKey, DateTime, JSON, Boolean
from datetime import datetime
class KnownNode(AlchemyBase):
__tablename__ = 'known_nodes'
id = Column(Integer, autoincrement=True, primary_key=True)
ip = Column(String(64), nullable=False, unique=True)
port = Column(Integer, nullable=False)
public_key = Column(String(256), nullable=False)
codebase_hash = Column(String(512), nullable=True) # Node software version
reputation = Column(Integer, nullable=False, default=0)
last_sync = Column(DateTime, nullable=False, default=datetime.now)
meta = Column(JSON, nullable=False, default={})
located_at = Column(DateTime, nullable=False, default=datetime.now)
class KnownNodeIncident(AlchemyBase):
__tablename__ = 'known_nodes_incidents'
id = Column(Integer, autoincrement=True, primary_key=True)
node_id = Column(Integer, ForeignKey('known_nodes.id'), nullable=False) # Reference to the node
incident_type = Column(String(64), nullable=False) # Type of incident, e.g., 'sync_failure', 'unreachable'
description = Column(String(512), nullable=True) # Detailed description of the incident
occurred_at = Column(DateTime, nullable=False, default=datetime.utcnow) # Timestamp when the incident occurred
severity = Column(Integer, nullable=False, default=1) # Severity level (1-low to 5-critical)
resolved = Column(Boolean, nullable=False, default=False) # Whether the incident has been resolved
resolved_at = Column(DateTime, nullable=True) # Timestamp when the incident was resolved
meta = Column(JSON, nullable=False, default={}) # Additional metadata if needed
class RemoteContentIndex(AlchemyBase):
__tablename__ = 'remote_content_index'
id = Column(Integer, autoincrement=True, primary_key=True)
remote_node_id = Column(Integer, ForeignKey('known_nodes.id'), nullable=False) # Reference to the remote node
content_type = Column(String(64), nullable=False) # Type of content (e.g., music, video, document)
encrypted_hash = Column(String(128), nullable=False) # Encrypted content hash provided initially
decrypted_hash = Column(String(128), nullable=True) # Decrypted content hash, available once permission is granted
ton_address = Column(String(128), nullable=True) # TON network address for the content
onchain_index = Column(Integer, nullable=True) # Onchain index or reference on a blockchain
meta = Column(JSON, nullable=False, default={}) # Additional metadata for flexible content description
last_updated = Column(DateTime, nullable=False, default=datetime.utcnow) # Timestamp of the last update
created_at = Column(DateTime, nullable=False, default=datetime.utcnow) # Record creation timestamp