diff options
Diffstat (limited to 'src/mesh/plugin_block_mesh.c')
-rw-r--r-- | src/mesh/plugin_block_mesh.c | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/src/mesh/plugin_block_mesh.c b/src/mesh/plugin_block_mesh.c index c5bb458bd..8b601652f 100644 --- a/src/mesh/plugin_block_mesh.c +++ b/src/mesh/plugin_block_mesh.c | |||
@@ -26,8 +26,14 @@ | |||
26 | 26 | ||
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" | ||
30 | |||
31 | /** | ||
32 | * Number of bits we set per entry in the bloomfilter. | ||
33 | * Do not change! | ||
34 | */ | ||
35 | #define BLOOMFILTER_K 16 | ||
29 | 36 | ||
30 | #define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING | ||
31 | 37 | ||
32 | /** | 38 | /** |
33 | * Function called to validate a reply or a request. For | 39 | * Function called to validate a reply or a request. For |
@@ -55,16 +61,52 @@ block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
55 | size_t xquery_size, const void *reply_block, | 61 | size_t xquery_size, const void *reply_block, |
56 | size_t reply_block_size) | 62 | size_t reply_block_size) |
57 | { | 63 | { |
58 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Evaluate called\n"); | 64 | struct GNUNET_HashCode chash; |
59 | if (GNUNET_BLOCK_TYPE_MESH_PEER == type) | 65 | struct GNUNET_HashCode mhash; |
60 | { | 66 | |
61 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type MESH PEER\n"); | 67 | switch (type) |
62 | } | ||
63 | else | ||
64 | { | 68 | { |
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n"); | 69 | case GNUNET_BLOCK_TYPE_MESH_PEER: |
70 | if (0 != xquery_size) | ||
71 | { | ||
72 | GNUNET_break_op (0); | ||
73 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
74 | } | ||
75 | if (NULL == reply_block) | ||
76 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
77 | if (sizeof (struct PBlock) != reply_block_size) | ||
78 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
79 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
80 | case GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE: | ||
81 | /* FIXME: have an xquery? not sure */ | ||
82 | if (0 != xquery_size) | ||
83 | { | ||
84 | GNUNET_break_op (0); | ||
85 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
86 | } | ||
87 | if (NULL == reply_block) | ||
88 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
89 | if (sizeof (struct PBlock) != reply_block_size) | ||
90 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
91 | if (NULL != bf) | ||
92 | { | ||
93 | GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); | ||
94 | GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); | ||
95 | if (NULL != *bf) | ||
96 | { | ||
97 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
98 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); | ||
103 | } | ||
104 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
105 | } | ||
106 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
107 | default: | ||
108 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
66 | } | 109 | } |
67 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
68 | } | 110 | } |
69 | 111 | ||
70 | 112 | ||
@@ -84,8 +126,20 @@ block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type, | |||
84 | const void *block, size_t block_size, | 126 | const void *block, size_t block_size, |
85 | struct GNUNET_HashCode * key) | 127 | struct GNUNET_HashCode * key) |
86 | { | 128 | { |
87 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get key called\n"); | 129 | const struct PBlock *pb; |
88 | return GNUNET_SYSERR; | 130 | |
131 | switch (type) | ||
132 | { | ||
133 | case GNUNET_BLOCK_TYPE_MESH_PEER: | ||
134 | if (sizeof (struct PBlock) != block_size) | ||
135 | return GNUNET_SYSERR; | ||
136 | pb = block; | ||
137 | *key = pb->id.hashPubKey; | ||
138 | return GNUNET_OK; | ||
139 | // FIXME: other types... | ||
140 | default: | ||
141 | return GNUNET_SYSERR; | ||
142 | } | ||
89 | } | 143 | } |
90 | 144 | ||
91 | 145 | ||
@@ -98,6 +152,7 @@ libgnunet_plugin_block_mesh_init (void *cls) | |||
98 | static enum GNUNET_BLOCK_Type types[] = | 152 | static enum GNUNET_BLOCK_Type types[] = |
99 | { | 153 | { |
100 | GNUNET_BLOCK_TYPE_MESH_PEER, | 154 | GNUNET_BLOCK_TYPE_MESH_PEER, |
155 | GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE, | ||
101 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 156 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
102 | }; | 157 | }; |
103 | struct GNUNET_BLOCK_PluginFunctions *api; | 158 | struct GNUNET_BLOCK_PluginFunctions *api; |