4
0

qdevice-net-instance.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2015-2020 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _QDEVICE_NET_INSTANCE_H_
  35. #define _QDEVICE_NET_INSTANCE_H_
  36. #include <sys/types.h>
  37. #include <stdlib.h>
  38. #include <stdint.h>
  39. #include "nss-sock.h"
  40. #include "qdevice-instance.h"
  41. #include "dynar.h"
  42. #include "node-list.h"
  43. #include "qdevice-net-disconnect-reason.h"
  44. #include "send-buffer-list.h"
  45. #include "tlv.h"
  46. #include "timer-list.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. enum qdevice_net_instance_state {
  51. QDEVICE_NET_INSTANCE_STATE_WAITING_CONNECT,
  52. QDEVICE_NET_INSTANCE_STATE_SENDING_PREINIT_REPLY,
  53. QDEVICE_NET_INSTANCE_STATE_WAITING_PREINIT_REPLY,
  54. QDEVICE_NET_INSTANCE_STATE_WAITING_STARTTLS_BEING_SENT,
  55. QDEVICE_NET_INSTANCE_STATE_WAITING_INIT_REPLY,
  56. QDEVICE_NET_INSTANCE_STATE_WAITING_VOTEQUORUM_CMAP_EVENTS,
  57. };
  58. struct qdevice_net_instance {
  59. PRFileDesc *socket;
  60. struct dynar receive_buffer;
  61. struct send_buffer_list send_buffer_list;
  62. int skipping_msg;
  63. size_t msg_already_received_bytes;
  64. enum qdevice_net_instance_state state;
  65. uint32_t last_msg_seq_num;
  66. uint32_t echo_request_expected_msg_seq_num;
  67. uint32_t echo_reply_received_msg_seq_num;
  68. enum tlv_tls_supported tls_supported;
  69. int using_tls;
  70. int tls_client_cert_sent;
  71. uint32_t heartbeat_interval; /* Adjusted heartbeat interval during normal operation */
  72. uint32_t sync_heartbeat_interval; /* Adjusted heartbeat interval during corosync sync */
  73. uint32_t cast_vote_timer_interval; /* Timer for cast vote */
  74. uint32_t connect_timeout;
  75. struct timer_list_entry *cast_vote_timer;
  76. enum tlv_vote cast_vote_timer_vote;
  77. int cast_vote_timer_paused;
  78. const char *host_addr;
  79. uint16_t host_port;
  80. const char *cluster_name;
  81. enum tlv_decision_algorithm_type decision_algorithm;
  82. struct timer_list_entry *echo_request_timer;
  83. int schedule_disconnect;
  84. struct tlv_ring_id last_sent_ring_id;
  85. struct tlv_tie_breaker tie_breaker;
  86. void *algorithm_data;
  87. enum qdevice_net_disconnect_reason disconnect_reason;
  88. struct qdevice_instance *qdevice_instance_ptr;
  89. struct nss_sock_non_blocking_client non_blocking_client;
  90. struct timer_list_entry *connect_timer;
  91. int force_ip_version;
  92. time_t last_echo_reply_received_time;
  93. time_t connected_since_time;
  94. const struct qdevice_advanced_settings *advanced_settings;
  95. struct timer_list_entry *regular_heuristics_timer;
  96. int server_supports_heuristics;
  97. int server_supports_keep_active_partition_tie_breaker;
  98. enum tlv_keep_active_partition_tie_breaker keep_active_partition_tie_breaker;
  99. enum tlv_heuristics latest_regular_heuristics_result;
  100. enum tlv_heuristics latest_connect_heuristics_result;
  101. enum tlv_heuristics latest_vq_heuristics_result;
  102. enum tlv_heuristics latest_heuristics_result;
  103. };
  104. extern int qdevice_net_instance_init(struct qdevice_net_instance *instance,
  105. enum tlv_tls_supported tls_supported,
  106. enum tlv_decision_algorithm_type decision_algorithm, uint32_t heartbeat_interval,
  107. uint32_t sync_heartbeat_interval, uint32_t cast_vote_timer_interval,
  108. const char *host_addr, uint16_t host_port, const char *cluster_name,
  109. const struct tlv_tie_breaker *tie_breaker, uint32_t connect_timeout, int force_ip_version,
  110. enum tlv_keep_active_partition_tie_breaker keep_active_partition_tie_breaker,
  111. int cmap_fd, int votequorum_fd, int local_socket_fd,
  112. const struct qdevice_advanced_settings *advanced_settings,
  113. int heuristics_pipe_cmd_send_fd, int heuristics_pipe_cmd_recv_fd,
  114. int heuristics_pipe_log_recv_fd);
  115. extern void qdevice_net_instance_clean(struct qdevice_net_instance *instance);
  116. extern int qdevice_net_instance_destroy(struct qdevice_net_instance *instance);
  117. extern int qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* _QDEVICE_NET_INSTANCE_H_ */