summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-08 07:58:36 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-08 07:58:36 +0100
commit3f52ce03cb13118bef9a6fbe380f229e2cbec45f (patch)
tree0f986c12192fcdd5d05fe575f66f01a0cf5ddf4e
parent7ad94d1427d304483e9bf1cf1d12065f8e41d712 (diff)
parent0120859e1ea2f0591602f446d4bc054e9230c801 (diff)
Merge branch 'master' of git+ssh://gnunet.org/gnunet
-rw-r--r--AUTHORS1
-rw-r--r--doc/documentation/chapters/developer.texi12
-rw-r--r--doc/documentation/chapters/philosophy.texi11
-rw-r--r--doc/documentation/chapters/user.texi6
-rw-r--r--doc/documentation/gnunet-c-tutorial.texi2
-rw-r--r--src/fs/fs_search.c19
-rw-r--r--src/fs/fs_uri.c25
-rw-r--r--src/gns/gnunet-dns2gns.c45
-rw-r--r--src/include/gnunet_fs_service.h3
-rw-r--r--src/include/gnunet_network_lib.h2
-rw-r--r--src/nat/gnunet-nat.c12
-rw-r--r--src/nse/gnunet-nse-profiler.c19
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c6
-rw-r--r--src/psycstore/psycstore_api.c3
-rw-r--r--src/rps/test_rps.c212
-rw-r--r--src/set/gnunet-service-set_union.c9
-rw-r--r--src/social/gnunet-service-social.c75
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4
-rw-r--r--src/transport/plugin_transport_tcp.c7
-rw-r--r--src/util/common_allocation.c5
-rw-r--r--src/util/configuration.c1
-rw-r--r--src/util/crypto_hash.c6
-rw-r--r--src/util/network.c86
-rw-r--r--src/util/scheduler.c17
24 files changed, 427 insertions, 161 deletions
diff --git a/AUTHORS b/AUTHORS
index e49319ac0..136848e3f 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -33,6 +33,7 @@ Contributions also came from:
Adam Warrington [ UPnP ]
Adriano Peluso [ Documentation export to Texinfo ]
Alex Harper [ OS X CPU load ]
+Amirouche Boubekki <amirouche@hypermove.net>
Andrew McDonald <andrew@mcdonald.org.uk> [ SHA-512]
Andy Green <andy@warmcat.com>
Antti Salonen
diff --git a/doc/documentation/chapters/developer.texi b/doc/documentation/chapters/developer.texi
index ada6d37a0..a99f6a481 100644
--- a/doc/documentation/chapters/developer.texi
+++ b/doc/documentation/chapters/developer.texi
@@ -94,6 +94,7 @@ following links:
@c ** FIXME: Link to files in source, not online.
@c ** FIXME: Where is the Java tutorial?
@itemize @bullet
+@c broken link
@item @uref{https://gnunet.org/git/gnunet.git/plain/doc/gnunet-c-tutorial.pdf, GNUnet C tutorial}
@item GNUnet Java tutorial
@end itemize
@@ -273,7 +274,7 @@ library is a wapper around block plugins which provide the necessary
functions for each block type.
@item @file{statistics/} --- statistics service
The statistics service enables associating
-values (of type uint64_t) with a componenet name and a string. The main
+values (of type uint64_t) with a component name and a string. The main
uses is debugging (counting events), performance tracking and user
entertainment (what did my peer do today?).
@item @file{arm/} --- Automatic Restart Manager (ARM)
@@ -2450,7 +2451,7 @@ memcpy (tbuf, nameTrans, strlen (nameTrans) + 1);
Note that, here the functions @code{htonl}, @code{htons} and
@code{GNUNET_TIME_absolute_hton} are applied to convert little endian
-into big endian, about the usage of the big/small edian order and the
+into big endian, about the usage of the big/small endian order and the
corresponding conversion function please refer to Introduction of
Big Endian and Little Endian.
@@ -7027,6 +7028,7 @@ bandwidth consumption.
@c %**end of header
+@c inconsistent use of ``must'' above it's written ``MUST''
In contrast to GET operations, developers @strong{must} manually re-run
PUT operations periodically (if they intend the content to continue to be
available). Content stored in the DHT expires or might be lost due to
@@ -7055,7 +7057,7 @@ Using the monitoring API, applications can choose to monitor these
requests, possibly limiting themselves to requests for a particular block
type.
-The monitoring API is not only usefu only for diagnostics, it can also be
+The monitoring API is not only useful for diagnostics, it can also be
used to trigger application operations based on PUT operations.
For example, an application may use PUTs to distribute work requests to
other peers.
@@ -7149,7 +7151,7 @@ already knows more than about a thousand blocks may need to send
several of these messages. Naturally, the client should transmit these
messages as quickly as possible after the original GET request such that
the DHT can filter those results in the network early on. Naturally, as
-these messages are send after the original request, it is conceivalbe
+these messages are sent after the original request, it is conceivalbe
that the DHT service may return blocks that match those already known
to the client anyway.
@@ -7240,7 +7242,7 @@ A peer can search the DHT by sending @code{struct PeerGetMessage}s of type
@code{GNUNET_MESSAGE_TYPE_DHT_P2P_GET} to other peers. In addition to the
usual information about the request (type, routing options, desired
replication level for the request, the key and the extended query), a GET
-request also again contains a hop counter, a Bloom filter over the peers
+request also contains a hop counter, a Bloom filter over the peers
that have processed the request already and depending on the routing
options the full path traversed by the GET.
Finally, a GET request includes a variable-size second Bloom filter and a
diff --git a/doc/documentation/chapters/philosophy.texi b/doc/documentation/chapters/philosophy.texi
index c8e2651c3..681d5acc3 100644
--- a/doc/documentation/chapters/philosophy.texi
+++ b/doc/documentation/chapters/philosophy.texi
@@ -47,7 +47,9 @@ Refer to @uref{https://www.gnu.org/philosophy/free-sw.html, https://www.gnu.org/
@item GNUnet must only disclose the minimal amount of information
necessary.
@c TODO: Explain 'fully' in the terminology section.
-@item GNUnet must be fully distributed and survive Byzantine failures
+@item GNUnet must be fully distributed and survive
+@uref{https://en.wikipedia.org/wiki/Byzantine_fault_tolerance, Byzantine failures}
+@footnote{@uref{https://en.wikipedia.org/wiki/Byzantine_fault_tolerance, https://en.wikipedia.org/wiki/Byzantine_fault_tolerance}}
at any position in the network.
@item GNUnet must make it explicit to the user which entities are
considered to be trustworthy when establishing secured communications.
@@ -163,7 +165,7 @@ DH (Diffie---Hellman) key exchange using ephemeral eliptic curve
cryptography. The ephemeral ECC (Eliptic Curve Cryptography) keys are
signed using ECDSA (@uref{http://en.wikipedia.org/wiki/ECDSA, ECDSA}).
The shared secret from ECDHE is used to create a pair of session keys
-@c FIXME: LOng word for HKDF
+@c FIXME: LOng word for HKDF. More FIXMEs: Explain MITM etc.
(using HKDF) which are then used to encrypt the communication between the
two peers using both 256-bit AES (Advanced Encryption Standard)
and 256-bit Twofish (with independently derived secret keys).
@@ -173,8 +175,6 @@ without requiring signatures each time. GNUnet uses SHA-512
(Secure Hash Algorithm) hash codes to verify the integrity of messages.
In GNUnet, the identity of a host is its public key. For that reason,
-@c FIXME: is it clear to the average reader what a man-in-the-middle
-@c attack is?
man-in-the-middle attacks will not break the authentication or accounting
goals. Essentially, for GNUnet, the IP of the host has nothing to do with
the identity of the host. As the public key is the only thing that truly
@@ -420,8 +420,9 @@ public key first.
@node Egos
@subsection Egos
+@c what is the difference between peer identity and egos? It seems
+@c like both are linked to public-private key pair.
Egos are your "identities" in GNUnet. Any user can assume multiple
identities, for example to separate their activities online. Egos can
correspond to pseudonyms or real-world identities. Technically, an
ego is first of all a public-private key pair.
-
diff --git a/doc/documentation/chapters/user.texi b/doc/documentation/chapters/user.texi
index 4159a6b32..1a30a7336 100644
--- a/doc/documentation/chapters/user.texi
+++ b/doc/documentation/chapters/user.texi
@@ -1183,6 +1183,8 @@ shared under the keyword "Das Kapital".
Search results are printed by gnunet-search like this:
+@c it will be better the avoid the ellipsis altogether because I don't
+@c understand the explanation below that
@example
$ gnunet-download -o "COPYING" --- gnunet://fs/chk/N8...C92.17992
=> The GNU Public License <= (mimetype: text/plain)
@@ -1192,6 +1194,7 @@ $ gnunet-download -o "COPYING" --- gnunet://fs/chk/N8...C92.17992
The first line is the command you would have to enter to download
the file. The argument passed to @code{-o} is the suggested
filename (you may change it to whatever you like).
+@c except it's triple dash in the above example ---
The @code{--} is followed by key for decrypting the file,
the query for searching the file, a checksum (in hexadecimal)
finally the size of the file in bytes.
@@ -1235,6 +1238,7 @@ GNUnet's file-encoding mechanism will ensure file integrity, even if the
existing file was not downloaded from GNUnet in the first place.
You may want to use the @command{-V} switch (must be added before
+@c Same as above it's triple dash
the @command{--}) to turn on verbose reporting. In this case,
@command{gnunet-download} will print the current number of
bytes downloaded whenever new data was received.
@@ -1301,7 +1305,7 @@ unavailable.
@c %**end of header
Each namespace is associated with meta-data that describes
-the namespace. This meta data is provided by the user at
+the namespace. This meta-data is provided by the user at
the time that the namespace is advertised. Advertisements
are published under keywords so that they can be found using
normal keyword-searches. This way, users can learn about new
diff --git a/doc/documentation/gnunet-c-tutorial.texi b/doc/documentation/gnunet-c-tutorial.texi
index f39c7de64..7eafa9ea9 100644
--- a/doc/documentation/gnunet-c-tutorial.texi
+++ b/doc/documentation/gnunet-c-tutorial.texi
@@ -244,6 +244,7 @@ $ wget $GNUPGFTP/libgpg-error/libgpg-error-1.27.tar.bz2
$ tar xf libgpg-error-1.27.tar.bz2
$ cd libgpg-error-1.27
$ ./configure
+$ make
$ sudo make install
$ cd ..
@end example
@@ -254,6 +255,7 @@ $ wget $GNUPGFTP/libgcrypt/libgcrypt-1.7.6.tar.bz2
$ tar xf libgcrypt-1.7.6.tar.bz2
$ cd libgcrypt-1.7.6
$ ./configure
+$ make
$ sudo make install
$ cd ..
@end example
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 8c6f5edcf..83aae2fc5 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -568,7 +568,13 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
/* check if new */
GNUNET_assert (NULL != sc);
- GNUNET_FS_uri_to_key (uri, &key);
+ if (GNUNET_OK !=
+ GNUNET_FS_uri_to_key (uri,
+ &key))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
&key,
@@ -680,8 +686,15 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
/* check if new */
GNUNET_assert (NULL != sc);
- GNUNET_FS_uri_to_key (uri, &key);
- GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query,
+ if (GNUNET_OK !=
+ GNUNET_FS_uri_to_key (uri,
+ &key))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
+ &uri->data.chk.chk.query,
&key);
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 11968b750..b90c75981 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -96,8 +96,9 @@
*
* @param uri uri to convert to a unique key
* @param key where to store the unique key
+ * @return #GNUNET_OK on success
*/
-void
+int
GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
struct GNUNET_HashCode *key)
{
@@ -105,25 +106,35 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
{
case GNUNET_FS_URI_CHK:
*key = uri->data.chk.chk.query;
- return;
+ return GNUNET_OK;
case GNUNET_FS_URI_SKS:
GNUNET_CRYPTO_hash (uri->data.sks.identifier,
- strlen (uri->data.sks.identifier), key);
- break;
+ strlen (uri->data.sks.identifier),
+ key);
+ return GNUNET_OK;
case GNUNET_FS_URI_KSK:
if (uri->data.ksk.keywordCount > 0)
+ {
GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
- strlen (uri->data.ksk.keywords[0]), key);
+ strlen (uri->data.ksk.keywords[0]),
+ key);
+ return GNUNET_OK;
+ }
+ else
+ {
+ memset (key, 0, sizeof (struct GNUNET_HashCode));
+ return GNUNET_SYSERR;
+ }
break;
case GNUNET_FS_URI_LOC:
GNUNET_CRYPTO_hash (&uri->data.loc.fi,
sizeof (struct FileIdentifier) +
sizeof (struct GNUNET_PeerIdentity),
key);
- break;
+ return GNUNET_OK;
default:
memset (key, 0, sizeof (struct GNUNET_HashCode));
- break;
+ return GNUNET_SYSERR;
}
}
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 424677d14..2f0de030d 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -533,14 +533,21 @@ read_dns4 (void *cls)
}
{
char buf[size + 1];
+ ssize_t sret;
addrlen = sizeof (v4);
- GNUNET_break (size ==
- GNUNET_NETWORK_socket_recvfrom (listen_socket4,
- buf,
- size + 1,
- (struct sockaddr *) &v4,
- &addrlen));
+ sret = GNUNET_NETWORK_socket_recvfrom (listen_socket4,
+ buf,
+ size + 1,
+ (struct sockaddr *) &v4,
+ &addrlen);
+ if (0 > sret)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "recvfrom");
+ return;
+ }
+ GNUNET_break (size == (size_t) sret);
handle_request (listen_socket4,
&v4,
addrlen,
@@ -579,16 +586,26 @@ read_dns6 (void *cls)
}
{
char buf[size];
+ ssize_t sret;
addrlen = sizeof (v6);
- GNUNET_break (size ==
- GNUNET_NETWORK_socket_recvfrom (listen_socket6,
- buf,
- size,
- (struct sockaddr *) &v6,
- &addrlen));
- handle_request (listen_socket6, &v6, addrlen,
- buf, size);
+ sret = GNUNET_NETWORK_socket_recvfrom (listen_socket6,
+ buf,
+ size,
+ (struct sockaddr *) &v6,
+ &addrlen);
+ if (0 > sret)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "recvfrom");
+ return;
+ }
+ GNUNET_break (size == (size_t) sret);
+ handle_request (listen_socket6,
+ &v6,
+ addrlen,
+ buf,
+ size);
}
}
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index ac418072e..cbad374b5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -109,8 +109,9 @@ typedef int
*
* @param uri uri to convert to a unique key
* @param key wherer to store the unique key
+ * @return #GNUNET_OK on success
*/
-void
+int
GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
struct GNUNET_HashCode *key);
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 9e692bbbf..2c344749f 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -53,7 +53,7 @@ struct GNUNET_NETWORK_FDSet
{
/**
- * Maximum number of any socket socket descriptor in the set (plus one)
+ * Maximum number of any socket descriptor in the set (plus one)
*/
int nsds;
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index b3cf2e946..72f343627 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -377,10 +377,16 @@ run (void *cls,
ls = GNUNET_NETWORK_socket_create (af,
SOCK_DGRAM,
IPPROTO_UDP);
+ if (NULL == ls)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "Failed to create socket\n");
+ goto fail_and_shutdown;
+ }
if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (ls,
- local_sa,
- local_len))
+ GNUNET_NETWORK_socket_bind (ls,
+ local_sa,
+ local_len))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to bind to %s: %s\n",
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 4a10022e3..b665812e5 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -374,13 +374,14 @@ nse_disconnect_adapter (void *cls,
*/
static int
stat_iterator (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value, int is_persistent)
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
{
char *output_buffer;
struct GNUNET_TIME_Absolute now;
- size_t size;
+ int size;
unsigned int flag;
GNUNET_assert (NULL != data_file);
@@ -390,8 +391,14 @@ stat_iterator (void *cls,
flag = 1;
size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
now.abs_value_us / 1000LL / 1000LL,
- value, flag);
- if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+ value, flag);
+ if (0 > size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
+ GNUNET_free (output_buffer);
+ return GNUNET_SYSERR;
+ }
+ if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
GNUNET_free (output_buffer);
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index bdb6e5e0d..6b39149be 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -1146,12 +1146,12 @@ handle_hello (void *cls,
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_PeerIdentity pid;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "HELLO message received for peer `%s'\n",
- GNUNET_i2s (&pid));
GNUNET_assert (GNUNET_OK ==
GNUNET_HELLO_get_id (hello,
&pid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "HELLO message received for peer `%s'\n",
+ GNUNET_i2s (&pid));
add_host_to_known_hosts (&pid);
update_hello (&pid,
hello);
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c
index 16f4a1ae9..5a4865dce 100644
--- a/src/psycstore/psycstore_api.c
+++ b/src/psycstore/psycstore_api.c
@@ -362,6 +362,9 @@ do_connect (struct GNUNET_PSYCSTORE_Handle *h)
static void
reconnect (void *cls)
{
+ struct GNUNET_PSYCSTORE_Handle *h = cls;
+
+ h->reconnect_task = NULL;
do_connect (cls);
}
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 0114a19fe..2cc1ac62e 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -62,6 +62,19 @@ static unsigned int mal_type = 0;
*/
static struct GNUNET_TESTBED_Peer **testbed_peers;
+/**
+ * @brief Indicates whether peer should go off- or online
+ */
+enum PEER_ONLINE_DELTA {
+ /**
+ * @brief Indicates peer going online
+ */
+ PEER_GO_ONLINE = 1,
+ /**
+ * @brief Indicates peer going offline
+ */
+ PEER_GO_OFFLINE = -1,
+};
/**
* Operation map entry
@@ -84,10 +97,10 @@ struct OpListEntry
struct GNUNET_TESTBED_Operation *op;
/**
- * Depending on whether we start or stop NSE service at the peer set this to 1
- * or -1
+ * Depending on whether we start or stop RPS service at the peer, set this to
+ * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
*/
- int delta;
+ enum PEER_ONLINE_DELTA delta;
/**
* Index of the regarding peer
@@ -188,7 +201,7 @@ struct RPSPeer
int online;
/**
- * Number of Peer IDs to request
+ * Number of Peer IDs to request during the whole test
*/
unsigned int num_ids_to_request;
@@ -218,6 +231,11 @@ struct RPSPeer
* Number of received PeerIDs
*/
unsigned int num_recv_ids;
+
+ /**
+ * Pending operation on that peer
+ */
+ const struct OpListEntry *entry_op_manage;
};
@@ -259,6 +277,11 @@ static int ok;
/**
* Identifier for the churn task that runs periodically
*/
+static struct GNUNET_SCHEDULER_Task *shutdown_task;
+
+/**
+ * Identifier for the churn task that runs periodically
+ */
static struct GNUNET_SCHEDULER_Task *churn_task;
/**
@@ -267,13 +290,21 @@ static struct GNUNET_SCHEDULER_Task *churn_task;
typedef void (*InitPeer) (struct RPSPeer *rps_peer);
/**
- * Called directly after connecting to the service
+ * @brief Called directly after connecting to the service
+ *
+ * @param rps_peer Specific peer the function is called on
+ * @param h the handle to the rps service
*/
-typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
+typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
/**
+ * @brief Executes functions to test the api/service for a given peer
+ *
* Called from within #rps_connect_complete_cb ()
- * Executes functions to test the api/service
+ * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
+ * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
+ *
+ * @param rps_peer the peer the task runs on
*/
typedef void (*MainTest) (struct RPSPeer *rps_peer);
@@ -306,7 +337,7 @@ struct SingleTestRun
char *name;
/**
- * Called to initialise peer
+ * Called with a single peer in order to initialise that peer
*/
InitPeer init_peer;
@@ -316,7 +347,7 @@ struct SingleTestRun
PreTest pre_test;
/**
- * Function to execute the functions to be tested
+ * Main function for each peer
*/
MainTest main_test;
@@ -502,6 +533,8 @@ shutdown_op (void *cls)
{
unsigned int i;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Shutdown task scheduled, going down.\n");
in_shutdown = GNUNET_YES;
if (NULL != churn_task)
{
@@ -583,6 +616,11 @@ info_cb (void *cb_cls,
{
struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
if (NULL == pinfo || NULL != emsg)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
@@ -632,6 +670,11 @@ rps_connect_complete_cb (void *cls,
struct RPSPeer *rps_peer = cls;
struct GNUNET_RPS_Handle *rps = ca_result;
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
rps_peer->rps_handle = rps;
rps_peer->online = GNUNET_YES;
num_peers_online++;
@@ -760,7 +803,10 @@ default_reply_handle (void *cls,
if (0 == evaluate ())
{
- GNUNET_SCHEDULER_shutdown ();
+ GNUNET_assert (NULL != shutdown_task);
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
+ GNUNET_assert (NULL!= shutdown_task);
}
}
@@ -904,12 +950,20 @@ static void mal_init_peer (struct RPSPeer *rps_peer)
rps_peer->num_ids_to_request = 1;
}
+
+/**
+ * @brief Set peers to (non-)malicious before execution
+ *
+ * Of signature #PreTest
+ *
+ * @param rps_peer the peer to set (non-) malicious
+ * @param h the handle to the service
+ */
static void
-mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
+mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
{
#ifdef ENABLE_MALICIOUS
uint32_t num_mal_peers;
- struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
GNUNET_assert ( (1 >= portion) &&
(0 < portion) );
@@ -934,6 +988,11 @@ mal_cb (struct RPSPeer *rps_peer)
{
uint32_t num_mal_peers;
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
#ifdef ENABLE_MALICIOUS
GNUNET_assert ( (1 >= portion) &&
(0 < portion) );
@@ -956,6 +1015,11 @@ mal_cb (struct RPSPeer *rps_peer)
static void
single_req_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
schedule_missing_requests (rps_peer);
}
@@ -965,6 +1029,11 @@ single_req_cb (struct RPSPeer *rps_peer)
static void
delay_req_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
schedule_missing_requests (rps_peer);
}
@@ -974,6 +1043,11 @@ delay_req_cb (struct RPSPeer *rps_peer)
static void
seed_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
GNUNET_SCHEDULER_add_delayed (
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
seed_peers, rps_peer);
@@ -985,6 +1059,11 @@ seed_cb (struct RPSPeer *rps_peer)
static void
seed_big_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
// TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
GNUNET_SCHEDULER_add_delayed (
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
@@ -1006,6 +1085,11 @@ single_peer_seed_cb (struct RPSPeer *rps_peer)
static void
seed_req_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
GNUNET_SCHEDULER_add_delayed (
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
seed_peers, rps_peer);
@@ -1020,6 +1104,11 @@ seed_req_cb (struct RPSPeer *rps_peer)
static void
req_cancel_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
schedule_missing_requests (rps_peer);
GNUNET_SCHEDULER_add_delayed (
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
@@ -1034,9 +1123,25 @@ req_cancel_cb (struct RPSPeer *rps_peer)
static void
churn (void *cls);
+/**
+ * @brief Starts churn
+ *
+ * Has signature of #MainTest
+ *
+ * This is not implemented too nicely as this is called for each peer, but we
+ * only need to call it once. (Yes we check that we only schedule the task
+ * once.)
+ *
+ * @param rps_peer The peer it's called for
+ */
static void
churn_test_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
/* Start churn */
if (GNUNET_YES == cur_test_run.have_churn && NULL == churn_task)
{
@@ -1073,6 +1178,11 @@ churn_cb (void *cls,
// FIXME
struct OpListEntry *entry = cls;
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
GNUNET_TESTBED_operation_done (entry->op);
if (NULL != emsg)
{
@@ -1084,7 +1194,7 @@ churn_cb (void *cls,
num_peers_online += entry->delta;
- if (0 > entry->delta)
+ if (PEER_GO_OFFLINE == entry->delta)
{ /* Peer hopefully just went offline */
if (GNUNET_YES != rps_peers[entry->index].online)
{
@@ -1102,7 +1212,7 @@ churn_cb (void *cls,
rps_peers[entry->index].online = GNUNET_NO;
}
- else if (0 < entry->delta)
+ else if (PEER_GO_ONLINE < entry->delta)
{ /* Peer hopefully just went online */
if (GNUNET_NO != rps_peers[entry->index].online)
{
@@ -1125,20 +1235,44 @@ churn_cb (void *cls,
}
rps_peers[entry->index].online = GNUNET_YES;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid value for delta: %i\n", entry->delta);
+ GNUNET_break (0);
+ }
GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
+ rps_peers[entry->index].entry_op_manage = NULL;
GNUNET_free (entry);
//if (num_peers_in_round[current_round] == peers_running)
// run_round ();
}
+/**
+ * @brief Set the rps-service up or down for a specific peer
+ *
+ * @param i index of action
+ * @param j index of peer
+ * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
+ * @param prob_go_on_off the probability of the action
+ */
static void
-manage_service_wrapper (unsigned int i, unsigned int j, int delta,
- double prob_go_on_off)
+manage_service_wrapper (unsigned int i, unsigned int j,
+ enum PEER_ONLINE_DELTA delta,
+ double prob_go_on_off)
{
struct OpListEntry *entry;
uint32_t prob;
+ GNUNET_assert (GNUNET_YES == rps_peers[j].online);
+
+ /* make sure that management operation is not already scheduled */
+ if (NULL != rps_peers[j].entry_op_manage)
+ {
+ return;
+ }
+
prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1146,15 +1280,19 @@ manage_service_wrapper (unsigned int i, unsigned int j, int delta,
i,
j,
GNUNET_i2s (rps_peers[j].peer_id),
- (0 > delta) ? "online" : "offline");
+ (PEER_GO_ONLINE == delta) ? "online" : "offline");
if (prob < prob_go_on_off * UINT32_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s goes %s\n",
GNUNET_i2s (rps_peers[j].peer_id),
- (0 > delta) ? "offline" : "online");
+ (PEER_GO_OFFLINE == delta) ? "offline" : "online");
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "testbed_peers points to %p, peer 0 to %p\n",
+ testbed_peers, testbed_peers[0]);
- if (0 > delta)
+ if (PEER_GO_OFFLINE == delta)
cancel_pending_req_rep (&rps_peers[j]);
entry = make_oplist_entry ();
entry->delta = delta;
@@ -1164,8 +1302,9 @@ manage_service_wrapper (unsigned int i, unsigned int j, int delta,
"rps",
&churn_cb,
entry,
- (0 > delta) ? 0 : 1);
+ (PEER_GO_OFFLINE == delta) ? 0 : 1);
}
+ rps_peers[j].entry_op_manage = entry;
}
@@ -1180,9 +1319,15 @@ churn (void *cls)
double portion_go_online;
double portion_go_offline;
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Churn function executing\n");
+ churn_task = NULL; /* Should be invalid by now */
+
/* Compute the probability for an online peer to go offline
* this round */
portion_online = num_peers_online * 1.0 / num_peers;
@@ -1290,6 +1435,11 @@ profiler_reply_handle (void *cls,
static void
profiler_cb (struct RPSPeer *rps_peer)
{
+ if (GNUNET_YES == in_shutdown)
+ {
+ return;
+ }
+
/* Start churn */
if (GNUNET_YES == cur_test_run.have_churn && NULL == churn_task)
{
@@ -1426,6 +1576,7 @@ run (void *cls,
entry);
}
+ /* Bring peers up */
num_mal_peers = round (portion * num_peers);
GNUNET_assert (num_peers == n_peers);
for (i = 0; i < n_peers; i++)
@@ -1448,7 +1599,7 @@ run (void *cls,
if (NULL != churn_task)
GNUNET_SCHEDULER_cancel (churn_task);
- GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
}
@@ -1609,14 +1760,21 @@ main (int argc, char *argv[])
with the malicious portion */
ok = 1;
- (void) GNUNET_TESTBED_test_run (cur_test_run.name,
- "test_rps.conf",
- num_peers,
- 0, NULL, NULL,
- &run, NULL);
+ ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
+ "test_rps.conf",
+ num_peers,
+ 0, NULL, NULL,
+ &run, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "_test_run returned.\n");
+ if (GNUNET_OK != ret_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Test did not run successfully!\n");
+ }
ret_value = cur_test_run.eval_cb();
- GNUNET_free (rps_peers );
+ GNUNET_free (rps_peers);
GNUNET_free (rps_peer_ids);
GNUNET_CONTAINER_multipeermap_destroy (peer_map);
return ret_value;
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 9586dcf27..219cc6235 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -389,10 +389,11 @@ get_ibf_key (const struct GNUNET_HashCode *src)
struct IBF_Key key;
uint16_t salt = 0;
- GNUNET_CRYPTO_kdf (&key, sizeof (key),
- src, sizeof *src,
- &salt, sizeof (salt),
- NULL, 0);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_kdf (&key, sizeof (key),
+ src, sizeof *src,
+ &salt, sizeof (salt),
+ NULL, 0));
return key;
}
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index 5b2a8ba9b..31e3a3dc2 100644
--- a/src/social/gnunet-service-social.c
+++ b/src/social/gnunet-service-social.c
@@ -503,17 +503,18 @@ cleanup_guest (struct Guest *gst)
struct GNUNET_CONTAINER_MultiHashMap *
plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests,
&plc->pub_key_hash);
- GNUNET_assert (NULL != plc_gst);
- GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst);
-
- if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst))
+ if (NULL != plc_gst)
{
- GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash,
- plc_gst);
- GNUNET_CONTAINER_multihashmap_destroy (plc_gst);
+ GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst);
+
+ if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst))
+ {
+ GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash,
+ plc_gst);
+ GNUNET_CONTAINER_multihashmap_destroy (plc_gst);
+ }
}
GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, gst);
-
if (NULL != gst->join_req)
GNUNET_free (gst->join_req);
if (NULL != gst->relays)
@@ -1391,19 +1392,27 @@ msg_proc_parse (const struct MsgProcRequest *mpreq,
const char **method_prefix,
struct GNUNET_HashCode *method_hash)
{
- uint8_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq);
- uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1],
- method_size, 1, method_prefix);
+ ssize_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq);
+ uint16_t offset;
- if (0 == offset || offset != method_size || *method_prefix == NULL)
+ if (method_size < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "offset = %u, method_size = %u, method_name = %s\n",
- offset, method_size, *method_prefix);
+ "MsgProcRequest has invalid size\n");
return GNUNET_SYSERR;
}
- GNUNET_CRYPTO_hash (*method_prefix, method_size, method_hash);
+ offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1],
+ method_size,
+ 1,
+ method_prefix);
+ if (0 == offset || offset != method_size || *method_prefix == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "MsgProcRequest contains invalid method\n");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_CRYPTO_hash (*method_prefix, (size_t) method_size, method_hash);
*flags = ntohl (mpreq->flags);
return GNUNET_OK;
}
@@ -1755,6 +1764,7 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
struct GNUNET_CONTAINER_MultiHashMap *
plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, &place_pub_hash);
struct Guest *gst = NULL;
+ int new_guest;
if (NULL != plc_gst)
gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash);
@@ -1763,9 +1773,12 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
"plc_gst = %p, gst = %p\n",
plc_gst,
gst);
+
+ new_guest = GNUNET_NO;
if (NULL == gst)
{
gst = GNUNET_new (struct Guest);
+ new_guest = GNUNET_YES;
}
if (NULL == gst->slave)
{
@@ -1841,6 +1854,9 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
plc_gst = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
(void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ }
+ if (GNUNET_YES == new_guest)
+ {
(void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
(void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst,
@@ -1862,6 +1878,7 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
ret = GNUNET_YES;
}
+ // TODO: explain why free(gst) not necessary
if (NULL != ret_gst)
*ret_gst = gst;
return ret;
@@ -2134,20 +2151,34 @@ handle_client_app_connect (void *cls,
{
struct Client *c = cls;
struct GNUNET_SERVICE_Client *client = c->client;
-
- uint8_t app_id_size = ntohs (creq->header.size) - sizeof (*creq);
+ ssize_t app_id_size = ntohs (creq->header.size) - sizeof (*creq);
const char *app_id = NULL;
- uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1],
- app_id_size, 1, &app_id);
+ uint16_t offset;
+
+ if (app_id_size < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "AppConnectRequest has invalid size\n");
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (client);
+ return;
+ }
+
+ offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1],
+ (size_t) app_id_size,
+ 1,
+ &app_id);
if (0 == offset || offset != app_id_size)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "AppConnectRequest contains invalid app ID\n");
GNUNET_break (0);
GNUNET_SERVICE_client_drop (client);
return;
}
struct GNUNET_HashCode app_id_hash;
- GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash);
+ GNUNET_CRYPTO_hash (app_id, (size_t) app_id_size, &app_id_hash);
GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client);
app_notify_ego_end (client);
@@ -2172,8 +2203,8 @@ handle_client_app_connect (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%p Application %s connected.\n", app, app_id);
- c->app_id = GNUNET_malloc (app_id_size);
- GNUNET_memcpy (c->app_id, app_id, app_id_size);
+ c->app_id = GNUNET_malloc ((size_t) app_id_size);
+ GNUNET_memcpy (c->app_id, app_id, (size_t) app_id_size);
GNUNET_SERVICE_client_continue (client);
}
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 8d3e47f94..2bf07bcd7 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1137,9 +1137,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
* our own receive rate and informs the neighbour about
* the new quota.
*
- * @param n neighbour entry to change qutoa for
+ * @param n neighbour entry to change quota for
* @param quota new quota
- * @return #GNUNET_YES if @a n is still valid, @GNUNET_NO if
+ * @return #GNUNET_YES if @a n is still valid, #GNUNET_NO if
* @a n was freed
*/
static int
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index c5d6e6d34..8b00543c3 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -3351,9 +3351,10 @@ handle_tcp_data (void *cls,
void *vaddr = NULL;
size_t alen;
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_SERVER_client_get_address (client,
+ &vaddr,
+ &alen));
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received unexpected %u bytes of type %u from `%s'\n",
(unsigned int) ntohs (message->size),
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index be2538c3f..1c55d72b5 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -475,8 +475,8 @@ GNUNET_xgrow_ (void **old,
*/
int
GNUNET_asprintf (char **buf,
- const char *format,
- ...)
+ const char *format,
+ ...)
{
int ret;
va_list args;
@@ -484,6 +484,7 @@ GNUNET_asprintf (char **buf,
va_start (args, format);
ret = VSNPRINTF (NULL, 0, format, args);
va_end (args);
+ GNUNET_assert (ret >= 0);
*buf = GNUNET_malloc (ret + 1);
va_start (args, format);
ret = VSPRINTF (*buf, format, args);
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 7f1d98902..25eeaf80f 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -421,7 +421,6 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
size_t m_size;
size_t c_size;
-
/* Pass1 : calculate the buffer size required */
m_size = 0;
for (sec = cfg->sections; NULL != sec; sec = sec->next)
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 20c7ca7ff..cce9cf82a 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -69,9 +69,9 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
char *np;
np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block,
- sizeof (struct GNUNET_HashCode),
- (char*) result,
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
+ sizeof (struct GNUNET_HashCode),
+ (char *) result,
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
GNUNET_assert (NULL != np);
*np = '\0';
}
diff --git a/src/util/network.c b/src/util/network.c
index 973878f93..0cb1529a6 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -91,8 +91,8 @@ GNUNET_NETWORK_test_pf (int pf)
if (EAFNOSUPPORT == errno)
return GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to create test socket: %s\n",
- STRERROR (errno));
+ "Failed to create test socket: %s\n",
+ STRERROR (errno));
return GNUNET_SYSERR;
}
#if WINDOWS
@@ -128,21 +128,20 @@ GNUNET_NETWORK_shorten_unixpath (char *unixpath)
if (slen < upm)
return unixpath; /* no shortening required */
GNUNET_CRYPTO_hash (unixpath, slen, &sh);
- while (16 +
- strlen (unixpath) >= upm)
+ while (16 + strlen (unixpath) >= upm)
{
if (NULL == (end = strrchr (unixpath, '/')))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to shorten unix path `%s' while keeping name unique\n"),
- unixpath);
+ _("Unable to shorten unix path `%s' while keeping name unique\n"),
+ unixpath);
GNUNET_free (unixpath);
return NULL;
}
*end = '\0';
}
GNUNET_CRYPTO_hash_to_enc (&sh, &ae);
- strncat (unixpath, (char*) ae.encoding, 16);
+ strncat (unixpath, (char *) ae.encoding, 16);
return unixpath;
}
@@ -239,7 +238,6 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
int flags = fcntl (fd->fd, F_GETFL);
if (flags == -1)
-
{
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
"fcntl");
@@ -311,7 +309,7 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
if (0 !=
setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE,
- (const void *) &abs_value,
+ (const void *) &abs_value,
sizeof (abs_value)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
@@ -342,8 +340,10 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
const char *abs_value = "1";
if (0 !=
- setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY,
- (const void *) abs_value,
+ setsockopt (h->fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (const void *) abs_value,
sizeof (abs_value)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
"setsockopt");
@@ -365,7 +365,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
*/
static int
initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
- int af,
+ int af,
int type)
{
int eno;
@@ -409,7 +409,7 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
#ifdef AF_UNIX
&& (af != AF_UNIX)
#endif
- )
+ )
socket_set_nodelay (h);
return GNUNET_OK;
}
@@ -426,7 +426,7 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
struct GNUNET_NETWORK_Handle *
GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
struct sockaddr *address,
- socklen_t *address_len)
+ socklen_t *address_len)
{
struct GNUNET_NETWORK_Handle *ret;
int eno;
@@ -443,7 +443,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
if (0 == gsn)
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Accepting connection on `%s'\n",
+ "Accepting connection on `%s'\n",
GNUNET_a2s ((const struct sockaddr *) &name,
namelen));
}
@@ -491,9 +491,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
const int on = 1;
if (AF_INET6 == desc->af)
- if (setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY,
- (const void *) &on,
- sizeof (on)))
+ if (setsockopt (desc->fd,
+ IPPROTO_IPV6,
+ IPV6_V6ONLY,
+ (const void *) &on,
+ sizeof (on)))
LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG,
"setsockopt");
}
@@ -593,8 +595,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
if (0 != unlink (dirname))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- dirname);
+ "unlink",
+ dirname);
}
else
{
@@ -1209,8 +1211,8 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
to->handles_size,
from->handles_pos * 2);
GNUNET_memcpy (to->handles,
- from->handles,
- from->handles_pos * sizeof (struct GNUNET_NETWORK_Handle *));
+ from->handles,
+ from->handles_pos * sizeof (struct GNUNET_NETWORK_Handle *));
to->handles_pos = from->handles_pos;
#endif
}
@@ -1327,9 +1329,9 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
int fd;
GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (h,
- &fd,
- sizeof (int)));
+ GNUNET_DISK_internal_file_handle_ (h,
+ &fd,
+ sizeof (int)));
FD_SET (fd,
&fds->sds);
fds->nsds = GNUNET_MAX (fd + 1,
@@ -1707,7 +1709,7 @@ initialize_select_thread ()
*/
int
GNUNET_NETWORK_test_port_free (int ipproto,
- uint16_t port)
+ uint16_t port)
{
struct GNUNET_NETWORK_Handle *socket;
int bind_status;
@@ -1718,37 +1720,35 @@ GNUNET_NETWORK_test_port_free (int ipproto,
struct addrinfo *ai;
GNUNET_snprintf (open_port_str,
- sizeof (open_port_str),
- "%u",
- (unsigned int) port);
- socktype = (IPPROTO_TCP == ipproto)
- ? SOCK_STREAM
- : SOCK_DGRAM;
+ sizeof (open_port_str),
+ "%u",
+ (unsigned int) port);
+ socktype = (IPPROTO_TCP == ipproto) ? SOCK_STREAM : SOCK_DGRAM;
ret = NULL;
memset (&hint, 0, sizeof (hint));
- hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
+ hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
hint.ai_socktype = socktype;
hint.ai_protocol = ipproto;
hint.ai_addrlen = 0;
hint.ai_addr = NULL;
hint.ai_canonname = NULL;
hint.ai_next = NULL;
- hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
+ hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
GNUNET_assert (0 == getaddrinfo (NULL,
- open_port_str,
- &hint,
- &ret));
+ open_port_str,
+ &hint,
+ &ret));
bind_status = GNUNET_NO;
for (ai = ret; NULL != ai; ai = ai->ai_next)
{
socket = GNUNET_NETWORK_socket_create (ai->ai_family,
- ai->ai_socktype,
- ai->ai_protocol);
+ ai->ai_socktype,
+ ai->ai_protocol);
if (NULL == socket)
continue;
bind_status = GNUNET_NETWORK_socket_bind (socket,
- ai->ai_addr,
- ai->ai_addrlen);
+ ai->ai_addr,
+ ai->ai_addrlen);
GNUNET_NETWORK_socket_close (socket);
if (GNUNET_OK != bind_status)
break;
@@ -1808,7 +1808,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
(tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value_us));
}
return select (nfds,
- (NULL != rfds) ? &rfds->sds : NULL,
+ (NULL != rfds) ? &rfds->sds : NULL,
(NULL != wfds) ? &wfds->sds : NULL,
(NULL != efds) ? &efds->sds : NULL,
(timeout.rel_value_us ==
@@ -2178,7 +2178,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding the socket event to the array as %d\n",
- nhandles);
+ nhandles);
handle_array[nhandles++] = select_finished_event;
if (timeout.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
{
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index fecbc0de5..9d37231e7 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -756,8 +756,9 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
t->fds = fdi;
if (1 == read_nh_len)
{
+ GNUNET_assert (NULL != read_nh);
+ GNUNET_assert (NULL != *read_nh);
fdi->fd = *read_nh;
- GNUNET_assert (NULL != fdi->fd);
fdi->et = GNUNET_SCHEDULER_ET_IN;
fdi->sock = GNUNET_NETWORK_get_fd (*read_nh);
t->read_fd = fdi->sock;
@@ -765,8 +766,9 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
}
else if (1 == write_nh_len)
{
+ GNUNET_assert (NULL != write_nh);
+ GNUNET_assert (NULL != *write_nh);
fdi->fd = *write_nh;
- GNUNET_assert (NULL != fdi->fd);
fdi->et = GNUNET_SCHEDULER_ET_OUT;
fdi->sock = GNUNET_NETWORK_get_fd (*write_nh);
t->read_fd = -1;
@@ -774,8 +776,9 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
}
else if (1 == read_fh_len)
{
+ GNUNET_assert (NULL != read_fh);
+ GNUNET_assert (NULL != *read_fh);
fdi->fh = *read_fh;
- GNUNET_assert (NULL != fdi->fh);
fdi->et = GNUNET_SCHEDULER_ET_IN;
fdi->sock = (*read_fh)->fd; // FIXME: does not work under WIN32
t->read_fd = fdi->sock;
@@ -783,8 +786,9 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
}
else
{
+ GNUNET_assert (NULL != write_fh);
+ GNUNET_assert (NULL != *write_fh);
fdi->fh = *write_fh;
- GNUNET_assert (NULL != fdi->fh);
fdi->et = GNUNET_SCHEDULER_ET_OUT;
fdi->sock = (*write_fh)->fd; // FIXME: does not work under WIN32
t->read_fd = -1;
@@ -1750,8 +1754,11 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
const struct GNUNET_DISK_FileHandle **write_fhandles;
unsigned int read_nhandles_len, write_nhandles_len,
read_fhandles_len, write_fhandles_len;
+ int no_fdsets = (NULL == rs) && (NULL == ws);
+ int no_socket_descriptors =
+ ((NULL != rs) && (0 == rs->nsds)) && ((NULL != ws) && (0 == ws->nsds));
- if (((NULL == rs) && (NULL == ws)) || ((0 == rs->nsds) && (0 == ws->nsds)))
+ if (no_fdsets || no_socket_descriptors)
return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
prio,
task,