issuer
[oweals/gnunet.git] / src / experimentation / gnunet-daemon-experimentation_capabilities.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file experimentation/gnunet-daemon-experimentation_capabilities.c
23  * @brief experimentation daemon: capabilities management
24  * @author Christian Grothoff
25  * @author Matthias Wachs
26  */
27 #include "platform.h"
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet-daemon-experimentation.h"
33
34 uint32_t GSE_node_capabilities;
35
36
37 #define GNUNET_EXPERIMENTATION_capabilities_count 11;
38
39 /**
40  * Capabilities a node has or an experiment requires string
41  */
42 #define GNUNET_EXPERIMENTATION_capabilities_string {"NONE", "PLUGIN_TCP", "PLUGIN_UDP", "PLUGIN_UNIX", "PLUGIN_HTTP_CLIENT", "PLUGIN_HTTP_SERVER", "PLUGIN_HTTPS_CLIENT", "PLUGIN_HTTPS_SERVER", "PLUGIN_WLAN", "HAVE_IPV6", "BEHIND_NAT"}
43
44 const char *
45 GNUNET_EXPERIMENTATION_capability_to_str (uint32_t cap)
46 {
47         char * capstr[] = GNUNET_EXPERIMENTATION_capabilities_string;
48         unsigned index = 0;
49         uint32_t test = 0;
50
51         if (0 == cap)
52                 return capstr[0];
53
54         index = (log(cap) / log (2)) + 1;
55
56         test = 1 << (index - 1);
57         if (test != cap)
58                 return "UNDEFINED";
59
60         if (index <= 11)
61                 return capstr[index];
62         else
63          return "UNDEFINED";
64
65
66 }
67
68 /**
69  * Are the capabilities provided?
70  *
71  * @param have bitstring containing the provided capabilities
72  * @param have bitstring containing the desired capabilities
73  */
74 int
75 GNUNET_EXPERIMENTATION_capabilities_have (uint32_t have, uint32_t desired)
76 {
77         if (desired == (desired & have))
78                 return GNUNET_YES;
79         else
80                 return GNUNET_NO;
81 }
82
83
84 /**
85  * Start the detecting capabilities
86  *
87  * @param cfg configuration handle
88  */
89 void
90 GNUNET_EXPERIMENTATION_capabilities_start ()
91 {
92         char *plugins;
93   char *pos;
94   unsigned int c1;
95   uint32_t index;
96   GSE_node_capabilities = NONE;
97
98         /* Plugins configured */
99
100   if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (GSE_cfg,
101                         "TRANSPORT", "PLUGINS", &plugins))
102   {
103           for (pos = strtok (plugins, " "); pos != NULL; pos = strtok (NULL, " "))
104           {
105               if (0 == strcmp (pos, "tcp"))
106                 GSE_node_capabilities |= PLUGIN_TCP;
107               else if (0 == strcmp (pos, "udp"))
108                 GSE_node_capabilities |= PLUGIN_UDP;
109                                         else if (0 == strcmp (pos, "unix"))
110                                                 GSE_node_capabilities |= PLUGIN_UNIX;
111                                         else if (0 == strcmp (pos, "http_client"))
112                                                 GSE_node_capabilities |= PLUGIN_HTTP_CLIENT;
113                                         else if (0 == strcmp (pos, "http_server"))
114                                                 GSE_node_capabilities |= PLUGIN_HTTP_SERVER;
115                                         else if (0 == strcmp (pos, "https_client"))
116                                                 GSE_node_capabilities |= PLUGIN_HTTP_CLIENT;
117                                         else if (0 == strcmp (pos, "https_server"))
118                                                 GSE_node_capabilities |= PLUGIN_HTTPS_SERVER;
119                                         else if (0 == strcmp (pos, "wlan"))
120                                                 GSE_node_capabilities |= PLUGIN_WLAN;
121           }
122           GNUNET_free (plugins);
123   }
124
125         /* IPv6 enabled
126          * FIXE: just having it not enabled is not really sufficient */
127   if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (GSE_cfg,
128                         "NAT", "DISABLEV6"))
129         GSE_node_capabilities |= HAVE_IPV6;
130
131   /* Behind NAT */
132   if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (GSE_cfg,
133                         "NAT", "BEHIND_NAT"))
134         GSE_node_capabilities |= BEHIND_NAT;
135
136   for (c1 = 0 ; c1 < 32; c1++)
137   {
138                 index = 1;
139                 index = index << c1;
140                 if (GNUNET_YES == GNUNET_EXPERIMENTATION_capabilities_have (GSE_node_capabilities, index))
141                 {
142                         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "We have `%s'\n",
143                                         GNUNET_EXPERIMENTATION_capability_to_str(index));
144                 }
145   }
146 }
147
148 /**
149  * Stop the detecting capabilities
150  */
151 void
152 GNUNET_EXPERIMENTATION_capabilities_stop ()
153 {
154
155 }
156
157 /* end of gnunet-daemon-experimentation_capabilities.c */