gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10856 - gnunet/src/hostlist


From: gnunet
Subject: [GNUnet-SVN] r10856 - gnunet/src/hostlist
Date: Fri, 9 Apr 2010 13:57:20 +0200

Author: wachs
Date: 2010-04-09 13:57:20 +0200 (Fri, 09 Apr 2010)
New Revision: 10856

Added:
   gnunet/src/hostlist/gnunet-daemon-hostlist.h
Modified:
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/hostlist/hostlist-server.c
   gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
Log:


Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-04-09 11:53:26 UTC 
(rev 10855)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-04-09 11:57:20 UTC 
(rev 10856)
@@ -42,8 +42,6 @@
 #include "gnunet_time_lib.h"
 #include "gnunet_util_lib.h"
 
-#define DEBUG_HOSTLIST GNUNET_YES
-
 /**
  * Set if we are allowed to advertise our hostlist to others.
  */
@@ -120,7 +118,32 @@
   GNUNET_GETOPT_OPTION_END
 };
 
+/**
+ * A HOSTLIST_ADV message is used to exchange information about
+ * hostlist advertisements.  This struct is always
+ * followed by the actual url under which the hostlist can be obtained:
+ *
+ * 1) transport-name (0-terminated)
+ * 2) address-length (uint32_t, network byte order; possibly
+ *    unaligned!)
+ * 3) address expiration (GNUNET_TIME_AbsoluteNBO); possibly
+ *    unaligned!)
+ * 4) address (address-length bytes; possibly unaligned!)
+ */
+struct GNUNET_HOSTLIST_ADV_Message
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT.
+   */
+  struct GNUNET_MessageHeader header;
 
+  /**
+   * Always zero (for alignment).
+   */
+  uint32_t reserved GNUNET_PACKED;
+};
+
+
 static void
 core_init (void *cls,
           struct GNUNET_CORE_Handle * server,

Added: gnunet/src/hostlist/gnunet-daemon-hostlist.h
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.h                                
(rev 0)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.h        2010-04-09 11:57:20 UTC 
(rev 10856)
@@ -0,0 +1,70 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file hostlist/gnunet-daemon-hostlist.h
+ * @brief common internal definitions for hostlist daemon
+ * @author Matthias Wachs
+ */
+#include <stdlib.h>
+#include "platform.h"
+#include "hostlist-client.h"
+#include "hostlist-server.h"
+#include "gnunet_core_service.h"
+#include "gnunet_getopt_lib.h"
+#include "gnunet_protocols.h"
+#include "gnunet_program_lib.h"
+#include "gnunet_statistics_service.h"
+#include "gnunet_strings_lib.h"
+#include "gnunet_time_lib.h"
+#include "gnunet_util_lib.h"
+
+/**
+ * General hostlist daemon debugging.
+ */
+#define DEBUG_HOSTLIST GNUNET_NO
+
+/**
+ * A HOSTLIST_ADV message is used to exchange information about
+ * hostlist advertisements.  This struct is always
+ * followed by the actual url under which the hostlist can be obtained:
+ *
+ * 1) transport-name (0-terminated)
+ * 2) address-length (uint32_t, network byte order; possibly
+ *    unaligned!)
+ * 3) address expiration (GNUNET_TIME_AbsoluteNBO); possibly
+ *    unaligned!)
+ * 4) address (address-length bytes; possibly unaligned!)
+ */
+struct GNUNET_HOSTLIST_ADV_Message
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT.
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Always zero (for alignment).
+   */
+  uint32_t reserved GNUNET_PACKED;
+};
+
+
+/* end of gnunet-daemon-hostlist.h */


Property changes on: gnunet/src/hostlist/gnunet-daemon-hostlist.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2010-04-09 11:53:26 UTC (rev 
10855)
+++ gnunet/src/hostlist/hostlist-server.c       2010-04-09 11:57:20 UTC (rev 
10856)
@@ -29,6 +29,8 @@
 #include "hostlist-server.h"
 #include "gnunet_hello_lib.h"
 #include "gnunet_peerinfo_service.h"
+#include "gnunet-daemon-hostlist.h"
+#include "gnunet_resolver_service.h"
 
 #define DEBUG_HOSTLIST_SERVER GNUNET_NO
 
@@ -97,7 +99,6 @@
   char *data;
 };
 
-
 /**
  * Task that will produce a new response object.
  */
@@ -105,7 +106,47 @@
 update_response (void *cls,
                 const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+/**
+ * Function that assembles our hostlist adv message.
+ */
+static int
+create_hostlist_adv_message (void)
+{
+  int length  = 0;
+  unsigned long long port;
 
+  char *uri;
+  char hostname[HOST_NAME_MAX];
+  char *protocol = "http://";;
+  char *port_s = malloc(6 * sizeof(char));
+
+  if (0 != gethostname (hostname, sizeof (hostname) - 1))
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+        "Could not get system's hostname, unable to create advertisement 
message");
+    return GNUNET_NO;
+  }
+  if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
+                                                   "HOSTLIST",
+                                                   "HTTPPORT",
+                                                   &port))
+    return GNUNET_SYSERR;
+
+  sprintf(port_s, "%llu", port);
+  length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2;
+
+  uri = malloc(length * sizeof(char));
+  uri = strcpy(uri, protocol);
+  uri = strcat(uri, hostname);
+  uri = strcat(uri, ":");
+  uri = strcat(uri, port_s);
+  uri = strcat(uri, "/");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri);
+
+
+  return GNUNET_OK;
+}
+
 /**
  * Function that assembles our response.
  */
@@ -113,27 +154,27 @@
 finish_response (struct HostSet *results)
 {
   struct GNUNET_TIME_Relative freq;
-  
+
   if (response != NULL)
     MHD_destroy_response (response);
 #if DEBUG_HOSTLIST_SERVER
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Creating hostlist response with %u bytes\n",
-             (unsigned int) results->size);
+              "Creating hostlist response with %u bytes\n",
+              (unsigned int) results->size);
 #endif
   response = MHD_create_response_from_data (results->size,
                                             results->data, MHD_YES, MHD_NO);
   if ( (daemon_handle_v4 != NULL) ||
-       (daemon_handle_v6 != NULL) )    
+       (daemon_handle_v6 != NULL) )
     {
       freq = RESPONSE_UPDATE_FREQUENCY;
       if (results->size == 0)
-       freq = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 
250);
-      /* schedule next update of the response */  
+        freq = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 
250);
+      /* schedule next update of the response */
       response_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                   freq,
-                                                   &update_response,
-                                                   NULL);
+                                                    freq,
+                                                    &update_response,
+                                                    NULL);
     }
   else
     {
@@ -142,9 +183,9 @@
       response = NULL;
     }
   GNUNET_STATISTICS_set (stats,
-                        gettext_noop("bytes in hostlist"),
-                        results->size,
-                        GNUNET_YES);
+                         gettext_noop("bytes in hostlist"),
+                         results->size,
+                         GNUNET_YES);
   GNUNET_free (results);
 }
 
@@ -366,6 +407,9 @@
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "A new peer connected to the server, preparing to send hostlist 
advertisement\n");
+  /* create a new advertisement message */
+  create_hostlist_adv_message();
+
 }
 
 

Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c  2010-04-09 
11:53:26 UTC (rev 10855)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c  2010-04-09 
11:57:20 UTC (rev 10856)
@@ -108,6 +108,7 @@
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Peers connected, shutting down.\n");
+  /*
   ok = 0;
   if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
     {
@@ -117,6 +118,7 @@
     }
   GNUNET_SCHEDULER_add_now (sched,
                            &clean_up, NULL);
+                           */
 }
 
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]