[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27728 - in msh: . src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27728 - in msh: . src |
Date: |
Tue, 2 Jul 2013 20:21:57 +0200 |
Author: harsha
Date: 2013-07-02 20:21:57 +0200 (Tue, 02 Jul 2013)
New Revision: 27728
Added:
msh/src/mtypes.h
Modified:
msh/configure.ac
msh/src/common.h
msh/src/mshd.c
Log:
- save before switching to libevent
Modified: msh/configure.ac
===================================================================
--- msh/configure.ac 2013-07-02 15:08:37 UTC (rev 27727)
+++ msh/configure.ac 2013-07-02 18:21:57 UTC (rev 27728)
@@ -15,7 +15,7 @@
AC_CHECK_LIB([mpi],[MPI_Init],,[AC_MSG_ERROR([cannot find MPI libraries])])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h unistd.h mpi.h netinet/in.h net/if.h
ifaddrs.h \
-sys/socket.h sys/types.h error.h errno.h limits.h],,
+sys/socket.h sys/select.h sys/time.h sys/types.h error.h errno.h limits.h],,
[AC_MSG_ERROR([a required standard UNIX header is missing])])
# Checks for typedefs, structures, and compiler characteristics.
Modified: msh/src/common.h
===================================================================
--- msh/src/common.h 2013-07-02 15:08:37 UTC (rev 27727)
+++ msh/src/common.h 2013-07-02 18:21:57 UTC (rev 27728)
@@ -12,6 +12,8 @@
#include <errno.h>
#include <string.h>
+#include <sys/select.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -19,6 +21,9 @@
#include <ifaddrs.h>
#include <netdb.h>
+#include <unistd.h>
+
+
#define MSH_OK 1
#define MSH_SYSERR -1
@@ -53,3 +58,8 @@
* Use this for fatal errors that cannot be handled
*/
#define MSH_assert(cond) MSH_assert_at (cond, __FILE__, __LINE__)
+
+/**
+ * Free if the given pointer is not NULL
+ */
+#define MSH_free_non_null(ptr) do { if (NULL != (ptr)) free (ptr); } while(0)
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-07-02 15:08:37 UTC (rev 27727)
+++ msh/src/mshd.c 2013-07-02 18:21:57 UTC (rev 27728)
@@ -3,6 +3,11 @@
#include "util.h"
/**
+ * The port number of our local socket
+ */
+uint16_t lport;
+
+/**
* The number of total mshd processes
*/
static int nproc;
@@ -23,6 +28,77 @@
static unsigned int nips;
/**
+ * Current IP verification round
+ */
+static unsigned int round;
+
+/**
+ * width of the round -- how many other mshd instances verify our IP addresses
+ * in a round
+ */
+static unsigned int rwidth;
+
+
+/**
+ * Select loop for a socket
+ *
+ * @param sock the fd corresponding to the socket
+ * @param timeout the timeout in milliseconds
+ * @return MSH_OK upon succes; MSH_SYSERR upon failure
+ */
+static int
+sock_select (int sock, long timeout)
+{
+ struct sockaddr_in addr;
+ socklen_t addrlen;
+ struct timeval tv;
+ fd_set fdset;
+ int ret;
+ int nsock;
+ unsigned int cnt;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = timeout;
+ do {
+ FD_ZERO (&fdset);
+ FD_SET (sock, &fdset);
+ ret = select (sock+1, fdset, NULL, NULL, &tv);
+ if (-1 == ret)
+ {
+ switch (errno)
+ {
+ case EBADF:
+ MSH_assert (0);
+ case EINVAL:
+ MSH_assert (0);
+ case ENOMEM:
+ MSH_assert (0);
+ case EINTR:
+ return MSH_SYSERR;
+ default:
+ LOG_STRERROR ("select");
+ MSH_assert (0);
+ }
+ }
+ if (0 == ret)
+ break;
+ MSH_assert (FD_ISSET (sock, &fdset));
+ addrlen = sizeof (addr);
+ nsock = accept (sock, &addr, &addrlen);
+ if (nsock < 0)
+ {
+ LOG_STRERROR ("accept");
+ return MSH_SYSERR;
+ }
+ MSH_assert (sizeof (addr) == addrlen);
+ (void) close (nsock);
+
+ } while ()
+
+}
+
+
+/**
* Callback function invoked for each interface found.
*
* @param cls closure
@@ -54,6 +130,81 @@
}
+/**
+ * Verify IP addresses of all the hosts where mshd services are running
+ *
+ * @return MSH_OK if verification is successful; MSH_SYSERR upon error (an
error
+ * message is logged)
+ */
+static int
+verify_addresses ()
+{
+ struct sockaddr_in saddr;
+ socklen_t addrlen;
+ int sock;
+ unsigned int cnt;
+
+ /* open a listen socket */
+ sock = socket (AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
+ if (-1 == sock)
+ {
+ LOG_STRERROR ("socket");
+ return MSH_SYSERR;
+ }
+ addrlen = sizeof (struct sockaddr_in);
+ (void) memset (&saddr, 0, addrlen);
+ saddr.sin_family = AF_INET;
+ if (-1 == bind (sock, &saddr, addrlen))
+ {
+ LOG_STRERROR ("bind");
+ goto clo_ret;
+ }
+ if (-1 == getsockname (sock, &saddr, &addrlen))
+ {
+ LOG_STRERROR ("getsockname");
+ goto clo_ret;
+ }
+ if (sizeof (struct sockaddr_in) != addrlen)
+ {
+ MSH_break (0);
+ goto clo_ret;
+ }
+ lport = ntohs (saddr.sin_port);
+ if (0 == lport)
+ {
+ MSH_break (0);
+ goto clo_ret;
+ }
+ if (-1 == listen (sock, rwidth))
+ {
+ LOG_STRERROR ("listen");
+ goto clo_ret;
+ }
+ goto contd;
+
+ contd:
+ LOG_DEBUG ("Bound to local port %u\n", lport);
+ if (MPI_SUCCESS != MPI_Barrier (MPI_COMM_WORLD))
+ {
+ MSH_break (0);
+ goto clo_ret;
+ }
+ for (cnt = 0; cnt < rwidth; cnt++)
+ send_addresses ((round * rwidth) + cnt);
+ sock_select (sock, timeout);
+ if (MPI_SUCCESS != MPI_Barrier (MPI_COMM_WORLD))
+ {
+ MSH_break (0);
+ goto clo_ret;
+ }
+ return MSH_OK;
+
+ clo_ret:
+ (void) close (sock);
+ return MSH_SYSERR;
+}
+
+
int
main (int argc, char **argv)
{
@@ -75,8 +226,12 @@
GNUNET_OS_network_interfaces_list (&net_if_processor, NULL);
if (0 == nips)
LOG_ERROR ("No IP addresses found\n");
+ for (; rount < nproc; round++)
+ if (MSH_OK != verify_addresses ())
+ goto fail;
fail:
MSH_break (MPI_SUCCESS == MPI_Finalize());
+ MSH_free_non_null (ip_addr_str);
return 1;
}
Added: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h (rev 0)
+++ msh/src/mtypes.h 2013-07-02 18:21:57 UTC (rev 27728)
@@ -0,0 +1,72 @@
+#include "common.h"
+
+
+/**
+ * gcc-ism to get packed structs. This won't work on W32 but then do we use
W32
+ * for HPC? ;)
+ */
+#define MSH_PACKED __attribute__((packed))
+
+/**
+ * Message header that will be included for all messages
+ */
+struct MSH_MessageHeader
+{
+ /**
+ * The size of the message
+ */
+ uint16_t size MSH_PACKED;
+};
+
+struct MSH_MSG_VerifyAddress
+{
+ /**
+ * Message header
+ */
+ struct MSH_MessageHeader header;
+
+ /**
+ * Randomly chosen port number
+ */
+ uint16_t port MSH_PACKED;
+
+ /**
+ * Number of IP addresses
+ */
+ uint16_t nips MSH_PACKED;
+
+ /**
+ * IPv4 addresses to follow as 32 bit unsigned integeters
+ */
+#if 0
+ /* Internet address. */
+ typedef uint32_t in_addr_t;
+ struct in_addr
+ {
+ in_addr_t s_addr;
+ };
+ /* Structure describing an Internet socket address. */
+ struct sockaddr_in
+ {
+ __SOCKADDR_COMMON (sin_);
+ in_port_t sin_port; /* Port number. */
+ struct in_addr sin_addr; /* Internet address. */
+
+ /* Pad to size of `struct sockaddr'. */
+ unsigned char sin_zero[sizeof (struct sockaddr) -
+ __SOCKADDR_COMMON_SIZE -
+ sizeof (in_port_t) -
+ sizeof (struct in_addr)];
+ };
+#endif
+}
+
+
+/*********************************************************************
+ * MPI tag numbers for each message type
+ *********************************************************************/
+
+#define MSH_MTYPE_VERIFY_ADDRESSES 100
+
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27728 - in msh: . src,
gnunet <=