diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-12 22:21:16 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-12 22:21:16 +0000 |
commit | bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5 (patch) | |
tree | 091423fbd715fc8c8ed0bd8107ae6b9cde4bf8c9 /src/mesh/mesh_api_new.c | |
parent | 33b69c82ed1aed813b58aa076fbbed72a8e834b4 (diff) | |
download | gnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.tar.gz gnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.zip |
WiP
Diffstat (limited to 'src/mesh/mesh_api_new.c')
-rw-r--r-- | src/mesh/mesh_api_new.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 11376681a..1fe9714e5 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -133,34 +133,35 @@ struct GNUNET_MESH_TransmitHandle { | |||
133 | * @return number of bytes written to buf | 133 | * @return number of bytes written to buf |
134 | */ | 134 | */ |
135 | static size_t | 135 | static size_t |
136 | send_connect_packet (void *cls, size_t size, void *buf) { | 136 | send_connect_packet (void *cls, size_t size, void *buf) |
137 | { | ||
137 | struct GNUNET_MESH_Handle *h = cls; | 138 | struct GNUNET_MESH_Handle *h = cls; |
138 | struct GNUNET_MESH_ClientConnect *msg; | 139 | struct GNUNET_MESH_ClientConnect *msg; |
139 | uint16_t *types; | 140 | uint16_t *types; |
140 | int ntypes; | 141 | uint16_t ntypes; |
141 | GNUNET_MESH_ApplicationType *apps; | 142 | GNUNET_MESH_ApplicationType *apps; |
142 | int napps; | 143 | uint16_t napps; |
143 | 144 | ||
144 | h->th = NULL; | 145 | h->th = NULL; |
145 | if (0 == size || buf == NULL) { | 146 | if (0 == size || buf == NULL) { |
146 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 147 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
147 | "Send: buffer size 0 or buffer invalid\n"); | 148 | "Send connect packet: buffer size 0 or buffer invalid\n"); |
148 | // FIXME: disconnect, reconnect, retry! | 149 | // FIXME: disconnect, reconnect, retry! |
149 | return 0; | 150 | return 0; |
150 | } | 151 | } |
151 | if (sizeof(struct GNUNET_MessageHeader) > size) { | 152 | if (sizeof(struct GNUNET_MessageHeader) > size) { |
152 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
153 | "Send: buffer size too small\n"); | 154 | "Send connect packet: buffer size too small\n"); |
154 | // FIXME: disconnect, reconnect, retry! | 155 | // FIXME: disconnect, reconnect, retry! |
155 | return 0; | 156 | return 0; |
156 | } | 157 | } |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Sending into %lu bytes buffer\n", | 159 | "Send connect packet: %lu bytes buffer\n", |
159 | size); | 160 | size); |
160 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 161 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
161 | msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; | 162 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); |
162 | 163 | ||
163 | for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { | 164 | for (ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { |
164 | types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1)); | 165 | types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1)); |
165 | types[ntypes] = h->message_handlers[ntypes].type; | 166 | types[ntypes] = h->message_handlers[ntypes].type; |
166 | } | 167 | } |
@@ -172,20 +173,24 @@ send_connect_packet (void *cls, size_t size, void *buf) { | |||
172 | apps[napps] = h->applications[napps]; | 173 | apps[napps] = h->applications[napps]; |
173 | } | 174 | } |
174 | 175 | ||
175 | msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) + | 176 | msg->header.size = htons(sizeof(struct GNUNET_MESH_ClientConnect) + |
176 | sizeof(uint16_t) * ntypes + | 177 | sizeof(uint16_t) * ntypes + |
177 | sizeof(GNUNET_MESH_ApplicationType) * napps; | 178 | sizeof(GNUNET_MESH_ApplicationType) * napps); |
178 | if(msg->header.size > size) { | ||
179 | /* TODO treat error / retry */ | ||
180 | return 0; | ||
181 | } | ||
182 | 179 | ||
183 | memcpy(&msg[1], types, sizeof(uint16_t) * ntypes); | 180 | memcpy(&msg[1], types, sizeof(uint16_t) * ntypes); |
184 | memcpy(&msg[1] + sizeof(uint16_t) * ntypes, | 181 | memcpy(&msg[1] + sizeof(uint16_t) * ntypes, |
185 | apps, | 182 | apps, |
186 | sizeof(GNUNET_MESH_ApplicationType) * napps); | 183 | sizeof(GNUNET_MESH_ApplicationType) * napps); |
187 | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
188 | return msg->header.size; | 185 | "Sent %lu bytes long message %d types and %d apps\n", |
186 | ntohs(msg->header.size), | ||
187 | ntypes, | ||
188 | napps | ||
189 | ); | ||
190 | msg->applications = htons(napps); | ||
191 | msg->types = htons(ntypes); | ||
192 | |||
193 | return ntohs(msg->header.size); | ||
189 | } | 194 | } |
190 | 195 | ||
191 | 196 | ||