gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28740 - msh/src


From: gnunet
Subject: [GNUnet-SVN] r28740 - msh/src
Date: Wed, 21 Aug 2013 11:55:11 +0200

Author: harsha
Date: 2013-08-21 11:55:11 +0200 (Wed, 21 Aug 2013)
New Revision: 28740

Modified:
   msh/src/addressmap.c
   msh/src/addressmap.h
   msh/src/common.h
   msh/src/mshd.c
Log:
write to a temporary hosts file


Modified: msh/src/addressmap.c
===================================================================
--- msh/src/addressmap.c        2013-08-21 09:53:53 UTC (rev 28739)
+++ msh/src/addressmap.c        2013-08-21 09:55:11 UTC (rev 28740)
@@ -584,6 +584,46 @@
 
 
 /**
+ * Function to print addresses of hosts which are running the instances
+ *
+ * @param m the address map
+ * @param fn file name
+ * @param GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
+int
+addressmap_write_hosts (AddressMap *m, const char *fn)
+{
+  struct InstanceAddrInfo *iainfo;
+  struct InstanceAddr *iaddr;
+  unsigned int cnt;
+  int ret;
+  FILE *fout;
+
+  ret = GNUNET_SYSERR;
+  fout = fopen (fn, "w+");
+  if (NULL == fout)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fopen");
+    return ret;
+  }
+  for (cnt = 0; cnt < m->size; cnt++)
+  {
+    iainfo = m->map[cnt];
+    GNUNET_assert (NULL != iainfo);
+    iaddr = iainfo->addr_head;
+    if (0 > fprintf (fout, "%s\n", ip2str (iaddr->ip)))
+      goto clo_ret;
+  }
+  (void) fflush (fout);
+  ret = GNUNET_OK;
+  
+ clo_ret:
+  (void) fclose (fout);
+  return ret;
+}
+
+
+/**
  * Handle for reverse mapping from IP addresses to instance addresses
  */
 struct ReverseAddressMap

Modified: msh/src/addressmap.h
===================================================================
--- msh/src/addressmap.h        2013-08-21 09:53:53 UTC (rev 28739)
+++ msh/src/addressmap.h        2013-08-21 09:55:11 UTC (rev 28740)
@@ -264,6 +264,17 @@
 
 
 /**
+ * Function to print addresses of hosts which are running the instances
+ *
+ * @param m the address map
+ * @param fn file name
+ * @param GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
+int
+addressmap_write_hosts (AddressMap *m, const char *fn);
+
+
+/**
  * Handle for reverse mapping from IP addresses to instance addresses
  */
 struct ReverseAddressMap;

Modified: msh/src/common.h
===================================================================
--- msh/src/common.h    2013-08-21 09:53:53 UTC (rev 28739)
+++ msh/src/common.h    2013-08-21 09:55:11 UTC (rev 28740)
@@ -24,8 +24,18 @@
   } while (0)
 
 
+/**
+ * Environmental variable determining the UNIX domain socket used for
+ * communication between MSH and local MSHD processes
+ */
 #define MSHD_SOCK_NAME "MSHD_SOCK"
 
+/**
+ * Environmental variable determining the file where the addresses of available
+ * hosts are written to
+ */
+#define MSHD_HOSTSFILE "MP_SAVEHOSTSFILE"
+
 #endif /* COMMON_H_ */
 
 /* End of common.h */

Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c      2013-08-21 09:53:53 UTC (rev 28739)
+++ msh/src/mshd.c      2013-08-21 09:55:11 UTC (rev 28740)
@@ -239,6 +239,11 @@
 static char *unixpath;
 
 /**
+ * The file where the addresses of available hosts are written to
+ */
+static char *hostsfile;
+
+/**
  * shutdown task
  */
 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
@@ -465,14 +470,21 @@
   addressmap_print (addrmap);
   listen_mode = LISTEN_MODE_SERV;
   rmap = addressmap_create_reverse_mapping (addrmap);
+  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 
+                                                &do_shutdown, NULL);
   pid = (intmax_t) getpid ();
   GNUNET_assert (0 < asprintf (&unixpath, "%ju.sock", pid));
   setenv (MSHD_SOCK_NAME, unixpath, 1);
+  hostsfile = GNUNET_DISK_mktemp ("MSHD_HOSTS");
+  if (GNUNET_OK != addressmap_write_hosts (addrmap, hostsfile))
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  setenv (MSHD_HOSTSFILE, hostsfile, 1);
   init_local_server (unixpath);
   init_daemon_server ();
   MSH_pmonitor_init ();
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 
-                                                &do_shutdown, NULL);
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == atask);
   atask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                            listen_socket, &accept_task, NULL);
@@ -1096,6 +1108,11 @@
   if (NULL != run_args)
     free_argv (run_args);
   GNUNET_free_non_null (unixpath);
+  if (NULL != hostsfile)
+  {
+    (void) unlink (hostsfile);
+    GNUNET_free (hostsfile);
+  }
   LOG_DEBUG ("Returning\n");
   GNUNET_break (MPI_SUCCESS == MPI_Finalize());
   return ret;




reply via email to

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