summaryrefslogtreecommitdiff
path: root/src/util/nc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/nc.c')
-rw-r--r--src/util/nc.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/util/nc.c b/src/util/nc.c
index ab7ef122d..9db321b8c 100644
--- a/src/util/nc.c
+++ b/src/util/nc.c
@@ -28,13 +28,14 @@
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31#define LOG(kind, ...) GNUNET_log_from(kind, "util-nc", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "util-nc", __VA_ARGS__)
32 32
33 33
34/** 34/**
35 * Lists of subscribers we manage for notifications. 35 * Lists of subscribers we manage for notifications.
36 */ 36 */
37struct SubscriberList { 37struct SubscriberList
38{
38 /** 39 /**
39 * This is a doubly linked list. 40 * This is a doubly linked list.
40 */ 41 */
@@ -71,7 +72,8 @@ struct SubscriberList {
71 * (notification) messages are queued up until the subscriber is able to 72 * (notification) messages are queued up until the subscriber is able to
72 * read them. 73 * read them.
73 */ 74 */
74struct GNUNET_NotificationContext { 75struct GNUNET_NotificationContext
76{
75 /** 77 /**
76 * Head of list of subscribers receiving notifications. 78 * Head of list of subscribers receiving notifications.
77 */ 79 */
@@ -95,15 +97,15 @@ struct GNUNET_NotificationContext {
95 * @param cls our `struct SubscriberList *` 97 * @param cls our `struct SubscriberList *`
96 */ 98 */
97static void 99static void
98handle_mq_destroy(void *cls) 100handle_mq_destroy (void *cls)
99{ 101{
100 struct SubscriberList *pos = cls; 102 struct SubscriberList *pos = cls;
101 struct GNUNET_NotificationContext *nc = pos->nc; 103 struct GNUNET_NotificationContext *nc = pos->nc;
102 104
103 GNUNET_CONTAINER_DLL_remove(nc->subscribers_head, 105 GNUNET_CONTAINER_DLL_remove (nc->subscribers_head,
104 nc->subscribers_tail, 106 nc->subscribers_tail,
105 pos); 107 pos);
106 GNUNET_free(pos); 108 GNUNET_free (pos);
107} 109}
108 110
109 111
@@ -116,11 +118,11 @@ handle_mq_destroy(void *cls)
116 * @return handle to the notification context 118 * @return handle to the notification context
117 */ 119 */
118struct GNUNET_NotificationContext * 120struct GNUNET_NotificationContext *
119GNUNET_notification_context_create(unsigned int queue_length) 121GNUNET_notification_context_create (unsigned int queue_length)
120{ 122{
121 struct GNUNET_NotificationContext *nc; 123 struct GNUNET_NotificationContext *nc;
122 124
123 nc = GNUNET_new(struct GNUNET_NotificationContext); 125 nc = GNUNET_new (struct GNUNET_NotificationContext);
124 nc->queue_length = queue_length; 126 nc->queue_length = queue_length;
125 return nc; 127 return nc;
126} 128}
@@ -132,19 +134,19 @@ GNUNET_notification_context_create(unsigned int queue_length)
132 * @param nc context to destroy. 134 * @param nc context to destroy.
133 */ 135 */
134void 136void
135GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc) 137GNUNET_notification_context_destroy (struct GNUNET_NotificationContext *nc)
136{ 138{
137 struct SubscriberList *pos; 139 struct SubscriberList *pos;
138 140
139 while (NULL != (pos = nc->subscribers_head)) 141 while (NULL != (pos = nc->subscribers_head))
140 { 142 {
141 GNUNET_CONTAINER_DLL_remove(nc->subscribers_head, 143 GNUNET_CONTAINER_DLL_remove (nc->subscribers_head,
142 nc->subscribers_tail, 144 nc->subscribers_tail,
143 pos); 145 pos);
144 GNUNET_MQ_destroy_notify_cancel(pos->mq_nh); 146 GNUNET_MQ_destroy_notify_cancel (pos->mq_nh);
145 GNUNET_free(pos); 147 GNUNET_free (pos);
146 } 148 }
147 GNUNET_free(nc); 149 GNUNET_free (nc);
148} 150}
149 151
150 152
@@ -155,8 +157,8 @@ GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
155 * @param mq message queue add 157 * @param mq message queue add
156 */ 158 */
157void 159void
158GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, 160GNUNET_notification_context_add (struct GNUNET_NotificationContext *nc,
159 struct GNUNET_MQ_Handle *mq) 161 struct GNUNET_MQ_Handle *mq)
160{ 162{
161 struct SubscriberList *cl; 163 struct SubscriberList *cl;
162 164
@@ -164,15 +166,15 @@ GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc,
164 if (cl->mq == mq) 166 if (cl->mq == mq)
165 return; 167 return;
166 /* already present */ 168 /* already present */
167 cl = GNUNET_new(struct SubscriberList); 169 cl = GNUNET_new (struct SubscriberList);
168 GNUNET_CONTAINER_DLL_insert(nc->subscribers_head, 170 GNUNET_CONTAINER_DLL_insert (nc->subscribers_head,
169 nc->subscribers_tail, 171 nc->subscribers_tail,
170 cl); 172 cl);
171 cl->nc = nc; 173 cl->nc = nc;
172 cl->mq = mq; 174 cl->mq = mq;
173 cl->mq_nh = GNUNET_MQ_destroy_notify(cl->mq, 175 cl->mq_nh = GNUNET_MQ_destroy_notify (cl->mq,
174 &handle_mq_destroy, 176 &handle_mq_destroy,
175 cl); 177 cl);
176} 178}
177 179
178 180
@@ -184,22 +186,22 @@ GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc,
184 * @param can_drop can this message be dropped due to queue length limitations 186 * @param can_drop can this message be dropped due to queue length limitations
185 */ 187 */
186void 188void
187GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, 189GNUNET_notification_context_broadcast (struct GNUNET_NotificationContext *nc,
188 const struct GNUNET_MessageHeader *msg, 190 const struct GNUNET_MessageHeader *msg,
189 int can_drop) 191 int can_drop)
190{ 192{
191 struct SubscriberList *pos; 193 struct SubscriberList *pos;
192 struct GNUNET_MQ_Envelope *env; 194 struct GNUNET_MQ_Envelope *env;
193 195
194 for (pos = nc->subscribers_head; NULL != pos; pos = pos->next) 196 for (pos = nc->subscribers_head; NULL != pos; pos = pos->next)
195 { 197 {
196 if ((GNUNET_YES == can_drop) && 198 if ((GNUNET_YES == can_drop) &&
197 (GNUNET_MQ_get_length(pos->mq) > nc->queue_length)) 199 (GNUNET_MQ_get_length (pos->mq) > nc->queue_length))
198 continue; 200 continue;
199 env = GNUNET_MQ_msg_copy(msg); 201 env = GNUNET_MQ_msg_copy (msg);
200 GNUNET_MQ_send(pos->mq, 202 GNUNET_MQ_send (pos->mq,
201 env); 203 env);
202 } 204 }
203} 205}
204 206
205 207
@@ -210,7 +212,7 @@ GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc,
210 * @return number of current subscribers 212 * @return number of current subscribers
211 */ 213 */
212unsigned int 214unsigned int
213GNUNET_notification_context_get_size(struct GNUNET_NotificationContext *nc) 215GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc)
214{ 216{
215 unsigned int num; 217 unsigned int num;
216 struct SubscriberList *pos; 218 struct SubscriberList *pos;