aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-07 15:50:44 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-07 15:50:44 +0000
commit375e1b742172911b41b1dd04c8c4efdb65caf408 (patch)
treebe457da2d75736d27bdaaa7f4707d50855fd56cf
parentab0702f90884738babca7948eb5310f633c612bc (diff)
downloadgnunet-375e1b742172911b41b1dd04c8c4efdb65caf408.tar.gz
gnunet-375e1b742172911b41b1dd04c8c4efdb65caf408.zip
-shortening in cli app (in progress)
-rw-r--r--src/gns/Makefile.am19
-rw-r--r--src/gns/gns_api.c19
-rw-r--r--src/gns/gnunet-gns.c18
-rw-r--r--src/gns/gnunet-service-gns.c13
4 files changed, 43 insertions, 26 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 10d3cd1cf..bff08d33f 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -20,7 +20,8 @@ lib_LTLIBRARIES = \
20 20
21bin_PROGRAMS = \ 21bin_PROGRAMS = \
22 gnunet-service-gns \ 22 gnunet-service-gns \
23 gnunet-gns-fcfsd 23 gnunet-gns-fcfsd \
24 gnunet-gns
24 25
25#noinst_PROGRAMS = \ 26#noinst_PROGRAMS = \
26# gnunet-gns-lookup 27# gnunet-gns-lookup
@@ -80,14 +81,14 @@ test_gns_dht_delegated_lookup_DEPENDENCIES = \
80 $(top_builddir)/src/dht/libgnunetdht.la \ 81 $(top_builddir)/src/dht/libgnunetdht.la \
81 $(top_builddir)/src/testing/libgnunettesting.la 82 $(top_builddir)/src/testing/libgnunettesting.la
82 83
83#gnunet_gns_lookup_SOURCES = \ 84gnunet_gns_SOURCES = \
84# gnunet-gns-lookup.c 85 gnunet-gns.c
85#gnunet_gns_lookup_LDADD = \ 86gnunet_gns_LDADD = \
86# $(top_builddir)/src/gns/libgnunetgns.la \ 87 $(top_builddir)/src/gns/libgnunetgns.la \
87# $(top_builddir)/src/util/libgnunetutil.la \ 88 $(top_builddir)/src/util/libgnunetutil.la \
88# $(GN_LIBINTL) 89 $(GN_LIBINTL)
89#gnunet_dns_lookup_DEPENDENCIES = \ 90gnunet_gns_DEPENDENCIES = \
90# libgnunetgns.la 91 libgnunetgns.la
91 92
92gnunet_service_gns_SOURCES = \ 93gnunet_service_gns_SOURCES = \
93 gnunet-service-gns.c 94 gnunet-service-gns.c
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index a1cd190de..104423c32 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -496,7 +496,7 @@ process_shorten_reply (void *cls, const GNUNET_HashCode * key, void *value)
496{ 496{
497 const struct GNUNET_GNS_ClientShortenResultMessage *gns_msg = cls; 497 const struct GNUNET_GNS_ClientShortenResultMessage *gns_msg = cls;
498 struct GNUNET_GNS_ShortenHandle *shorten_handle = value; 498 struct GNUNET_GNS_ShortenHandle *shorten_handle = value;
499 const char *name = (const char*) &shorten_handle[1]; 499 const char *name = (const char*)&((struct GNUNET_GNS_ClientShortenMessage *) &((shorten_handle->message)[1]))[1]; //FIXME
500 const char *short_name; 500 const char *short_name;
501 501
502 if (ntohs (((struct GNUNET_MessageHeader*)gns_msg)->size) < 502 if (ntohs (((struct GNUNET_MessageHeader*)gns_msg)->size) <
@@ -599,7 +599,9 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
599 struct GNUNET_GNS_Handle *handle = cls; 599 struct GNUNET_GNS_Handle *handle = cls;
600 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; 600 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
601 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; 601 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
602 602
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
604 "Got message\n");
603 if (msg == NULL) 605 if (msg == NULL)
604 { 606 {
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -610,6 +612,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
610 612
611 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT) 613 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT)
612 { 614 {
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Got lookup msg\n");
613 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg; 617 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
614 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_lookup_requests, 618 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_lookup_requests,
615 &lookup_msg->key, 619 &lookup_msg->key,
@@ -618,6 +622,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
618 } 622 }
619 else if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT) 623 else if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT)
620 { 624 {
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
626 "Got shorten msg\n");
621 shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg; 627 shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg;
622 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_shorten_requests, 628 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_shorten_requests,
623 &shorten_msg->key, 629 &shorten_msg->key,
@@ -642,8 +648,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
642 * @return handle to the GNS service, or NULL on error 648 * @return handle to the GNS service, or NULL on error
643 */ 649 */
644struct GNUNET_GNS_Handle * 650struct GNUNET_GNS_Handle *
645GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 651GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
646 unsigned int ht_len)
647{ 652{
648 struct GNUNET_GNS_Handle *handle; 653 struct GNUNET_GNS_Handle *handle;
649 654
@@ -652,9 +657,9 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
652 handle->uid_gen = 657 handle->uid_gen =
653 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 658 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
654 handle->active_lookup_requests = 659 handle->active_lookup_requests =
655 GNUNET_CONTAINER_multihashmap_create (ht_len); 660 GNUNET_CONTAINER_multihashmap_create (5);
656 handle->active_shorten_requests = 661 handle->active_shorten_requests =
657 GNUNET_CONTAINER_multihashmap_create (ht_len); 662 GNUNET_CONTAINER_multihashmap_create (5);
658 if (GNUNET_NO == try_connect (handle)) 663 if (GNUNET_NO == try_connect (handle))
659 { 664 {
660 GNUNET_GNS_disconnect (handle); 665 GNUNET_GNS_disconnect (handle);
@@ -790,7 +795,7 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
790 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, 795 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
791 pending); 796 pending);
792 pending->in_pending_queue = GNUNET_YES; 797 pending->in_pending_queue = GNUNET_YES;
793 shorten_handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupHandle)); 798 shorten_handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_ShortenHandle));
794 shorten_handle->proc = proc; 799 shorten_handle->proc = proc;
795 shorten_handle->proc_cls = proc_cls; 800 shorten_handle->proc_cls = proc_cls;
796 shorten_handle->message = pending; 801 shorten_handle->message = pending;
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 3fdd8d29f..6a9241897 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -39,7 +39,7 @@ static struct GNUNET_GNS_Handle *gns;
39/** 39/**
40 * GNS name to shorten. (-s option) 40 * GNS name to shorten. (-s option)
41 */ 41 */
42static struct char *name; 42static char *name;
43 43
44/** 44/**
45 * Task run on shutdown. Cleans up everything. 45 * Task run on shutdown. Cleans up everything.
@@ -59,6 +59,12 @@ do_shutdown (void *cls,
59} 59}
60 60
61 61
62static void
63process_shorten_result(void* cls, const char* nlong, const char* nshort)
64{
65 printf("%s shortened to %s\n", nlong, nshort);
66}
67
62/** 68/**
63 * Main function that will be run. 69 * Main function that will be run.
64 * 70 *
@@ -78,11 +84,13 @@ run (void *cls, char *const *args, const char *cfgfile,
78 _("Failed to connect to GNS\n")); 84 _("Failed to connect to GNS\n"));
79 return; 85 return;
80 } 86 }
81 if (NULL == s) 87
88 if (name != NULL)
82 { 89 {
83 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 90 /** shorten name */
84 return; 91 GNUNET_GNS_shorten(gns, name, &process_shorten_result, NULL);
85 } 92 }
93
86 // FIXME: do work here... 94 // FIXME: do work here...
87 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 95 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
88} 96}
@@ -100,7 +108,7 @@ main (int argc, char *const *argv)
100{ 108{
101 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 109 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
102 {'s', "shorten", NULL, 110 {'s', "shorten", NULL,
103 gettext_noop ("try to shorten a given GNS name"), 0, 111 gettext_noop ("try to shorten a given GNS name"), 1,
104 &GNUNET_GETOPT_set_string, &name}, 112 &GNUNET_GETOPT_set_string, &name},
105 GNUNET_GETOPT_OPTION_END 113 GNUNET_GETOPT_OPTION_END
106 }; 114 };
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 18bcc5c3e..5bd64c484 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -1969,19 +1969,19 @@ send_shorten_response(const char* name, struct ClientShortenHandle *csh)
1969 rmsg->key = csh->key; 1969 rmsg->key = csh->key;
1970 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); 1970 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
1971 rmsg->header.size = 1971 rmsg->header.size =
1972 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage *) + 1972 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
1973 strlen(name)); 1973 strlen(name));
1974 1974
1975 strcpy((char*)&rmsg[1], name); 1975 strcpy((char*)&rmsg[1], name);
1976 1976
1977 GNUNET_SERVER_notification_context_unicast (nc, csh->client, 1977 GNUNET_SERVER_notification_context_unicast (nc, csh->client,
1978 (const struct GNUNET_MessageHeader *) &rmsg, 1978 (const struct GNUNET_MessageHeader *) rmsg,
1979 GNUNET_NO); 1979 GNUNET_NO);
1980 1980
1981 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); 1981 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
1982 1982
1983 GNUNET_free(csh); 1983 //GNUNET_free(csh);
1984 GNUNET_free(rmsg); 1984 //GNUNET_free(rmsg);
1985 1985
1986} 1986}
1987 1987
@@ -2001,13 +2001,16 @@ static void handle_shorten(void *cls,
2001 size_t msg_size = 0; 2001 size_t msg_size = 0;
2002 struct ClientShortenHandle *csh; 2002 struct ClientShortenHandle *csh;
2003 2003
2004 if (ntohs (message->size) != sizeof (struct GNUNET_GNS_ClientShortenMessage)) 2004 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
2005 { 2005 {
2006 GNUNET_break_op (0); 2006 GNUNET_break_op (0);
2007 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2007 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2008 return; 2008 return;
2009 } 2009 }
2010 2010
2011 GNUNET_SERVER_notification_context_add (nc, client);
2012 GNUNET_SERVER_client_keep (client);
2013
2011 struct GNUNET_GNS_ClientShortenMessage *sh_msg = 2014 struct GNUNET_GNS_ClientShortenMessage *sh_msg =
2012 (struct GNUNET_GNS_ClientShortenMessage *) message; 2015 (struct GNUNET_GNS_ClientShortenMessage *) message;
2013 2016