aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-06-22 08:16:13 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-06-22 08:16:13 +0000
commit2f026740efd324bac70d4ba7281a303918fbc64f (patch)
treeb9064827d2db6ba289d594bde7d0b07028064380
parentb3728eecdc7cd36723980109eb4815fe4a397ad0 (diff)
downloadgnunet-2f026740efd324bac70d4ba7281a303918fbc64f.tar.gz
gnunet-2f026740efd324bac70d4ba7281a303918fbc64f.zip
Added MessageTokenizer functionality
-rw-r--r--src/transport/plugin_transport_http.c94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 455a92814..ad1c2b863 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -423,7 +423,6 @@ static void messageTokenizerCallback (void *cls,
423 struct Session * cs; 423 struct Session * cs;
424 GNUNET_assert(cls != NULL); 424 GNUNET_assert(cls != NULL);
425 cs = (struct Session *) cls; 425 cs = (struct Session *) cls;
426
427 plugin->env->receive(plugin->env->cls, &(cs->sender), message, 1, NULL , cs->addr_inbound_str, strlen(cs->addr_inbound_str)); 426 plugin->env->receive(plugin->env->cls, &(cs->sender), message, 1, NULL , cs->addr_inbound_str, strlen(cs->addr_inbound_str));
428} 427}
429 428
@@ -506,22 +505,9 @@ accessHandlerCallback (void *cls,
506 cs = plugin->sessions; 505 cs = plugin->sessions;
507 while ( NULL != cs) 506 while ( NULL != cs)
508 { 507 {
509
510 /* Comparison based on ip address */
511 // res = (0 == memcmp(&(conn_info->client_addr->sin_addr),&(cs->addr->sin_addr), sizeof (struct in_addr))) ? GNUNET_YES : GNUNET_NO;
512
513 /* Comparison based on ip address, port number and address family */
514 // res = (0 == memcmp((conn_info->client_addr),(cs->addr), sizeof (struct sockaddr_in))) ? GNUNET_YES : GNUNET_NO;
515
516 /* Comparison based on PeerIdentity */
517 res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO; 508 res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO;
518
519 if ( GNUNET_YES == res) 509 if ( GNUNET_YES == res)
520 {
521 /* existing session for this address found */
522 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Session for peer `%s' found\n",GNUNET_i2s(&cs->sender));*/
523 break; 510 break;
524 }
525 cs = cs->next; 511 cs = cs->next;
526 } 512 }
527 } 513 }
@@ -636,91 +622,13 @@ accessHandlerCallback (void *cls,
636 { 622 {
637 send_error_to_client = GNUNET_YES; 623 send_error_to_client = GNUNET_YES;
638 cur_msg = NULL; 624 cur_msg = NULL;
639 /* split and check messages and forward here */
640 /* checking size */
641
642 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader)) 625 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader))
643 { 626 {
644 cur_msg = (struct GNUNET_MessageHeader *) cs->pending_inbound_msg->buf; 627 cur_msg = (struct GNUNET_MessageHeader *) cs->pending_inbound_msg->buf;
645 //unsigned int len = ntohs (cur_msg->size);
646
647 res = GNUNET_SERVER_mst_receive(cs->msgtok,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos, GNUNET_NO, GNUNET_NO); 628 res = GNUNET_SERVER_mst_receive(cs->msgtok,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos, GNUNET_NO, GNUNET_NO);
648 if ((res != GNUNET_SYSERR) && (res != GNUNET_NO)) 629 if ((res != GNUNET_SYSERR) && (res != GNUNET_NO))
649 send_error_to_client = GNUNET_NO; 630 send_error_to_client = GNUNET_NO;
650#if 0
651 if (len == cs->pending_inbound_msg->pos)
652 {
653 if ( AF_INET == cs->addr_inbound->sin_family)
654 {
655 inet_ntop(AF_INET, &(cs->addr_inbound)->sin_addr,address,INET_ADDRSTRLEN);
656 GNUNET_asprintf(&tmp,"%s:%u",address,ntohs(cs->addr_inbound->sin_port));
657 }
658
659 if ( AF_INET6 == cs->addr_inbound->sin_family)
660 {
661 inet_ntop(AF_INET6, &((struct sockaddr_in6 *) cs->addr_inbound)->sin6_addr,address,INET6_ADDRSTRLEN);
662 GNUNET_asprintf(&tmp,"[%s]:%u",address,ntohs(cs->addr_inbound->sin_port));
663
664 }
665 plugin->env->receive(plugin->env->cls, &(cs->sender), cur_msg, 1, NULL , tmp, strlen(tmp));
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Forwarded 1 message with %u bytes of data to transport service\n", cs->pending_inbound_msg->pos);
667 GNUNET_free(tmp);
668 send_error_to_client = GNUNET_NO;
669 }
670 if (len < cs->pending_inbound_msg->pos)
671 {
672 /* more than one message in recieved data, have to split up*/
673 char * tmp = NULL;
674 unsigned int bytes_proc = 0;
675 unsigned int c_msgs = 0;
676 unsigned int len;
677 /* one message in recieved data, can pass directly*/
678 if ( AF_INET == cs->addr_inbound->sin_family)
679 {
680 inet_ntop(AF_INET, &(cs->addr_inbound)->sin_addr,address,INET_ADDRSTRLEN);
681 GNUNET_asprintf(&tmp,"%s:%u",address,ntohs(cs->addr_inbound->sin_port));
682 }
683
684 if ( AF_INET6 == cs->addr_inbound->sin_family)
685 {
686 inet_ntop(AF_INET6, &((struct sockaddr_in6 *) cs->addr_inbound)->sin6_addr,address,INET6_ADDRSTRLEN);
687 GNUNET_asprintf(&tmp,"[%s]:%u",address,ntohs(cs->addr_inbound->sin_port));
688
689 }
690 send_error_to_client = GNUNET_NO;
691 while (bytes_proc < cs->pending_inbound_msg->pos)
692 {
693 cur_msg = (struct GNUNET_MessageHeader *) &cs->pending_inbound_msg->buf[bytes_proc];
694 len = ntohs (cur_msg->size);
695 if ((bytes_proc+len) <=cs->pending_inbound_msg->pos)
696 {
697 plugin->env->receive(plugin->env->cls, &(cs->sender), cur_msg, 1, NULL , tmp, strlen(tmp));
698 bytes_proc += ntohs(cur_msg->size);
699 c_msgs++;
700 }
701 else
702 {
703 send_error_to_client = GNUNET_YES;
704 break;
705 }
706 }
707
708 if (send_error_to_client == GNUNET_NO)
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Forwarded %u messages with %u bytes of data to transport service\n",
710 c_msgs, bytes_proc);
711 else
712 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Forwarded %u messages with %u bytes, last msg was inconsistent, %u bytes left\n",
713 c_msgs, bytes_proc,cs->pending_inbound_msg->pos-bytes_proc);
714 GNUNET_free(tmp);
715 }
716 if (len > cs->pending_inbound_msg->pos)
717 {
718 /* message size bigger than data recieved -> malformed */
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved malformed message: size in header %u bytes, recieved: %u \n", len, cs->pending_inbound_msg->pos);
720 }
721#endif
722 } 631 }
723
724 if (send_error_to_client == GNUNET_NO) 632 if (send_error_to_client == GNUNET_NO)
725 { 633 {
726 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); 634 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
@@ -735,8 +643,6 @@ accessHandlerCallback (void *cls,
735 MHD_destroy_response (response); 643 MHD_destroy_response (response);
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n"); 644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n");
737 } 645 }
738
739 //GNUNET_free_non_null (cur_msg);
740 cs->is_put_in_progress = GNUNET_NO; 646 cs->is_put_in_progress = GNUNET_NO;
741 cs->is_bad_request = GNUNET_NO; 647 cs->is_bad_request = GNUNET_NO;
742 cs->pending_inbound_msg->pos = 0; 648 cs->pending_inbound_msg->pos = 0;