aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 15:54:30 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 15:54:30 +0000
commit810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d (patch)
treee6950609e302c8cee5dd49cd75a890e660dde02a /src/gns/gnunet-service-gns.c
parent16f524720ce08aadb35912731217eaeafc690dba (diff)
downloadgnunet-810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d.tar.gz
gnunet-810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d.zip
- Add reverse resolution with limited functionality
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c89
1 files changed, 87 insertions, 2 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 386e6d744..221d75bba 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -35,6 +35,7 @@
35#include "gnunet_statistics_service.h" 35#include "gnunet_statistics_service.h"
36#include "gns.h" 36#include "gns.h"
37#include "gnunet-service-gns_resolver.h" 37#include "gnunet-service-gns_resolver.h"
38#include "gnunet-service-gns_reverser.h"
38#include "gnunet-service-gns_shorten.h" 39#include "gnunet-service-gns_shorten.h"
39#include "gnunet-service-gns_interceptor.h" 40#include "gnunet-service-gns_interceptor.h"
40#include "gnunet_protocols.h" 41#include "gnunet_protocols.h"
@@ -109,6 +110,11 @@ struct ClientLookupHandle
109 struct GNS_ResolverHandle *lookup; 110 struct GNS_ResolverHandle *lookup;
110 111
111 /** 112 /**
113 * Active handle for a reverse lookup
114 */
115 struct GNS_ReverserHandle *rev_lookup;
116
117 /**
112 * request id 118 * request id
113 */ 119 */
114 uint32_t request_id; 120 uint32_t request_id;
@@ -367,7 +373,10 @@ client_disconnect_cb (void *cls,
367 client); 373 client);
368 while (NULL != (clh = gc->clh_head)) 374 while (NULL != (clh = gc->clh_head))
369 { 375 {
370 GNS_resolver_lookup_cancel (clh->lookup); 376 if (NULL != clh->lookup)
377 GNS_resolver_lookup_cancel (clh->lookup);
378 if (NULL != clh->rev_lookup)
379 GNS_reverse_lookup_cancel (clh->rev_lookup);
371 GNUNET_CONTAINER_DLL_remove (gc->clh_head, 380 GNUNET_CONTAINER_DLL_remove (gc->clh_head,
372 gc->clh_tail, 381 gc->clh_tail,
373 clh); 382 clh);
@@ -846,6 +855,47 @@ send_lookup_response (void* cls,
846 GNUNET_NO); 855 GNUNET_NO);
847} 856}
848 857
858/**
859 * Reply to client with the result from our reverse lookup.
860 *
861 * @param cls the closure (our client lookup handle)
862 * @param rd_count the number of records in @a rd
863 * @param rd the record data
864 */
865static void
866send_reverse_lookup_response (void* cls,
867 const char *name)
868{
869 struct ClientLookupHandle *clh = cls;
870 struct GNUNET_MQ_Envelope *env;
871 struct ReverseLookupResultMessage *rmsg;
872 size_t len;
873
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
875 "Sending LOOKUP_RESULT message with %s\n",
876 name);
877
878 if (NULL == name)
879 len = 1;
880 else
881 len = strlen (name) + 1;
882 env = GNUNET_MQ_msg_extra (rmsg,
883 len,
884 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT);
885 rmsg->id = clh->request_id;
886 if (1 < len)
887 GNUNET_memcpy ((char*) &rmsg[1],
888 name,
889 strlen (name));
890 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client),
891 env);
892 GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head, clh->gc->clh_tail, clh);
893 GNUNET_free (clh);
894 GNUNET_STATISTICS_update (statistics,
895 "Completed reverse lookups", 1,
896 GNUNET_NO);
897}
898
849 899
850/** 900/**
851 * Checks a #GNUNET_MESSAGE_TYPE_GNS_LOOKUP message 901 * Checks a #GNUNET_MESSAGE_TYPE_GNS_LOOKUP message
@@ -856,7 +906,7 @@ send_lookup_response (void* cls,
856 */ 906 */
857static int 907static int
858check_lookup (void *cls, 908check_lookup (void *cls,
859 const struct LookupMessage *l_msg) 909 const struct LookupMessage *l_msg)
860{ 910{
861 size_t msg_size; 911 size_t msg_size;
862 const char* name; 912 const char* name;
@@ -936,6 +986,37 @@ handle_lookup (void *cls,
936 1, GNUNET_NO); 986 1, GNUNET_NO);
937} 987}
938 988
989/**
990 * Handle reverse lookup requests from client
991 *
992 * @param cls the closure
993 * @param client the client
994 * @param message the message
995 */
996static void
997handle_rev_lookup (void *cls,
998 const struct ReverseLookupMessage *sh_msg)
999{
1000 struct GnsClient *gc = cls;
1001 struct ClientLookupHandle *clh;
1002
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1004 "Received REVERSE_LOOKUP message\n");
1005 GNUNET_SERVICE_client_continue (gc->client);
1006
1007 clh = GNUNET_new (struct ClientLookupHandle);
1008 GNUNET_CONTAINER_DLL_insert (gc->clh_head, gc->clh_tail, clh);
1009 clh->gc = gc;
1010 clh->request_id = sh_msg->id;
1011 clh->rev_lookup = GNS_reverse_lookup (&sh_msg->zone_pkey,
1012 &sh_msg->root_pkey,
1013 &send_reverse_lookup_response,
1014 clh);
1015 GNUNET_STATISTICS_update (statistics,
1016 "Reverse lookup attempts",
1017 1, GNUNET_NO);
1018}
1019
939 1020
940/** 1021/**
941 * The zone monitor is now in SYNC with the current state of the 1022 * The zone monitor is now in SYNC with the current state of the
@@ -1149,6 +1230,10 @@ GNUNET_SERVICE_MAIN
1149 GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 1230 GNUNET_MESSAGE_TYPE_GNS_LOOKUP,
1150 struct LookupMessage, 1231 struct LookupMessage,
1151 NULL), 1232 NULL),
1233 GNUNET_MQ_hd_fixed_size (rev_lookup,
1234 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP,
1235 struct ReverseLookupMessage,
1236 NULL),
1152 GNUNET_MQ_handler_end()); 1237 GNUNET_MQ_handler_end());
1153 1238
1154 1239