aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/mesh_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/mesh_api.c')
-rw-r--r--src/mesh/mesh_api.c122
1 files changed, 70 insertions, 52 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 926feb8af..f27e86b71 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -1034,28 +1034,34 @@ static void
1034process_get_tunnels (struct GNUNET_MESH_Handle *h, 1034process_get_tunnels (struct GNUNET_MESH_Handle *h,
1035 const struct GNUNET_MessageHeader *message) 1035 const struct GNUNET_MessageHeader *message)
1036{ 1036{
1037 struct GNUNET_PeerIdentity *id; 1037 struct GNUNET_MESH_LocalInfoTunnel *msg;
1038 uint16_t size; 1038 uint16_t size;
1039 unsigned int i;
1040 1039
1041 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n");
1042 1041
1043 if (NULL == h->tunnels_cb) 1042 if (NULL == h->tunnels_cb)
1044 { 1043 {
1045 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); 1044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
1046 return; 1045 return;
1047 } 1046 }
1048 1047
1049 size = ntohs (message->size); 1048 size = ntohs (message->size);
1050 size /= sizeof (struct GNUNET_PeerIdentity); 1049 if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size)
1051 id = (struct GNUNET_PeerIdentity *) &message[1]; 1050 {
1051 h->tunnels_cb (h->tunnel_cls, NULL, 0, 0, 0, 0);
1052 h->tunnels_cb = NULL;
1053 h->tunnels_cls = NULL;
1054 return;
1055 }
1052 1056
1053 for (i = 0; i < size; i++) 1057 msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
1054 h->tunnels_cb (h->tunnels_cls, &id[i]); 1058 h->tunnels_cb (h->tunnel_cls,
1055 h->tunnels_cb (h->tunnels_cls, NULL); 1059 &msg->destination,
1060 ntohl (msg->channels),
1061 ntohl (msg->connections),
1062 ntohl (msg->estate),
1063 ntohl (msg->cstate));
1056 1064
1057 h->tunnels_cb = NULL;
1058 h->tunnels_cls = NULL;
1059} 1065}
1060 1066
1061 1067
@@ -1066,43 +1072,48 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
1066 * @param h Mesh handle. 1072 * @param h Mesh handle.
1067 * @param message Message itself. 1073 * @param message Message itself.
1068 */ 1074 */
1069// static void 1075static void
1070// process_show_channel (struct GNUNET_MESH_Handle *h, 1076process_get_tunnel (struct GNUNET_MESH_Handle *h,
1071// const struct GNUNET_MessageHeader *message) 1077 const struct GNUNET_MessageHeader *message)
1072// { 1078{
1073// struct GNUNET_MESH_LocalInfo *msg; 1079 struct GNUNET_MESH_LocalInfoTunnel *msg;
1074// size_t esize; 1080 size_t esize;
1075// 1081
1076// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); 1082 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnel messasge received\n");
1077// 1083
1078// if (NULL == h->channel_cb) 1084 if (NULL == h->tunnel_cb)
1079// { 1085 {
1080// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); 1086 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
1081// return; 1087 return;
1082// } 1088 }
1083// 1089
1084// /* Verify message sanity */ 1090 /* Verify message sanity */
1085// msg = (struct GNUNET_MESH_LocalInfo *) message; 1091 msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
1086// esize = sizeof (struct GNUNET_MESH_LocalInfo); 1092 esize = sizeof (struct GNUNET_MESH_LocalInfo);
1087// if (ntohs (message->size) != esize) 1093 if (ntohs (message->size) != esize)
1088// { 1094 {
1089// GNUNET_break_op (0); 1095 GNUNET_break_op (0);
1090// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1091// "Show channel message: size %hu - expected %u\n", 1097 "Get Tunnel message: size %hu - expected %u\n",
1092// ntohs (message->size), 1098 ntohs (message->size),
1093// esize); 1099 esize);
1094// 1100
1095// h->channel_cb (h->channel_cls, NULL, NULL); 1101 h->tunnel_cb (h->tunnel_cls, NULL, 0, 0, 0, 0);
1096// h->channel_cb = NULL; 1102 h->tunnel_cb = NULL;
1097// h->channel_cls = NULL; 1103 h->tunnel_cls = NULL;
1098// 1104
1099// return; 1105 return;
1100// } 1106 }
1101// 1107
1102// h->channel_cb (h->channel_cls, 1108 h->tunnel_cb (h->tunnel_cls,
1103// &msg->destination, 1109 &msg->destination,
1104// &msg->owner); 1110 ntohl (msg->channels),
1105// } 1111 ntohl (msg->connections),
1112 ntohl (msg->estate),
1113 ntohl (msg->cstate));
1114 h->tunnel_cb = NULL;
1115 h->tunnel_cls = NULL;
1116}
1106 1117
1107/** 1118/**
1108 * Function to process all messages received from the service 1119 * Function to process all messages received from the service
@@ -1153,6 +1164,9 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1153 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: 1164 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
1154 process_get_tunnels (h, msg); 1165 process_get_tunnels (h, msg);
1155 break; 1166 break;
1167 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
1168 process_get_tunnel (h, msg);
1169 break;
1156// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: 1170// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
1157// process_show_channel (h, msg); 1171// process_show_channel (h, msg);
1158// break; 1172// break;
@@ -1161,7 +1175,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1161 LOG (GNUNET_ERROR_TYPE_WARNING, 1175 LOG (GNUNET_ERROR_TYPE_WARNING,
1162 "unsolicited message form service (type %s)\n", 1176 "unsolicited message form service (type %s)\n",
1163 GM_m2s (ntohs (msg->type))); 1177 GM_m2s (ntohs (msg->type)));
1164 } 1178 } FPRINTF (stdout, "\n");
1165 LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n"); 1179 LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
1166 if (GNUNET_YES == h->in_receive) 1180 if (GNUNET_YES == h->in_receive)
1167 { 1181 {
@@ -1435,6 +1449,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1435 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: 1449 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
1436 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: 1450 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
1437 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: 1451 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
1452 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
1453 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
1438 break; 1454 break;
1439 default: 1455 default:
1440 GNUNET_break (0); 1456 GNUNET_break (0);
@@ -1756,7 +1772,7 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
1756 h->tunnels_cb = NULL; 1772 h->tunnels_cb = NULL;
1757 cls = h->tunnels_cls; 1773 cls = h->tunnels_cls;
1758 h->tunnels_cls = NULL; 1774 h->tunnels_cls = NULL;
1759 1775
1760 return cls; 1776 return cls;
1761} 1777}
1762 1778
@@ -1780,7 +1796,7 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
1780void 1796void
1781GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, 1797GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
1782 const struct GNUNET_PeerIdentity *id, 1798 const struct GNUNET_PeerIdentity *id,
1783 GNUNET_MESH_TunnelsCB callback, 1799 GNUNET_MESH_TunnelCB callback,
1784 void *callback_cls) 1800 void *callback_cls)
1785{ 1801{
1786 struct GNUNET_MESH_LocalInfo msg; 1802 struct GNUNET_MESH_LocalInfo msg;
@@ -1790,6 +1806,8 @@ GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
1790 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); 1806 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
1791 msg.destination = *id; 1807 msg.destination = *id;
1792 send_packet (h, &msg.header, NULL); 1808 send_packet (h, &msg.header, NULL);
1809 h->tunnel_cb = callback;
1810 h->tunnel_cls = callback_cls;
1793} 1811}
1794 1812
1795 1813
@@ -1818,7 +1836,7 @@ GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
1818 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); 1836 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
1819 msg.owner = *initiator; 1837 msg.owner = *initiator;
1820 msg.channel_id = htonl (channel_number); 1838 msg.channel_id = htonl (channel_number);
1821 msg.reserved = 0; 1839// msg.reserved = 0;
1822 send_packet (h, &msg.header, NULL); 1840 send_packet (h, &msg.header, NULL);
1823 h->channel_cb = callback; 1841 h->channel_cb = callback;
1824 h->channel_cls = callback_cls; 1842 h->channel_cls = callback_cls;