diff options
-rw-r--r-- | src/mesh/Makefile.am | 17 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_new.c | 16 | ||||
-rw-r--r-- | src/mesh/mesh_block_lib.c | 131 | ||||
-rw-r--r-- | src/mesh/mesh_block_lib.h | 94 | ||||
-rw-r--r-- | src/mesh/mesh_protocol.h | 2 | ||||
-rw-r--r-- | src/mesh/plugin_block_mesh.c | 50 |
6 files changed, 260 insertions, 50 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index d78cf004e..61ef32974 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -22,7 +22,8 @@ bin_PROGRAMS = \ | |||
22 | gnunet-service-mesh gnunet-service-mesh_new | 22 | gnunet-service-mesh gnunet-service-mesh_new |
23 | 23 | ||
24 | lib_LTLIBRARIES = \ | 24 | lib_LTLIBRARIES = \ |
25 | libgnunetmesh.la | 25 | libgnunetmesh.la \ |
26 | libgnunetmeshblock.la | ||
26 | 27 | ||
27 | plugin_LTLIBRARIES = \ | 28 | plugin_LTLIBRARIES = \ |
28 | libgnunet_plugin_block_mesh.la | 29 | libgnunet_plugin_block_mesh.la |
@@ -47,7 +48,7 @@ gnunet_service_mesh_LDADD = \ | |||
47 | $(top_builddir)/src/block/libgnunetblock.la \ | 48 | $(top_builddir)/src/block/libgnunetblock.la \ |
48 | $(top_builddir)/src/util/libgnunetutil.la | 49 | $(top_builddir)/src/util/libgnunetutil.la |
49 | gnunet_service_mesh_DEPENDENCIES = \ | 50 | gnunet_service_mesh_DEPENDENCIES = \ |
50 | $(top_builddir)/src/core/libgnunetcore.la\ | 51 | $(top_builddir)/src/core/libgnunetcore.la \ |
51 | $(top_builddir)/src/dht/libgnunetdht.la \ | 52 | $(top_builddir)/src/dht/libgnunetdht.la \ |
52 | $(top_builddir)/src/util/libgnunetutil.la | 53 | $(top_builddir)/src/util/libgnunetutil.la |
53 | 54 | ||
@@ -55,6 +56,7 @@ gnunet_service_mesh_new_SOURCES = \ | |||
55 | gnunet-service-mesh_new.c \ | 56 | gnunet-service-mesh_new.c \ |
56 | mesh_tunnel_tree.c mesh_tunnel_tree.h | 57 | mesh_tunnel_tree.c mesh_tunnel_tree.h |
57 | gnunet_service_mesh_new_LDADD = \ | 58 | gnunet_service_mesh_new_LDADD = \ |
59 | libgnunetmeshblock.la \ | ||
58 | $(top_builddir)/src/core/libgnunetcore.la\ | 60 | $(top_builddir)/src/core/libgnunetcore.la\ |
59 | $(top_builddir)/src/dht/libgnunetdht.la \ | 61 | $(top_builddir)/src/dht/libgnunetdht.la \ |
60 | $(top_builddir)/src/regex/libgnunetregex.la \ | 62 | $(top_builddir)/src/regex/libgnunetregex.la \ |
@@ -74,6 +76,17 @@ libgnunetmesh_la_LDFLAGS = \ | |||
74 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 76 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
75 | -version-info 1:0:0 | 77 | -version-info 1:0:0 |
76 | 78 | ||
79 | libgnunetmeshblock_la_SOURCES = \ | ||
80 | mesh_block_lib.c | ||
81 | libgnunetmeshblock_la_LIBADD = \ | ||
82 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
83 | $(XLIB) \ | ||
84 | $(LTLIBINTL) | ||
85 | libgnunetmeshblock_la_LDFLAGS = \ | ||
86 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
87 | -version-info 1:0:0 | ||
88 | |||
89 | |||
77 | check_PROGRAMS = \ | 90 | check_PROGRAMS = \ |
78 | test_mesh_api \ | 91 | test_mesh_api \ |
79 | test_mesh_tree_api \ | 92 | test_mesh_tree_api \ |
diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c index d7446bc43..4aee2dc40 100644 --- a/src/mesh/gnunet-service-mesh_new.c +++ b/src/mesh/gnunet-service-mesh_new.c | |||
@@ -4029,6 +4029,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
4029 | size_t len; | 4029 | size_t len; |
4030 | 4030 | ||
4031 | // FIXME: does proof have to be NULL terminated? | 4031 | // FIXME: does proof have to be NULL terminated? |
4032 | ctx->dht_get_handle = NULL; | ||
4032 | proof = (char *) &block[1]; | 4033 | proof = (char *) &block[1]; |
4033 | if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key)) | 4034 | if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key)) |
4034 | { | 4035 | { |
@@ -4050,6 +4051,21 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
4050 | return; | 4051 | return; |
4051 | } | 4052 | } |
4052 | // FIXME complete | 4053 | // FIXME complete |
4054 | ctx->n_dht_gets++; | ||
4055 | ctx->dht_get_handle = GNUNET_realloc (ctx->dht_get_handle, | ||
4056 | sizeof(struct GNUNET_DHT_GetHandle *) | ||
4057 | * ctx->n_dht_gets); | ||
4058 | |||
4059 | /* Start search in DHT */ | ||
4060 | ctx->dht_get_handle[ctx->n_dht_gets - 1] = | ||
4061 | GNUNET_DHT_get_start (dht_handle, /* handle */ | ||
4062 | GNUNET_BLOCK_TYPE_MESH_REGEX, /* type */ | ||
4063 | &key, /* key to search */ | ||
4064 | DHT_REPLICATION_LEVEL, /* replication level */ | ||
4065 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
4066 | NULL, /* xquery */ // FIXME BLOOMFILTER | ||
4067 | 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE | ||
4068 | &dht_get_string_handler, ctx); | ||
4053 | return; | 4069 | return; |
4054 | } | 4070 | } |
4055 | 4071 | ||
diff --git a/src/mesh/mesh_block_lib.c b/src/mesh/mesh_block_lib.c new file mode 100644 index 000000000..e56aa5725 --- /dev/null +++ b/src/mesh/mesh_block_lib.c | |||
@@ -0,0 +1,131 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 2011 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 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh_block_lib.c | ||
24 | */ | ||
25 | |||
26 | #ifdef __cplusplus | ||
27 | extern "C" | ||
28 | { | ||
29 | #if 0 | ||
30 | /* keep Emacsens' auto-indent happy */ | ||
31 | } | ||
32 | #endif | ||
33 | #endif | ||
34 | |||
35 | #include "mesh_block_lib.h" | ||
36 | |||
37 | /** | ||
38 | * Iterator over edges in a block. | ||
39 | * | ||
40 | * @param cls Closure. | ||
41 | * @param token Token that follows to next state. | ||
42 | * @param len Lenght of token. | ||
43 | * @param key Hash of next state. | ||
44 | */ | ||
45 | static int | ||
46 | check_edge (void *cls, | ||
47 | const char *token, | ||
48 | size_t len, | ||
49 | const struct GNUNET_HashCode *key) | ||
50 | { | ||
51 | return GNUNET_YES; | ||
52 | } | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Check if the regex block is well formed, including all edges | ||
57 | * | ||
58 | * @param block The start of the block. | ||
59 | * @param size The size of the block. | ||
60 | * | ||
61 | * @return GNUNET_OK in case it's fine, GNUNET_SYSERR otherwise. | ||
62 | */ | ||
63 | int | ||
64 | GNUNET_MESH_regex_block_check (const struct MeshRegexBlock *block, | ||
65 | size_t size) | ||
66 | { | ||
67 | return GNUNET_MESH_regex_block_iterate(NULL, block, size, &check_edge); | ||
68 | } | ||
69 | |||
70 | |||
71 | /** | ||
72 | * Iterate over all edges of a block of a regex state. | ||
73 | * | ||
74 | * @param cls Closure for the iterator. | ||
75 | * @param block Block to iterate over. | ||
76 | * @param size Size of block. | ||
77 | * @param iterator Function to call on each edge in the block. | ||
78 | * | ||
79 | * @return How many bytes of block have been processed | ||
80 | */ | ||
81 | int | ||
82 | GNUNET_MESH_regex_block_iterate (void *cls, | ||
83 | const struct MeshRegexBlock *block, | ||
84 | size_t size, | ||
85 | GNUNET_MESH_EgdeIterator iterator) | ||
86 | { | ||
87 | struct MeshRegexEdge *edge; | ||
88 | unsigned int n; | ||
89 | unsigned int n_token; | ||
90 | unsigned int i; | ||
91 | size_t offset; | ||
92 | char *aux; | ||
93 | |||
94 | offset = sizeof (struct MeshRegexBlock); | ||
95 | if (offset > size) // Is it safe to access the regex block? | ||
96 | return GNUNET_SYSERR; | ||
97 | n = ntohl (block->n_proof); | ||
98 | offset =+ n; | ||
99 | if (offset > size) // Is it safe to access the regex proof? | ||
100 | return GNUNET_SYSERR; | ||
101 | aux = (char *) &block[1]; // Skip regex block | ||
102 | aux = &aux[n]; // Skip regex proof | ||
103 | n = ntohl (block->n_edges); | ||
104 | for (i = 0; i < n; n++) // aux always points at the end of the previous block | ||
105 | { | ||
106 | offset += sizeof (struct MeshRegexEdge); | ||
107 | if (offset > size) // Is it safe to access the next edge block? | ||
108 | return GNUNET_SYSERR; | ||
109 | edge = (struct MeshRegexEdge *) aux; | ||
110 | n_token = ntohl (edge->n_token); | ||
111 | offset += n_token; | ||
112 | if (offset > size) // Is it safe to access the edge token? | ||
113 | return GNUNET_SYSERR; | ||
114 | aux = (char *) &edge[1]; // Skip edge block | ||
115 | if (NULL != iterator) | ||
116 | if (GNUNET_NO == iterator (cls, aux, n_token, &edge->key)) | ||
117 | return GNUNET_OK; | ||
118 | aux = &aux[n_token]; // Skip edge token | ||
119 | } | ||
120 | // The total size should be exactly the size of (regex + all edges) blocks | ||
121 | return (offset == size) ? GNUNET_OK : GNUNET_SYSERR; | ||
122 | } | ||
123 | |||
124 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
125 | { | ||
126 | #endif | ||
127 | #ifdef __cplusplus | ||
128 | } | ||
129 | #endif | ||
130 | |||
131 | /* end of mesh_protocol.h */ | ||
diff --git a/src/mesh/mesh_block_lib.h b/src/mesh/mesh_block_lib.h new file mode 100644 index 000000000..47e63289c --- /dev/null +++ b/src/mesh/mesh_block_lib.h | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 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 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh_block_lib.h | ||
24 | */ | ||
25 | |||
26 | #ifndef MESH_BLOCK_LIB_H_ | ||
27 | #define MESH_BLOCK_LIB_H_ | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 | ||
33 | /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "platform.h" | ||
39 | #include "block_mesh.h" | ||
40 | |||
41 | /** | ||
42 | * Check if the regex block is well formed, including all edges | ||
43 | * | ||
44 | * @param block The start of the block. | ||
45 | * @param size The size of the block. | ||
46 | * | ||
47 | * @return GNUNET_OK in case it's fine, GNUNET_SYSERR otherwise. | ||
48 | */ | ||
49 | int | ||
50 | GNUNET_MESH_regex_block_check (const struct MeshRegexBlock *block, | ||
51 | size_t size); | ||
52 | |||
53 | /** | ||
54 | * Iterator over edges in a block. | ||
55 | * | ||
56 | * @param cls Closure. | ||
57 | * @param token Token that follows to next state. | ||
58 | * @param len Lenght of token. | ||
59 | * @param key Hash of next state. | ||
60 | * | ||
61 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. | ||
62 | */ | ||
63 | typedef int (*GNUNET_MESH_EgdeIterator)(void *cls, | ||
64 | const char *token, | ||
65 | size_t len, | ||
66 | const struct GNUNET_HashCode *key); | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Iterate over all edges of a block of a regex state. | ||
71 | * | ||
72 | * @param cls Closure for the iterator. | ||
73 | * @param block Block to iterate over. | ||
74 | * @param size Size of block. | ||
75 | * @param iterator Function to call on each edge in the block. | ||
76 | * | ||
77 | * @return GNUNET_SYSERR if an error has been encountered, GNUNET_OK otherwise | ||
78 | */ | ||
79 | int | ||
80 | GNUNET_MESH_regex_block_iterate (void *cls, | ||
81 | const struct MeshRegexBlock *block, | ||
82 | size_t size, | ||
83 | GNUNET_MESH_EgdeIterator iterator); | ||
84 | |||
85 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
86 | { | ||
87 | #endif | ||
88 | #ifdef __cplusplus | ||
89 | } | ||
90 | #endif | ||
91 | |||
92 | /* ifndef MESH_BLOCK_LIB_H */ | ||
93 | #endif | ||
94 | /* end of mesh_block_lib.h */ | ||
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 885f1f344..a699d1897 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h | |||
@@ -287,6 +287,6 @@ GNUNET_NETWORK_STRUCT_END | |||
287 | } | 287 | } |
288 | #endif | 288 | #endif |
289 | 289 | ||
290 | /* ifndef MES_PROTOCOL_H */ | 290 | /* ifndef MESH_PROTOCOL_H */ |
291 | #endif | 291 | #endif |
292 | /* end of mesh_protocol.h */ | 292 | /* end of mesh_protocol.h */ |
diff --git a/src/mesh/plugin_block_mesh.c b/src/mesh/plugin_block_mesh.c index 9dd34f358..6f024845b 100644 --- a/src/mesh/plugin_block_mesh.c +++ b/src/mesh/plugin_block_mesh.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_block_plugin.h" | 28 | #include "gnunet_block_plugin.h" |
29 | #include "block_mesh.h" | 29 | #include "block_mesh.h" |
30 | #include "mesh_block_lib.h" | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Number of bits we set per entry in the bloomfilter. | 33 | * Number of bits we set per entry in the bloomfilter. |
@@ -36,52 +37,6 @@ | |||
36 | 37 | ||
37 | 38 | ||
38 | /** | 39 | /** |
39 | * Check if the regex block is well formed, including all edges | ||
40 | * | ||
41 | * @param block The start of the block. | ||
42 | * @param size The size of the block. | ||
43 | * | ||
44 | * @return GNUNET_OK in case it's fine, GNUNET_SYSERR otherwise. | ||
45 | */ | ||
46 | static int | ||
47 | check_mesh_regex_block (const struct MeshRegexBlock *block, size_t size) | ||
48 | { | ||
49 | struct MeshRegexEdge *edge; | ||
50 | unsigned int n; | ||
51 | unsigned int n_token; | ||
52 | unsigned int i; | ||
53 | size_t offset; | ||
54 | char *aux; | ||
55 | |||
56 | offset = sizeof (struct MeshRegexBlock); | ||
57 | if (offset > size) // Is it safe to access the regex block? | ||
58 | return GNUNET_SYSERR; | ||
59 | n = ntohl (block->n_proof); | ||
60 | offset =+ n; | ||
61 | if (offset > size) // Is it safe to access the regex proof? | ||
62 | return GNUNET_SYSERR; | ||
63 | aux = (char *) &block[1]; // Skip regex block | ||
64 | aux = &aux[n]; // Skip regex proof | ||
65 | n = ntohl (block->n_edges); | ||
66 | for (i = 0; i < n; n++) // aux always points at the end of the previous block | ||
67 | { | ||
68 | offset += sizeof (struct MeshRegexEdge); | ||
69 | if (offset > size) // Is it safe to access the next edge block? | ||
70 | return GNUNET_SYSERR; | ||
71 | edge = (struct MeshRegexEdge *) aux; | ||
72 | n_token = ntohl (edge->n_token); | ||
73 | offset += n_token; | ||
74 | if (offset > size) // Is it safe to access the edge token? | ||
75 | return GNUNET_SYSERR; | ||
76 | aux = (char *) &edge[1]; // Skip edge block | ||
77 | aux = &aux[n_token]; // Skip edge token | ||
78 | } | ||
79 | // The total size should be exactly the size of (regex + all edges) blocks | ||
80 | return (offset == size) ? GNUNET_OK : GNUNET_SYSERR; | ||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Function called to validate a reply or a request. For | 40 | * Function called to validate a reply or a request. For |
86 | * request evaluation, simply pass "NULL" for the reply_block. | 41 | * request evaluation, simply pass "NULL" for the reply_block. |
87 | * Note that it is assumed that the reply has already been | 42 | * Note that it is assumed that the reply has already been |
@@ -158,7 +113,8 @@ block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
158 | } | 113 | } |
159 | if (NULL == reply_block) | 114 | if (NULL == reply_block) |
160 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 115 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
161 | if (GNUNET_OK != check_mesh_regex_block (reply_block, reply_block_size)) | 116 | if (GNUNET_OK != GNUNET_MESH_regex_block_check (reply_block, |
117 | reply_block_size)) | ||
162 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 118 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
163 | if (NULL != bf) | 119 | if (NULL != bf) |
164 | { | 120 | { |