aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--po/POTFILES.in2
-rw-r--r--src/Makefile.am7
-rw-r--r--src/ats/ats_api_performance.c2
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_mq_lib.h47
-rw-r--r--src/include/gnunet_nt_lib.h123
-rw-r--r--src/nt/Makefile.am36
-rw-r--r--src/nt/nt.c410
-rw-r--r--src/util/mq.c24
10 files changed, 648 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index b43aa84be..35b2ef659 100644
--- a/configure.ac
+++ b/configure.ac
@@ -598,7 +598,7 @@ AC_CHECK_LIB(ogg, ogg_stream_flush_fill,
598PKG_CHECK_MODULES([GLIB], 598PKG_CHECK_MODULES([GLIB],
599 [glib-2.0], 599 [glib-2.0],
600 [# check for pbc library 600 [# check for pbc library
601 pbc=0 601 pbc=0
602 AC_CHECK_HEADER([pbc/pbc.h],pbc=1) 602 AC_CHECK_HEADER([pbc/pbc.h],pbc=1)
603 AC_CHECK_HEADER([gabe.h],abe=1) 603 AC_CHECK_HEADER([gabe.h],abe=1)
604 AM_CONDITIONAL(HAVE_PBC, [test "x$pbc" = x1]) 604 AM_CONDITIONAL(HAVE_PBC, [test "x$pbc" = x1])
@@ -1807,6 +1807,7 @@ src/nat-auto/Makefile
1807src/nat-auto/nat-auto.conf 1807src/nat-auto/nat-auto.conf
1808src/nse/Makefile 1808src/nse/Makefile
1809src/nse/nse.conf 1809src/nse/nse.conf
1810src/nt/Makefile
1810src/peerinfo/Makefile 1811src/peerinfo/Makefile
1811src/peerinfo/peerinfo.conf 1812src/peerinfo/peerinfo.conf
1812src/peerinfo-tool/Makefile 1813src/peerinfo-tool/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 129c43cdd..a7d35588f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -193,6 +193,7 @@ src/gns/w32nsp-uninstall.c
193src/hello/address.c 193src/hello/address.c
194src/hello/gnunet-hello.c 194src/hello/gnunet-hello.c
195src/hello/hello.c 195src/hello/hello.c
196src/hello/hello-ng.c
196src/hostlist/gnunet-daemon-hostlist.c 197src/hostlist/gnunet-daemon-hostlist.c
197src/hostlist/gnunet-daemon-hostlist_client.c 198src/hostlist/gnunet-daemon-hostlist_client.c
198src/hostlist/gnunet-daemon-hostlist_server.c 199src/hostlist/gnunet-daemon-hostlist_server.c
@@ -250,6 +251,7 @@ src/nse/gnunet-nse.c
250src/nse/gnunet-nse-profiler.c 251src/nse/gnunet-nse-profiler.c
251src/nse/gnunet-service-nse.c 252src/nse/gnunet-service-nse.c
252src/nse/nse_api.c 253src/nse/nse_api.c
254src/nt/nt.c
253src/peerinfo/gnunet-service-peerinfo.c 255src/peerinfo/gnunet-service-peerinfo.c
254src/peerinfo/peerinfo_api.c 256src/peerinfo/peerinfo_api.c
255src/peerinfo/peerinfo_api_notify.c 257src/peerinfo/peerinfo_api_notify.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 39cbaa893..5e2b0e493 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,7 @@ if HAVE_EXPERIMENTAL
16 psycutil \ 16 psycutil \
17 psycstore \ 17 psycstore \
18 psyc \ 18 psyc \
19 social 19 social
20# dv (FTBFS) 20# dv (FTBFS)
21if HAVE_ABE 21if HAVE_ABE
22if HAVE_JSON 22if HAVE_JSON
@@ -24,7 +24,7 @@ if HAVE_JSON
24 abe \ 24 abe \
25 credential \ 25 credential \
26 reclaim-attribute \ 26 reclaim-attribute \
27 reclaim 27 reclaim
28endif 28endif
29endif 29endif
30if HAVE_JSON 30if HAVE_JSON
@@ -80,6 +80,7 @@ else
80SUBDIRS = \ 80SUBDIRS = \
81 include $(INTLEMU_SUBDIRS) \ 81 include $(INTLEMU_SUBDIRS) \
82 util \ 82 util \
83 nt \
83 gnsrecord \ 84 gnsrecord \
84 hello \ 85 hello \
85 block \ 86 block \
@@ -129,6 +130,6 @@ SUBDIRS = \
129 $(EXP_DIR) \ 130 $(EXP_DIR) \
130 $(JSON_DIR) \ 131 $(JSON_DIR) \
131 $(REST_DIR) \ 132 $(REST_DIR) \
132 integration-tests 133 integration-tests
133 134
134endif 135endif
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index 0c196ea43..11e71e94e 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 41b2b1382..185f649ac 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -87,6 +87,7 @@ gnunetinclude_HEADERS = \
87 gnunet_nc_lib.h \ 87 gnunet_nc_lib.h \
88 gnunet_network_lib.h \ 88 gnunet_network_lib.h \
89 gnunet_nse_service.h \ 89 gnunet_nse_service.h \
90 gnunet_nt_lib.h \
90 gnunet_op_lib.h \ 91 gnunet_op_lib.h \
91 gnunet_os_lib.h \ 92 gnunet_os_lib.h \
92 gnunet_peer_lib.h \ 93 gnunet_peer_lib.h \
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 226b3389f..3d3a74e3b 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -875,6 +875,51 @@ const struct GNUNET_MessageHeader *
875GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq); 875GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
876 876
877 877
878
879/**
880 * Enum defining all known preference categories.
881 */
882enum GNUNET_MQ_PreferenceKind
883{
884
885 /**
886 * No preference was expressed.
887 */
888 GNUNET_MQ_PREFERENCE_NONE = 0,
889
890 /**
891 * The preferred transmission for this envelope focuses on
892 * maximizing bandwidth.
893 */
894 GNUNET_MQ_PREFERENCE_BANDWIDTH = 1,
895
896 /**
897 * The preferred transmission for this envelope foces on
898 * minimizing latency.
899 */
900 GNUNET_MQ_PREFERENCE_LATENCY = 2,
901
902 /**
903 * The preferred transmission for this envelope foces on
904 * reliability.
905 */
906 GNUNET_MQ_PREFERENCE_RELIABILITY = 3
907
908};
909
910
911/**
912 * Convert an `enum GNUNET_MQ_PreferenceType` to a string
913 *
914 * @param type the preference type
915 * @return a string or NULL if invalid
916 */
917const char *
918GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
919
920
921
922
878#endif 923#endif
879 924
880/** @} */ /* end of group mq */ 925/** @} */ /* end of group mq */
diff --git a/src/include/gnunet_nt_lib.h b/src/include/gnunet_nt_lib.h
new file mode 100644
index 000000000..3d89aa7b2
--- /dev/null
+++ b/src/include/gnunet_nt_lib.h
@@ -0,0 +1,123 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18/**
19 * @file network type characterization
20 * @author Christian Grothoff
21 * @author Matthias Wachs
22 *
23 * @defgroup nt network type characterization
24 *
25 * @{
26 */
27#ifndef GNUNET_NT_LIB_H
28#define GNUNET_NT_LIB_H
29
30/**
31 * Types of networks (with separate quotas) we support.
32 */
33enum GNUNET_NetworkType
34{
35 /**
36 * Category of last resort.
37 */
38 GNUNET_NT_UNSPECIFIED = 0,
39
40 /**
41 * Loopback (same host).
42 */
43 GNUNET_NT_LOOPBACK = 1,
44
45 /**
46 * Local area network.
47 */
48 GNUNET_NT_LAN = 2,
49
50 /**
51 * Wide area network (i.e. Internet)
52 */
53 GNUNET_NT_WAN = 3,
54
55 /**
56 * Wireless LAN (i.e. 802.11abgn)
57 */
58 GNUNET_NT_WLAN = 4,
59
60 /**
61 * Bluetooth LAN
62 */
63 GNUNET_NT_BT = 5
64
65/**
66 * Number of network types supported by ATS
67 */
68#define GNUNET_NT_COUNT 6
69
70};
71
72
73/**
74 * Convert a `enum GNUNET_NetworkType` to a string
75 *
76 * @param net the network type
77 * @return a string or NULL if invalid
78 */
79const char *
80GNUNET_NT_to_string (enum GNUNET_NetworkType net);
81
82
83/**
84 * Handle for the LAN Characterization library.
85 */
86struct GNUNET_NT_InterfaceScanner;
87
88
89/**
90 * Returns where the address is located: loopback, LAN or WAN.
91 *
92 * @param is handle from #GNUNET_ATS_interface_scanner_init()
93 * @param addr address
94 * @param addrlen address length
95 * @return type of the network the address belongs to
96 */
97enum GNUNET_NetworkType
98GNUNET_NT_scanner_get_type (struct GNUNET_NT_InterfaceScanner *is,
99 const struct sockaddr *addr,
100 socklen_t addrlen);
101
102
103/**
104 * Initialize the address characterization client handle.
105 *
106 * @return scanner handle, NULL on error
107 */
108struct GNUNET_NT_InterfaceScanner *
109GNUNET_NT_scanner_init (void);
110
111
112/**
113 * Terminate interface scanner.
114 *
115 * @param is scanner we are done with
116 */
117void
118GNUNET_NT_scanner_done (struct GNUNET_NT_InterfaceScanner *is);
119
120
121#endif
122
123/** @} */ /* end of group */
diff --git a/src/nt/Makefile.am b/src/nt/Makefile.am
new file mode 100644
index 000000000..68b6a55e7
--- /dev/null
+++ b/src/nt/Makefile.am
@@ -0,0 +1,36 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4if MINGW
5 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
6endif
7
8if USE_COVERAGE
9 AM_CFLAGS = --coverage
10endif
11
12lib_LTLIBRARIES = libgnunetnt.la
13
14libgnunetnt_la_SOURCES = \
15 nt.c
16
17libgnunetnt_la_LIBADD = \
18 $(top_builddir)/src/util/libgnunetutil.la
19libgnunetnt_la_LDFLAGS = \
20 $(GN_LIB_LDFLAGS) \
21 -version-info 0:0:0
22
23#if ENABLE_TEST_RUN
24#TESTS = \
25# test_nt
26#endif
27
28#check_PROGRAMS= \
29# test_nt
30#
31#test_nt_SOURCES = \
32# test_nt.c
33#test_nt_LDADD = \
34# libgnunetnt.la \
35# $(top_builddir)/src/util/libgnunetutil.la \
36# $(XLIB)
diff --git a/src/nt/nt.c b/src/nt/nt.c
new file mode 100644
index 000000000..5764f8f4a
--- /dev/null
+++ b/src/nt/nt.c
@@ -0,0 +1,410 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18/**
19 * @file nt/nt_api_scanner.c
20 * @brief LAN interface scanning to determine IPs in LAN
21 * @author Christian Grothoff
22 * @author Matthias Wachs
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_nt_lib.h"
27
28/**
29 * How frequently do we scan the interfaces for changes to the addresses?
30 */
31#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
32
33
34/**
35 * Convert a `enum GNUNET_NetworkType` to a string
36 *
37 * @param net the network type
38 * @return a string or NULL if invalid
39 */
40const char *
41GNUNET_NT_to_string (enum GNUNET_NetworkType net)
42{
43 switch (net)
44 {
45 case GNUNET_NT_UNSPECIFIED:
46 return "UNSPECIFIED";
47 case GNUNET_NT_LOOPBACK:
48 return "LOOPBACK";
49 case GNUNET_NT_LAN:
50 return "LAN";
51 case GNUNET_NT_WAN:
52 return "WAN";
53 case GNUNET_NT_WLAN:
54 return "WLAN";
55 case GNUNET_NT_BT:
56 return "BLUETOOTH";
57 default:
58 return NULL;
59 }
60}
61
62
63/**
64 * We keep a list of our local networks so we can answer
65 * LAN vs. WAN questions. Note: WLAN is not detected yet.
66 * (maybe we can do that heuristically based on interface
67 * name in the future?).
68 */
69struct NT_Network
70{
71 /**
72 * Kept in a DLL.
73 */
74 struct NT_Network *next;
75
76 /**
77 * Kept in a DLL.
78 */
79 struct NT_Network *prev;
80
81 /**
82 * Network address.
83 */
84 struct sockaddr *network;
85
86 /**
87 * Netmask to determine what is in the LAN.
88 */
89 struct sockaddr *netmask;
90
91 /**
92 * How long are @e network and @e netmask?
93 */
94 socklen_t length;
95};
96
97
98/**
99 * Handle to the interface scanner.
100 */
101struct GNUNET_NT_InterfaceScanner
102{
103
104 /**
105 * Head of LAN networks list.
106 */
107 struct NT_Network *net_head;
108
109 /**
110 * Tail of LAN networks list.
111 */
112 struct NT_Network *net_tail;
113
114 /**
115 * Task for periodically refreshing our LAN network list.
116 */
117 struct GNUNET_SCHEDULER_Task *interface_task;
118
119};
120
121
122/**
123 * Delete all entries from the current network list.
124 *
125 * @param is scanner to clean up
126 */
127static void
128delete_networks (struct GNUNET_NT_InterfaceScanner *is)
129{
130 struct NT_Network *cur;
131
132 while (NULL != (cur = is->net_head))
133 {
134 GNUNET_CONTAINER_DLL_remove (is->net_head,
135 is->net_tail,
136 cur);
137 GNUNET_free (cur);
138 }
139}
140
141
142/**
143 * Function invoked for each interface found. Adds the interface's
144 * network addresses to the respective DLL, so we can distinguish
145 * between LAN and WAN.
146 *
147 * @param cls closure with the `struct GNUNET_NT_InterfaceScanner`
148 * @param name name of the interface (can be NULL for unknown)
149 * @param isDefault is this presumably the default interface
150 * @param addr address of this interface (can be NULL for unknown or unassigned)
151 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
152 * @param netmask the network mask (can be NULL for unknown or unassigned)
153 * @param addrlen length of the address
154 * @return #GNUNET_OK to continue iteration
155 */
156static int
157interface_proc (void *cls,
158 const char *name,
159 int isDefault,
160 const struct sockaddr *addr,
161 const struct sockaddr *broadcast_addr,
162 const struct sockaddr *netmask,
163 socklen_t addrlen)
164{
165 struct GNUNET_NT_InterfaceScanner *is = cls;
166 /* Calculate network */
167 struct NT_Network *net = NULL;
168
169 /* Skipping IPv4 loopback addresses since we have special check */
170 if (addr->sa_family == AF_INET)
171 {
172 const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
173
174 if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000))
175 return GNUNET_OK;
176 }
177 /* Skipping IPv6 loopback addresses since we have special check */
178 if (addr->sa_family == AF_INET6)
179 {
180 const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
181 if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
182 return GNUNET_OK;
183 }
184
185 if (addr->sa_family == AF_INET)
186 {
187 const struct sockaddr_in *addr4 = (const struct sockaddr_in *) addr;
188 const struct sockaddr_in *netmask4 = (const struct sockaddr_in *) netmask;
189 struct sockaddr_in *tmp;
190 struct sockaddr_in network4;
191
192 net = GNUNET_malloc (sizeof (struct NT_Network) + 2 * sizeof (struct sockaddr_in));
193 tmp = (struct sockaddr_in *) &net[1];
194 net->network = (struct sockaddr *) &tmp[0];
195 net->netmask = (struct sockaddr *) &tmp[1];
196 net->length = addrlen;
197
198 memset (&network4, 0, sizeof (network4));
199 network4.sin_family = AF_INET;
200#if HAVE_SOCKADDR_IN_SIN_LEN
201 network4.sin_len = sizeof (network4);
202#endif
203 network4.sin_addr.s_addr = (addr4->sin_addr.s_addr & netmask4->sin_addr.s_addr);
204
205 GNUNET_memcpy (net->netmask, netmask4, sizeof (struct sockaddr_in));
206 GNUNET_memcpy (net->network, &network4, sizeof (struct sockaddr_in));
207 }
208
209 if (addr->sa_family == AF_INET6)
210 {
211 const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *) addr;
212 const struct sockaddr_in6 *netmask6 = (const struct sockaddr_in6 *) netmask;
213 struct sockaddr_in6 * tmp;
214 struct sockaddr_in6 network6;
215
216 net = GNUNET_malloc (sizeof (struct NT_Network) + 2 * sizeof (struct sockaddr_in6));
217 tmp = (struct sockaddr_in6 *) &net[1];
218 net->network = (struct sockaddr *) &tmp[0];
219 net->netmask = (struct sockaddr *) &tmp[1];
220 net->length = addrlen;
221
222 memset (&network6, 0, sizeof (network6));
223 network6.sin6_family = AF_INET6;
224#if HAVE_SOCKADDR_IN_SIN_LEN
225 network6.sin6_len = sizeof (network6);
226#endif
227 unsigned int c = 0;
228 uint32_t *addr_elem = (uint32_t *) &addr6->sin6_addr;
229 uint32_t *mask_elem = (uint32_t *) &netmask6->sin6_addr;
230 uint32_t *net_elem = (uint32_t *) &network6.sin6_addr;
231 for (c = 0; c < 4; c++)
232 net_elem[c] = addr_elem[c] & mask_elem[c];
233
234 GNUNET_memcpy (net->netmask, netmask6, sizeof (struct sockaddr_in6));
235 GNUNET_memcpy (net->network, &network6, sizeof (struct sockaddr_in6));
236 }
237 if (NULL == net)
238 return GNUNET_OK; /* odd / unsupported address family */
239
240 /* Store in list */
241#if VERBOSE_NT
242 char * netmask = GNUNET_strdup (GNUNET_a2s((struct sockaddr *) net->netmask, addrlen));
243 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
244 "nt",
245 "Adding network `%s', netmask `%s'\n",
246 GNUNET_a2s ((struct sockaddr *) net->network,
247 addrlen),
248 netmask);
249 GNUNET_free (netmask);
250#endif
251 GNUNET_CONTAINER_DLL_insert (is->net_head,
252 is->net_tail,
253 net);
254
255 return GNUNET_OK;
256}
257
258
259/**
260 * Periodically get list of network addresses from our interfaces.
261 *
262 * @param cls closure
263 */
264static void
265get_addresses (void *cls)
266{
267 struct GNUNET_NT_InterfaceScanner *is = cls;
268
269 is->interface_task = NULL;
270 delete_networks (is);
271 GNUNET_OS_network_interfaces_list (&interface_proc,
272 is);
273 is->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVAL,
274 &get_addresses,
275 is);
276}
277
278
279/**
280 * Returns where the address is located: LAN or WAN or ...
281 *
282 * @param is the interface scanner handle
283 * @param addr address
284 * @param addrlen address length
285 * @return type of the network the address belongs to
286 */
287enum GNUNET_NetworkType
288GNUNET_NT_scanner_address_get_type (struct GNUNET_NT_InterfaceScanner *is,
289 const struct sockaddr *addr,
290 socklen_t addrlen)
291{
292 struct NT_Network *cur = is->net_head;
293 enum GNUNET_NetworkType type = GNUNET_NT_UNSPECIFIED;
294
295 switch (addr->sa_family)
296 {
297 case AF_UNIX:
298 type = GNUNET_NT_LOOPBACK;
299 break;
300 case AF_INET:
301 {
302 const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
303
304 if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000))
305 type = GNUNET_NT_LOOPBACK;
306 break;
307 }
308 case AF_INET6:
309 {
310 const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
311
312 if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
313 type = GNUNET_NT_LOOPBACK;
314 break;
315 }
316 default:
317 GNUNET_break (0);
318 break;
319 }
320
321 /* Check local networks */
322 while ((NULL != cur) && (GNUNET_NT_UNSPECIFIED == type))
323 {
324 if (addrlen != cur->length)
325 {
326 cur = cur->next;
327 continue;
328 }
329 if (addr->sa_family == AF_INET)
330 {
331 const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
332 const struct sockaddr_in *net4 = (const struct sockaddr_in *) cur->network;
333 const struct sockaddr_in *mask4 = (const struct sockaddr_in *) cur->netmask;
334
335 if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) == net4->sin_addr.s_addr)
336 type = GNUNET_NT_LAN;
337 }
338 if (addr->sa_family == AF_INET6)
339 {
340 const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
341 const struct sockaddr_in6 *net6 = (const struct sockaddr_in6 *) cur->network;
342 const struct sockaddr_in6 *mask6 = (const struct sockaddr_in6 *) cur->netmask;
343
344 int res = GNUNET_YES;
345 int c = 0;
346 uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
347 uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
348 uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
349 for (c = 0; c < 4; c++)
350 if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
351 res = GNUNET_NO;
352
353 if (res == GNUNET_YES)
354 type = GNUNET_NT_LAN;
355 }
356 cur = cur->next;
357 }
358
359 /* no local network found for this address, default: WAN */
360 if (type == GNUNET_NT_UNSPECIFIED)
361 type = GNUNET_NT_WAN;
362 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
363 "nt-scanner-api",
364 "`%s' is in network `%s'\n",
365 GNUNET_a2s (addr,
366 addrlen),
367 GNUNET_NT_to_string (type));
368 return type;
369}
370
371
372/**
373 * Initialize the interface scanner.
374 *
375 * @return interface scanner
376 */
377struct GNUNET_NT_InterfaceScanner *
378GNUNET_NT_scanner_init ()
379{
380 struct GNUNET_NT_InterfaceScanner *is;
381
382 is = GNUNET_new (struct GNUNET_NT_InterfaceScanner);
383 GNUNET_OS_network_interfaces_list (&interface_proc,
384 is);
385 is->interface_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_PROCESSING_INTERVAL,
386 &get_addresses,
387 is);
388 return is;
389}
390
391
392/**
393 * Client is done with the interface scanner, release resources.
394 *
395 * @param is handle to release
396 */
397void
398GNUNET_NT_scanner_done (struct GNUNET_NT_InterfaceScanner *is)
399{
400 if (NULL != is->interface_task)
401 {
402 GNUNET_SCHEDULER_cancel (is->interface_task);
403 is->interface_task = NULL;
404 }
405 delete_networks (is);
406 GNUNET_free (is);
407}
408
409
410/* end of nt.c */
diff --git a/src/util/mq.c b/src/util/mq.c
index eaac85575..8bf1f9752 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -1270,5 +1270,27 @@ GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1270} 1270}
1271 1271
1272 1272
1273/**
1274 * Convert an `enum GNUNET_MQ_PreferenceType` to a string
1275 *
1276 * @param type the preference type
1277 * @return a string or NULL if invalid
1278 */
1279const char *
1280GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type)
1281{
1282 switch (type) {
1283 case GNUNET_MQ_PREFERENCE_NONE:
1284 return "NONE";
1285 case GNUNET_MQ_PREFERENCE_BANDWIDTH:
1286 return "BANDWIDTH";
1287 case GNUNET_MQ_PREFERENCE_LATENCY:
1288 return "LATENCY";
1289 case GNUNET_MQ_PREFERENCE_RELIABILITY:
1290 return "RELIABILITY";
1291 };
1292 return NULL;
1293}
1294
1273 1295
1274/* end of mq.c */ 1296/* end of mq.c */