Skip to content

Commit

Permalink
Merge pull request #1459 from pguyot/w02/erlang-distribution-01
Browse files Browse the repository at this point in the history
Introduce erlang distribution

- Add support for handshake from OTP nodes
- Add support for monitoring processes and sending messages to registered processes from OTP nodes

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Jan 18, 2025
2 parents b8b193a + 04a3e5b commit 095e61a
Show file tree
Hide file tree
Showing 24 changed files with 2,258 additions and 17 deletions.
1 change: 1 addition & 0 deletions examples/erlang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ pack_runnable(mqtt_client mqtt_client estdlib eavmlib)
pack_runnable(network_console network_console estdlib eavmlib alisp)
pack_runnable(logging_example logging_example estdlib eavmlib)
pack_runnable(http_client http_client estdlib eavmlib)
pack_runnable(disterl disterl estdlib)
41 changes: 41 additions & 0 deletions examples/erlang/disterl.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%
% This file is part of AtomVM.
%
% Copyright 2024 Paul Guyot <pguyot@kallisys.net>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(disterl).

-export([start/0]).

start() ->
{ok, _KernelPid} = kernel:start(normal, []),
{ok, _NetKernelPid} = net_kernel:start('atomvm@127.0.0.1', #{name_domain => longnames}),
io:format("Distribution was started\n"),
io:format("Node is ~p\n", [node()]),
net_kernel:set_cookie(<<"AtomVM">>),
io:format("Cookie is ~s\n", [net_kernel:get_cookie()]),
register(disterl, self()),
io:format(
"This AtomVM node is waiting for 'quit' message, and this process is registered as 'disterl'\n"
),
io:format("On an OTP node with long names distribution, run:\n"),
io:format("erlang:set_cookie('atomvm@127.0.0.1', 'AtomVM').\n"),
io:format("{disterl, 'atomvm@127.0.0.1'} ! quit.\n"),
receive
quit -> ok
end.
7 changes: 7 additions & 0 deletions libs/estdlib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ project(estdlib)
include(BuildErlang)

set(ERLANG_MODULES
application
base64
binary
calendar
code
crypto
dist_util
erl_epmd
erts_debug
ets
Expand All @@ -41,6 +43,9 @@ set(ERLANG_MODULES
gen_tcp_inet
gen_tcp_socket
supervisor
kernel
net_kernel
net_kernel_sup
inet
io_lib
io
Expand All @@ -54,6 +59,8 @@ set(ERLANG_MODULES
queue
sets
socket
socket_dist
socket_dist_controller
ssl
string
timer
Expand Down
37 changes: 37 additions & 0 deletions libs/estdlib/src/application.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%
% This file is part of AtomVM.
%
% Copyright 2025 Paul Guyot <pguyot@kallisys.net>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(application).
-export([get_env/3]).
-export_type([start_type/0]).

-type start_type() :: normal | {takeover, Node :: node()} | {failover, Node :: node()}.

%%-----------------------------------------------------------------------------
%% @param Application application to get the parameter value of
%% @param Parameter parameter to get the value of
%% @param Default default value if parameter is not found
%% @returns default value
%% @doc Retrieve the value of the configuration parameter `Parameter' for
%% application `Application' or `Default' if not found.
%% @end
%%-----------------------------------------------------------------------------
-spec get_env(Application :: atom(), Parameter :: atom(), Default :: any()) -> any().
get_env(_Application, _Parameter, Default) -> Default.
Loading

0 comments on commit 095e61a

Please sign in to comment.