<commit_before>defmodule Sippet.Transport do
  @moduledoc """
  The `Sippet.Transport` is responsible for the actual transmission of requests
  and responses over network transports.

  Network transport protocols are implemented following the
  `Sippet.Transport.Plug` behavior, and they are configured as:

      config :sippet, Sippet.Transport,
        udp: Sippet.Transport.UDP.Plug

  Whenever a message is received by a plug, the `Sippet.Transport.Queue` is
  used to process, validate and route it through the transaction layer or core.
  """

  import Supervisor.Spec

  alias Sippet.Message, as: Message
  alias Sippet.Message.RequestLine, as: RequestLine
  alias Sippet.Message.StatusLine, as: StatusLine
  alias Sippet.Transport.Pool, as: Pool
  alias Sippet.URI, as: URI

  @doc """
  Starts the transport process hierarchy.
  """
  @spec start_link() :: Supervisor.on_start
  def start_link() do
    children = [
      Pool.spec() |
      plugs_specs()
    ]

    options = [
      strategy: :one_for_one,
      name: __MODULE__
    ]

    Supervisor.start_link(children, options)
  end

  defp plugs_specs() do
    Application.get_env(:sippet, __MODULE__)
    |> plugs_specs([])
  end

  defp plugs_specs([], result), do: result
  defp plugs_specs([{_protocol, module} | rest], result),
    do: plugs_specs(rest, [worker(module, []) | result])

  @doc """
  Sends a message to the network.

  If specified, the `transaction` will receive the transport error if occurs.
  See `Sippet.Transaction.receive_error/2`.

  This function may block the caller temporarily due to resource constraints.
  """
  @spec send_message(Message.t, GenServer.server | nil) :: :ok
  def send_message(message, transaction \\ nil) do
    {protocol, host, port} = get_destination(message)
    plug = protocol |> to_plug()<commit_msg>Avoid initialization errors case there's no configuration available.<commit_after>defmodule Sippet.Transport do
  @moduledoc """
  The `Sippet.Transport` is responsible for the actual transmission of requests
  and responses over network transports.

  Network transport protocols are implemented following the
  `Sippet.Transport.Plug` behavior, and they are configured as:

      config :sippet, Sippet.Transport,
        udp: Sippet.Transport.UDP.Plug

  Whenever a message is received by a plug, the `Sippet.Transport.Queue` is
  used to process, validate and route it through the transaction layer or core.
  """

  import Supervisor.Spec

  alias Sippet.Message, as: Message
  alias Sippet.Message.RequestLine, as: RequestLine
  alias Sippet.Message.StatusLine, as: StatusLine
  alias Sippet.Transport.Pool, as: Pool
  alias Sippet.URI, as: URI

  @doc """
  Starts the transport process hierarchy.
  """
  @spec start_link() :: Supervisor.on_start
  def start_link() do
    children = [
      Pool.spec() |
      plugs_specs()
    ]

    options = [
      strategy: :one_for_one,
      name: __MODULE__
    ]

    Supervisor.start_link(children, options)
  end

  defp plugs_specs() do
    Application.get_env(:sippet, __MODULE__, [])
    |> plugs_specs([])
  end

  defp plugs_specs([], result), do: result
  defp plugs_specs([{_protocol, module} | rest], result),
    do: plugs_specs(rest, [worker(module, []) | result])

  @doc """
  Sends a message to the network.

  If specified, the `transaction` will receive the transport error if occurs.
  See `Sippet.Transaction.receive_error/2`.

  This function may block the caller temporarily due to resource constraints.
  """
  @spec send_message(Message.t, GenServer.server | nil) :: :ok
  def send_message(message, transaction \\ nil) do
    {protocol, host, port} = get_destination(message)
    plug = protocol |> to_plug()
{'fraction_non_alphanumeric': 0.09787004583445673, 'fraction_numerical': 0.0005392289026691831, 'mean_word_length': 3.6843434343434343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7284524', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1089, 'n_words': 358}