Merge pull request #18 from internetee/add-logging-of-process-and-ip-address

Add logging of IP address and process number
This commit is contained in:
Maciej Szlosarczyk 2019-07-30 10:58:05 +03:00 committed by GitHub
commit ae478d685d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,6 +40,7 @@ handle_cast(serve,
State = #state{socket = Socket, State = #state{socket = Socket,
session_id = _SessionId}) -> session_id = _SessionId}) ->
{ok, {PeerIp, _PeerPort}} = ssl:peername(Socket), {ok, {PeerIp, _PeerPort}} = ssl:peername(Socket),
log_opened_connection(PeerIp),
case ssl:handshake(Socket) of case ssl:handshake(Socket) of
{ok, SecureSocket} -> {ok, SecureSocket} ->
NewState = state_from_socket(SecureSocket, State), NewState = state_from_socket(SecureSocket, State),
@ -168,6 +169,11 @@ log_on_invalid_handshake(Ip, Error) ->
[ReadableIp, Error]), [ReadableIp, Error]),
exit(normal). exit(normal).
log_opened_connection(Ip) ->
ReadableIp = epp_util:readable_ip(Ip),
lager:info("New client connection. IP: ~s, Process: ~p.~n",
[ReadableIp, self()]).
%% Extract state info from socket. Fail if you must. %% Extract state info from socket. Fail if you must.
state_from_socket(Socket, State) -> state_from_socket(Socket, State) ->
{ok, PeerCert} = ssl:peercert(Socket), {ok, PeerCert} = ssl:peercert(Socket),