mirror of
https://github.com/internetee/epp_proxy.git
synced 2025-08-15 12:03:47 +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}}.
|
{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, AcceptSocket} = gen_tcp:accept(ListenSocket),
|
||||||
{ok, NewOwner} = create_worker(AcceptSocket),
|
{ok, NewOwner} = create_worker(AcceptSocket),
|
||||||
ok = gen_tcp:controlling_process(AcceptSocket, NewOwner),
|
ok = gen_tcp:controlling_process(AcceptSocket, NewOwner),
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
|
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
|
||||||
-export([code_change/3]).
|
-export([code_change/3]).
|
||||||
|
|
||||||
-export([request/3]).
|
|
||||||
|
|
||||||
-record(state,{socket, length, session_id}).
|
-record(state,{socket, length, session_id}).
|
||||||
-record(request,{method, url, body, cookies, headers}).
|
-record(request,{method, url, body, cookies, headers}).
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
-module(epp_util).
|
-module(epp_util).
|
||||||
|
|
||||||
-export([create_map/1, create_session_id/1, frame_length/1,
|
-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).
|
-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(),
|
-spec create_map(pid()) -> #{string() => pid(), string() => float(),
|
||||||
string() => string()}.
|
string() => string()}.
|
||||||
create_map(Pid) when is_pid(Pid) ->
|
create_map(Pid) when is_pid(Pid) ->
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-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() ->
|
create_map_test() ->
|
||||||
Pid = spawn(fun () -> ok end),
|
Pid = spawn(fun () -> ok end),
|
||||||
Map = epp_util:create_map(Pid),
|
Map = epp_util:create_map(Pid),
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
[
|
[
|
||||||
{epp_proxy, [{tcp_port, 1133},
|
{epp_proxy, [{tcp_port, 17001,
|
||||||
{tls_port, 4444},
|
{tls_port, 17002},
|
||||||
{epp_session_url, "https://registry.test/epp/session/"},
|
{epp_session_url, "https://registry.test/epp/session/"},
|
||||||
{epp_command_url, "https://registry.test/epp/command/"}]}
|
{epp_command_url, "https://registry.test/epp/command/"},
|
||||||
|
{cacertfile_path, "/opt/shared/ca/certs/ca.crt.pem"},
|
||||||
|
{certfile_path, "/opt/shared/ca/certs/ca.crt.pem"},
|
||||||
|
{keyfile_path, "/opt/shared/ca/certs/ca.crt.pem"}]}
|
||||||
].
|
].
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
[epp_proxy,
|
[epp_proxy,
|
||||||
hackney,
|
hackney,
|
||||||
sasl,
|
sasl,
|
||||||
ssl,
|
|
||||||
xmerl]},
|
xmerl]},
|
||||||
|
|
||||||
{sys_config, "./config/sys.config"},
|
{sys_config, "./config/sys.config"},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue