Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.5 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <functional>
  8. #include "json11/json11.hpp"
  9. #define WS_CONTINUATION 0
  10. #define WS_TEXT 1
  11. #define WS_BINARY 2
  12. #define WS_CLOSE 8
  13. #define WS_PING 9
  14. #define WS_PONG 10
  15. class timerfd_manager_t;
  16. struct http_options_t
  17. {
  18. int timeout;
  19. bool want_streaming;
  20. };
  21. struct http_response_t
  22. {
  23. bool eof = false;
  24. int error_code = 0;
  25. int status_code = 0;
  26. std::string status_line;
  27. std::map<std::string, std::string> headers;
  28. int ws_msg_type = -1;
  29. std::string body;
  30. };
  31. struct http_co_t;
  32. struct websocket_t
  33. {
  34. http_co_t *co;
  35. void post_message(int type, const std::string & msg);
  36. void close();
  37. };
  38. void parse_http_headers(std::string & res, http_response_t *parsed);
  39. std::vector<std::string> getifaddr_list(bool include_v6 = false);
  40. uint64_t stoull_full(const std::string & str, int base = 10);
  41. void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
  42. const http_options_t & options, std::function<void(const http_response_t *response)> callback);
  43. void http_request_json(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
  44. int timeout, std::function<void(std::string, json11::Json r)> callback);
  45. websocket_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, const std::string & path,
  46. int timeout, std::function<void(const http_response_t *msg)> callback);