Skip to content

Instantly share code, notes, and snippets.

@eproxus
Created March 4, 2011 09:26
Show Gist options
  • Select an option

  • Save eproxus/854389 to your computer and use it in GitHub Desktop.

Select an option

Save eproxus/854389 to your computer and use it in GitHub Desktop.

Revisions

  1. eproxus revised this gist Mar 29, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions virus.erl
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    %% @doc A small module that jumps between connected nodes.
    %% @author Gianfranco Alongi <gianfranco.alongi@erlang-solutions.com>
    %% @author Adam Lindberg <[email protected]>
    %% @author Gianfranco Alongi <gianfranco.alongi@gmail.com>
    %% @author Adam Lindberg <[email protected]>

    -module(virus).
    -export([start/0]).
  2. eproxus revised this gist Mar 12, 2011. No changes.
  3. eproxus revised this gist Mar 11, 2011. 1 changed file with 23 additions and 12 deletions.
    35 changes: 23 additions & 12 deletions virus.erl
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,35 @@
    %% @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(fun virus/0).
    start() -> spawn_process(code:get_object_code(?MODULE)).
    start(Beam) -> spawn_process(Beam).

    virus() ->
    io:format(user, "You're infested!~n", []),
    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().
    virus_loop(Beam).

    virus_loop() ->
    virus_loop(Beam) ->
    receive
    {nodeup, Node} ->
    infest(Node),
    io:format("~p has joined!~n", [Node])
    infest(Node, Beam),
    io:format(user, "~p has joined!~n", [Node])
    end,
    virus_loop().
    virus_loop(Beam).

    infest(Node) ->
    {Mod, Bin, File} = code:get_object_code(?MODULE),
    infest(Node, {Mod, Bin, File} = Beam) ->
    {module, Mod} = rpc:call(Node, code, load_binary, [Mod, File, Bin]),
    rpc:call(Node, ?MODULE, start, []).
    rpc:call(Node, ?MODULE, start, [Beam]).
  4. eproxus revised this gist Mar 11, 2011. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions virus.erl
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    %% @doc A small module that jumps between connected nodes.
    %% @author Gianfranco Alongi <[email protected]>

    -module(virus).
    -export([start/0]).

  5. eproxus revised this gist Mar 11, 2011. 1 changed file with 12 additions and 8 deletions.
    20 changes: 12 additions & 8 deletions virus.erl
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,22 @@
    %% @doc A small module that jumps between connected nodes.
    %% @author Gianfranco Alongi <[email protected]>

    -module(virus).
    -export([start/0]).

    start() ->
    spawn(fun virus/0).

    virus() ->
    io:format(user, "You're infested!~n", []),
    net_kernel:monitor_nodes(true),
    [ infest(Node) || Node <- nodes() ],
    loop().
    %[infest(Node) || Node <- nodes()],
    virus_loop().

    loop() ->
    receive {nodeup, Node} -> infest(Node) end,
    loop().
    virus_loop() ->
    receive
    {nodeup, Node} ->
    infest(Node),
    io:format("~p has joined!~n", [Node])
    end,
    virus_loop().

    infest(Node) ->
    {Mod, Bin, File} = code:get_object_code(?MODULE),
  6. eproxus created this gist Mar 4, 2011.
    20 changes: 20 additions & 0 deletions virus.erl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    %% @doc A small module that jumps between connected nodes.
    %% @author Gianfranco Alongi <[email protected]>

    -module(virus).
    -export([start/0]).

    start() ->
    io:format(user, "You're infested!~n", []),
    net_kernel:monitor_nodes(true),
    [ infest(Node) || Node <- nodes() ],
    loop().

    loop() ->
    receive {nodeup, Node} -> infest(Node) end,
    loop().

    infest(Node) ->
    {Mod, Bin, File} = code:get_object_code(?MODULE),
    {module, Mod} = rpc:call(Node, code, load_binary, [Mod, File, Bin]),
    rpc:call(Node, ?MODULE, start, []).