Skip to main content

A lightweight IPC library with bridge and streaming support

Project description

CommIPC: Asynchronous Secure Distributed Inter-Process Communication

CommIPC is an asynchronous Inter-Process Communication (IPC) system designed for Linux environments. Written in pure Python, it provides communication through Unix Domain Sockets for local processes and TCP for cross-network communication, featuring integrated bridging, synchronization, and security mechanisms.

Table of Contents

Key Features

  • Zero-Trust Security:
    • HMAC-SHA256 Handshake: Mandatory cryptographic challenge for every client connection.
    • End-to-End Signature: All channel messages are signed with HMAC-SHA256 based on channel passwords, ensuring data integrity even if the server is compromised.
  • Advanced Channel Management:
    • Owner-Based Administration: The first client to join a channel is the Admin/Owner, with exclusive rights to manage security.
    • Explicit Password Protection: Support for protecting channels (including system channels) with unique, cryptographically derived keys.
    • Flexible Lifecycle Policies: Configurable policies for handling owner disconnection (terminate or promote).
  • High Resilience:
    • Auto-Reconnect: Robust reconnection logic with exponential backoff and transparent state restoration (channels, providers).
    • Synchronous Persistence: Client APIs wait for server confirmation for registrations and security changes, preventing communication hangs.
  • Dependency-Free: Implemented entirely using the Python standard library, requiring no external packages.

Architecture Overview

The system operates as a hub-and-spoke model locally, which can be extended into a mesh or linear topology using bridges.

graph TD
    subgraph "Local Network A"
        SrvA["CommIPCServer (Primary)"]
        CliA1["Client A1"] <--> SrvA
        CliA2["Client A2"] <--> SrvA
    end
    
    subgraph "Bridge Link"
        Bridge["CommIPCBridge"]
    end
    
    subgraph "Remote Network B"
        SrvB["CommIPCServer (Secondary)"]
        CliB1["Client B1"] <--> SrvB
    end
    
    SrvA <--> Bridge <--> SrvB

Components

  • CommIPCServer: The central message coordinator responsible for client lifecycle management, authentication, and message routing.
  • CommIPC: The primary client interface for application integration.
  • CommIPCChannel: A high-level abstraction layer for interacting with specific logical communication channels.
  • CommIPCBridge: A specialized interconnect service that synchronizes providers and subscribers across discrete server instances.

Usage Guide

Basic RPC (Request-Response)

Service Provider

import asyncio
from comm_ipc.client import CommIPC

async def main():
    client = CommIPC(client_id="math_service")
    channel = await client.open("math_operations")
    
    def add(params):
        return params.data["a"] + params.data["b"]
        
    await channel.add_event("sum", call=add)
    
    # Maintain the service loop
    await asyncio.Future() 

if __name__ == "__main__":
    asyncio.run(main())

Service Consumer

import asyncio
from comm_ipc.client import CommIPC

async def main():
    client = CommIPC(client_id="application_client")
    channel = await client.open("math_operations")
    
    response = await channel.event("sum", {"a": 15, "b": 25})
    print(f"Calculated Sum: {response.data}") # Expected Output: 40

if __name__ == "__main__":
    asyncio.run(main())

Streaming Responses

Stream Provider

async def sequence_generator(request):
    n = request.data.get("limit", 10)
    for i in range(n):
        yield i
        await asyncio.sleep(0.05)

await channel.add_stream("data_feed", call=sequence_generator)

Stream Consumer

async for chunk in channel.stream("data_feed", {"limit": 5}):
    print(f"Received Chunk: {chunk.data}")

Cross-Network Bridging

from comm_ipc.bridge import CommIPCBridge

# Establishes a link between a local Unix socket and a remote TCP server
bridge = CommIPCBridge(socket_path1="/tmp/local_service.sock")
await bridge.connect(
    target1_params={}, 
    target2_params={"host": "192.168.1.100", "port": 9000}
)

Security & Channel Management

Protecting a Channel (Owner)

# The first client to open the channel becomes the owner
channel = await client.open("secure-data")
await client.set_password("secure-data", "strong-password")

Joining a Protected Channel

# Fails if password is wrong or missing
channel = await client.open("secure-data", password="strong-password")

Protecting System Channels

You can secure internal system channels (logs, errors, registration events) by providing a system_passwords dictionary when initializing the server:

server = CommIPCServer(
    system_passwords={
        "__comm_ipc_logs": "log-secret",
        "__comm_ipc_errors": "error-secret",
        "__comm_ipc_system": "sys-secret"
    }
)

Performance and Resilience

CommIPC is optimized for reliability:

  • Auto-Reconnect: Automatically recovers from server restarts and network interruptions.
  • State Preservation: Transparently restores all active channel memberships and event providers after a reconnection event.
  • Optional Client Logging: Clients are silent by default; set verbose=True during initialization to enable terminal logging.
  • Unix Domain Sockets: Minimizes latency for local-host communication by bypassing the network stack.

Testing

The project maintains a comprehensive verification suite located in the tests/ directory.

# Execute the full validation suite
PYTHONPATH=. pytest tests/

The test coverage includes:

  • Zero-Trust Verification: HMAC handshakes, signature integrity, and E2E verification.
  • Advanced Management: Ownership logic, lifecycle policies, and resource cleanup.
  • Resilience: Auto-reconnect stability and state restoration.
  • Distributed Systems: Bridge synchronization and circular path detection.
  • Streaming: Asynchronous iterator support across local and remote instances.

License

This project is licensed under the LGPLv3 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comm_ipc-0.1.0.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comm_ipc-0.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file comm_ipc-0.1.0.tar.gz.

File metadata

  • Download URL: comm_ipc-0.1.0.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comm_ipc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac92a61ca5b643bc8bc61e1b321f1106ca63f7d9eb55e188187a8141b00ae04b
MD5 684553352919030546faea20376be331
BLAKE2b-256 adc51b95974bb897d2cae0181f3fd93bac43bb426071e2f8ddc194a9188d54a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for comm_ipc-0.1.0.tar.gz:

Publisher: publish.yml on shashstormer/comm_ipc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comm_ipc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: comm_ipc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comm_ipc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2f0ce72cf750b2d96a9ba62e6d57a42da407e0e417451388ab9fa6b4f51b16d
MD5 5c130202f9806c1c4dea36f317d45ae1
BLAKE2b-256 35a1197e955755db01f1b603c340ba19b8849903e6cc897f740745480964a463

See more details on using hashes here.

Provenance

The following attestation bundles were made for comm_ipc-0.1.0-py3-none-any.whl:

Publisher: publish.yml on shashstormer/comm_ipc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page