X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmesh%2Fgnunet-service-mesh.c;h=dba4116cf4df036e27ea3c88b6a720c15fba64f5;hb=f4d040c0f0dd2fef3d73b1f4532c76219f760f75;hp=52eb89eb238fafd64be167fb54174ae15c8d2636;hpb=5c3ed7bd316e53dbc47a44f7d8e5fc1937ad11bc;p=oweals%2Fgnunet.git diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 52eb89eb2..dba4116cf 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -170,6 +170,22 @@ struct MeshPeerQueue }; +/** + * Struct to store regex information announced by clients. + */ +struct MeshRegexDescriptor +{ + /** + * Regular expression itself. + */ + char *regex; + + /** + * How many characters per edge can we squeeze? + */ + uint16_t compression; +}; + /** * Struct containing all info possibly needed to build a package when called * back by core. @@ -691,7 +707,7 @@ struct MeshClient /** * Regular expressions describing the services offered by this client. */ - char **regexes; // FIXME add timeout? API to remove a regex? + struct MeshRegexDescriptor *regexes; // FIXME regex add timeout? API to remove a regex? /** * Number of regular expressions in regexes. @@ -1586,12 +1602,14 @@ regex_iterator (void *cls, * @param regex The regular expresion. */ static void -regex_put (const char *regex) +regex_put (const struct MeshRegexDescriptor *regex) { struct GNUNET_REGEX_Automaton *dfa; - DEBUG_DHT (" regex_put (%s) start\n", regex); - dfa = GNUNET_REGEX_construct_dfa (regex, strlen(regex)); + DEBUG_DHT (" regex_put (%s) start\n", regex->regex); + dfa = GNUNET_REGEX_construct_dfa (regex->regex, + strlen(regex->regex), + regex->compression); GNUNET_REGEX_iterate_all_edges (dfa, ®ex_iterator, NULL); GNUNET_REGEX_automaton_destroy (dfa); DEBUG_DHT (" regex_put (%s) end\n", regex); @@ -1785,7 +1803,7 @@ announce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) for (i = 0; i < c->n_regex; i++) { - regex_put (c->regexes[i]); + regex_put (&c->regexes[i]); } c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_regex, @@ -6526,6 +6544,8 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n"); return; } + + return; c = clients; while (NULL != c) { @@ -6567,7 +6587,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) GNUNET_CONTAINER_multihashmap_destroy (c->types); for (i = 0; i < c->n_regex; i++) { - GNUNET_free (c->regexes[i]); + GNUNET_free (c->regexes[i].regex); } GNUNET_free_non_null (c->regexes); if (GNUNET_SCHEDULER_NO_TASK != c->regex_announce_task) @@ -6695,6 +6715,8 @@ static void handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { + struct GNUNET_MESH_RegexAnnounce *msg; + struct MeshRegexDescriptor rd; struct MeshClient *c; char *regex; size_t len; @@ -6710,18 +6732,24 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); - len = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader); + msg = (struct GNUNET_MESH_RegexAnnounce *) message; + len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce); regex = GNUNET_malloc (len + 1); - memcpy (regex, &message[1], len); + memcpy (regex, &msg[1], len); regex[len] = '\0'; - GNUNET_array_append (c->regexes, c->n_regex, regex); + rd.regex = regex; + rd.compression = ntohs (msg->compression_characters); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " length %u\n", len); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " cm %u\n", ntohs(rd.compression)); + GNUNET_array_append (c->regexes, c->n_regex, rd); if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task) { c->regex_announce_task = GNUNET_SCHEDULER_add_now(&announce_regex, c); } else { - regex_put(regex); + regex_put(&rd); } GNUNET_SERVER_receive_done (client, GNUNET_OK); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n"); @@ -7683,11 +7711,11 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } + clinfo->bck_pid++; /* Ok, everything is correct, send the message * (pretend we got it from a mesh peer) */ - clinfo->bck_pid++; { char buf[ntohs (message->size)] GNUNET_ALIGN; struct GNUNET_MESH_ToOrigin *copy; @@ -7698,15 +7726,8 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_PEER_resolve (t->id.oid, ©->oid); copy->tid = htonl (t->id.tid); copy->ttl = htonl (default_ttl); - if (ntohl (copy->pid) != (t->bck_pid + 1)) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "To Origin PID, expected %u, got %u\n", - t->bck_pid + 1, - ntohl (copy->pid)); - return; - } + copy->pid = htonl (++(t->bck_pid)); + copy->sender = my_full_id; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " calling generic handler...\n");