aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_new.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-07-13 17:42:17 +0000
committerBart Polot <bart@net.in.tum.de>2012-07-13 17:42:17 +0000
commitd83d4a5b98f35790d84231a6b0124a3ccf0af21f (patch)
tree70b9b8e2b21634d952eb5344ac68f3a9f977e2ba /src/mesh/gnunet-service-mesh_new.c
parent46859c40d868ff4d5430656eb29130d72c604514 (diff)
downloadgnunet-d83d4a5b98f35790d84231a6b0124a3ccf0af21f.tar.gz
gnunet-d83d4a5b98f35790d84231a6b0124a3ccf0af21f.zip
- fix for a periodic accepting state, some refactoring
Diffstat (limited to 'src/mesh/gnunet-service-mesh_new.c')
-rw-r--r--src/mesh/gnunet-service-mesh_new.c122
1 files changed, 95 insertions, 27 deletions
diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c
index d5e28d6e4..a0adfd691 100644
--- a/src/mesh/gnunet-service-mesh_new.c
+++ b/src/mesh/gnunet-service-mesh_new.c
@@ -804,11 +804,31 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp,
804 size_t size, const void *data); 804 size_t size, const void *data);
805 805
806 806
807/******************************************************************************/ 807/**
808/************************ ITERATORS ****************************/ 808 * Function to process DHT string to regex matching.
809/******************************************************************************/ 809 * Called on each result obtained for the DHT search.
810 *
811 * @param cls closure (search context)
812 * @param exp when will this value expire
813 * @param key key of the result
814 * @param get_path path of the get request (not used)
815 * @param get_path_length lenght of get_path (not used)
816 * @param put_path path of the put request (not used)
817 * @param put_path_length length of the put_path (not used)
818 * @param type type of the result
819 * @param size number of bytes in data
820 * @param data pointer to the result data
821 */
822static void
823dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
824 const struct GNUNET_HashCode * key,
825 const struct GNUNET_PeerIdentity *get_path,
826 unsigned int get_path_length,
827 const struct GNUNET_PeerIdentity *put_path,
828 unsigned int put_path_length,
829 enum GNUNET_BLOCK_Type type,
830 size_t size, const void *data);
810 831
811/* FIXME move iterators here */
812 832
813/** 833/**
814 * Iterator over edges in a regex block retrieved from the DHT. 834 * Iterator over edges in a regex block retrieved from the DHT.
@@ -825,14 +845,32 @@ regex_edge_iterator (void *cls,
825 const char *token, 845 const char *token,
826 size_t len, 846 size_t len,
827 const struct GNUNET_HashCode *key); 847 const struct GNUNET_HashCode *key);
848
849
828/** 850/**
829 * Iterator over hash map entries. 851 * Find a path to a peer that offers a regex servcie compatible
852 * with a given string.
853 *
854 * @param key The key of the accepting state.
855 * @param ctx Context containing info about the string, tunnel, etc.
856 */
857static void
858regex_find_path (const struct GNUNET_HashCode *key,
859 struct MeshRegexSearchContext *ctx);
860
861/******************************************************************************/
862/************************ ITERATORS ****************************/
863/******************************************************************************/
864
865/* FIXME move iterators here */
866
867/**
868 * Iterator over found existing mesh regex blocks that match an ongoing search.
830 * 869 *
831 * @param cls closure 870 * @param cls closure
832 * @param key current key code 871 * @param key current key code
833 * @param value value in the hash map 872 * @param value value in the hash map
834 * @return GNUNET_YES if we should continue to 873 * @return GNUNET_YES if we should continue to iterate,
835 * iterate,
836 * GNUNET_NO if not. 874 * GNUNET_NO if not.
837 */ 875 */
838static int 876static int
@@ -843,7 +881,20 @@ regex_result_iterator (void *cls,
843 struct MeshRegexBlock *block = value; 881 struct MeshRegexBlock *block = value;
844 struct MeshRegexSearchContext *ctx = cls; 882 struct MeshRegexSearchContext *ctx = cls;
845 883
846 // block was checked when stored, no need to check again 884 if (GNUNET_YES == ntohl(block->accepting) &&
885 ctx->position == strlen (ctx->info->description))
886 {
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Found accepting known block\n");
888 regex_find_path (key, ctx);
889 return GNUNET_YES; // We found an accept state!
890 }
891 else
892 {
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n",
894 ctx->position, strlen(ctx->info->description),
895 ntohl(block->accepting));
896
897 }
847 (void) GNUNET_MESH_regex_block_iterate (block, SIZE_MAX, 898 (void) GNUNET_MESH_regex_block_iterate (block, SIZE_MAX,
848 &regex_edge_iterator, ctx); 899 &regex_edge_iterator, ctx);
849 900
@@ -882,6 +933,7 @@ regex_edge_iterator (void *cls,
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* ctlen : %u\n", current_len); 933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* ctlen : %u\n", current_len);
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tklen : %u\n", len); 934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tklen : %u\n", len);
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tk[0] : %c\n", token[0]); 935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* tk[0] : %c\n", token[0]);
936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* nextk : %s\n", GNUNET_h2s(key));
885 if (len > current_len) 937 if (len > current_len)
886 { 938 {
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token too long, END\n"); 939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Token too long, END\n");
@@ -894,7 +946,7 @@ regex_edge_iterator (void *cls,
894 } 946 }
895 new_ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext)); 947 new_ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext));
896 new_ctx->info = info; 948 new_ctx->info = info;
897 new_ctx->position += ctx->position + len; 949 new_ctx->position = ctx->position + len;
898 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx); 950 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
899 if (GNUNET_YES == 951 if (GNUNET_YES ==
900 GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, key)) 952 GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, key))
@@ -1096,6 +1148,36 @@ regex_put (const char *regex)
1096 1148
1097} 1149}
1098 1150
1151/**
1152 * Find a path to a peer that offers a regex servcie compatible
1153 * with a given string.
1154 *
1155 * @param key The key of the accepting state.
1156 * @param ctx Context containing info about the string, tunnel, etc.
1157 */
1158static void
1159regex_find_path (const struct GNUNET_HashCode *key,
1160 struct MeshRegexSearchContext *ctx)
1161{
1162 struct GNUNET_DHT_GetHandle *get_h;
1163
1164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n");
1165 get_h = GNUNET_DHT_get_start (dht_handle, /* handle */
1166 GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* type */
1167 key, /* key to search */
1168 DHT_REPLICATION_LEVEL, /* replication level */
1169 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
1170 GNUNET_DHT_RO_RECORD_ROUTE,
1171 NULL, /* xquery */ // FIXME BLOOMFILTER
1172 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
1173 &dht_get_string_accept_handler, ctx);
1174 GNUNET_break (GNUNET_OK ==
1175 GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles,
1176 key,
1177 get_h,
1178 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1179}
1180
1099 1181
1100/******************************************************************************/ 1182/******************************************************************************/
1101/************************ PERIODIC FUNCTIONS ****************************/ 1183/************************ PERIODIC FUNCTIONS ****************************/
@@ -4025,7 +4107,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
4025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a path ACK msg [%s]\n", 4107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a path ACK msg [%s]\n",
4026 GNUNET_i2s (&my_full_id)); 4108 GNUNET_i2s (&my_full_id));
4027 msg = (struct GNUNET_MESH_PathACK *) message; 4109 msg = (struct GNUNET_MESH_PathACK *) message;
4028 t = tunnel_get (&msg->oid, msg->tid); 4110 t = tunnel_get (&msg->oid, ntohl(msg->tid));
4029 if (NULL == t) 4111 if (NULL == t)
4030 { 4112 {
4031 /* TODO notify that we don't know the tunnel */ 4113 /* TODO notify that we don't know the tunnel */
@@ -4396,7 +4478,8 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
4396 const struct GNUNET_PeerIdentity *get_path, 4478 const struct GNUNET_PeerIdentity *get_path,
4397 unsigned int get_path_length, 4479 unsigned int get_path_length,
4398 const struct GNUNET_PeerIdentity *put_path, 4480 const struct GNUNET_PeerIdentity *put_path,
4399 unsigned int put_path_length, enum GNUNET_BLOCK_Type type, 4481 unsigned int put_path_length,
4482 enum GNUNET_BLOCK_Type type,
4400 size_t size, const void *data) 4483 size_t size, const void *data)
4401{ 4484{
4402 const struct MeshRegexAccept *block = data; 4485 const struct MeshRegexAccept *block = data;
@@ -4490,22 +4573,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp,
4490 { 4573 {
4491 if (GNUNET_YES == ntohl (block->accepting)) 4574 if (GNUNET_YES == ntohl (block->accepting))
4492 { 4575 {
4493 struct GNUNET_DHT_GetHandle *get_h; 4576 regex_find_path(key, ctx);
4494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n");
4495 get_h = GNUNET_DHT_get_start (dht_handle, /* handle */
4496 GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* type */
4497 key, /* key to search */
4498 DHT_REPLICATION_LEVEL, /* replication level */
4499 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
4500 GNUNET_DHT_RO_RECORD_ROUTE,
4501 NULL, /* xquery */ // FIXME BLOOMFILTER
4502 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
4503 &dht_get_string_accept_handler, ctx);
4504 GNUNET_break (GNUNET_OK ==
4505 GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles,
4506 key,
4507 get_h,
4508 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
4509 } 4577 }
4510 else 4578 else
4511 { 4579 {