Packages
baby
0.26.0
0.35.1
0.35.0
0.34.0
0.33.0
0.32.0
0.31.0
0.30.1
0.30.0
0.26.0
0.25.2
0.25.1
0.25.0
0.23.0
0.22.0
0.21.1
0.21.0
0.20.0
0.19.0
0.18.0
0.17.0
0.16.4
0.16.3
0.16.1
0.16.0
0.15.1
0.15.0
0.14.1
0.14.0
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.0
0.7.0
0.6.0
Bushbaby Automated Bamboo Yields
Current section
Files
Jump to
Current section
Files
lib/baby.ex
defmodule Baby do
require Logger
alias Baby.Util
alias Baby.Connection.Registry
@moduledoc """
Bushbaby Automated Bamboo Yields
Reference `bushbaby` protocol node
### Configuration
`spool_dir`: The path to the `Baobab` bamboo store spool
`clumps`: List of per-clump keyword configurations
- `id`: a binary `clump_id`
- `controlling_identity`: a `Baobab.Identity` by which this peer will be known
- `port`: an integer port to which to bind
- `cryouts`: list of keyword configurations for periodic peer replication
- `host`: peer host address
- `port`: peer port
- `period`: `{integer quantity, atom unit}` ({17, :minute})
"""
@doc """
Connect to a remote hort and port
Keyword id_options relative to the configured `Baobab` store
- clump_id
- identity
"""
def connect(host, port, id_options \\ [])
def connect(host, port, id_options) when is_binary(port),
do: connect(host, String.to_integer(port), id_options)
def connect(host, port, id_options) when is_binary(host),
do: host |> Util.host_to_ip() |> connect(port, id_options)
def connect(host, port, id_options) do
Baby.Connection.start_link(
host: host,
port: port,
identity: Keyword.get(id_options, :identity),
clump_id: Keyword.get(id_options, :clump_id)
)
end
@doc """
Determine if there is an active connection on a given `{host, port}`
"""
def is_connected?({host, port}) when is_tuple(host), do: Registry.active?({host, port})
def is_connected?({host, port}) do
case Util.host_to_ip(host) do
:error -> false
ip -> is_connected?({ip, port})
end
end
def is_connected?(_), do: false
@doc """
Determine if there is an active connection on an array of `{host, port}`
Returns a map with the tuples as keys and a boolean result
"""
def are_connected?(queries)
def are_connected?(queries) do
check_connections(queries, %{})
end
defp check_connections([], acc), do: acc
defp check_connections([pair | rest], acc) do
check_connections(rest, Map.put(acc, pair, is_connected?(pair)))
end
end