Skip to content

Commit

Permalink
Cleanup unused code, add whenwhere docs
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Rigby <[email protected]>
  • Loading branch information
ConnorRigby authored and fhunleth committed Jun 17, 2024
1 parent 894d113 commit c60fce3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
23 changes: 15 additions & 8 deletions lib/vintage_net/connectivity/when_where.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ defmodule VintageNet.Connectivity.WhenWhere do
This connectivity checker requires the following options:
* `:url` - Required. HTTP URL for an Internet-reachable host
* `:url` - Required. HTTP URL for an Internet-reachable whenwhere server
* `:max_response_size` - Optional max response size in bytes. Defaults to 1024 bytes.
* `:timeout_millis` - Optional time to wait for a response in milliseconds. Defaults to 5000 ms.
Upon success, this check will place the following properties in the property table:
* `["interface", ifname, "connection", "now"]` - ISO8601 DateTime.
* `["interface", ifname, "connection", "time_zone"]` - Detected Timezone.
* `["interface", ifname, "connection", "latitude"]` - Geolocation latitude.
* `["interface", ifname, "connection", "longitude"]` - Geolocation longitude.
* `["interface", ifname, "connection", "country"]` - Geolocation country code.
* `["interface", ifname, "connection", "country_region"]` - Geolocation country_region code.
* `["interface", ifname, "connection", "city"]` - Geolocation city name.
* `["interface", ifname, "connection", "address"]` - Public IP Address used to access the server.
"""

@behaviour VintageNet.Connectivity.Check
import VintageNet.Connectivity.WebRequest, only: [validate_url: 1]

alias VintageNet.Connectivity.HTTPClient
require Logger

@default_max_response_size 1024
@max_response_size 1024
@default_timeout_millis 5_000

@impl VintageNet.Connectivity.Check
Expand All @@ -27,9 +37,7 @@ defmodule VintageNet.Connectivity.WhenWhere do
:ok <- validate_url(url) do
{:ok,
{__MODULE__,
url: url,
max_response_size: Keyword.get(options, :max_response_size, @default_max_response_size),
timeout_millis: Keyword.get(options, :timeout_millis, @default_timeout_millis)}}
url: url, timeout_millis: Keyword.get(options, :timeout_millis, @default_timeout_millis)}}
else
_ -> :error
end
Expand Down Expand Up @@ -67,9 +75,8 @@ defmodule VintageNet.Connectivity.WhenWhere do
request_headers = [{"Content-Type", "application/x-erlang-binary"}]
request = HTTPClient.create_request(url, ifname, request_headers)

case HTTPClient.make_request(request, options[:max_response_size], options[:timeout_millis]) do
case HTTPClient.make_request(request, @max_response_size, options[:timeout_millis]) do
{:ok, {{_version, 200, _status_message}, headers, body}} ->
Logger.debug(%{term: inspect(body)})
{:ok, headers, :erlang.binary_to_term(body, [:safe])}

error ->
Expand Down
7 changes: 2 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule VintageNet.MixProject do
[
app: :vintage_net,
version: @version,
elixir: "~> 1.13",
elixir: "~> 1.11",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
compilers: [:elixir_make | Mix.compilers()],
Expand Down Expand Up @@ -61,17 +61,14 @@ defmodule VintageNet.MixProject do
url: "http://www.msftconnecttest.com/connecttest.txt", match: "Microsoft Connect Test"},
{:whenwhere, url: "https://whenwhere.nerves-project.org"}
],
internet_hostname_list: [
{"google.com", 443}
],
regulatory_domain: "00",
# Contain processes in cgroups by setting to:
# [cgroup_base: "vintage_net", cgroup_controllers: ["cpu"]]
muontrap_options: [],
power_managers: [],
route_metric_fun: &VintageNet.Route.DefaultMetric.compute_metric/2
],
extra_applications: [:logger, :crypto, :ssl, :public_key, :inets],
extra_applications: [:logger, :crypto],
mod: {VintageNet.Application, []}
]
end
Expand Down
16 changes: 0 additions & 16 deletions test/vintage_net/connectivity/when_where_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,4 @@ defmodule VintageNet.Connectivity.WhenWhereTest do
end)
end
end

test "when/where no cname" do
ifname = Utils.get_ifname_for_tests()

{:ok, normalized_whenwhere} =
WhenWhere.normalize({WhenWhere, url: "http://dnlawqcegshx3.cloudfront.net"})

assert {:ok, {:internet, properties}} = WhenWhere.check(ifname, normalized_whenwhere)

for property <- @properties do
assert Enum.find(properties, fn
{^property, _} -> true
_ -> false
end)
end
end
end

0 comments on commit c60fce3

Please sign in to comment.