Permalink
Browse files

Move logging to the session fsm

Move logging from perv -> pervon. Remove some logging: only log session
start, finish, file writes and errors.
  • Loading branch information...
1 parent 0289309 commit b3f672e40b0491ce5468772e9943e942a140ee9c @msantos committed Sep 15, 2010
Showing with 21 additions and 26 deletions.
  1. +2 −18 src/perv.erl
  2. +19 −8 src/pervon.erl
View
@@ -37,7 +37,6 @@
-define(SERVER, ?MODULE).
-export([start_link/0, start_link/1]).
--export([session/4]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -69,7 +68,8 @@ handle_cast(_Msg, State) ->
{noreply, State}.
% Sniffed packet
-handle_info([{pkthdr, _}, {packet, Packet}], #state{c = C} = State) ->
+handle_info([{pkthdr, {_, {caplen, Length}, {len, Length}}}, {packet, Packet}],
+ #state{c = C} = State) ->
P = epcap_net:decapsulate(Packet),
C1 = match(P, C),
{noreply, State#state{c = C1}};
@@ -123,12 +123,6 @@ match([ #ether{},
Key = {{Saddr, 80}, {Daddr, Dport}},
case dict:find(Key, Connections) of
{ok, Pid} ->
- error_logger:info_report([
- {session, perv:session(Saddr, 80, Daddr, Dport)},
- {payload_size, byte_size(Payload)},
- {rst, RST},
- {fin, FIN}
- ]),
buf(Pid, SeqNo, Payload, Len - (HL * 4) - (Off * 4)),
pervon:stop(Pid),
dict:erase(Key, Connections);
@@ -159,10 +153,6 @@ match([ #ether{},
Key = {{Saddr, 80}, {Daddr, Dport}},
case dict:find(Key, Connections) of
{ok, Pid} ->
- error_logger:info_report([
- {session, perv:session(Saddr, 80, Daddr, Dport)},
- {payload_size, byte_size(Payload)}
- ]),
buf(Pid, SeqNo, Payload, Len - (HL * 4) - (Off * 4)),
Connections;
error ->
@@ -173,12 +163,6 @@ match(_, Connections) ->
Connections.
-% Established socket ntoa
-session(Saddr, Sport, Daddr, Dport) ->
- inet_parse:ntoa(Saddr) ++ ":" ++ integer_to_list(Sport) ++ "-" ++
- inet_parse:ntoa(Daddr) ++ ":" ++ integer_to_list(Dport).
-
-
% Send the packet payload to the gen_fsm.
%
% As an optimization, do not send packets with 0 byte payloads.
View
@@ -36,7 +36,7 @@
% Interface
-export([start_link/1]).
-export([buf/3, stop/1]).
--export([content/3]).
+-export([content/3, session/4]).
-export([filename/4]).
% States
-export([perving/2, perving/3, archiving/2]).
@@ -82,6 +82,10 @@ start_link({{Saddr, Sport}, {Daddr, Dport}}) ->
init([{{Saddr, Sport}, {Daddr, Dport}}]) ->
process_flag(trap_exit, true),
+ error_logger:info_report([
+ {session, start},
+ {connection, session(Saddr, Sport, Daddr, Dport)}
+ ]),
{ok, perving, #state{
saddr = Saddr,
sport = Sport,
@@ -139,11 +143,8 @@ archiving(timeout, #state{
catch
throw:Error -> Error;
Type:_Error -> error_logger:error_report([
- {type, Type},
- {saddr, Saddr},
- {sport, Sport},
- {daddr, Daddr},
- {dport, Dport}
+ {session, Type},
+ {connection, session(Saddr, Sport, Daddr, Dport)}
])
end,
@@ -192,7 +193,6 @@ subtype(Type, "quicktime") -> {Type,"mov"};
subtype(Type, "x-flv") -> {Type,"flv"};
subtype(Type, Subtype) ->
- error_logger:info_report([{subtype, Subtype}]),
case re:run(Subtype, "^[a-zA-Z0-9.+-]{1,128}+$", [{capture, none}]) of
match -> {Type,Subtype};
nomatch -> throw([{unsupported, {Type,Subtype}}])
@@ -207,7 +207,13 @@ dump(#state{
data = Data
}) ->
Body = list_to_binary(gb_trees:values(Data)),
- Name = perv:session(Saddr, Sport, Daddr, Dport),
+ Name = session(Saddr, Sport, Daddr, Dport),
+
+ error_logger:info_report([
+ {session, finished},
+ {connection, session(Saddr, Sport, Daddr, Dport)},
+ {payload_size, byte_size(Body)}
+ ]),
case Debug of
true ->
@@ -258,3 +264,8 @@ write_content(Filename, Content) ->
ok = file:write_file(Filename, Content).
+% Established socket ntoa
+session(Saddr, Sport, Daddr, Dport) ->
+ inet_parse:ntoa(Saddr) ++ ":" ++ integer_to_list(Sport) ++ "-" ++
+ inet_parse:ntoa(Daddr) ++ ":" ++ integer_to_list(Dport).
+

0 comments on commit b3f672e

Please sign in to comment.