aboutsummaryrefslogtreecommitdiff
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.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/core/core_api_monitor_peers.c b/src/core/core_api_monitor_peers.c
index 90f4a3d15..3be8e3859 100644
--- a/src/core/core_api_monitor_peers.c
+++ b/src/core/core_api_monitor_peers.c
@@ -32,7 +32,8 @@
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{
36 /** 37 /**
37 * Our configuration. 38 * Our configuration.
38 */ 39 */
@@ -62,7 +63,7 @@ struct GNUNET_CORE_MonitorHandle {
62 * @param mh monitoring session to reconnect to CORE 63 * @param mh monitoring session to reconnect to CORE
63 */ 64 */
64static void 65static void
65reconnect(struct GNUNET_CORE_MonitorHandle *mh); 66reconnect (struct GNUNET_CORE_MonitorHandle *mh);
66 67
67 68
68/** 69/**
@@ -74,12 +75,12 @@ reconnect(struct GNUNET_CORE_MonitorHandle *mh);
74 * @param error error code 75 * @param error error code
75 */ 76 */
76static void 77static void
77handle_mq_error(void *cls, enum GNUNET_MQ_Error error) 78handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
78{ 79{
79 struct GNUNET_CORE_MonitorHandle *mh = cls; 80 struct GNUNET_CORE_MonitorHandle *mh = cls;
80 81
81 (void)error; 82 (void) error;
82 reconnect(mh); 83 reconnect (mh);
83} 84}
84 85
85 86
@@ -90,14 +91,14 @@ handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
90 * @param mon_message monitor message 91 * @param mon_message monitor message
91 */ 92 */
92static void 93static void
93handle_receive_info(void *cls, const struct MonitorNotifyMessage *mon_message) 94handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message)
94{ 95{
95 struct GNUNET_CORE_MonitorHandle *mh = cls; 96 struct GNUNET_CORE_MonitorHandle *mh = cls;
96 97
97 mh->peer_cb(mh->peer_cb_cls, 98 mh->peer_cb (mh->peer_cb_cls,
98 &mon_message->peer, 99 &mon_message->peer,
99 (enum GNUNET_CORE_KxState)ntohl(mon_message->state), 100 (enum GNUNET_CORE_KxState) ntohl (mon_message->state),
100 GNUNET_TIME_absolute_ntoh(mon_message->timeout)); 101 GNUNET_TIME_absolute_ntoh (mon_message->timeout));
101} 102}
102 103
103 104
@@ -108,32 +109,32 @@ handle_receive_info(void *cls, const struct MonitorNotifyMessage *mon_message)
108 * @param mh monitoring session to reconnect to CORE 109 * @param mh monitoring session to reconnect to CORE
109 */ 110 */
110static void 111static void
111reconnect(struct GNUNET_CORE_MonitorHandle *mh) 112reconnect (struct GNUNET_CORE_MonitorHandle *mh)
112{ 113{
113 struct GNUNET_MQ_MessageHandler handlers[] = 114 struct GNUNET_MQ_MessageHandler handlers[] =
114 { GNUNET_MQ_hd_fixed_size(receive_info, 115 { GNUNET_MQ_hd_fixed_size (receive_info,
115 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, 116 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY,
116 struct MonitorNotifyMessage, 117 struct MonitorNotifyMessage,
117 mh), 118 mh),
118 GNUNET_MQ_handler_end() }; 119 GNUNET_MQ_handler_end () };
119 struct GNUNET_MQ_Envelope *env; 120 struct GNUNET_MQ_Envelope *env;
120 struct GNUNET_MessageHeader *msg; 121 struct GNUNET_MessageHeader *msg;
121 122
122 if (NULL != mh->mq) 123 if (NULL != mh->mq)
123 GNUNET_MQ_destroy(mh->mq); 124 GNUNET_MQ_destroy (mh->mq);
124 /* FIXME: use backoff? */ 125 /* FIXME: use backoff? */
125 mh->mq = 126 mh->mq =
126 GNUNET_CLIENT_connect(mh->cfg, "core", handlers, &handle_mq_error, mh); 127 GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh);
127 if (NULL == mh->mq) 128 if (NULL == mh->mq)
128 return; 129 return;
129 /* notify callback about reconnect */ 130 /* notify callback about reconnect */
130 if (NULL != mh->peer_cb) 131 if (NULL != mh->peer_cb)
131 mh->peer_cb(mh->peer_cb_cls, 132 mh->peer_cb (mh->peer_cb_cls,
132 NULL, 133 NULL,
133 GNUNET_CORE_KX_CORE_DISCONNECT, 134 GNUNET_CORE_KX_CORE_DISCONNECT,
134 GNUNET_TIME_UNIT_FOREVER_ABS); 135 GNUNET_TIME_UNIT_FOREVER_ABS);
135 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); 136 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS);
136 GNUNET_MQ_send(mh->mq, env); 137 GNUNET_MQ_send (mh->mq, env);
137} 138}
138 139
139 140
@@ -154,23 +155,23 @@ reconnect(struct GNUNET_CORE_MonitorHandle *mh)
154 * @return NULL on error 155 * @return NULL on error
155 */ 156 */
156struct GNUNET_CORE_MonitorHandle * 157struct GNUNET_CORE_MonitorHandle *
157GNUNET_CORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, 158GNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
158 GNUNET_CORE_MonitorCallback peer_cb, 159 GNUNET_CORE_MonitorCallback peer_cb,
159 void *peer_cb_cls) 160 void *peer_cb_cls)
160{ 161{
161 struct GNUNET_CORE_MonitorHandle *mh; 162 struct GNUNET_CORE_MonitorHandle *mh;
162 163
163 GNUNET_assert(NULL != peer_cb); 164 GNUNET_assert (NULL != peer_cb);
164 mh = GNUNET_new(struct GNUNET_CORE_MonitorHandle); 165 mh = GNUNET_new (struct GNUNET_CORE_MonitorHandle);
165 mh->cfg = cfg; 166 mh->cfg = cfg;
166 reconnect(mh); 167 reconnect (mh);
167 mh->peer_cb = peer_cb; 168 mh->peer_cb = peer_cb;
168 mh->peer_cb_cls = peer_cb_cls; 169 mh->peer_cb_cls = peer_cb_cls;
169 if (NULL == mh->mq) 170 if (NULL == mh->mq)
170 { 171 {
171 GNUNET_free(mh); 172 GNUNET_free (mh);
172 return NULL; 173 return NULL;
173 } 174 }
174 return mh; 175 return mh;
175} 176}
176 177
@@ -181,14 +182,14 @@ GNUNET_CORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
181 * @param mh monitor to stop 182 * @param mh monitor to stop
182 */ 183 */
183void 184void
184GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh) 185GNUNET_CORE_monitor_stop (struct GNUNET_CORE_MonitorHandle *mh)
185{ 186{
186 if (NULL != mh->mq) 187 if (NULL != mh->mq)
187 { 188 {
188 GNUNET_MQ_destroy(mh->mq); 189 GNUNET_MQ_destroy (mh->mq);
189 mh->mq = NULL; 190 mh->mq = NULL;
190 } 191 }
191 GNUNET_free(mh); 192 GNUNET_free (mh);
192} 193}
193 194
194 195