[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28197 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28197 - msh/src |
Date: |
Fri, 19 Jul 2013 15:26:00 +0200 |
Author: harsha
Date: 2013-07-19 15:26:00 +0200 (Fri, 19 Jul 2013)
New Revision: 28197
Modified:
msh/src/Makefile.am
msh/src/addressmap.c
msh/src/bitmap.c
msh/src/common.h
msh/src/mshd.c
msh/src/reduce.c
msh/src/scheduler.c
msh/src/test_addressmap.c
msh/src/test_bitmap.c
msh/src/test_scheduler.c
msh/src/test_scheduler_socket.c
msh/src/util.c
msh/src/util.h
Log:
- use gnunetutil
Modified: msh/src/Makefile.am
===================================================================
--- msh/src/Makefile.am 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/Makefile.am 2013-07-19 13:26:00 UTC (rev 28197)
@@ -4,7 +4,7 @@
mshd_SOURCES = mshd.c mshd.h util.c util.h scheduler.c scheduler.h \
common.h bitmap.c bitmap.h addressmap.c addressmap.h reduce.h reduce.c
-mshd_LDADD = -levent -lm
+mshd_LDADD = -lgnunetutil -levent -lm
mshd_CPPFLAGS = $(LIBEVENT_CPPFLAGS)
mshd_LDFLAGS = $(LIBEVENT_LDFLAGS)
@@ -16,19 +16,21 @@
test_scheduler_SOURCES = test_scheduler.c scheduler.c scheduler.h common.h \
util.c util.h common.h
-test_scheduler_LDADD = -levent
+test_scheduler_LDADD = -lgnunetutil -levent
test_scheduler_CPPFLAGS = $(LIBEVENT_CPPFLAGS)
test_scheduler_LDFLAGS = $(LIBEVENT_LDFLAGS)
test_scheduler_socket_SOURCES = test_scheduler_socket.c scheduler.c
scheduler.h \
common.h util.c util.h
-test_scheduler_socket_LDADD = -levent
+test_scheduler_socket_LDADD = -lgnunetutil -levent
test_scheduler_socket_CPPFLAGS = $(LIBEVENT_CPPFLAGS)
test_scheduler_socket_LDFLAGS = $(LIBEVENT_LDFLAGS)
test_bitmap_SOURCES = test_bitmap.c bitmap.c bitmap.h
+test_bitmap_LDADD = -lgnunetutil
test_addressmap_SOURCES = test_addressmap.c addressmap.c addressmap.h
+test_addressmap_LDADD = -lgnunetutil
TESTS = \
test-scheduler \
Modified: msh/src/addressmap.c
===================================================================
--- msh/src/addressmap.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/addressmap.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -5,11 +5,18 @@
*/
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include "util.h"
#include "addressmap.h"
#include "mtypes.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__)
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
/**
* An address of an instance
*/
@@ -83,7 +90,7 @@
{
struct InstanceAddr *iaddr;
- iaddr = MSH_malloc (sizeof (struct InstanceAddr));
+ iaddr = GNUNET_malloc (sizeof (struct InstanceAddr));
iaddr->port = port;
iaddr->ip = ip;
return iaddr;
@@ -113,7 +120,7 @@
{
struct InstanceAddrInfo *iainfo;
- iainfo = MSH_malloc (sizeof (struct InstanceAddrInfo));
+ iainfo = GNUNET_malloc (sizeof (struct InstanceAddrInfo));
iainfo->rank = rank;
return iainfo;
}
@@ -124,7 +131,7 @@
*
* @param iainfo the instance information object
* @param iaddr the address to add
- * @return MSH_OK if the instance address is added; MSH_NO if the given address
+ * @return GNUNET_OK if the instance address is added; GNUNET_NO if the given
address
* is already present (in this case the address object will not be
* added)
*/
@@ -138,7 +145,7 @@
while (NULL != addr)
{
if (instance_address_ip (iaddr) == instance_address_ip (addr))
- return MSH_NO;
+ return GNUNET_NO;
if (instance_address_ip (iaddr) < instance_address_ip (addr))
break;
addr = addr->next;
@@ -146,11 +153,11 @@
iainfo->naddrs++;
if (NULL == addr)
{
- DLL_insert_tail (iainfo->addr_head, iainfo->addr_tail, iaddr);
- return MSH_OK;
+ GNUNET_CONTAINER_DLL_insert_tail (iainfo->addr_head, iainfo->addr_tail,
iaddr);
+ return GNUNET_OK;
}
- DLL_insert_before (iainfo->addr_head, iainfo->addr_tail, addr, iaddr);
- return MSH_OK;
+ GNUNET_CONTAINER_DLL_insert_before (iainfo->addr_head, iainfo->addr_tail,
addr, iaddr);
+ return GNUNET_OK;
}
@@ -160,7 +167,7 @@
* @param iainfo the instance address info object
* @param cb the callback to call for each iterated address
* @param cls the closure for the above callback
- * @return MSH_OK if the iteration completed successfully; MSH_SYSERR if the
+ * @return GNUNET_OK if the iteration completed successfully; GNUNET_SYSERR if
the
* iteration was terminated
*/
int
@@ -171,15 +178,15 @@
{
struct InstanceAddr *iaddr;
- MSH_assert (NULL != cb);
+ GNUNET_assert (NULL != cb);
iaddr = iainfo->addr_head;
while (NULL != iaddr)
{
- if (MSH_OK != cb (cls, iaddr->port, iaddr->ip))
- return MSH_SYSERR;
+ if (GNUNET_OK != cb (cls, iaddr->port, iaddr->ip))
+ return GNUNET_SYSERR;
iaddr = iaddr->next;
}
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -210,7 +217,7 @@
while (NULL != (addr = iainfo->addr_head))
{
- DLL_remove (iainfo->addr_head, iainfo->addr_tail, addr);
+ GNUNET_CONTAINER_DLL_remove (iainfo->addr_head, iainfo->addr_tail, addr);
free (addr);
}
free (iainfo);
@@ -246,7 +253,7 @@
{
struct AddressMap *m;
- m = MSH_malloc (sizeof (struct AddressMap) + sizeof (struct InstanceAddrInfo
+ m = GNUNET_malloc (sizeof (struct AddressMap) + sizeof (struct
InstanceAddrInfo
*) * nproc);
m->size = nproc;
return m;
@@ -260,7 +267,7 @@
* @param rank the MPI rank of the instance whose address is being added
* @param port the port number through which the instance is reachable
* @param ip the IP address through which the instance is reachable
- * @return MSH_OK if the instance address is added; MSH_NO if the given address
+ * @return GNUNET_OK if the instance address is added; GNUNET_NO if the given
address
* is already present (in this case the address object will not be
* added)
*/
@@ -270,7 +277,7 @@
struct InstanceAddrInfo *iainfo;
struct InstanceAddr *iaddr;
- MSH_assert (rank < m->size);
+ GNUNET_assert (rank < m->size);
iainfo = m->map[rank];
if (NULL == iainfo)
{
@@ -278,12 +285,12 @@
iainfo = m->map[rank];
}
iaddr = instance_address_create_sockaddr_in (port, ip);
- if (MSH_NO == instance_address_info_add_address (iainfo, iaddr))
+ if (GNUNET_NO == instance_address_info_add_address (iainfo, iaddr))
{
instance_address_destroy (iaddr);
- return MSH_NO;
+ return GNUNET_NO;
}
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -293,7 +300,7 @@
*
* @param m the addressmap
* @param new the instance address information object
- * @return the number of addresses in common; MSH_SYSERR upon error
+ * @return the number of addresses in common; GNUNET_SYSERR upon error
*/
int
addressmap_intersect (AddressMap *m, struct InstanceAddrInfo *new)
@@ -306,12 +313,12 @@
unsigned int n;
rank = new->rank;
- MSH_assert (rank < m->size);
+ GNUNET_assert (rank < m->size);
old = m->map[rank];
if (NULL == old)
{
m->map[rank] = new;
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
}
old_ia = old->addr_head;
new_ia = new->addr_head;
@@ -322,9 +329,9 @@
|| (instance_address_ip (old_ia) < instance_address_ip (new_ia)) )
{
tmp = old_ia->next;
- DLL_remove (old->addr_head, old->addr_tail, old_ia);
+ GNUNET_CONTAINER_DLL_remove (old->addr_head, old->addr_tail, old_ia);
free (old_ia);
- MSH_assert (old->naddrs > 0);
+ GNUNET_assert (old->naddrs > 0);
old->naddrs--;
old_ia = tmp;
continue;
@@ -349,7 +356,7 @@
* @param m the address map
* @param cb the iterator callback
* @param cls the closure to pass to the iterator callback
- * @return MSH_OK to signify successful completion of the iteration; MSH_SYSERR
+ * @return GNUNET_OK to signify successful completion of the iteration;
GNUNET_SYSERR
* if the iteration was cancelled
*/
int
@@ -364,10 +371,10 @@
{
if (NULL == (iainfo = m->map[cnt]))
continue;
- if (MSH_SYSERR == cb (cls, iainfo))
- return MSH_SYSERR;
+ if (GNUNET_SYSERR == cb (cls, iainfo))
+ return GNUNET_SYSERR;
}
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -378,8 +385,8 @@
* @param rank the instance rank
* @param cb the iterator callback
* @param cls the closure for the callback
- * @return MSH_OK if the iteration was successfully completed; MSH_SYSERR if
the
- * iteration was aborted in the iteration callback; MSH_NO if no
+ * @return GNUNET_OK if the iteration was successfully completed;
GNUNET_SYSERR if the
+ * iteration was aborted in the iteration callback; GNUNET_NO if no
* addresses were found in the address map
*/
int
@@ -389,10 +396,10 @@
{
struct InstanceAddrInfo *iainfo;
- MSH_assert (rank < m->size);
+ GNUNET_assert (rank < m->size);
iainfo = m->map[rank];
if (NULL == iainfo)
- return MSH_NO;
+ return GNUNET_NO;
return instance_address_info_iterate_addresses (iainfo, cb, cls);
}
@@ -426,7 +433,7 @@
* @param iaddr_msgs instance addresses. The memory allocated for the instance
* address messages is to be freed by the caller after sending the
* messages
- * @return the number of message in iaddr_msgs; MSH_SYSERR upon failure (the
+ * @return the number of message in iaddr_msgs; GNUNET_SYSERR upon failure (the
* contents of iaddr_msgs are left unchanged)
*/
int
@@ -446,25 +453,25 @@
if (NULL == m->map[cnt])
{
LOG_ERROR ("Addresses for an instance is missing\n");
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
}
n++;
}
cnt = n;
- _iaddr_msgs = MSH_malloc (sizeof (struct MSH_MSG_InstanceAdresses *) * n);
+ _iaddr_msgs = GNUNET_malloc (sizeof (struct MSH_MSG_InstanceAdresses *) * n);
for (cnt = 0; cnt < m->size; cnt++)
{
- MSH_assert (NULL != (iainfo = m->map[cnt]));
+ GNUNET_assert (NULL != (iainfo = m->map[cnt]));
msize = sizeof (struct MSH_MSG_InstanceAdresses)
+ (sizeof (uint32_t) * iainfo->naddrs);
- _iaddr_msgs[cnt] = MSH_malloc (msize);
+ _iaddr_msgs[cnt] = GNUNET_malloc (msize);
_iaddr_msgs[cnt]->header.size = htons (msize);
_iaddr_msgs[cnt]->rank = htons (iainfo->rank);
_iaddr_msgs[cnt]->nips = htons (iainfo->naddrs);
iaddr = iainfo->addr_head;
for (nip = 0; nip < iainfo->naddrs; nip++, iaddr = iaddr->next)
{
- MSH_assert (NULL != iaddr);
+ GNUNET_assert (NULL != iaddr);
_iaddr_msgs[cnt]->ipaddrs[nip] = instance_address_ip (iaddr);
}
}
@@ -481,7 +488,7 @@
* @param iaddr_msg the message containing instance addresses
* @return the number of addresses present in the address map for this instance
* after intersecting with the addresses from the given messager;
- * MSH_SYSERR if the given message is not successfully parsed
+ * GNUNET_SYSERR if the given message is not successfully parsed
*/
int
addressmap_intersect_msg (AddressMap *m,
@@ -500,13 +507,13 @@
if (size < (sizeof (struct MSH_MSG_InstanceAdresses)
+ (sizeof (uint32_t) * n)) )
{
- MSH_break (0);
- return MSH_SYSERR;
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
if (n == 0)
{
- MSH_break (0);
- return MSH_SYSERR;
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
iainfo = instance_address_info_create (rank);
for (cnt = 0; cnt < n; cnt++)
Modified: msh/src/bitmap.c
===================================================================
--- msh/src/bitmap.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/bitmap.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -44,7 +44,7 @@
unsigned int array_size;
array_size = (len + ELE_BITSIZE - 1) / ELE_BITSIZE;
- bm = MSH_malloc (sizeof (struct BitMap) + (array_size * sizeof
+ bm = GNUNET_malloc (sizeof (struct BitMap) + (array_size * sizeof
(bm->barray[0])) );
bm->len = len;
bm->array_size = array_size;
@@ -90,11 +90,11 @@
unsigned int bitidx;
typeof (bm->barray[0]) one;
- MSH_assert (id < bm->len);
- MSH_assert ( (0 == val) || (1 == val) );
+ GNUNET_assert (id < bm->len);
+ GNUNET_assert ( (0 == val) || (1 == val) );
off = id / ELE_BITSIZE;
bitidx = id % ELE_BITSIZE;
- MSH_assert (off < bm->array_size);
+ GNUNET_assert (off < bm->array_size);
one = (typeof (bm->barray[0])) 1; /* cast */
one = one << bitidx;
if (1 == val)
@@ -118,10 +118,10 @@
unsigned int bitidx;
typeof (bm->barray[0]) one;
- MSH_assert (id < bm->len);
+ GNUNET_assert (id < bm->len);
off = id / ELE_BITSIZE;
bitidx = id % ELE_BITSIZE;
- MSH_assert (off < bm->array_size);
+ GNUNET_assert (off < bm->array_size);
one = (typeof (bm->barray[0])) 1; /* cast */
return (0 == (bm->barray[off] & (one << bitidx))) ? 0 : 1;
}
@@ -145,7 +145,7 @@
max = max - 1;
off = bm->len / ELE_BITSIZE;
bitidx = bm->len % ELE_BITSIZE;
- MSH_assert (off < bm->array_size);
+ GNUNET_assert (off < bm->array_size);
for (cnt = 0; cnt < off; cnt ++)
{
if (0 != max ^ bm->barray[cnt])
Modified: msh/src/common.h
===================================================================
--- msh/src/common.h 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/common.h 2013-07-19 13:26:00 UTC (rev 28197)
@@ -12,207 +12,17 @@
#endif
#include "../config.h"
+#define HAVE_USED_CONFIG_H
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <limits.h>
-
-#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>
-#include <net/if.h>
-#include <ifaddrs.h>
-#include <netdb.h>
-#include <signal.h>
-#include <unistd.h>
-
#include <event2/event.h>
+#define MSH_close(fd) \
+ do {if (0 != close (fd)) \
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close"); \
+ } while (0)
-#define MSH_OK 1
-
-#define MSH_SYSERR -1
-
-#define MSH_YES 1
-
-#define MSH_NO 0
-
-#define LOG_DEBUG(...) \
- fprintf (stderr, __VA_ARGS__)
-
-#define LOG_ERROR(...) \
- fprintf (stderr, __VA_ARGS__)
-
-#define LOG_STRERROR(fname) \
- LOG_ERROR ("%s:%d: %s() failed -- %s\n", __FILE__, __LINE__, fname,
strerror(errno))
-
-
-/**
- * Always allocate and clear memory
- */
-#define MSH_malloc(size) calloc (1, size);
-
-/**
- * Use this for internal assertion violations that are
- * not fatal (can be handled) but should not occur.
- */
-#define MSH_break(cond) do { if (! (cond)) { LOG_ERROR ("Assertion failed at
%s:%d.\n", __FILE__, __LINE__); } } while(0)
-
-
-/**
- * Use this for fatal errors that cannot be handled
- */
-#define MSH_assert_at(cond, file, line) do { if (! (cond)) { LOG_ERROR
("Assertion failed at %s:%d.\n", file, line); abort(); } } while(0)
-
-/**
- * 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)
-
-/**
- * Close a file descriptor while printing a warning upon any failure
- */
-#define MSH_close(fd) do { if(0 != close(fd)) LOG_STRERROR ("close"); else fd
= -1; } while (0)
-
-/* ******************** doubly-linked list *************** */
-/* To avoid mistakes: head->prev == tail->next == NULL */
-
-/**
- * Insert an element at the head of a DLL. Assumes that head, tail and
- * element are structs with prev and next fields.
- *
- * @param head pointer to the head of the DLL
- * @param tail pointer to the tail of the DLL
- * @param element element to insert
- */
-#define DLL_insert(head,tail,element) do { \
- MSH_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- MSH_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->next = (head); \
- (element)->prev = NULL; \
- if ((tail) == NULL) \
- (tail) = element; \
- else \
- (head)->prev = element; \
- (head) = (element); } while (0)
-
-
-/**
- * Insert an element at the tail of a DLL. Assumes that head, tail and
- * element are structs with prev and next fields.
- *
- * @param head pointer to the head of the DLL
- * @param tail pointer to the tail of the DLL
- * @param element element to insert
- */
-#define DLL_insert_tail(head,tail,element) do { \
- MSH_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- MSH_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->prev = (tail); \
- (element)->next = NULL; \
- if ((head) == NULL) \
- (head) = element; \
- else \
- (tail)->next = element; \
- (tail) = (element); } while (0)
-
-
-/**
- * Insert an element into a DLL after the given other element. Insert
- * at the head if the other element is NULL.
- *
- * @param head pointer to the head of the DLL
- * @param tail pointer to the tail of the DLL
- * @param other prior element, NULL for insertion at head of DLL
- * @param element element to insert
- */
-#define DLL_insert_after(head,tail,other,element) do { \
- MSH_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- MSH_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->prev = (other); \
- if (NULL == other) \
- { \
- (element)->next = (head); \
- (head) = (element); \
- } \
- else \
- { \
- (element)->next = (other)->next; \
- (other)->next = (element); \
- } \
- if (NULL == (element)->next) \
- (tail) = (element); \
- else \
- (element)->next->prev = (element); } while (0)
-
-
-/**
- * Insert an element into a DLL before the given other element. Insert
- * at the tail if the other element is NULL.
- *
- * @param head pointer to the head of the DLL
- * @param tail pointer to the tail of the DLL
- * @param other prior element, NULL for insertion at head of DLL
- * @param element element to insert
- */
-#define DLL_insert_before(head,tail,other,element) do { \
- MSH_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- MSH_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->next = (other); \
- if (NULL == other) \
- { \
- (element)->prev = (tail); \
- (tail) = (element); \
- } \
- else \
- { \
- (element)->prev = (other)->prev; \
- (other)->prev = (element); \
- } \
- if (NULL == (element)->prev) \
- (head) = (element); \
- else \
- (element)->prev->next = (element); } while (0)
-
-
-/**
- * Remove an element from a DLL. Assumes that head, tail and
- * element point to structs with prev and next fields.
- *
- * Using the head or tail pointer as the element
- * argument does NOT work with this macro.
- * Make sure to store head/tail in another pointer
- * and use it to remove the head or tail of the list.
- *
- * @param head pointer to the head of the DLL
- * @param tail pointer to the tail of the DLL
- * @param element element to remove
- */
-#define DLL_remove(head,tail,element) do { \
- MSH_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
- MSH_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
- if ((element)->prev == NULL) \
- (head) = (element)->next; \
- else \
- (element)->prev->next = (element)->next; \
- if ((element)->next == NULL) \
- (tail) = (element)->prev; \
- else \
- (element)->next->prev = (element)->prev; \
- (element)->next = NULL; \
- (element)->prev = NULL; } while (0)
-
#endif /* COMMON_H_ */
/* End of common.h */
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/mshd.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -1,4 +1,5 @@
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include <mpi.h>
#include "util.h"
#include "scheduler.h"
@@ -6,6 +7,16 @@
#include "bitmap.h"
#include "addressmap.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd", __VA_ARGS__)
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
+#define LOG_STRERROR(kind,cmd) \
+ GNUNET_log_from_strerror (kind, "mshd", cmd)
+
/**
* Context for verifying addresses
*/
@@ -178,7 +189,7 @@
if (0 != getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0,
NI_NUMERICHOST))
{
- LOG_STRERROR ("getnameinfo");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "getnameinfo");
return NULL;
}
return hostip;
@@ -190,7 +201,7 @@
{
static char hostip[NI_MAXHOST];
- MSH_break (0 < snprintf (hostip, NI_MAXHOST, "%u.%u.%u.%u",
+ GNUNET_break (0 < snprintf (hostip, NI_MAXHOST, "%u.%u.%u.%u",
ip >> 24,
(ip >> 16) % 256,
(ip >> 8) % 256,
@@ -209,7 +220,7 @@
* @param broadcast_addr the broadcast address (can be NULL for unknown or
unassigned)
* @param netmask the network mask (can be NULL for unknown or unassigned))
* @param addrlen length of the address
- * @return MSH_OK to continue iteration, MSH_SYSERR to abort
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
*/
static int net_if_processor (void *cls, const char *name,
int isDefault,
@@ -222,14 +233,14 @@
const struct sockaddr_in *inaddr;
if (sizeof (struct sockaddr_in) != addrlen)
- return MSH_OK; /* Only consider IPv4 for now */
+ return GNUNET_OK; /* Only consider IPv4 for now */
hostip = saddr2str (addr, addrlen);
if (NULL == hostip)
- return MSH_OK;
+ return GNUNET_OK;
inaddr = (const struct sockaddr_in *) addr;
- MSH_array_append (s_addrs, nips, inaddr->sin_addr.s_addr);
+ GNUNET_array_append (s_addrs, nips, inaddr->sin_addr.s_addr);
LOG_DEBUG ("%d: Found IP: %s\n", rank, hostip);
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -248,7 +259,7 @@
uint32_t cid;
scheduler_remove (ctx->task);
- DLL_remove (rhead, rtail, ctx);
+ GNUNET_CONTAINER_DLL_remove (rhead, rtail, ctx);
free (ctx);
if (IS_SHUTDOWN_EVENT (flags))
{
@@ -258,12 +269,12 @@
rsize = read (sock, &cid, sizeof (uint32_t));
if (rsize < 0)
{
- LOG_STRERROR ("read");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "read");
goto err_ret;
}
if (rsize == 0)
{
- MSH_break (0);
+ GNUNET_break (0);
goto err_ret;
}
cid = ntohl (cid);
@@ -303,13 +314,13 @@
LOG_DEBUG ("%d: Got a connect\n", rank);
if (0 > (csock = accept4 (sock, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC)))
{
- LOG_STRERROR ("accept4");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "accept4");
MSH_close (sock);
scheduler_shutdown ();
return;
}
- rctx = MSH_malloc (sizeof (struct ReadContext));
- DLL_insert_tail (rhead, rtail, rctx);
+ rctx = GNUNET_malloc (sizeof (struct ReadContext));
+ GNUNET_CONTAINER_DLL_insert_tail (rhead, rtail, rctx);
rctx->task = scheduler_add_socket (csock, EV_READ, &read_socket, rctx, NULL);
/* resume accepting connections on the listen sock */
atask = scheduler_add_socket (sock, EV_READ, &accept_task, &atask, NULL);
@@ -335,7 +346,7 @@
{
int total_rounds;
- MSH_assert (NULL == rtask);
+ GNUNET_assert (NULL == rtask);
/* Number of rounds required to contact all processes except ourselves
(rwidth
in parallel in each round) */
total_rounds = ((nproc - 1) + (rwidth - 1)) / rwidth;
@@ -373,7 +384,7 @@
MSH_close (ctx->sock);
scheduler_remove (ctx->close_task);
}
- DLL_remove (vactx_head, vactx_tail, ctx);
+ GNUNET_CONTAINER_DLL_remove (vactx_head, vactx_tail, ctx);
free (ctx);
}
for (cnt = 0; cnt < rwidth; cnt++)
@@ -416,17 +427,17 @@
if (ctx->sock == sock)
MSH_close (sock);
else if (-1 == sock)
- MSH_break (0);
+ GNUNET_break (0);
if (IS_SHUTDOWN_EVENT (flags))
{
- DLL_remove (vactx_head, vactx_tail, ctx);
+ GNUNET_CONTAINER_DLL_remove (vactx_head, vactx_tail, ctx);
free (ctx);
return;
}
/* FIXME: add the addresses associated with the contex to the mapping */
lb = rank - current_round * rwidth - rwidth + nproc;
- MSH_assert (0 <= lb);
+ GNUNET_assert (0 <= lb);
lb %= nproc;
source = instance_address_info_get_rank (ctx->iainfo);
if (lb <= source)
@@ -456,7 +467,7 @@
ctx->soh = NULL;
if (-1 == sockfd)
{
- MSH_break (0);
+ GNUNET_break (0);
/* FIXME: Check if we already got a mapping for the instance */
goto err_ret;
}
@@ -466,7 +477,7 @@
id = htonl ((uint32_t) rank);
if (sizeof (uint32_t) != write (sockfd, &id, sizeof (uint32_t)))
{
- MSH_break (0); /* FIXME: handle error */
+ GNUNET_break (0); /* FIXME: handle error */
MSH_close (sockfd);
goto err_ret;
}
@@ -475,7 +486,7 @@
return;
err_ret:
- DLL_remove (vactx_head, vactx_tail, ctx);
+ GNUNET_CONTAINER_DLL_remove (vactx_head, vactx_tail, ctx);
free (ctx);
}
@@ -492,7 +503,7 @@
in_addr.sin_family = AF_INET;
in_addr.sin_port = htons (port);
in_addr.sin_addr.s_addr = htonl ((uint32_t) ip);
- ctx = MSH_malloc (sizeof (struct VerifyAddressesCtx));
+ ctx = GNUNET_malloc (sizeof (struct VerifyAddressesCtx));
ctx->soh = scheduler_open_socket ((struct sockaddr *) &in_addr,
sizeof (struct sockaddr_in),
&socket_open_cb, ctx);
@@ -502,12 +513,12 @@
ctx->iainfo = iainfo;
if (NULL == ctx->soh)
{
- MSH_break (0);
+ GNUNET_break (0);
free (ctx);
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
}
- DLL_insert_tail (vactx_head, vactx_tail, ctx);
- return MSH_OK;
+ GNUNET_CONTAINER_DLL_insert_tail (vactx_head, vactx_tail, ctx);
+ return GNUNET_OK;
}
@@ -516,9 +527,9 @@
* socket
*
* @param iainfo the instance's address information
- * @return MSH_OK upon success initialisation of the connection to instance's
+ * @return GNUNET_OK upon success initialisation of the connection to
instance's
* listen socket (this does not mean that the connection is
- * established or an address is verified); MSH_SYSERR upon error
+ * established or an address is verified); GNUNET_SYSERR upon error
*/
static int
verify_addresses (struct InstanceAddrInfo *iainfo)
@@ -527,11 +538,11 @@
struct InstanceAddr *iaddr;
bmx = 0;
- if (MSH_OK != instance_address_info_iterate_addresses (iainfo,
+ if (GNUNET_OK != instance_address_info_iterate_addresses (iainfo,
&address_iterator_cb,
iainfo))
- return MSH_SYSERR;
- return MSH_OK;
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
}
@@ -565,7 +576,7 @@
LOG_DEBUG ("%d: Parsed address: %s\n", rank, ip2str ((in_addr_t) ntohl
(msg->ipaddrs[cnt])));
iaddr = instance_address_create_sockaddr_in (ntohs (msg->port),
(in_addr_t) ntohl
(msg->ipaddrs[cnt]));
- MSH_break (MSH_OK == instance_address_info_add_address (iainfo, iaddr));
+ GNUNET_break (GNUNET_OK == instance_address_info_add_address (iainfo,
iaddr));
}
return iainfo;
}
@@ -583,7 +594,7 @@
MPI_Status status;
int cnt;
- iainfos = MSH_malloc (sizeof (struct InstanceAddrInfo *) * rwidth);
+ iainfos = GNUNET_malloc (sizeof (struct InstanceAddrInfo *) * rwidth);
for (cnt=0; cnt < rwidth; cnt++)
{
struct MSH_MSG_VerifyAddress *msg;
@@ -593,7 +604,7 @@
int source;
int ret;
- MSH_break (MPI_SUCCESS ==
+ GNUNET_break (MPI_SUCCESS ==
MPI_Probe (MPI_ANY_SOURCE, MSH_MTYPE_VERIFY_ADDRESSES,
MPI_COMM_WORLD, &status));
MPI_Get_elements (&status, MPI_BYTE, &rsize);
@@ -601,29 +612,29 @@
(rank - current_round * rwidth - rwidth) <= p <= (rank - (current_round
* rwidth) -1) */
lb = rank - current_round * rwidth - rwidth + nproc;
up = rank - (current_round * rwidth) - 1 + nproc;
- MSH_assert (lb >= 0);
- MSH_assert (up >= 0);
+ GNUNET_assert (lb >= 0);
+ GNUNET_assert (up >= 0);
lb %= nproc;
up %= nproc;
source = status.MPI_SOURCE;
if (lb == up)
if (source != lb)
{
- MSH_break (0);
+ GNUNET_break (0);
LOG_ERROR ("%d: Error: source %d; lb: %d; up: %d\n", rank, source, lb,
up);
goto err_ret;
}
else if ((source > up) || (source < lb))
{
- MSH_break (0);
+ GNUNET_break (0);
goto err_ret;
}
- msg = MSH_malloc (rsize);
+ msg = GNUNET_malloc (rsize);
if (MPI_SUCCESS != MPI_Recv (msg, rsize, MPI_BYTE, source,
MSH_MTYPE_VERIFY_ADDRESSES, MPI_COMM_WORLD,
MPI_STATUS_IGNORE))
{
- MSH_break (0);
+ GNUNET_break (0);
goto err_ret;
}
LOG_DEBUG ("%d: Received message of size %d from %d\n", rank, rsize,
source);
@@ -651,7 +662,7 @@
* Send our addresses to an MPI processes
*
* @param rank the rank of the process which has to receive our request
- * @return MSH_OK on success; MSH_SYSERR upon error
+ * @return GNUNET_OK on success; GNUNET_SYSERR upon error
*/
static int
send_addresses ()
@@ -666,7 +677,7 @@
unsigned int width;
msize = sizeof (struct MSH_MSG_VerifyAddress) + (nips * sizeof (uint32_t));
- msg = MSH_malloc (msize);
+ msg = GNUNET_malloc (msize);
msg->header.size = htons (msize);
msg->port = htons (lport);
msg->nips = htons (nips);
@@ -678,13 +689,13 @@
if ( (0 != ( (nproc - 1) % rwidth)) && (current_round == ( (nproc - 1) /
rwidth)) )
width = (nproc - 1) % rwidth;
cpys = NULL;
- cpys = MSH_malloc (msize * width);
- sreqs = MSH_malloc (width);
+ cpys = GNUNET_malloc (msize * width);
+ sreqs = GNUNET_malloc (width);
for (cnt=0; cnt < width; cnt++)
{
(void) memcpy (&cpys[cnt], msg, msize);
target = (current_round * rwidth) + cnt + 1;
- MSH_assert (target < nproc);
+ GNUNET_assert (target < nproc);
target = (rank + target) % nproc;
LOG_DEBUG ("%d: Sending message to %d\n", rank, target);
ret = MPI_Isend (&cpys[cnt], msize, MPI_BYTE, target,
@@ -698,14 +709,14 @@
{
for (cnt--; cnt >= 0; cnt--)
{
- MSH_break (MPI_SUCCESS == MPI_Cancel (&sreqs[cnt]));
- MSH_break (MPI_SUCCESS == MPI_Wait (&sreqs[cnt], MPI_STATUS_IGNORE));
+ GNUNET_break (MPI_SUCCESS == MPI_Cancel (&sreqs[cnt]));
+ GNUNET_break (MPI_SUCCESS == MPI_Wait (&sreqs[cnt], MPI_STATUS_IGNORE));
}
goto err_ret;
}
for (cnt=0; cnt < width; cnt++)
{
- MSH_break (MPI_SUCCESS == MPI_Wait (&sreqs[cnt], MPI_STATUS_IGNORE));
+ GNUNET_break (MPI_SUCCESS == MPI_Wait (&sreqs[cnt], MPI_STATUS_IGNORE));
}
LOG_DEBUG ("%d: Round: %d -- All messages sent successfully\n", rank,
current_round);
if (NULL != cpys)
@@ -715,9 +726,9 @@
}
err_ret:
- MSH_free_non_null (cpys);
- MSH_free_non_null (sreqs);
- return (MPI_SUCCESS == ret) ? MSH_OK : MSH_SYSERR;
+ GNUNET_free_non_null (cpys);
+ GNUNET_free_non_null (sreqs);
+ return (MPI_SUCCESS == ret) ? GNUNET_OK : GNUNET_SYSERR;
}
@@ -727,7 +738,7 @@
* on listen socket and verifies the IP addresses of other instances by
* connecting to their listen sockets
*
- * @return MSH_OK if verification is successful; MSH_SYSERR upon error (an
error
+ * @return GNUNET_OK if verification is successful; GNUNET_SYSERR upon error
(an error
* message is logged)
*/
static int
@@ -743,26 +754,26 @@
(void) memset (&addr, 0, addrlen);
sock = open_listen_socket ((struct sockaddr *) &addr, addrlen, rwidth);
if (-1 == sock)
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
lport = ntohs (addr.sin_port);
if (0 == lport)
{
- MSH_break (0);
+ GNUNET_break (0);
goto clo_ret;
}
if (MPI_SUCCESS != MPI_Barrier (MPI_COMM_WORLD))
{
- MSH_break (0);
+ GNUNET_break (0);
goto clo_ret;
}
- if (MSH_SYSERR == send_addresses ())
+ if (GNUNET_SYSERR == send_addresses ())
goto clo_ret;
if (NULL == (riainfos = receive_addresses ()))
goto clo_ret;
atask = scheduler_add_socket (sock, EV_READ, &accept_task, &atask, NULL);
if (MPI_SUCCESS != MPI_Barrier (MPI_COMM_WORLD))
{
- MSH_break (0);
+ GNUNET_break (0);
goto clo_ret;
}
tv.tv_sec = 1;
@@ -771,11 +782,11 @@
verify_addresses (riainfos[cnt]);
listen_sock = sock;
finalise_task = scheduler_add (&finalise_round, NULL, &tv);
- return MSH_OK;
+ return GNUNET_OK;
clo_ret:
(void) close (sock);
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
}
@@ -815,7 +826,7 @@
rtask = NULL;
if (IS_SHUTDOWN_EVENT (flags))
return;
- if (MSH_OK != run_round_ ())
+ if (GNUNET_OK != run_round_ ())
scheduler_shutdown ();
}
@@ -906,7 +917,7 @@
return 1;
default:
printf ("Unknown option: %c\n", c);
- MSH_assert (0);
+ GNUNET_assert (0);
}
}
if (MPI_SUCCESS != MPI_Init(&argc, &argv))
@@ -937,9 +948,9 @@
}
bitmap = bitmap_create (rwidth);
addrmap = addressmap_create (nproc);
- if (MSH_OK != scheduler_run (&run, NULL))
+ if (GNUNET_OK != scheduler_run (&run, NULL))
{
- MSH_break (0);
+ GNUNET_break (0);
goto fail;
}
ret = 0;
@@ -955,8 +966,8 @@
addressmap_destroy (addrmap);
addrmap = NULL;
}
- MSH_break (MPI_SUCCESS == MPI_Finalize());
- MSH_free_non_null (s_addrs);
+ GNUNET_break (MPI_SUCCESS == MPI_Finalize());
+ GNUNET_free_non_null (s_addrs);
LOG_ERROR ("Returning\n");
return ret;
}
Modified: msh/src/reduce.c
===================================================================
--- msh/src/reduce.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/reduce.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -5,17 +5,24 @@
*/
#include "common.h"
-#include <math.h>
+#include <gnunet/gnunet_util_lib.h>
#include <mpi.h>
#include "addressmap.h"
#include "mshd.h"
#include "mtypes.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__);
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__);
+
/**
* Send our addressmap to the instance with the given rank
*
* @param instance the rank of the instance to which our addressmap has to be
sent
- * @return MSH_OK upon success; MSH_SYSERR upon failure
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
*/
static int
send_addressmap (int instance)
@@ -27,14 +34,14 @@
int cnt;
int ret;
- ret = MSH_SYSERR;
+ ret = GNUNET_SYSERR;
send_reqs = NULL;
- if (MSH_SYSERR == (nmsg = addressmap_pack (addrmap, &iaddr_msgs)))
+ if (GNUNET_SYSERR == (nmsg = addressmap_pack (addrmap, &iaddr_msgs)))
{
- MSH_break (0);
+ GNUNET_break (0);
return ret;
}
- send_reqs = MSH_malloc (sizeof (MPI_Request) * nmsg);
+ send_reqs = GNUNET_malloc (sizeof (MPI_Request) * nmsg);
for (cnt = 0; cnt < nmsg; cnt++)
{
if (MPI_SUCCESS !=
@@ -42,38 +49,38 @@
instance, MSH_MTYPE_INSTANCE_ADDRESS, MPI_COMM_WORLD,
&send_reqs[cnt]))
{
- MSH_break (0);
+ GNUNET_break (0);
cnt--;
goto cleanup;
}
}
- stats = MSH_malloc (sizeof (MPI_Status) * nmsg);
+ stats = GNUNET_malloc (sizeof (MPI_Status) * nmsg);
if (MPI_SUCCESS != MPI_Waitall (nmsg, send_reqs, stats))
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
for (cnt = 0; cnt < nmsg; cnt++)
{
if (MPI_SUCCESS != stats[cnt].MPI_ERROR)
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
}
- ret = MSH_OK;
+ ret = GNUNET_OK;
cleanup:
for (;(NULL != send_reqs) && (cnt >= 0); cnt--)
{
- MSH_break (MPI_SUCCESS == MPI_Cancel (&send_reqs[cnt]));
- MSH_break (MPI_SUCCESS == MPI_Wait (&send_reqs[cnt], MPI_STATUS_IGNORE));
+ GNUNET_break (MPI_SUCCESS == MPI_Cancel (&send_reqs[cnt]));
+ GNUNET_break (MPI_SUCCESS == MPI_Wait (&send_reqs[cnt],
MPI_STATUS_IGNORE));
}
for (cnt = 0; cnt < nmsg; cnt++)
free (iaddr_msgs[cnt]);
- MSH_free_non_null (iaddr_msgs);
- MSH_free_non_null (send_reqs);
- MSH_free_non_null (stats);
+ GNUNET_free_non_null (iaddr_msgs);
+ GNUNET_free_non_null (send_reqs);
+ GNUNET_free_non_null (stats);
return ret;
}
@@ -82,7 +89,7 @@
* Receive address maps during a given reduction step
*
* @param step the current reduction step
- * @return MSH_OK upon success; MSH_SYSERR upon failure
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
*/
static int
receive_addressmap (unsigned int step)
@@ -101,7 +108,7 @@
step_width = (unsigned int) pow (rwidth, step);
lb = 0;
ub = 0;
- ret = MSH_SYSERR;
+ ret = GNUNET_SYSERR;
if (rank + step_width <= nproc)
{
nrecv = rwidth;
@@ -117,34 +124,34 @@
ub = nproc - 1;
}
}
- MSH_assert (nrecv >= 0);
+ GNUNET_assert (nrecv >= 0);
nrecv *= nproc;
for (cnt = 0; cnt < nrecv; cnt++)
{
if (MPI_SUCCESS != MPI_Probe (MPI_ANY_SOURCE, MSH_MTYPE_INSTANCE_ADDRESS,
MPI_COMM_WORLD, &stat))
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
if (!((lb <= stat.MPI_SOURCE ) && (stat.MPI_SOURCE <= ub)))
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
msize = 0;
if ((MPI_SUCCESS != MPI_Get_elements (&stat, MPI_BYTE, &msize))
|| (msize <= 0))
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
- msg = MSH_malloc (msize);
+ msg = GNUNET_malloc (msize);
if (MPI_SUCCESS != MPI_Recv (msg, msize, MPI_BYTE, stat.MPI_SOURCE,
MSH_MTYPE_INSTANCE_ADDRESS, MPI_COMM_WORLD,
MPI_STATUS_IGNORE))
{
- MSH_break (0);
+ GNUNET_break (0);
goto cleanup;
}
LOG_DEBUG ("%d: [%u/%d] Received an instance address from %d\n", rank,
@@ -159,10 +166,10 @@
msg = NULL;
}
- ret = MSH_OK;
+ ret = GNUNET_OK;
cleanup:
- MSH_free_non_null (msg);
+ GNUNET_free_non_null (msg);
return ret;
}
@@ -170,7 +177,7 @@
/**
* Perform an ntree reduction on address maps
*
- * @return MSH_OK upon success; MSH_SYSERR upon failure
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
*/
int
reduce_ntree ()
@@ -184,7 +191,7 @@
for (step = 1; step < max_steps; step++)
{
if (MPI_SUCCESS != MPI_Barrier (MPI_COMM_WORLD))
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
step_width = (unsigned int) pow (rwidth, step);
if (0 != (aggregator = (rank % step_width)))
{
Modified: msh/src/scheduler.c
===================================================================
--- msh/src/scheduler.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/scheduler.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -4,8 +4,20 @@
* @author Sree Harsha Totakura <address@hidden>
*/
+#include "common.h"
+#include "gnunet/gnunet_util_lib.h"
#include "scheduler.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-scheduler", __VA_ARGS__);
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__);
+
+#define LOG_STRERROR(cmd) \
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "mshd", cmd)
+
/**
* variable for 0 time. Externalised in scheduler.h
*/
@@ -61,15 +73,15 @@
{
struct Task *task;
- MSH_assert (NULL != ebase);
- task = MSH_malloc (sizeof (struct Task));
+ GNUNET_assert (NULL != ebase);
+ task = GNUNET_malloc (sizeof (struct Task));
task->ev = event_new (ebase, sock, flags, cb, cls);
if (0 != event_add (task->ev, tv))
{
free (task);
return NULL;
}
- DLL_insert_tail (thead, ttail, task);
+ GNUNET_CONTAINER_DLL_insert_tail (thead, ttail, task);
return task;
}
@@ -118,8 +130,8 @@
void
scheduler_remove (struct Task *task)
{
- DLL_remove (thead, ttail, task);
- MSH_break (0 == event_del (task->ev));
+ GNUNET_CONTAINER_DLL_remove (thead, ttail, task);
+ GNUNET_break (0 == event_del (task->ev));
event_free (task->ev);
free (task);
}
@@ -151,7 +163,7 @@
*
* @param cb the callback to call when the scheduler is ready. Further tasks
* can be added through this callback.
- * @return MSH_OK if all tasks are successfully executed; MSH_SYSERR upon error
+ * @return GNUNET_OK if all tasks are successfully executed; GNUNET_SYSERR
upon error
*/
int
scheduler_run (event_callback_fn cb, void *cls)
@@ -164,7 +176,7 @@
if (NULL == ebase)
{
LOG_ERROR ("Cannot allocate libevent event base\n");
- return MSH_SYSERR;
+ return GNUNET_SYSERR;
}
sev = evtimer_new (ebase, cb, cls);
evtimer_add (sev, TV_IMMEDIATE);
@@ -172,7 +184,7 @@
evtimer_del (sev);
event_free (sev);
event_base_free (ebase);
- return (1 == ret) ? MSH_OK : MSH_SYSERR;
+ return (1 == ret) ? GNUNET_OK : GNUNET_SYSERR;
}
@@ -224,7 +236,7 @@
h->task = NULL;
cb = h->cb;
cbcls = h->cls;
- MSH_assert (h->sock == sock);
+ GNUNET_assert (h->sock == sock);
free (h);
if (IS_SHUTDOWN_EVENT (flags))
goto err_ret;
@@ -267,10 +279,10 @@
struct SocketOpenHandle *h;
int sock;
- MSH_assert (NULL != cb);
+ GNUNET_assert (NULL != cb);
if (-1 == (sock = open_socket (addr, addrlen)))
return NULL;
- h = MSH_malloc (sizeof (struct SocketOpenHandle));
+ h = GNUNET_malloc (sizeof (struct SocketOpenHandle));
h->cb = cb;
h->cls = cls;
h->sock = sock;
Modified: msh/src/test_addressmap.c
===================================================================
--- msh/src/test_addressmap.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/test_addressmap.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -5,11 +5,22 @@
*/
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include "util.h"
#include "addressmap.h"
#include "mtypes.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__)
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
+#define LOG_STRERROR(cmd) \
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "test-addressmap", cmd)
+
+
static unsigned int cnt;
@@ -20,13 +31,13 @@
* @param cls the closure passed to instance_address_info_iterate_addresses()
* @param port the port where the instance is listening
* @param ip the ip of the instance
- * @return MSH_OK to continue iteration; MSH_SYSERR to terminate
+ * @return GNUNET_OK to continue iteration; GNUNET_SYSERR to terminate
*/
static int
iterator_cb (void *cls, uint16_t port, in_addr_t ip)
{
cnt++;
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -37,7 +48,7 @@
int n;
unsigned int cnt;
- MSH_assert (0 < (n = addressmap_pack (m, &iaddr_msgs)));
+ GNUNET_assert (0 < (n = addressmap_pack (m, &iaddr_msgs)));
for (cnt = 0; cnt < n; cnt++)
{
free (iaddr_msgs[cnt]);
@@ -50,7 +61,7 @@
instance_address_info_free_iterator (void *cls, struct InstanceAddrInfo
*iainfo)
{
instance_address_info_destroy (iainfo);
- return MSH_OK;
+ return GNUNET_OK;
}
@@ -61,14 +72,14 @@
struct MSH_MSG_InstanceAdresses **iaddr_msgs;
m = addressmap_create (2);
- MSH_assert (MSH_OK == addressmap_add (m, 1, 0, 12));
- MSH_assert (MSH_OK == addressmap_add (m, 1, 0, 2));
- MSH_assert (MSH_OK == addressmap_add (m, 1, 0, 7));
- MSH_assert (MSH_OK == addressmap_add (m, 1, 0, 14));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 1, 0, 12));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 1, 0, 2));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 1, 0, 7));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 1, 0, 14));
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m, 1, &iterator_cb,
NULL));
- MSH_assert (4 == cnt);
+ GNUNET_assert (4 == cnt);
/* prepare a second addressmap */
{
@@ -76,27 +87,27 @@
struct MSH_MSG_AddressMap *map_msg;
m2 = addressmap_create (2);
- MSH_assert (MSH_OK == addressmap_add (m2, 1, 0, 2));
- MSH_assert (MSH_OK == addressmap_add (m2, 1, 0, 7));
- MSH_assert (MSH_OK == addressmap_add (m2, 1, 0, 14));
- MSH_assert (MSH_OK == addressmap_add (m2, 0, 0, 3));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m2, 1, 0, 2));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m2, 1, 0, 7));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m2, 1, 0, 14));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m2, 0, 0, 3));
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m2, 1, &iterator_cb,
NULL));
- MSH_assert (3 == cnt);
+ GNUNET_assert (3 == cnt);
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m2, 0, &iterator_cb,
NULL));
- MSH_assert (1 == cnt);
- MSH_assert (0 < addressmap_pack (m2, &iaddr_msgs));
+ GNUNET_assert (1 == cnt);
+ GNUNET_assert (0 < addressmap_pack (m2, &iaddr_msgs));
addressmap_destroy (m2);
}
/* check intersection of the message with the first addressmap */
- MSH_assert (3 == addressmap_intersect_msg (m, iaddr_msgs[1]));
+ GNUNET_assert (3 == addressmap_intersect_msg (m, iaddr_msgs[1]));
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m, 1, &iterator_cb,
NULL));
- MSH_assert (3 == cnt);
+ GNUNET_assert (3 == cnt);
addressmap_destroy (m);
free (iaddr_msgs[1]);
free (iaddr_msgs[0]);
@@ -112,20 +123,20 @@
struct InstanceAddrInfo *iainfo;
m = addressmap_create (2);
- MSH_assert (MSH_OK == addressmap_add (m, 0, 0, 12));
- MSH_assert (MSH_OK == addressmap_add (m, 0, 0, 9));
- MSH_assert (MSH_OK == addressmap_add (m, 0, 0, 13));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 0, 0, 12));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 0, 0, 9));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 0, 0, 13));
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m, 0, &iterator_cb,
NULL));
- MSH_assert (3 == cnt);
+ GNUNET_assert (3 == cnt);
- MSH_assert (MSH_OK != addressmap_add (m, 0, 0, 12)); /* 12 was added before
*/
- MSH_assert (MSH_OK == addressmap_add (m, 0, 0, 19));
+ GNUNET_assert (GNUNET_OK != addressmap_add (m, 0, 0, 12)); /* 12 was added
before */
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 0, 0, 19));
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m, 0, &iterator_cb,
NULL));
- MSH_assert (4 == cnt);
+ GNUNET_assert (4 == cnt);
/* test address map intersections */
iainfo = instance_address_info_create (0);
@@ -137,13 +148,13 @@
instance_address_info_add_address (iainfo, addr3);
addressmap_intersect (m, iainfo);
cnt = 0;
- MSH_assert (MSH_OK ==
+ GNUNET_assert (GNUNET_OK ==
addressmap_iterate_instance_addresses (m, 0, &iterator_cb,
NULL));
- MSH_assert (2 == cnt);
+ GNUNET_assert (2 == cnt);
instance_address_info_destroy (iainfo);
/* test message serialization of the addressmap */
- MSH_assert (MSH_OK == addressmap_add (m, 1, 0, 99));
+ GNUNET_assert (GNUNET_OK == addressmap_add (m, 1, 0, 99));
test_serialization (m);
addressmap_destroy (m);
Modified: msh/src/test_bitmap.c
===================================================================
--- msh/src/test_bitmap.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/test_bitmap.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -5,8 +5,19 @@
*/
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include "bitmap.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__)
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
+#define LOG_STRERROR(cmd) \
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "test-bitmap", cmd)
+
#define FAIL_TEST(cond,ret) \
do { if (!cond){fprintf (stderr, "Assertion failed at %s:%d\n", __FILE__,
__LINE__); ret;} }while(0)
@@ -18,7 +29,7 @@
bm = bitmap_create (len);
bitmap_set (bm, 13, 1);
- MSH_assert (1 == bitmap_isbitset (bm, 13));
+ GNUNET_assert (1 == bitmap_isbitset (bm, 13));
for (cnt = 0; cnt < len; cnt++)
{
if (cnt == 13)
Modified: msh/src/test_scheduler.c
===================================================================
--- msh/src/test_scheduler.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/test_scheduler.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -1,6 +1,14 @@
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include "scheduler.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__)
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
struct Task *task;
struct Task *sig_tasks[2];
@@ -38,9 +46,9 @@
static unsigned int cnt;
struct timeval tv;
- MSH_assert (-1 == nosock);
- MSH_assert (NULL == cls);
- MSH_assert (0 != (EV_TIMEOUT & flags));
+ GNUNET_assert (-1 == nosock);
+ GNUNET_assert (NULL == cls);
+ GNUNET_assert (0 != (EV_TIMEOUT & flags));
LOG_DEBUG ("Run\n");
if (0 == cnt++)
{
@@ -58,6 +66,6 @@
int main (int argc, char *argv[])
{
- MSH_assert (MSH_OK == scheduler_run (run, NULL));
+ GNUNET_assert (GNUNET_OK == scheduler_run (run, NULL));
return 0;
}
Modified: msh/src/test_scheduler_socket.c
===================================================================
--- msh/src/test_scheduler_socket.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/test_scheduler_socket.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -1,6 +1,17 @@
#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
#include "scheduler.h"
+#define LOG(kind,...) \
+ GNUNET_log_from (kind, "mshd-addressmap", __VA_ARGS__)
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
+#define LOG_STRERROR(cmd) \
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING,
"test-scheduler-socket", cmd)
+
struct Task *sig_tasks[2];
struct Task *atask;
@@ -55,7 +66,7 @@
MSH_close (lsock);
return;
}
- MSH_assert (fd == lsock);
+ GNUNET_assert (fd == lsock);
LOG_DEBUG ("Got a connect\n");
caddrlen = sizeof (caddr);
if (0 > (csock = accept4 (lsock, &caddr, &caddrlen,
@@ -77,7 +88,7 @@
oh = NULL;
if (fd < 0)
{
- MSH_break (0);
+ GNUNET_break (0);
return;
}
LOG_DEBUG ("Connected to local listen socket\n");
@@ -104,9 +115,9 @@
if (IS_SHUTDOWN_EVENT (flags))
return;
- MSH_assert (-1 == nosock);
- MSH_assert (NULL == cls);
- MSH_assert (0 != (EV_TIMEOUT & flags));
+ GNUNET_assert (-1 == nosock);
+ GNUNET_assert (NULL == cls);
+ GNUNET_assert (0 != (EV_TIMEOUT & flags));
LOG_DEBUG ("Run\n");
sig_tasks[0] = scheduler_add_signal (SIGTERM, &shutdown_signal,
&sig_tasks[0],
NULL);
@@ -134,7 +145,7 @@
result = 0;
lsock = -1;
csock = -1;
- if (MSH_OK != scheduler_run (run, NULL))
+ if (GNUNET_OK != scheduler_run (run, NULL))
return 1;
return (2 == result) ? 0 : 1;
}
Modified: msh/src/util.c
===================================================================
--- msh/src/util.c 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/util.c 2013-07-19 13:26:00 UTC (rev 28197)
@@ -1,92 +1,10 @@
#include "common.h"
#include "util.h"
-#define DEFAULT_INTERFACE "eth0"
+#define LOG_STRERROR(cmd) \
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "mshd-util", cmd)
/**
- * @brief Enumerate all network interfaces
- *
- * @param proc the callback function
- * @param proc_cls closure for proc
- */
-void
-GNUNET_OS_network_interfaces_list (NetworkInterfaceProcessor proc,
- void *proc_cls)
-{
- struct ifaddrs *ifa_first;
- struct ifaddrs *ifa_ptr;
- socklen_t alen;
-
- if (getifaddrs (&ifa_first) == 0)
- {
- for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
- {
- if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
- (ifa_ptr->ifa_flags & IFF_UP) != 0)
- {
- if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
- (ifa_ptr->ifa_addr->sa_family != AF_INET6))
- continue;
- if (ifa_ptr->ifa_addr->sa_family == AF_INET)
- alen = sizeof (struct sockaddr_in);
- else
- alen = sizeof (struct sockaddr_in6);
- if (MSH_OK !=
- proc (proc_cls, ifa_ptr->ifa_name,
- 0 == strcmp (ifa_ptr->ifa_name, DEFAULT_INTERFACE),
- ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr,
- ifa_ptr->ifa_netmask, alen))
- break;
- }
- }
- freeifaddrs (ifa_first);
- }
-}
-
-
-/**
- * Grow an array. Grows old by (*oldCount-newCount)*elementSize bytes
- * and sets *oldCount to newCount.
- *
- * @param old address of the pointer to the array
- * *old may be NULL
- * @param elementSize the size of the elements of the array
- * @param oldCount address of the number of elements in the *old array
- * @param newCount number of elements in the new array, may be 0
- * @param filename where in the code was the call to GNUNET_array_grow
- * @param linenumber where in the code was the call to GNUNET_array_grow
- */
-void
-MSH_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
- unsigned int newCount, const char *filename, int linenumber)
-{
- void *tmp;
- size_t size;
-
- MSH_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
- size = newCount * elementSize;
- if (size == 0)
- {
- tmp = NULL;
- }
- else
- {
- tmp = MSH_malloc (size);
- if (*oldCount > newCount)
- *oldCount = newCount; /* shrink is also allowed! */
- memcpy (tmp, *old, elementSize * (*oldCount));
- }
-
- if (*old != NULL)
- {
- free (*old);
- }
- *old = tmp;
- *oldCount = newCount;
-}
-
-
-/**
* Creates a new non-blocking socket and binds it to the given address and
makes
* it a listen socket
*
@@ -121,7 +39,7 @@
}
if (newaddrlen != addrlen)
{
- MSH_break (0);
+ GNUNET_break (0);
goto clo_ret;
}
if (-1 == listen (sock, backlog))
Modified: msh/src/util.h
===================================================================
--- msh/src/util.h 2013-07-19 12:26:55 UTC (rev 28196)
+++ msh/src/util.h 2013-07-19 13:26:00 UTC (rev 28197)
@@ -1,105 +1,9 @@
#ifndef MSH_UTIL_H
#define MSH_UTIL_H
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <gnunet/gnunet_common.h>
-
/**
- * Callback function invoked for each interface found.
- *
- * @param cls closure
- * @param name name of the interface (can be NULL for unknown)
- * @param isDefault is this presumably the default interface
- * @param addr address of this interface (can be NULL for unknown or
unassigned)
- * @param broadcast_addr the broadcast address (can be NULL for unknown or
unassigned)
- * @param netmask the network mask (can be NULL for unknown or unassigned))
- * @param addrlen length of the address
- * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
- */
-typedef int (*NetworkInterfaceProcessor) (void *cls, const char *name,
- int isDefault,
- const struct sockaddr *addr,
- const struct sockaddr
*broadcast_addr,
- const struct sockaddr *netmask,
- socklen_t addrlen);
-
-
-/**
- * @brief Enumerate all network interfaces
- *
- * @param proc the callback function
- * @param proc_cls closure for proc
- */
-void
-GNUNET_OS_network_interfaces_list (NetworkInterfaceProcessor proc,
- void *proc_cls);
-
-
-/**
- * Grow an array, the new elements are zeroed out.
- * Grows old by (*oldCount-newCount)*elementSize
- * bytes and sets *oldCount to newCount.
- *
- * Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro.
- *
- * @param old address of the pointer to the array
- * *old may be NULL
- * @param elementSize the size of the elements of the array
- * @param oldCount address of the number of elements in the *old array
- * @param newCount number of elements in the new array, may be 0 (then *old
will be NULL afterwards)
- * @param filename where is this call being made (for debugging)
- * @param linenumber line where this call is being made (for debugging)
- */
-void
-MSH_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
- unsigned int newCount, const char *filename, int linenumber);
-
-
-/**
- * Grow a well-typed (!) array. This is a convenience
- * method to grow a vector <tt>arr</tt> of size <tt>size</tt>
- * to the new (target) size <tt>tsize</tt>.
- * <p>
- *
- * Example (simple, well-typed stack):
- *
- * <pre>
- * static struct foo * myVector = NULL;
- * static int myVecLen = 0;
- *
- * static void push(struct foo * elem) {
- * GNUNET_array_grow(myVector, myVecLen, myVecLen+1);
- * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo));
- * }
- *
- * static void pop(struct foo * elem) {
- * if (myVecLen == 0) die();
- * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo));
- * GNUNET_array_grow(myVector, myVecLen, myVecLen-1);
- * }
- * </pre>
- *
- * @param arr base-pointer of the vector, may be NULL if size is 0;
- * will be updated to reflect the new address. The TYPE of
- * arr is important since size is the number of elements and
- * not the size in bytes
- * @param size the number of elements in the existing vector (number
- * of elements to copy over)
- * @param tsize the target size for the resulting vector, use 0 to
- * free the vector (then, arr will be NULL afterwards).
- */
-#define MSH_array_grow(arr,size,tsize) MSH_xgrow_((void**)&arr,
sizeof(arr[0]), &size, tsize, __FILE__, __LINE__)
-
-
-/**
- * Append an element to a list (growing the
- * list by one).
- */
-#define MSH_array_append(arr,size,element) do {
MSH_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
-
-
-/**
* Creates a new non-blocking socket and binds it to the given address and
makes
* it a listen socket
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28197 - msh/src,
gnunet <=