Created
December 17, 2008 04:57
-
-
Save stesla/36943 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-module(clusterl_dedup). | |
-export([init/0, first/1]). | |
-define(TABLE, ?MODULE). | |
-define(DELETION_TIMEOUT, 3600000). % 1 hour | |
init() -> | |
ets:new(?TABLE, [public, named_table]). | |
first(Frame) -> | |
Result = ets:insert_new(?TABLE, {Frame}), | |
schedule_deletion(Result, Frame), | |
Result. | |
schedule_deletion(false, _Frame) -> | |
ignore; | |
schedule_deletion(true, Frame) -> | |
F = fun() -> | |
receive after ?DELETION_TIMEOUT -> | |
ets:delete(?TABLE, Frame) | |
end | |
end, | |
proc_lib:spawn_link(F). | |
This file contains hidden or 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
handle_info({signal, Link, Ip, Frame}, StateName, State) -> | |
case clusterl_dedup:first(Frame) of | |
false -> | |
ignore; | |
true -> | |
?FRAME(Time, ?HEADER(From, To, Hops), Data) = Frame, | |
RealFrom = case From of | |
origin -> {ip, Ip}; | |
_ -> From | |
end, | |
handle_frame(Link, Time, RealFrom, To, Hops, Data, State) | |
end, | |
{next_state, StateName, State}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment