Object.NetworkTransport (object v0.1.2)

Network transport layer abstraction for Object communication.

Provides a unified interface for multiple transport protocols including TCP, UDP, WebSockets, and gRPC. Handles connection management, pooling, multiplexing, and encryption.

Features

  • Multiple transport protocol support
  • Connection pooling and reuse
  • Automatic reconnection with exponential backoff
  • TLS/SSL encryption
  • Message framing and fragmentation
  • Bandwidth throttling and QoS
  • Circuit breaker pattern

Summary

Functions

Returns a specification to start this module under a supervisor.

Establishes a connection to a remote endpoint.

Closes a specific connection.

Gets metrics for the transport layer.

Sends data over a specific connection.

Sends data to a specific endpoint, using connection pooling.

Starts the network transport service.

Types

circuit_breaker_state()

@type circuit_breaker_state() :: %{
  state: :closed | :open | :half_open,
  failure_count: non_neg_integer(),
  last_failure: DateTime.t() | nil,
  success_count: non_neg_integer()
}

connection()

@type connection() :: %{
  id: connection_id(),
  socket: port() | pid(),
  transport: transport_type(),
  host: String.t(),
  port: non_neg_integer(),
  state: :connected | :disconnected | :connecting,
  last_activity: DateTime.t(),
  bytes_sent: non_neg_integer(),
  bytes_received: non_neg_integer(),
  message_count: non_neg_integer(),
  error_count: non_neg_integer(),
  circuit_breaker: circuit_breaker_state()
}

connection_id()

@type connection_id() :: String.t()

connection_opts()

@type connection_opts() :: [
  host: String.t(),
  port: non_neg_integer(),
  transport: transport_type(),
  ssl: boolean(),
  pool_size: pos_integer(),
  timeout: timeout(),
  reconnect_interval: pos_integer(),
  max_reconnect_attempts: pos_integer()
]

transport_metrics()

@type transport_metrics() :: %{
  total_connections: non_neg_integer(),
  active_connections: non_neg_integer(),
  total_bytes_sent: non_neg_integer(),
  total_bytes_received: non_neg_integer(),
  total_messages: non_neg_integer(),
  avg_latency_ms: float()
}

transport_state()

@type transport_state() :: %{
  connections: %{required(connection_id()) => connection()},
  pools: %{required(String.t()) => [connection()]},
  config: connection_opts(),
  metrics: transport_metrics()
}

transport_type()

@type transport_type() :: :tcp | :udp | :websocket | :grpc

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connect(host, port, opts \\ [])

@spec connect(String.t(), non_neg_integer(), Keyword.t()) ::
  {:ok, connection_id()} | {:error, term()}

Establishes a connection to a remote endpoint.

disconnect(conn_id)

@spec disconnect(connection_id()) :: :ok

Closes a specific connection.

get_metrics()

@spec get_metrics() :: transport_metrics()

Gets metrics for the transport layer.

send_data(conn_id, data)

@spec send_data(connection_id(), binary()) :: :ok | {:error, term()}

Sends data over a specific connection.

send_to(host, port, data, opts \\ [])

@spec send_to(String.t(), non_neg_integer(), binary(), Keyword.t()) ::
  :ok | {:error, term()}

Sends data to a specific endpoint, using connection pooling.

start_link(opts \\ [])

Starts the network transport service.