diff --git a/Makefile b/Makefile index 5560bbab..c3bb314d 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ libfio_blockstore.so: ./libblockstore.so fio_engine.cpp json11.o g++ $(CXXFLAGS) -shared -o libfio_blockstore.so fio_engine.cpp json11.o ./libblockstore.so -ltcmalloc_minimal -luring OSD_OBJS := osd.o osd_secondary.o osd_receive.o osd_send.o osd_peering.o osd_flush.o osd_peering_pg.o \ - osd_primary.o osd_primary_subops.o osd_cluster.o osd_http.o osd_rmw.o json11.o timerfd_interval.o base64.o timerfd_manager.o + osd_primary.o osd_primary_subops.o osd_cluster.o http_client.o osd_rmw.o json11.o timerfd_interval.o base64.o timerfd_manager.o base64.o: base64.cpp base64.h g++ $(CXXFLAGS) -c -o $@ $< osd_secondary.o: osd_secondary.cpp osd.h osd_ops.h ringloop.h @@ -43,7 +43,7 @@ osd_peering.o: osd_peering.cpp osd.h osd_ops.h osd_peering_pg.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< osd_cluster.o: osd_cluster.cpp osd.h osd_ops.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< -osd_http.o: osd_http.cpp osd_http.h osd.h osd_ops.h ringloop.h +http_client.o: http_client.cpp http_client.h osd.h osd_ops.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< osd_flush.o: osd_flush.cpp osd.h osd_ops.h osd_peering_pg.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< @@ -57,7 +57,7 @@ osd_primary.o: osd_primary.cpp osd_primary.h osd_rmw.h osd.h osd_ops.h osd_peeri g++ $(CXXFLAGS) -c -o $@ $< osd_primary_subops.o: osd_primary_subops.cpp osd_primary.h osd_rmw.h osd.h osd_ops.h osd_peering_pg.h xor.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< -osd.o: osd.cpp osd.h osd_http.h osd_ops.h osd_peering_pg.h ringloop.h +osd.o: osd.cpp osd.h http_client.h osd_ops.h osd_peering_pg.h ringloop.h g++ $(CXXFLAGS) -c -o $@ $< osd: ./libblockstore.so osd_main.cpp osd.h osd_ops.h $(OSD_OBJS) g++ $(CXXFLAGS) -o osd osd_main.cpp $(OSD_OBJS) ./libblockstore.so -ltcmalloc_minimal -luring diff --git a/osd_http.cpp b/http_client.cpp similarity index 96% rename from osd_http.cpp rename to http_client.cpp index 3b0d5eb8..04ee0297 100644 --- a/osd_http.cpp +++ b/http_client.cpp @@ -2,13 +2,17 @@ #include #include +#include #include #include +#include +#include +#include -#include "osd.h" #include "json11/json11.hpp" -#include "osd_http.h" +#include "http_client.h" +#include "timerfd_manager.h" #define READ_BUFFER_SIZE 9000 @@ -64,8 +68,7 @@ struct http_co_t #define DEFAULT_TIMEOUT 5000 -// FIXME: Remove osd_t dependency from here -void osd_t::http_request(const std::string & host, const std::string & request, +void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request, const http_options_t & options, std::function callback) { http_co_t *handler = new http_co_t(); @@ -79,10 +82,10 @@ void osd_t::http_request(const std::string & host, const std::string & request, handler->start_connection(); } -void osd_t::http_request_json(const std::string & host, const std::string & request, +void http_request_json(timerfd_manager_t *tfd, const std::string & host, const std::string & request, int timeout, std::function callback) { - http_request(host, request, { .timeout = timeout }, [this, callback](const http_response_t* res) + http_request(tfd, host, request, { .timeout = timeout }, [callback](const http_response_t* res) { if (res->error_code != 0) { @@ -105,7 +108,7 @@ void osd_t::http_request_json(const std::string & host, const std::string & requ }); } -websocket_t* osd_t::open_websocket(const std::string & host, const std::string & path, +websocket_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, const std::string & path, int timeout, std::function callback) { std::string request = "GET "+path+" HTTP/1.1\r\n" diff --git a/osd_http.h b/http_client.h similarity index 56% rename from osd_http.h rename to http_client.h index d2bb439a..2a42e017 100644 --- a/osd_http.h +++ b/http_client.h @@ -2,6 +2,8 @@ #include #include #include +#include +#include "json11/json11.hpp" #define WS_CONTINUATION 0 #define WS_TEXT 1 @@ -10,6 +12,8 @@ #define WS_PING 9 #define WS_PONG 10 +class timerfd_manager_t; + struct http_options_t { int timeout; @@ -37,5 +41,16 @@ struct websocket_t }; void parse_http_headers(std::string & res, http_response_t *parsed); + std::vector getifaddr_list(bool include_v6 = false); + uint64_t stoull_full(const std::string & str, int base = 10); + +void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request, + const http_options_t & options, std::function callback); + +void http_request_json(timerfd_manager_t *tfd, const std::string & host, const std::string & request, + int timeout, std::function callback); + +websocket_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, const std::string & path, + int timeout, std::function callback); diff --git a/osd.cpp b/osd.cpp index b8a5445e..080623d8 100644 --- a/osd.cpp +++ b/osd.cpp @@ -6,7 +6,6 @@ #include #include "osd.h" -#include "osd_http.h" const char* osd_op_names[] = { "", diff --git a/osd.h b/osd.h index 923664ec..a83696e6 100644 --- a/osd.h +++ b/osd.h @@ -18,7 +18,7 @@ #include "timerfd_manager.h" #include "osd_ops.h" #include "osd_peering_pg.h" -#include "osd_http.h" +#include "http_client.h" #include "json11/json11.hpp" #define OSD_OP_IN 0 @@ -294,12 +294,6 @@ class osd_t uint64_t recovery_stat_bytes[2][2] = { 0 }; // cluster connection - void http_request(const std::string & host, const std::string & request, - const http_options_t & options, std::function callback); - void http_request_json(const std::string & host, const std::string & request, int timeout, - std::function callback); - websocket_t* open_websocket(const std::string & host, const std::string & path, int timeout, - std::function callback); void etcd_call(std::string api, json11::Json payload, int timeout, std::function callback); void etcd_txn(json11::Json txn, int timeout, std::function callback); json_kv_t parse_etcd_kv(const json11::Json & kv_json); diff --git a/osd_cluster.cpp b/osd_cluster.cpp index f3aca1a1..649e9c29 100644 --- a/osd_cluster.cpp +++ b/osd_cluster.cpp @@ -1,5 +1,4 @@ #include "osd.h" -#include "osd_http.h" #include "base64.h" #define ETCD_CONFIG_WATCH_ID 1 @@ -39,7 +38,7 @@ void osd_t::etcd_call(std::string api, json11::Json payload, int timeout, std::f "Content-Length: "+std::to_string(req.size())+"\r\n" "Connection: close\r\n" "\r\n"+req; - http_request_json(etcd_address, req, timeout, callback); + http_request_json(tfd, etcd_address, req, timeout, callback); } // Startup sequence: @@ -244,7 +243,7 @@ void osd_t::report_statistics() void osd_t::start_etcd_watcher() { etcd_watches_initialised = 0; - etcd_watch_ws = open_websocket(etcd_address, etcd_api_path+"/watch", ETCD_SLOW_TIMEOUT, [this](const http_response_t *msg) + etcd_watch_ws = open_websocket(tfd, etcd_address, etcd_api_path+"/watch", ETCD_SLOW_TIMEOUT, [this](const http_response_t *msg) { if (msg->body.length()) {