"""SAM raw session -- raw I2P protocol delivery. Ported from net.i2p.sam.SAMRawSession. """ import logging logger = logging.getLogger(__name__) class SAMRawSession: """Raw protocol session (no wrapper, max 32KB). Raw sessions send data without the streaming or datagram wrappers. The protocol field specifies the I2P protocol number. """ MAX_SIZE = 32 * 1024 # 32KB maximum payload def __init__( self, nickname: str, destination_b64: str, protocol: int = 18, ) -> None: self._nickname = nickname self._destination_b64 = destination_b64 self._protocol = protocol async def send( self, target_dest: str, data: bytes, protocol: int = 18, from_port: int = 0, to_port: int = 0, ) -> None: """Send raw data to the target destination. Args: target_dest: Base64-encoded target destination. data: Payload bytes (max 32KB). protocol: I2P protocol number. from_port: Source port (virtual). to_port: Destination port (virtual). Raises: ValueError: If data exceeds MAX_SIZE. """ if len(data) > self.MAX_SIZE: raise ValueError( f"Raw payload exceeds maximum size: {len(data)} > {self.MAX_SIZE}" ) logger.debug("RAW SEND to %s...%s (%d bytes, proto=%d) from session %s", target_dest[:16], target_dest[-8:], len(data), protocol, self._nickname) # In production, this would send raw data through I2P tunnels.