aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-25 21:32:36 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-25 21:32:36 +0100
commit612b5ec8e3a3f1388631e9c637aef085e3767777 (patch)
treec5d4219387619fcc392b31247051813b71731621 /src/transport
parent27270fd74bb5e0a7c55e9667b335fa0d8497bc51 (diff)
downloadgnunet-612b5ec8e3a3f1388631e9c637aef085e3767777.tar.gz
gnunet-612b5ec8e3a3f1388631e9c637aef085e3767777.zip
basics of handling of msgs from communicator
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-tng.c98
1 files changed, 91 insertions, 7 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 3cccf5173..9f0e7845c 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -459,8 +459,7 @@ struct TransportDVLearn
459 459
460 /* Followed by @e num_hops `struct GNUNET_PeerIdentity` values, 460 /* Followed by @e num_hops `struct GNUNET_PeerIdentity` values,
461 excluding the initiator of the DV trace; the last entry is the 461 excluding the initiator of the DV trace; the last entry is the
462 current sender; the current peer must not be included except if 462 current sender; the current peer must not be included. */
463 it is the sender. */
464 463
465}; 464};
466 465
@@ -2258,7 +2257,20 @@ struct CommunicatorMessageContext
2258static void 2257static void
2259finish_cmc_handling (struct CommunicatorMessageContext *cmc) 2258finish_cmc_handling (struct CommunicatorMessageContext *cmc)
2260{ 2259{
2261 // FIXME: if (0 != ntohl (im->fc_on)) => send ACK when done to communicator for flow control! 2260 if (0 != ntohl (cmc->im.fc_on))
2261 {
2262 /* send ACK when done to communicator for flow control! */
2263 struct GNUNET_MQ_Envelope *env;
2264 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
2265
2266 env = GNUNET_MQ_msg (ack,
2267 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
2268 ack->reserved = htonl (0);
2269 ack->fc_id = cmc->im.fc_id;
2270 ack->sender = cmc->im.sender;
2271 GNUNET_MQ_send (cmc->tc->mq,
2272 env);
2273 }
2262 GNUNET_SERVICE_client_continue (cmc->tc->client); 2274 GNUNET_SERVICE_client_continue (cmc->tc->client);
2263 2275
2264 GNUNET_free (cmc); 2276 GNUNET_free (cmc);
@@ -2294,7 +2306,24 @@ static int
2294check_fragment_box (void *cls, 2306check_fragment_box (void *cls,
2295 const struct TransportFragmentBox *fb) 2307 const struct TransportFragmentBox *fb)
2296{ 2308{
2297 // FIXME! check that off + size-of-payload <= total-length! 2309 uint16_t size = ntohs (fb->header.size);
2310 uint16_t bsize = size - sizeof (*fb);
2311
2312 if (0 == bsize)
2313 {
2314 GNUNET_break_op (0);
2315 return GNUNET_SYSERR;
2316 }
2317 if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size))
2318 {
2319 GNUNET_break_op (0);
2320 return GNUNET_SYSERR;
2321 }
2322 if (ntohs (fb->frag_off) >= ntohs (fb->msg_size))
2323 {
2324 GNUNET_break_op (0);
2325 return GNUNET_SYSERR;
2326 }
2298 return GNUNET_YES; 2327 return GNUNET_YES;
2299} 2328}
2300 2329
@@ -2394,7 +2423,13 @@ static int
2394check_backchannel_encapsulation (void *cls, 2423check_backchannel_encapsulation (void *cls,
2395 const struct TransportBackchannelEncapsulationMessage *be) 2424 const struct TransportBackchannelEncapsulationMessage *be)
2396{ 2425{
2397 // FIXME: do work! 2426 uint16_t size = ntohs (be->header.size);
2427
2428 if (size - sizeof (*be) < sizeof (struct GNUNET_MessageHeader))
2429 {
2430 GNUNET_break_op (0);
2431 return GNUNET_SYSERR;
2432 }
2398 return GNUNET_YES; 2433 return GNUNET_YES;
2399} 2434}
2400 2435
@@ -2444,7 +2479,32 @@ static int
2444check_dv_learn (void *cls, 2479check_dv_learn (void *cls,
2445 const struct TransportDVLearn *dvl) 2480 const struct TransportDVLearn *dvl)
2446{ 2481{
2447 // FIXME: do work! 2482 uint16_t size = ntohs (dvl->header.size);
2483 uint16_t num_hops = ntohs (dvl->num_hops);
2484 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvl[1];
2485
2486 if (size != sizeof (*dvl) + num_hops * sizeof (struct GNUNET_PeerIdentity))
2487 {
2488 GNUNET_break_op (0);
2489 return GNUNET_SYSERR;
2490 }
2491 for (unsigned int i=0;i<num_hops;i++)
2492 {
2493 if (0 == memcmp (&dvl->initiator,
2494 &hops[i],
2495 sizeof (struct GNUNET_PeerIdentity)))
2496 {
2497 GNUNET_break_op (0);
2498 return GNUNET_SYSERR;
2499 }
2500 if (0 == memcmp (&GST_my_identity,
2501 &hops[i],
2502 sizeof (struct GNUNET_PeerIdentity)))
2503 {
2504 GNUNET_break_op (0);
2505 return GNUNET_SYSERR;
2506 }
2507 }
2448 return GNUNET_YES; 2508 return GNUNET_YES;
2449} 2509}
2450 2510
@@ -2477,7 +2537,31 @@ static int
2477check_dv_box (void *cls, 2537check_dv_box (void *cls,
2478 const struct TransportDVBox *dvb) 2538 const struct TransportDVBox *dvb)
2479{ 2539{
2480 // FIXME: do work! 2540 uint16_t size = ntohs (dvb->header.size);
2541 uint16_t num_hops = ntohs (dvb->num_hops);
2542 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1];
2543 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops];
2544 uint16_t isize;
2545 uint16_t itype;
2546
2547 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct GNUNET_MessageHeader))
2548 {
2549 GNUNET_break_op (0);
2550 return GNUNET_SYSERR;
2551 }
2552 isize = ntohs (inbox->size);
2553 if (size != sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize)
2554 {
2555 GNUNET_break_op (0);
2556 return GNUNET_SYSERR;
2557 }
2558 itype = ntohs (inbox->type);
2559 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) ||
2560 (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype) )
2561 {
2562 GNUNET_break_op (0);
2563 return GNUNET_SYSERR;
2564 }
2481 return GNUNET_YES; 2565 return GNUNET_YES;
2482} 2566}
2483 2567