summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plop.erl31
-rw-r--r--src/plop_app.erl1
2 files changed, 26 insertions, 6 deletions
diff --git a/src/plop.erl b/src/plop.erl
index 114695d..f90d287 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -39,6 +39,7 @@
%%-include("db.hrl").
-include_lib("public_key/include/public_key.hrl").
-include_lib("eunit/include/eunit.hrl").
+-include_lib("hackney/include/hackney_lib.hrl").
%%%%% moved from plop.hrl, maybe remove
-define(PLOPVERSION, 0).
@@ -193,6 +194,28 @@ storage_nodes_quorum() ->
{ok, Value} = application:get_env(plop, storage_nodes_quorum),
Value.
+send_http_request(TreeLeafHash, URL, Headers, RequestBody) ->
+ ParentPid = self(),
+ RequestId = make_ref(),
+ CACertFile = application:get_env(catlfish, https_cacertfile, none),
+ spawn(fun () ->
+ Starttime = os:timestamp(),
+ ParsedURL = hackney_url:parse_url(URL),
+ #hackney_url{path = Path} = ParsedURL,
+ lager:debug("leafhash ~s: sending http request to ~p", [mochihex:to_hex(TreeLeafHash), URL]),
+ {ok, ConnRef} = hackney:connect(ParsedURL, [{ssl_options, [{cacertfile, CACertFile}]}]),
+ lager:debug("leafhash ~s: connected to ~p", [mochihex:to_hex(TreeLeafHash), URL]),
+ {ok, StatusCode, RespHeaders, ClientRef} = hackney:send_request(ConnRef, {post, Path, Headers, RequestBody}),
+ lager:debug("leafhash ~s: received headers for ~p", [mochihex:to_hex(TreeLeafHash), URL]),
+ {ok, Body} = hackney:body(ClientRef),
+ Stoptime = os:timestamp(),
+ hackney:close(ClientRef),
+ lager:debug("leafhash ~s: received body for ~p: time ~p", [mochihex:to_hex(TreeLeafHash), URL, timer:now_diff(Stoptime, Starttime)]),
+ StatusLine = {none, StatusCode, none},
+ ParentPid ! {http, {RequestId, {StatusLine, RespHeaders, Body}}}
+ end),
+ RequestId.
+
send_storage_sendentry(URLBase, LogEntry, TreeLeafHash) ->
Request = mochijson2:encode(
{[{plop_version, 1},
@@ -201,9 +224,7 @@ send_storage_sendentry(URLBase, LogEntry, TreeLeafHash) ->
]}),
lager:debug("leafhash ~s: send sendentry to storage node ~p",
[mochihex:to_hex(TreeLeafHash), URLBase]),
- {ok, RequestId} = httpc:request(post, {URLBase ++ "sendentry", [],
- "text/json", list_to_binary(Request)},
- [], [{sync, false}]),
+ RequestId = send_http_request(TreeLeafHash, URLBase ++ "sendentry", [{"Content-Type", "text/json"}], list_to_binary(Request)),
{RequestId, URLBase}.
send_storage_entrycommitted(URLBase, EntryHash, TreeLeafHash) ->
@@ -212,9 +233,7 @@ send_storage_entrycommitted(URLBase, EntryHash, TreeLeafHash) ->
{entryhash, base64:encode(EntryHash)},
{treeleafhash, base64:encode(TreeLeafHash)}
]}),
- httpc:request(post, {URLBase ++ "entrycommitted", [],
- "text/json", list_to_binary(Request)},
- [], [{sync, false}]).
+ send_http_request(TreeLeafHash, URLBase ++ "entrycommitted", [{"Content-Type", "text/json"}], list_to_binary(Request)).
store_loop(TreeLeafHash, Requests, RepliesUntilQuorum) ->
receive
diff --git a/src/plop_app.erl b/src/plop_app.erl
index 767bf06..9cb5558 100644
--- a/src/plop_app.erl
+++ b/src/plop_app.erl
@@ -6,6 +6,7 @@
-export([start/2, stop/1]).
start(normal, Args) ->
+ hackney:start(),
plop_sup:start_link(Args).
stop(_State) ->