summaryrefslogtreecommitdiff
path: root/src/core/core_api_monitor_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core_api_monitor_peers.c')
-rw-r--r--src/core/core_api_monitor_peers.c84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/core/core_api_monitor_peers.c b/src/core/core_api_monitor_peers.c
index 165f741d2..90f4a3d15 100644
--- a/src/core/core_api_monitor_peers.c
+++ b/src/core/core_api_monitor_peers.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file core/core_api_monitor_peers.c 22 * @file core/core_api_monitor_peers.c
@@ -32,9 +32,7 @@
32/** 32/**
33 * Handle to a CORE monitoring operation. 33 * Handle to a CORE monitoring operation.
34 */ 34 */
35struct GNUNET_CORE_MonitorHandle 35struct GNUNET_CORE_MonitorHandle {
36{
37
38 /** 36 /**
39 * Our configuration. 37 * Our configuration.
40 */ 38 */
@@ -64,7 +62,7 @@ struct GNUNET_CORE_MonitorHandle
64 * @param mh monitoring session to reconnect to CORE 62 * @param mh monitoring session to reconnect to CORE
65 */ 63 */
66static void 64static void
67reconnect (struct GNUNET_CORE_MonitorHandle *mh); 65reconnect(struct GNUNET_CORE_MonitorHandle *mh);
68 66
69 67
70/** 68/**
@@ -76,12 +74,12 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh);
76 * @param error error code 74 * @param error error code
77 */ 75 */
78static void 76static void
79handle_mq_error (void *cls, enum GNUNET_MQ_Error error) 77handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
80{ 78{
81 struct GNUNET_CORE_MonitorHandle *mh = cls; 79 struct GNUNET_CORE_MonitorHandle *mh = cls;
82 80
83 (void) error; 81 (void)error;
84 reconnect (mh); 82 reconnect(mh);
85} 83}
86 84
87 85
@@ -92,14 +90,14 @@ handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
92 * @param mon_message monitor message 90 * @param mon_message monitor message
93 */ 91 */
94static void 92static void
95handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message) 93handle_receive_info(void *cls, const struct MonitorNotifyMessage *mon_message)
96{ 94{
97 struct GNUNET_CORE_MonitorHandle *mh = cls; 95 struct GNUNET_CORE_MonitorHandle *mh = cls;
98 96
99 mh->peer_cb (mh->peer_cb_cls, 97 mh->peer_cb(mh->peer_cb_cls,
100 &mon_message->peer, 98 &mon_message->peer,
101 (enum GNUNET_CORE_KxState) ntohl (mon_message->state), 99 (enum GNUNET_CORE_KxState)ntohl(mon_message->state),
102 GNUNET_TIME_absolute_ntoh (mon_message->timeout)); 100 GNUNET_TIME_absolute_ntoh(mon_message->timeout));
103} 101}
104 102
105 103
@@ -110,32 +108,32 @@ handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message)
110 * @param mh monitoring session to reconnect to CORE 108 * @param mh monitoring session to reconnect to CORE
111 */ 109 */
112static void 110static void
113reconnect (struct GNUNET_CORE_MonitorHandle *mh) 111reconnect(struct GNUNET_CORE_MonitorHandle *mh)
114{ 112{
115 struct GNUNET_MQ_MessageHandler handlers[] = 113 struct GNUNET_MQ_MessageHandler handlers[] =
116 {GNUNET_MQ_hd_fixed_size (receive_info, 114 { GNUNET_MQ_hd_fixed_size(receive_info,
117 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, 115 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY,
118 struct MonitorNotifyMessage, 116 struct MonitorNotifyMessage,
119 mh), 117 mh),
120 GNUNET_MQ_handler_end ()}; 118 GNUNET_MQ_handler_end() };
121 struct GNUNET_MQ_Envelope *env; 119 struct GNUNET_MQ_Envelope *env;
122 struct GNUNET_MessageHeader *msg; 120 struct GNUNET_MessageHeader *msg;
123 121
124 if (NULL != mh->mq) 122 if (NULL != mh->mq)
125 GNUNET_MQ_destroy (mh->mq); 123 GNUNET_MQ_destroy(mh->mq);
126 /* FIXME: use backoff? */ 124 /* FIXME: use backoff? */
127 mh->mq = 125 mh->mq =
128 GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh); 126 GNUNET_CLIENT_connect(mh->cfg, "core", handlers, &handle_mq_error, mh);
129 if (NULL == mh->mq) 127 if (NULL == mh->mq)
130 return; 128 return;
131 /* notify callback about reconnect */ 129 /* notify callback about reconnect */
132 if (NULL != mh->peer_cb) 130 if (NULL != mh->peer_cb)
133 mh->peer_cb (mh->peer_cb_cls, 131 mh->peer_cb(mh->peer_cb_cls,
134 NULL, 132 NULL,
135 GNUNET_CORE_KX_CORE_DISCONNECT, 133 GNUNET_CORE_KX_CORE_DISCONNECT,
136 GNUNET_TIME_UNIT_FOREVER_ABS); 134 GNUNET_TIME_UNIT_FOREVER_ABS);
137 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); 135 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS);
138 GNUNET_MQ_send (mh->mq, env); 136 GNUNET_MQ_send(mh->mq, env);
139} 137}
140 138
141 139
@@ -156,23 +154,23 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh)
156 * @return NULL on error 154 * @return NULL on error
157 */ 155 */
158struct GNUNET_CORE_MonitorHandle * 156struct GNUNET_CORE_MonitorHandle *
159GNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 157GNUNET_CORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
160 GNUNET_CORE_MonitorCallback peer_cb, 158 GNUNET_CORE_MonitorCallback peer_cb,
161 void *peer_cb_cls) 159 void *peer_cb_cls)
162{ 160{
163 struct GNUNET_CORE_MonitorHandle *mh; 161 struct GNUNET_CORE_MonitorHandle *mh;
164 162
165 GNUNET_assert (NULL != peer_cb); 163 GNUNET_assert(NULL != peer_cb);
166 mh = GNUNET_new (struct GNUNET_CORE_MonitorHandle); 164 mh = GNUNET_new(struct GNUNET_CORE_MonitorHandle);
167 mh->cfg = cfg; 165 mh->cfg = cfg;
168 reconnect (mh); 166 reconnect(mh);
169 mh->peer_cb = peer_cb; 167 mh->peer_cb = peer_cb;
170 mh->peer_cb_cls = peer_cb_cls; 168 mh->peer_cb_cls = peer_cb_cls;
171 if (NULL == mh->mq) 169 if (NULL == mh->mq)
172 { 170 {
173 GNUNET_free (mh); 171 GNUNET_free(mh);
174 return NULL; 172 return NULL;
175 } 173 }
176 return mh; 174 return mh;
177} 175}
178 176
@@ -183,14 +181,14 @@ GNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
183 * @param mh monitor to stop 181 * @param mh monitor to stop
184 */ 182 */
185void 183void
186GNUNET_CORE_monitor_stop (struct GNUNET_CORE_MonitorHandle *mh) 184GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
187{ 185{
188 if (NULL != mh->mq) 186 if (NULL != mh->mq)
189 { 187 {
190 GNUNET_MQ_destroy (mh->mq); 188 GNUNET_MQ_destroy(mh->mq);
191 mh->mq = NULL; 189 mh->mq = NULL;
192 } 190 }
193 GNUNET_free (mh); 191 GNUNET_free(mh);
194} 192}
195 193
196 194