diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-25 20:01:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-25 20:01:13 +0000 |
commit | 4a381daf63c41550306834dc605378bb39afc6da (patch) | |
tree | 565f2a066344c38fcc1aa57cbff13fc1ef7a7a1e /src/testbed/testbed_api_barriers.c | |
parent | 3971743af72d4517e9cf5cc2e08645e11b917331 (diff) | |
download | gnunet-4a381daf63c41550306834dc605378bb39afc6da.tar.gz gnunet-4a381daf63c41550306834dc605378bb39afc6da.zip |
first steps towards MQ
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index c79ccd853..fb70737be 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -109,34 +109,28 @@ barrier_remove (struct GNUNET_TESTBED_Barrier *barrier) | |||
109 | 109 | ||
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages | 112 | * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message. |
113 | * | 113 | * |
114 | * @param c the controller handle to determine the connection this message | 114 | * @param cls the controller handle to determine the connection this message |
115 | * belongs to | 115 | * belongs to |
116 | * @param msg the barrier status message | 116 | * @param msg the barrier status message |
117 | * @return GNUNET_OK to keep the connection active; GNUNET_SYSERR to tear it | 117 | * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it |
118 | * down signalling an error | 118 | * down signalling an error (message malformed) |
119 | */ | 119 | */ |
120 | int | 120 | int |
121 | GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | 121 | check_barrier_status_ (struct GNUNET_TESTBED_Controller *c, |
122 | const struct GNUNET_TESTBED_BarrierStatusMsg | 122 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
123 | *msg) | ||
124 | { | 123 | { |
125 | struct GNUNET_TESTBED_Barrier *barrier; | ||
126 | char *emsg; | ||
127 | const char *name; | ||
128 | struct GNUNET_HashCode key; | ||
129 | size_t emsg_len; | ||
130 | int status; | ||
131 | uint16_t msize; | 124 | uint16_t msize; |
132 | uint16_t name_len; | 125 | uint16_t name_len; |
126 | int status; | ||
127 | const char *name; | ||
128 | size_t emsg_len; | ||
133 | 129 | ||
134 | emsg = NULL; | ||
135 | barrier = NULL; | ||
136 | msize = ntohs (msg->header.size); | 130 | msize = ntohs (msg->header.size); |
137 | name = msg->data; | 131 | name = msg->data; |
138 | name_len = ntohs (msg->name_len); | 132 | name_len = ntohs (msg->name_len); |
139 | LOG_DEBUG ("Received BARRIER_STATUS msg\n"); | 133 | |
140 | if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) | 134 | if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) |
141 | { | 135 | { |
142 | GNUNET_break_op (0); | 136 | GNUNET_break_op (0); |
@@ -150,19 +144,54 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
150 | status = ntohs (msg->status); | 144 | status = ntohs (msg->status); |
151 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | 145 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) |
152 | { | 146 | { |
153 | status = -1; | ||
154 | emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len | 147 | emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len |
155 | + 1); | 148 | + 1); /* +1!? */ |
156 | if (0 == emsg_len) | 149 | if (0 == emsg_len) |
157 | { | 150 | { |
158 | GNUNET_break_op (0); | 151 | GNUNET_break_op (0); |
159 | return GNUNET_SYSERR; | 152 | return GNUNET_SYSERR; |
160 | } | 153 | } |
161 | emsg_len++; | 154 | } |
162 | emsg = GNUNET_malloc (emsg_len); | 155 | return GNUNET_OK; |
163 | emsg_len--; | 156 | } |
164 | emsg[emsg_len] = '\0'; | 157 | |
165 | (void) memcpy (emsg, msg->data + name_len + 1, emsg_len); | 158 | |
159 | /** | ||
160 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages | ||
161 | * | ||
162 | * @param c the controller handle to determine the connection this message | ||
163 | * belongs to | ||
164 | * @param msg the barrier status message | ||
165 | */ | ||
166 | void | ||
167 | handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | ||
168 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | ||
169 | { | ||
170 | struct GNUNET_TESTBED_Barrier *barrier; | ||
171 | char *emsg; | ||
172 | const char *name; | ||
173 | struct GNUNET_HashCode key; | ||
174 | size_t emsg_len; | ||
175 | int status; | ||
176 | uint16_t msize; | ||
177 | uint16_t name_len; | ||
178 | |||
179 | emsg = NULL; | ||
180 | barrier = NULL; | ||
181 | msize = ntohs (msg->header.size); | ||
182 | name = msg->data; | ||
183 | name_len = ntohs (msg->name_len); | ||
184 | LOG_DEBUG ("Received BARRIER_STATUS msg\n"); | ||
185 | status = ntohs (msg->status); | ||
186 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | ||
187 | { | ||
188 | status = -1; | ||
189 | emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len | ||
190 | + 1); | ||
191 | emsg = GNUNET_malloc (emsg_len + 1); | ||
192 | memcpy (emsg, | ||
193 | msg->data + name_len + 1, | ||
194 | emsg_len); | ||
166 | } | 195 | } |
167 | if (NULL == barrier_map) | 196 | if (NULL == barrier_map) |
168 | { | 197 | { |
@@ -181,13 +210,12 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
181 | GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header)); | 210 | GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header)); |
182 | barrier->cb (barrier->cls, name, barrier, status, emsg); | 211 | barrier->cb (barrier->cls, name, barrier, status, emsg); |
183 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) | 212 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) |
184 | return GNUNET_OK; /* just initialised; skip cleanup */ | 213 | return; /* just initialised; skip cleanup */ |
185 | 214 | ||
186 | cleanup: | 215 | cleanup: |
187 | GNUNET_free_non_null (emsg); | 216 | GNUNET_free_non_null (emsg); |
188 | if (NULL != barrier) | 217 | if (NULL != barrier) |
189 | barrier_remove (barrier); | 218 | barrier_remove (barrier); |
190 | return GNUNET_OK; | ||
191 | } | 219 | } |
192 | 220 | ||
193 | 221 | ||