mirror of
https://github.com/internetee/epp_proxy.git
synced 2025-08-15 03:53:48 +02:00
Move session_id function to util module
This commit is contained in:
parent
e7aa9b9770
commit
0c8cbaefc7
6 changed files with 24 additions and 9 deletions
|
@ -24,7 +24,8 @@ init(Port) ->
|
|||
|
||||
{ok, #state{socket=ListenSocket, port=Port, options=Options}}.
|
||||
|
||||
handle_cast(accept, State = #state{socket=ListenSocket, port=Port, options=Options}) ->
|
||||
handle_cast(accept,
|
||||
State = #state{socket=ListenSocket, port=Port, options=Options}) ->
|
||||
{ok, AcceptSocket} = gen_tcp:accept(ListenSocket),
|
||||
{ok, NewOwner} = create_worker(AcceptSocket),
|
||||
ok = gen_tcp:controlling_process(AcceptSocket, NewOwner),
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
|
||||
-export([code_change/3]).
|
||||
|
||||
-export([request/3]).
|
||||
|
||||
-record(state,{socket, length, session_id}).
|
||||
-record(request,{method, url, body, cookies, headers}).
|
||||
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
-module(epp_util).
|
||||
|
||||
-export([create_map/1, create_session_id/1, frame_length/1,
|
||||
frame_length_to_receive/1, frame_length_to_send/1]).
|
||||
frame_length_to_receive/1, frame_length_to_send/1,
|
||||
session_id/1]).
|
||||
|
||||
-define(OFFSET, 4).
|
||||
|
||||
% Give me a process id, I'll create a random map for you.
|
||||
%% Given a pid, return a sha512 hash of unique attributes.
|
||||
-spec session_id(pid()) -> list(char()).
|
||||
session_id(Pid) ->
|
||||
UniqueMap = create_map(Pid),
|
||||
BinaryHash = create_session_id(UniqueMap),
|
||||
BinaryHash.
|
||||
|
||||
%% Give me a process id, I'll create a random map for you.
|
||||
-spec create_map(pid()) -> #{string() => pid(), string() => float(),
|
||||
string() => string()}.
|
||||
create_map(Pid) when is_pid(Pid) ->
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
session_id_test() ->
|
||||
Pid = spawn(fun () -> ok end),
|
||||
SessionId = epp_util:session_id(Pid),
|
||||
?assert(is_list(SessionId)),
|
||||
?assert(length(SessionId) > 0).
|
||||
|
||||
create_map_test() ->
|
||||
Pid = spawn(fun () -> ok end),
|
||||
Map = epp_util:create_map(Pid),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue