documentation
[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
45 /**
46  * Print a single capability value
47  *
48  * @param cap capability value
49  * @return the string to print
50  */
51 const char *
52 GNUNET_EXPERIMENTATION_capability_to_str (uint32_t cap)
53 {
54         char * capstr[] = GNUNET_EXPERIMENTATION_capabilities_string;
55         unsigned index = 0;
56         uint32_t test = 0;
57
58         if (0 == cap)
59                 return capstr[0];
60
61         index = (log(cap) / log (2)) + 1;
62
63         test = 1 << (index - 1);
64         if (test != cap)
65                 return "UNDEFINED";
66
67         if (index <= 11)
68                 return capstr[index];
69         else
70          return "UNDEFINED";
71
72
73 }
74
75
76 /**
77  * Are the capabilities provided?
78  *
79  * @param have bitstring containing the provided capabilities
80  * @param desired bitstring containing the desired capabilities\
81  * @return GNUNET_YES or GNUNET_NO
82  */
83 int
84 GNUNET_EXPERIMENTATION_capabilities_have (uint32_t have, uint32_t desired)
85 {
86         if (desired == (desired & have))
87                 return GNUNET_YES;
88         else
89                 return GNUNET_NO;
90 }
91
92
93 /**
94  * Start the detecting capabilities
95  */
96 void
97 GNUNET_EXPERIMENTATION_capabilities_start ()
98 {
99         char *plugins;
100   char *pos;
101   unsigned int c1;
102   uint32_t index;
103   GSE_node_capabilities = NONE;
104
105         /* Plugins configured */
106
107   if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (GSE_cfg,
108                         "TRANSPORT", "PLUGINS", &plugins))
109   {
110           for (pos = strtok (plugins, " "); pos != NULL; pos = strtok (NULL, " "))
111           {
112               if (0 == strcmp (pos, "tcp"))
113                 GSE_node_capabilities |= PLUGIN_TCP;
114               else if (0 == strcmp (pos, "udp"))
115                 GSE_node_capabilities |= PLUGIN_UDP;
116                                         else if (0 == strcmp (pos, "unix"))
117                                                 GSE_node_capabilities |= PLUGIN_UNIX;
118                                         else if (0 == strcmp (pos, "http_client"))
119                                                 GSE_node_capabilities |= PLUGIN_HTTP_CLIENT;
120                                         else if (0 == strcmp (pos, "http_server"))
121                                                 GSE_node_capabilities |= PLUGIN_HTTP_SERVER;
122                                         else if (0 == strcmp (pos, "https_client"))
123                                                 GSE_node_capabilities |= PLUGIN_HTTP_CLIENT;
124                                         else if (0 == strcmp (pos, "https_server"))
125                                                 GSE_node_capabilities |= PLUGIN_HTTPS_SERVER;
126                                         else if (0 == strcmp (pos, "wlan"))
127                                                 GSE_node_capabilities |= PLUGIN_WLAN;
128           }
129           GNUNET_free (plugins);
130   }
131
132         /* IPv6 enabled
133          * FIXE: just having it not enabled is not really sufficient */
134   if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (GSE_cfg,
135                         "NAT", "DISABLEV6"))
136         GSE_node_capabilities |= HAVE_IPV6;
137
138   /* Behind NAT */
139   if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (GSE_cfg,
140                         "NAT", "BEHIND_NAT"))
141         GSE_node_capabilities |= BEHIND_NAT;
142
143   for (c1 = 0 ; c1 < 32; c1++)
144   {
145                 index = 1;
146                 index = index << c1;
147                 if (GNUNET_YES == GNUNET_EXPERIMENTATION_capabilities_have (GSE_node_capabilities, index))
148                 {
149                         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "We have `%s'\n",
150                                         GNUNET_EXPERIMENTATION_capability_to_str(index));
151                 }
152   }
153 }
154
155 /**
156  * Stop the detecting capabilities
157  */
158 void
159 GNUNET_EXPERIMENTATION_capabilities_stop ()
160 {
161
162 }
163
164 /* end of gnunet-daemon-experimentation_capabilities.c */