1 /*
2  * Copyright (C) 2009-2014 Codership Oy <info@codership.com>
3  */
4 
5 #include "gcomm/conf.hpp"
6 #include "defaults.hpp"
7 #include "common.h"
8 
9 #include <limits>
10 
11 static std::string const Delim = ".";
12 
13 // Protonet
14 std::string const gcomm::Conf::ProtonetBackend("protonet.backend");
15 std::string const gcomm::Conf::ProtonetVersion("protonet.version");
16 
17 // TCP
18 static std::string const SocketPrefix("socket" + Delim);
19 std::string const gcomm::Conf::TcpNonBlocking =
20     SocketPrefix + "non_blocking";
21 std::string const gcomm::Conf::SocketChecksum =
22     SocketPrefix + "checksum";
23 std::string const gcomm::Conf::SocketRecvBufSize =
24     SocketPrefix + "recv_buf_size";
25 std::string const gcomm::Conf::SocketSendBufSize =
26     SocketPrefix + "send_buf_size";
27 
28 // GMCast
29 std::string const gcomm::Conf::GMCastScheme = "gmcast";
30 static std::string const GMCastPrefix(gcomm::Conf::GMCastScheme + Delim);
31 std::string const gcomm::Conf::GMCastVersion =
32     GMCastPrefix + "version";
33 std::string const gcomm::Conf::GMCastGroup =
34     GMCastPrefix + "group";
35 std::string const gcomm::Conf::GMCastListenAddr =
36     GMCastPrefix + "listen_addr";
37 std::string const gcomm::Conf::GMCastMCastAddr =
38     GMCastPrefix + "mcast_addr";
39 std::string const gcomm::Conf::GMCastMCastPort =
40     GMCastPrefix + "mcast_port";
41 std::string const gcomm::Conf::GMCastMCastTTL =
42     GMCastPrefix + "mcast_ttl";
43 std::string const gcomm::Conf::GMCastTimeWait =
44     GMCastPrefix + "time_wait";
45 std::string const gcomm::Conf::GMCastPeerTimeout =
46     GMCastPrefix + "peer_timeout";
47 std::string const gcomm::Conf::GMCastMaxInitialReconnectAttempts =
48     GMCastPrefix + "mira";
49 std::string const gcomm::Conf::GMCastPeerAddr =
50     GMCastPrefix + "peer_addr";
51 std::string const gcomm::Conf::GMCastIsolate =
52     GMCastPrefix + "isolate";
53 std::string const gcomm::Conf::GMCastSegment =
54     GMCastPrefix + "segment";
55 
56 // EVS
57 std::string const gcomm::Conf::EvsScheme = "evs";
58 static std::string const EvsPrefix(gcomm::Conf::EvsScheme + Delim);
59 std::string const gcomm::Conf::EvsVersion =
60     EvsPrefix + "version";
61 std::string const gcomm::Conf::EvsViewForgetTimeout =
62     EvsPrefix + "view_forget_timeout";
63 std::string const gcomm::Conf::EvsInactiveTimeout =
64     EvsPrefix + "inactive_timeout";
65 std::string const gcomm::Conf::EvsSuspectTimeout =
66     EvsPrefix + "suspect_timeout";
67 std::string const gcomm::Conf::EvsInactiveCheckPeriod =
68     EvsPrefix + "inactive_check_period";
69 std::string const gcomm::Conf::EvsInstallTimeout =
70     EvsPrefix + "install_timeout";
71 std::string const gcomm::Conf::EvsKeepalivePeriod =
72     EvsPrefix + "keepalive_period";
73 std::string const gcomm::Conf::EvsJoinRetransPeriod =
74     EvsPrefix + "join_retrans_period";
75 std::string const gcomm::Conf::EvsStatsReportPeriod =
76     EvsPrefix + "stats_report_period";
77 std::string const gcomm::Conf::EvsDebugLogMask =
78     EvsPrefix + "debug_log_mask";
79 std::string const gcomm::Conf::EvsInfoLogMask =
80     EvsPrefix + "info_log_mask";
81 std::string const gcomm::Conf::EvsSendWindow =
82     EvsPrefix + "send_window";
83 std::string const gcomm::Conf::EvsUserSendWindow =
84     EvsPrefix + "user_send_window";
85 std::string const gcomm::Conf::EvsUseAggregate =
86     EvsPrefix + "use_aggregate";
87 std::string const gcomm::Conf::EvsCausalKeepalivePeriod =
88     EvsPrefix + "causal_keepalive_period";
89 std::string const gcomm::Conf::EvsMaxInstallTimeouts =
90     EvsPrefix + "max_install_timeouts";
91 std::string const gcomm::Conf::EvsDelayMargin =
92     EvsPrefix + "delay_margin";
93 std::string const gcomm::Conf::EvsDelayedKeepPeriod =
94     EvsPrefix + "delayed_keep_period";
95 std::string const gcomm::Conf::EvsEvict =
96     EvsPrefix + "evict";
97 std::string const gcomm::Conf::EvsAutoEvict =
98     EvsPrefix + "auto_evict";
99 
100 // PC
101 std::string const gcomm::Conf::PcScheme = "pc";
102 static std::string const PcPrefix(gcomm::Conf::PcScheme + Delim);
103 std::string const gcomm::Conf::PcVersion = PcPrefix + "version";
104 std::string const gcomm::Conf::PcIgnoreSb = PcPrefix + "ignore_sb";
105 std::string const gcomm::Conf::PcIgnoreQuorum =
106     PcPrefix + "ignore_quorum";
107 std::string const gcomm::Conf::PcChecksum = PcPrefix + "checksum";
108 std::string const gcomm::Conf::PcLinger = PcPrefix + "linger";
109 std::string const gcomm::Conf::PcAnnounceTimeout =
110     PcPrefix + "announce_timeout";
111 std::string const gcomm::Conf::PcNpvo = PcPrefix + "npvo";
112 std::string const gcomm::Conf::PcBootstrap = PcPrefix + "bootstrap";
113 std::string const gcomm::Conf::PcWaitPrim = PcPrefix + "wait_prim";
114 std::string const gcomm::Conf::PcWaitPrimTimeout =
115     PcPrefix + "wait_prim_timeout";
116 std::string const gcomm::Conf::PcWeight = PcPrefix + "weight";
117 std::string const gcomm::Conf::PcRecovery = PcPrefix + "recovery";
118 
119 void
register_params(gu::Config & cnf)120 gcomm::Conf::register_params(gu::Config& cnf)
121 {
122 #define GCOMM_CONF_ADD(_x_) cnf.add(_x_);
123 #define GCOMM_CONF_ADD_DEFAULT(_x_) cnf.add(_x_, Defaults::_x_);
124 
125     GCOMM_CONF_ADD (COMMON_BASE_HOST_KEY);
126     GCOMM_CONF_ADD (COMMON_BASE_PORT_KEY);
127 
128     GCOMM_CONF_ADD_DEFAULT(ProtonetBackend);
129     GCOMM_CONF_ADD_DEFAULT(ProtonetVersion);
130 
131     GCOMM_CONF_ADD        (TcpNonBlocking);
132     GCOMM_CONF_ADD_DEFAULT(SocketChecksum);
133     GCOMM_CONF_ADD_DEFAULT(SocketRecvBufSize);
134     GCOMM_CONF_ADD_DEFAULT(SocketSendBufSize);
135 
136     GCOMM_CONF_ADD_DEFAULT(GMCastVersion);
137     GCOMM_CONF_ADD        (GMCastGroup);
138     GCOMM_CONF_ADD        (GMCastListenAddr);
139     GCOMM_CONF_ADD        (GMCastMCastAddr);
140     GCOMM_CONF_ADD        (GMCastMCastPort);
141     GCOMM_CONF_ADD        (GMCastMCastTTL);
142     GCOMM_CONF_ADD        (GMCastMCastAddr);
143     GCOMM_CONF_ADD        (GMCastTimeWait);
144     GCOMM_CONF_ADD        (GMCastPeerTimeout);
145     GCOMM_CONF_ADD        (GMCastMaxInitialReconnectAttempts);
146     GCOMM_CONF_ADD        (GMCastPeerAddr);
147     GCOMM_CONF_ADD        (GMCastIsolate);
148     GCOMM_CONF_ADD_DEFAULT(GMCastSegment);
149 
150     GCOMM_CONF_ADD        (EvsVersion);
151     GCOMM_CONF_ADD_DEFAULT(EvsViewForgetTimeout);
152     GCOMM_CONF_ADD_DEFAULT(EvsSuspectTimeout);
153     GCOMM_CONF_ADD_DEFAULT(EvsInactiveTimeout);
154     GCOMM_CONF_ADD_DEFAULT(EvsInactiveCheckPeriod);
155     GCOMM_CONF_ADD        (EvsInstallTimeout);
156     GCOMM_CONF_ADD        (EvsKeepalivePeriod);
157     GCOMM_CONF_ADD_DEFAULT(EvsJoinRetransPeriod);
158     GCOMM_CONF_ADD_DEFAULT(EvsStatsReportPeriod);
159     GCOMM_CONF_ADD        (EvsDebugLogMask);
160     GCOMM_CONF_ADD        (EvsInfoLogMask);
161     GCOMM_CONF_ADD_DEFAULT(EvsSendWindow);
162     GCOMM_CONF_ADD_DEFAULT(EvsUserSendWindow);
163     GCOMM_CONF_ADD        (EvsUseAggregate);
164     GCOMM_CONF_ADD        (EvsCausalKeepalivePeriod);
165     GCOMM_CONF_ADD_DEFAULT(EvsMaxInstallTimeouts);
166     GCOMM_CONF_ADD_DEFAULT(EvsDelayMargin);
167     GCOMM_CONF_ADD_DEFAULT(EvsDelayedKeepPeriod);
168     GCOMM_CONF_ADD        (EvsEvict);
169     GCOMM_CONF_ADD_DEFAULT(EvsAutoEvict);
170 
171     GCOMM_CONF_ADD_DEFAULT(PcVersion);
172     GCOMM_CONF_ADD_DEFAULT(PcIgnoreSb);
173     GCOMM_CONF_ADD_DEFAULT(PcIgnoreQuorum);
174     GCOMM_CONF_ADD_DEFAULT(PcChecksum);
175     GCOMM_CONF_ADD_DEFAULT(PcAnnounceTimeout);
176     GCOMM_CONF_ADD        (PcLinger);
177     GCOMM_CONF_ADD_DEFAULT(PcNpvo);
178     GCOMM_CONF_ADD        (PcBootstrap);
179     GCOMM_CONF_ADD_DEFAULT(PcWaitPrim);
180     GCOMM_CONF_ADD_DEFAULT(PcWaitPrimTimeout);
181     GCOMM_CONF_ADD_DEFAULT(PcWeight);
182     GCOMM_CONF_ADD_DEFAULT(PcRecovery);
183 
184 #undef GCOMM_CONF_ADD
185 #undef GCOMM_CONF_ADD_DEFAULT
186 }
187 
check_params(const gu::Config & conf)188 void gcomm::Conf::check_params(const gu::Config& conf)
189 {
190     check_recv_buf_size(conf.get(SocketRecvBufSize));
191 }
192 
check_recv_buf_size(const std::string & str)193 size_t gcomm::Conf::check_recv_buf_size(const std::string& str)
194 {
195     // signed type to check for negative values
196     return (str == Defaults::SocketRecvBufSize ||
197             check_range<long long>(SocketRecvBufSize, str,
198                                    0, std::numeric_limits<long long>::max()));
199 }
200 
check_send_buf_size(const std::string & str)201 size_t gcomm::Conf::check_send_buf_size(const std::string& str)
202 {
203     // signed type to check for negative values
204     return (str == Defaults::SocketSendBufSize ||
205             check_range<long long>(SocketSendBufSize, str,
206                                    0, std::numeric_limits<long long>::max()));
207 }
208