initial commit
This commit is contained in:
commit
9b189b7f4f
4
.formatter.exs
Normal file
4
.formatter.exs
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# Files generated from /asn1/*
|
||||
/src/FloofProtocol.*
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
floof-*.tar
|
||||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
||||
|
||||
.#*
|
||||
result
|
||||
result-*
|
||||
flamegraph.svg
|
||||
perf.data*
|
21
README.md
Normal file
21
README.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Floof
|
||||
|
||||
**TODO: Add description**
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `floof` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:floof, "~> 0.1.0"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at <https://hexdocs.pm/floof>.
|
||||
|
97
asn1/FloofProtocol.asn1
Normal file
97
asn1/FloofProtocol.asn1
Normal file
|
@ -0,0 +1,97 @@
|
|||
FloofProtocol { 2 25 187636631533261907981725980838781846034 }
|
||||
DEFINITIONS EXPLICIT TAGS ::= BEGIN
|
||||
|
||||
ActId ::= OCTET STRING (SIZE(16..1024))
|
||||
ActIdBunch ::= SEQUENCE(SIZE(1..1024)) OF ActId
|
||||
Summary ::= SEQUENCE {
|
||||
ids ActIdBunch
|
||||
}
|
||||
Request ::= SEQUENCE {
|
||||
ids ActIdBunch
|
||||
}
|
||||
Signature ::= SEQUENCE {
|
||||
algorithm OBJECT IDENTIFIER,
|
||||
value OCTET STRING
|
||||
}
|
||||
Severity ::= ENUMERATED {
|
||||
emergency (0),
|
||||
alert (1),
|
||||
critical (2),
|
||||
error (3),
|
||||
warning (4),
|
||||
notice (5),
|
||||
info (6),
|
||||
debug (7),
|
||||
trace (8)
|
||||
}
|
||||
|
||||
RelativeDistinguishedName ::= SEQUENCE {
|
||||
type OBJECT IDENTIFIER,
|
||||
value ANY
|
||||
}
|
||||
|
||||
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
|
||||
|
||||
ModificationOperation ::= CHOICE {
|
||||
set [0] OCTET STRING,
|
||||
delete [1] NULL,
|
||||
add [2]OCTET STRING,
|
||||
append [3] OCTET STRING,
|
||||
patch [4] OCTET STRING
|
||||
}
|
||||
|
||||
Modification ::= SEQUENCE {
|
||||
container RDNSequence,
|
||||
op ModificationOperation
|
||||
}
|
||||
|
||||
Content ::= CHOICE {
|
||||
freeForm OCTET STRING,
|
||||
modification Modification
|
||||
}
|
||||
|
||||
XferInner ::= SEQUENCE {
|
||||
id ActId,
|
||||
|
||||
-- domain name --
|
||||
domain PrintableString (SIZE(1..253)),
|
||||
|
||||
-- source system name --
|
||||
source RDNSequence,
|
||||
|
||||
-- message topic --
|
||||
topic RDNSequence,
|
||||
|
||||
-- message attributes --
|
||||
attrs SET OF RelativeDistinguishedName,
|
||||
|
||||
-- message severity --
|
||||
severity Severity,
|
||||
|
||||
data Content
|
||||
}
|
||||
|
||||
XferBlob ::= SEQUENCE {
|
||||
-- message priority (when severity is equal)
|
||||
-- used for queue priority augmention and can be modified in-transit
|
||||
priority INTEGER (0..65536),
|
||||
|
||||
-- message time-to-live eol timestamp in seconds since epoch
|
||||
ttl INTEGER (0..MAX),
|
||||
|
||||
-- message markers (e.g. review data and such)
|
||||
markers SEQUENCE OF RelativeDistinguishedName,
|
||||
|
||||
-- signature of DER serialization of *data*
|
||||
signature Signature,
|
||||
|
||||
data XferInner
|
||||
}
|
||||
|
||||
ProtoMessage ::= CHOICE {
|
||||
summary [0] Summary,
|
||||
request [1] Request,
|
||||
xfer [2] XferBlob
|
||||
}
|
||||
|
||||
END
|
29
lib/floof.ex
Normal file
29
lib/floof.ex
Normal file
|
@ -0,0 +1,29 @@
|
|||
defmodule Floof do
|
||||
@moduledoc """
|
||||
Documentation for `Floof`.
|
||||
"""
|
||||
|
||||
require Logger
|
||||
|
||||
def accept(port) do
|
||||
{:ok, socket} = :gen_tcp.listen(port, [
|
||||
:binary,
|
||||
packet: 4,
|
||||
active: false,
|
||||
reuseaddr: true
|
||||
])
|
||||
Logger.info("Accepting connections on #{port}")
|
||||
loop_acceptor(socket)
|
||||
end
|
||||
|
||||
def loop_acceptor(socket) do
|
||||
{:ok, client} = :gen_tcp.accept(socket)
|
||||
{:ok, pid} = Task.Supervisor.start_child(
|
||||
Floof.TaskSupervisor, fn -> serve(client) end)
|
||||
:ok = :gen_tcp.controlling_process(client, pid)
|
||||
loop_acceptor(socket)
|
||||
end
|
||||
|
||||
def serve(_) do
|
||||
end
|
||||
end
|
24
lib/floof/application.ex
Normal file
24
lib/floof/application.ex
Normal file
|
@ -0,0 +1,24 @@
|
|||
defmodule Floof.Application do
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
# for more information on OTP Applications
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
port = String.to_integer(System.get_env("FLOOF_PORT") || "2540")
|
||||
|
||||
children = [
|
||||
# Starts a worker by calling: Floof.Worker.start_link(arg)
|
||||
# {Floof.Worker, arg}
|
||||
{Task.Supervisor, name: Floof.TaskSupervisor},
|
||||
{Task, fn -> Floof.accept(port) end}
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
# for other strategies and supported options
|
||||
opts = [strategy: :one_for_one, name: Floof.Supervisor]
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
end
|
31
mix.exs
Normal file
31
mix.exs
Normal file
|
@ -0,0 +1,31 @@
|
|||
defmodule Floof.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :floof,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.13",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
compilers: [:asn1] ++ Mix.compilers(),
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger, :asn1],
|
||||
mod: {Floof.Application, []}
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{:asn1ex, git: "https://github.com/vicentfg/asn1ex"},
|
||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
||||
]
|
||||
end
|
||||
end
|
4
mix.lock
Normal file
4
mix.lock
Normal file
|
@ -0,0 +1,4 @@
|
|||
%{
|
||||
"asn1ex": {:git, "https://github.com/vicentfg/asn1ex", "0255348e2fffbdfd1eef7b46f71dc733318a36a0", []},
|
||||
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||
}
|
11
shell.nix
Normal file
11
shell.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell {
|
||||
# nativeBuildInputs is usually what you want -- tools you need to run
|
||||
nativeBuildInputs =
|
||||
let erlpkgs = pkgs.buildPackages.beam.packages.erlangR24;
|
||||
in [
|
||||
erlpkgs.elixir
|
||||
erlpkgs.hex
|
||||
erlpkgs.rebar3
|
||||
];
|
||||
}
|
8
test/floof_test.exs
Normal file
8
test/floof_test.exs
Normal file
|
@ -0,0 +1,8 @@
|
|||
defmodule FloofTest do
|
||||
use ExUnit.Case
|
||||
doctest Floof
|
||||
|
||||
test "greets the world" do
|
||||
assert Floof.hello() == :world
|
||||
end
|
||||
end
|
1
test/test_helper.exs
Normal file
1
test/test_helper.exs
Normal file
|
@ -0,0 +1 @@
|
|||
ExUnit.start()
|
Loading…
Reference in a new issue