diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2016-10-26 15:56:48 +0000 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2016-10-26 15:56:48 +0000 |
commit | a4d4706ab21992e4ad58f8630b1ef49bd50816ce (patch) | |
tree | eec9d3d2fe189d88002e4c656711cfb55648aac3 /src | |
parent | 9f4e9817091fc93c5669df2f7cad8b361ac67b39 (diff) | |
download | gnunet-a4d4706ab21992e4ad58f8630b1ef49bd50816ce.tar.gz gnunet-a4d4706ab21992e4ad58f8630b1ef49bd50816ce.zip |
Don't mind me, I'm just going to put this function back together
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 117 |
1 files changed, 40 insertions, 77 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 956da15b5..eb13cb637 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -3238,9 +3238,7 @@ GCC_is_direct (struct CadetConnection *c) | |||
3238 | 3238 | ||
3239 | 3239 | ||
3240 | /** | 3240 | /** |
3241 | * Internal implementation of the send function. | 3241 | * Sends a completely built message on a connection, properly registering |
3242 | * | ||
3243 | * Sends an completely built message on a connection, properly registering | ||
3244 | * all used resources. | 3242 | * all used resources. |
3245 | * | 3243 | * |
3246 | * @param message Message to send. | 3244 | * @param message Message to send. |
@@ -3256,17 +3254,51 @@ GCC_is_direct (struct CadetConnection *c) | |||
3256 | * NULL on error or if @c cont is NULL. | 3254 | * NULL on error or if @c cont is NULL. |
3257 | * Invalid on @c cont call. | 3255 | * Invalid on @c cont call. |
3258 | */ | 3256 | */ |
3259 | static struct CadetConnectionQueue * | 3257 | struct CadetConnectionQueue * |
3260 | send_prebuilt_message (const struct GNUNET_MessageHeader *message, | 3258 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, |
3261 | uint16_t payload_type, uint32_t payload_id, | 3259 | uint16_t payload_type, uint32_t payload_id, |
3262 | struct CadetConnection *c, int fwd, int force, | 3260 | struct CadetConnection *c, int fwd, int force, |
3263 | GCC_sent cont, void *cont_cls) | 3261 | GCC_sent cont, void *cont_cls) |
3264 | { | 3262 | { |
3265 | struct CadetFlowControl *fc; | 3263 | struct CadetFlowControl *fc; |
3266 | struct CadetConnectionQueue *q; | 3264 | struct CadetConnectionQueue *q; |
3267 | uint16_t size; | 3265 | uint16_t size; |
3268 | uint16_t type; | 3266 | uint16_t type; |
3269 | 3267 | ||
3268 | size = ntohs (message->size); | ||
3269 | type = ntohs (message->type); | ||
3270 | |||
3271 | /* Allocate a copy of the message on the stack, so we can modify it as needed, | ||
3272 | * adding the Connection ID, PID, and other data the Tunnel layer doesn't | ||
3273 | * have access to. | ||
3274 | */ | ||
3275 | char cbuf[size]; | ||
3276 | struct GNUNET_MessageHeader *copy = (struct GNUNET_MessageHeader *)cbuf; | ||
3277 | |||
3278 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type | ||
3279 | || GNUNET_MESSAGE_TYPE_CADET_KX == type) | ||
3280 | { | ||
3281 | GNUNET_memcpy (copy, message, size); | ||
3282 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type) | ||
3283 | { | ||
3284 | struct GNUNET_CADET_AX *axmsg; | ||
3285 | |||
3286 | axmsg = (struct GNUNET_CADET_AX *) copy; | ||
3287 | axmsg->cid = c->id; | ||
3288 | axmsg->pid = htonl (GCC_get_pid (c, fwd)); | ||
3289 | } | ||
3290 | else /* case GNUNET_MESSAGE_TYPE_CADET_KX */ | ||
3291 | { | ||
3292 | struct GNUNET_CADET_KX *kmsg; | ||
3293 | |||
3294 | GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_KX == type); | ||
3295 | kmsg = (struct GNUNET_CADET_KX *) copy; | ||
3296 | kmsg->reserved = htonl (0); | ||
3297 | kmsg->cid = c->id; | ||
3298 | } | ||
3299 | message = copy; | ||
3300 | } | ||
3301 | |||
3270 | GCC_check_connections (); | 3302 | GCC_check_connections (); |
3271 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3303 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3272 | if (0 == fc->queue_max) | 3304 | if (0 == fc->queue_max) |
@@ -3353,75 +3385,6 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3353 | 3385 | ||
3354 | 3386 | ||
3355 | /** | 3387 | /** |
3356 | * Sends an already built message on a connection, properly registering | ||
3357 | * all used resources. | ||
3358 | * | ||
3359 | * @param message Message to send. | ||
3360 | * @param payload_type Type of payload, in case the message is encrypted. | ||
3361 | * @param payload_id ID of the payload (PID, ACK, ...). | ||
3362 | * @param c Connection on which this message is transmitted. | ||
3363 | * @param fwd Is this a fwd message? | ||
3364 | * @param force Force the connection to accept the message (buffer overfill). | ||
3365 | * @param cont Continuation called once message is sent. Can be NULL. | ||
3366 | * @param cont_cls Closure for @c cont. | ||
3367 | * | ||
3368 | * @return Handle to cancel the message before it's sent. | ||
3369 | * NULL on error or if @c cont is NULL. | ||
3370 | * Invalid on @c cont call. | ||
3371 | */ | ||
3372 | struct CadetConnectionQueue * | ||
3373 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | ||
3374 | uint16_t payload_type, uint32_t payload_id, | ||
3375 | struct CadetConnection *c, int fwd, int force, | ||
3376 | GCC_sent cont, void *cont_cls) | ||
3377 | { | ||
3378 | uint16_t size; | ||
3379 | uint16_t type; | ||
3380 | |||
3381 | size = ntohs (message->size); | ||
3382 | type = ntohs (message->type); | ||
3383 | |||
3384 | /* Allocate a copy of the message on the stack, so we can modify it as needed, | ||
3385 | * adding the Connection ID, PID, and other data the Tunnel layer doesn't | ||
3386 | * have access to. | ||
3387 | */ | ||
3388 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type | ||
3389 | || GNUNET_MESSAGE_TYPE_CADET_KX == type) | ||
3390 | { | ||
3391 | struct GNUNET_MessageHeader *copy; | ||
3392 | unsigned char cbuf[size]; | ||
3393 | |||
3394 | copy = (struct GNUNET_MessageHeader *) cbuf; | ||
3395 | GNUNET_memcpy (copy, message, size); | ||
3396 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type) | ||
3397 | { | ||
3398 | struct GNUNET_CADET_AX *axmsg; | ||
3399 | |||
3400 | axmsg = (struct GNUNET_CADET_AX *) copy; | ||
3401 | axmsg->cid = c->id; | ||
3402 | axmsg->pid = htonl (GCC_get_pid (c, fwd)); | ||
3403 | } | ||
3404 | else /* case GNUNET_MESSAGE_TYPE_CADET_KX */ | ||
3405 | { | ||
3406 | struct GNUNET_CADET_KX *kmsg; | ||
3407 | |||
3408 | GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_KX == type); | ||
3409 | kmsg = (struct GNUNET_CADET_KX *) copy; | ||
3410 | kmsg->reserved = htonl (0); | ||
3411 | kmsg->cid = c->id; | ||
3412 | } | ||
3413 | return send_prebuilt_message (copy, payload_type, payload_id, | ||
3414 | c, fwd, force, | ||
3415 | cont, cont_cls); | ||
3416 | } | ||
3417 | return send_prebuilt_message (message, payload_type, payload_id, | ||
3418 | c, fwd, force, | ||
3419 | cont, cont_cls); | ||
3420 | |||
3421 | } | ||
3422 | |||
3423 | |||
3424 | /** | ||
3425 | * Cancel a previously sent message while it's in the queue. | 3388 | * Cancel a previously sent message while it's in the queue. |
3426 | * | 3389 | * |
3427 | * ONLY can be called before the continuation given to the send function | 3390 | * ONLY can be called before the continuation given to the send function |