diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-06-24 03:31:39 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-06-24 03:31:39 +0000 |
commit | cb7305d0f07f5a351ba4c4cb8e4c42c55d3914cb (patch) | |
tree | 8e5dc433fadfce173e19a928640aa657a4a815fd | |
parent | 62920ed494f6bfaf0879a3f637026291ee5d7fb1 (diff) | |
download | gnunet-cb7305d0f07f5a351ba4c4cb8e4c42c55d3914cb.tar.gz gnunet-cb7305d0f07f5a351ba4c4cb8e4c42c55d3914cb.zip |
- more info API
-rw-r--r-- | src/cadet/cadet_api.c | 32 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_local.c | 72 |
2 files changed, 81 insertions, 23 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 12d1ba2da..c65475b10 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -1078,13 +1078,9 @@ process_get_peer (struct GNUNET_CADET_Handle *h, | |||
1078 | struct GNUNET_CADET_LocalInfoTunnel *msg; | 1078 | struct GNUNET_CADET_LocalInfoTunnel *msg; |
1079 | size_t esize; | 1079 | size_t esize; |
1080 | size_t msize; | 1080 | size_t msize; |
1081 | unsigned int ch_n; | ||
1082 | unsigned int c_n; | ||
1083 | struct GNUNET_CADET_Hash *conns; | ||
1084 | CADET_ChannelNumber *chns; | ||
1085 | 1081 | ||
1086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n"); | 1082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n"); |
1087 | if (NULL == h->info_cb.tunnel_cb) | 1083 | if (NULL == h->info_cb.peer_cb) |
1088 | { | 1084 | { |
1089 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); | 1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n"); |
1090 | return; | 1086 | return; |
@@ -1093,38 +1089,28 @@ process_get_peer (struct GNUNET_CADET_Handle *h, | |||
1093 | /* Verify message sanity */ | 1089 | /* Verify message sanity */ |
1094 | msg = (struct GNUNET_CADET_LocalInfoTunnel *) message; | 1090 | msg = (struct GNUNET_CADET_LocalInfoTunnel *) message; |
1095 | msize = ntohs (message->size); | 1091 | msize = ntohs (message->size); |
1096 | esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); | 1092 | esize = sizeof (struct GNUNET_CADET_LocalInfoPeer); |
1097 | if (esize > msize) | 1093 | if (esize > msize) |
1098 | { | 1094 | { |
1099 | GNUNET_break_op (0); | 1095 | GNUNET_break_op (0); |
1100 | h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); | 1096 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); |
1101 | goto clean_cls; | 1097 | goto clean_cls; |
1102 | } | 1098 | } |
1103 | ch_n = ntohl (msg->channels); | 1099 | // esize += ch_n * sizeof (CADET_ChannelNumber); |
1104 | c_n = ntohl (msg->connections); | 1100 | // esize += c_n * sizeof (struct GNUNET_CADET_Hash); |
1105 | esize += ch_n * sizeof (CADET_ChannelNumber); | ||
1106 | esize += c_n * sizeof (struct GNUNET_CADET_Hash); | ||
1107 | if (msize != esize) | 1101 | if (msize != esize) |
1108 | { | 1102 | { |
1109 | GNUNET_break_op (0); | 1103 | GNUNET_break_op (0); |
1110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "m:%u, e: %u (%u ch, %u conn)\n", | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "m:%u, e: %u\n", msize, esize); |
1111 | msize, esize, ch_n, c_n); | 1105 | h->info_cb.peer_cb (h->info_cls, NULL, 0, 0, 0, NULL); |
1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n", | ||
1113 | sizeof (struct GNUNET_CADET_LocalInfoTunnel), | ||
1114 | sizeof (CADET_ChannelNumber), sizeof (struct GNUNET_HashCode)); | ||
1115 | h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); | ||
1116 | goto clean_cls; | 1106 | goto clean_cls; |
1117 | } | 1107 | } |
1118 | 1108 | ||
1119 | /* Call Callback with tunnel info. */ | 1109 | /* Call Callback with tunnel info. */ |
1120 | conns = (struct GNUNET_CADET_Hash *) &msg[1]; | 1110 | h->info_cb.peer_cb (h->info_cls, &msg->destination, 0, 0, 0, NULL); |
1121 | chns = (CADET_ChannelNumber *) &conns[c_n]; | ||
1122 | h->info_cb.tunnel_cb (h->info_cls, &msg->destination, | ||
1123 | ch_n, c_n, chns, conns, | ||
1124 | ntohs (msg->estate), ntohs (msg->cstate)); | ||
1125 | 1111 | ||
1126 | clean_cls: | 1112 | clean_cls: |
1127 | h->info_cb.tunnel_cb = NULL; | 1113 | h->info_cb.peer_cb = NULL; |
1128 | h->info_cls = NULL; | 1114 | h->info_cls = NULL; |
1129 | } | 1115 | } |
1130 | 1116 | ||
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c index b1c9a8bab..b612be6dd 100644 --- a/src/cadet/gnunet-service-cadet_local.c +++ b/src/cadet/gnunet-service-cadet_local.c | |||
@@ -680,6 +680,76 @@ handle_get_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
680 | 680 | ||
681 | 681 | ||
682 | /** | 682 | /** |
683 | * Handler for client's SHOW_PEER request. | ||
684 | * | ||
685 | * @param cls Closure (unused). | ||
686 | * @param client Identification of the client. | ||
687 | * @param message The actual message. | ||
688 | */ | ||
689 | void | ||
690 | handle_show_peer (void *cls, struct GNUNET_SERVER_Client *client, | ||
691 | const struct GNUNET_MessageHeader *message) | ||
692 | { | ||
693 | const struct GNUNET_CADET_LocalInfo *msg; | ||
694 | struct GNUNET_CADET_LocalInfoPeer *resp; | ||
695 | struct CadetPeer *p; | ||
696 | struct CadetClient *c; | ||
697 | size_t size; | ||
698 | |||
699 | /* Sanity check for client registration */ | ||
700 | if (NULL == (c = GML_client_get (client))) | ||
701 | { | ||
702 | GNUNET_break (0); | ||
703 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
704 | return; | ||
705 | } | ||
706 | |||
707 | msg = (struct GNUNET_CADET_LocalInfo *) message; | ||
708 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
709 | "Received peer info request from client %u for peer %s\n", | ||
710 | c->id, GNUNET_i2s_full (&msg->peer)); | ||
711 | |||
712 | p = GCP_get (&msg->peer); | ||
713 | if (NULL == p) | ||
714 | { | ||
715 | /* We don't know the peer */ | ||
716 | struct GNUNET_CADET_LocalInfoPeer warn; | ||
717 | |||
718 | LOG (GNUNET_ERROR_TYPE_INFO, "Peer %s unknown %u\n", | ||
719 | GNUNET_i2s_full (&msg->peer), sizeof (warn)); | ||
720 | warn.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | ||
721 | warn.header.size = htons (sizeof (warn)); | ||
722 | warn.destination = msg->peer; | ||
723 | warn.paths = htons (0); | ||
724 | warn.tunnel = htons (NULL != GCP_get_tunnel (p)); | ||
725 | |||
726 | GNUNET_SERVER_notification_context_unicast (nc, client, | ||
727 | &warn.header, | ||
728 | GNUNET_NO); | ||
729 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
730 | return; | ||
731 | } | ||
732 | |||
733 | size = sizeof (struct GNUNET_CADET_LocalInfoPeer); | ||
734 | // size += c_n * sizeof (struct GNUNET_CADET_Hash); | ||
735 | |||
736 | resp = GNUNET_malloc (size); | ||
737 | resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER); | ||
738 | resp->header.size = htons (size); | ||
739 | resp->destination = msg->peer; | ||
740 | resp->paths = htons (0); | ||
741 | resp->tunnel = htons (0); | ||
742 | |||
743 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | ||
744 | &resp->header, GNUNET_NO); | ||
745 | GNUNET_free (resp); | ||
746 | |||
747 | LOG (GNUNET_ERROR_TYPE_INFO, "Show peer request from client %u completed.\n"); | ||
748 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
749 | } | ||
750 | |||
751 | |||
752 | /** | ||
683 | * Iterator over all tunnels to send a monitoring client info about each tunnel. | 753 | * Iterator over all tunnels to send a monitoring client info about each tunnel. |
684 | * | 754 | * |
685 | * @param cls Closure (). | 755 | * @param cls Closure (). |
@@ -908,6 +978,8 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | |||
908 | sizeof (struct GNUNET_CADET_LocalAck)}, | 978 | sizeof (struct GNUNET_CADET_LocalAck)}, |
909 | {&handle_get_peers, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 979 | {&handle_get_peers, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, |
910 | sizeof (struct GNUNET_MessageHeader)}, | 980 | sizeof (struct GNUNET_MessageHeader)}, |
981 | {&handle_show_peer, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, | ||
982 | sizeof (struct GNUNET_CADET_LocalInfo)}, | ||
911 | {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | 983 | {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, |
912 | sizeof (struct GNUNET_MessageHeader)}, | 984 | sizeof (struct GNUNET_MessageHeader)}, |
913 | {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, | 985 | {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, |