From a036f119a62bcf2e81ae51e0f3e7f996f56f10bd Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Mon, 14 Sep 2015 16:01:26 +0900 Subject: [PATCH] Add send_spam_to_everyone(), add 1% chance of using it --- src/machi_chain_manager1.erl | 5 +++++ src/machi_fitness.erl | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/machi_chain_manager1.erl b/src/machi_chain_manager1.erl index 276498d..b04f7d7 100644 --- a/src/machi_chain_manager1.erl +++ b/src/machi_chain_manager1.erl @@ -1062,6 +1062,11 @@ do_react_to_env(S) -> true -> S end, + %% Perhaps tell the fitness server to spam everyone. + case random:uniform(100) of + 42 -> machi_fitness:send_spam_to_everyone(S#ch_mgr.fitness_svr); + _ -> ok + end, %% NOTE: If we use the fitness server's unfit list at the start, then %% we would need to add some kind of poll/check for down members to %% check if they are now up. Instead, our lazy attempt to read from diff --git a/src/machi_fitness.erl b/src/machi_fitness.erl index b97da48..1c26af0 100644 --- a/src/machi_fitness.erl +++ b/src/machi_fitness.erl @@ -37,7 +37,8 @@ -export([start_link/1, get_unfit_list/1, update_local_down_list/3, add_admin_down/3, delete_admin_down/2, - send_fitness_update_spam/3]). + send_fitness_update_spam/3, + send_spam_to_everyone/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -75,6 +76,9 @@ delete_admin_down(PidSpec, DownFLU) -> send_fitness_update_spam(Pid, FromName, Dict) -> gen_server:call(Pid, {incoming_spam, FromName, Dict}, infinity). +send_spam_to_everyone(Pid) -> + gen_server:call(Pid, {send_spam_to_everyone}, infinity). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init([{MyFluName}|Args]) -> @@ -117,6 +121,9 @@ handle_call({delete_admin_down, DownFLU}, _From, handle_call({incoming_spam, Author, Dict}, _From, S) -> {Res, S2} = do_incoming_spam(Author, Dict, S), {reply, Res, S2}; +handle_call({send_spam_to_everyone}, _From, S) -> + {Res, S2} = do_send_spam_to_everyone(S), + {reply, Res, S2}; handle_call(_Request, _From, S) -> Reply = whhhhhhhhhhhhhhaaaaaaaaaaaaaaa, {reply, Reply, S}. @@ -299,7 +306,7 @@ calc_unfit2([H|T], G) -> [H|calc_unfit2(T, G)] end. -do_incoming_spam(Author, Map, +do_incoming_spam(_Author, Map, #state{my_flu_name=MyFluName,pending_map=OldMap, members_dict=MembersDict}=S) -> OldMapV = map_value(OldMap), @@ -320,6 +327,11 @@ do_incoming_spam(Author, Map, {ok, S2} end. +do_send_spam_to_everyone(#state{my_flu_name=MyFluName, + pending_map=Map,members_dict=MembersDict}=S) -> + _ = send_spam(Map, [MyFluName], MembersDict, S), + {ok, S}. + do_map_change(NewMap, DontSendList, MembersDict, #state{my_flu_name=_MyFluName, pending_map=OldMap}=S) -> send_spam(NewMap, DontSendList, MembersDict, S),