A Python port of the Invisible Internet Project (I2P)
at main 45 lines 1.0 kB view raw
1"""ClientMessage — container for client-originated messages. 2 3Ported from net.i2p.data.i2cp.ClientMessage. 4Used by the message routing system to track outbound messages. 5""" 6 7from __future__ import annotations 8 9import hashlib 10from dataclasses import dataclass 11 12 13class SendFlags: 14 """Send flags for outbound messages.""" 15 16 NONE = 0 17 TAG_THRESHOLD_LOW = 1 18 TAG_THRESHOLD_HIGH = 2 19 20 21@dataclass 22class ClientMessage: 23 """A client-originated message with routing metadata.""" 24 25 from_dest: bytes 26 to_dest: bytes 27 payload: bytes 28 message_id: int 29 message_nonce: int 30 expiration: int | None = None 31 flags: int = 0 32 33 @property 34 def from_hash(self) -> bytes: 35 """SHA-256 hash of the source destination.""" 36 return hashlib.sha256(self.from_dest).digest() 37 38 @property 39 def to_hash(self) -> bytes: 40 """SHA-256 hash of the target destination.""" 41 return hashlib.sha256(self.to_dest).digest() 42 43 @property 44 def payload_size(self) -> int: 45 return len(self.payload)