2 days agoCheck for the presence of stdatomic.h before using it. master
Guus Sliepen [Tue, 7 Jul 2020 08:26:21 +0000 (10:26 +0200)]
Check for the presence of stdatomic.h before using it.

5 days agoDon't use assert() to check the results of pthread_*() calls.
Guus Sliepen [Sat, 4 Jul 2020 11:59:52 +0000 (13:59 +0200)]
Don't use assert() to check the results of pthread_*() calls.

This was done to debug the code, but it fails when MeshLink is compiled with
-DNDEBUG. Remove all assert()s from calls to pthread functions, and instead
add explicit checks to only those functions that can fail.

5 days agoExport meshlink_set_dev_class_maxtimeout().
Guus Sliepen [Sat, 4 Jul 2020 10:26:15 +0000 (12:26 +0200)]
Export meshlink_set_dev_class_maxtimeout().

5 days agoEnsure the maxtimeout value is taken from the destination node's device class.
Guus Sliepen [Sat, 4 Jul 2020 10:26:00 +0000 (12:26 +0200)]
Ensure the maxtimeout value is taken from the destination node's device class.

2 weeks agoMake the maximum outgoing connection timeout runtime configurable.
Guus Sliepen [Wed, 24 Jun 2020 20:22:01 +0000 (22:22 +0200)]
Make the maximum outgoing connection timeout runtime configurable.

This moves maxtimeout to the dev_class_traits, and adds a function to
change it, similar to how we handle other configurable timeouts.

2 weeks agoFix compiling the C++ examples.
Guus Sliepen [Tue, 16 Jun 2020 19:34:52 +0000 (21:34 +0200)]
Fix compiling the C++ examples.

3 weeks agoRevert "Fix warnings caused by C-only flags passed to the C++ compiler."
Guus Sliepen [Tue, 16 Jun 2020 18:07:12 +0000 (20:07 +0200)]
Revert "Fix warnings caused by C-only flags passed to the C++ compiler."

This reverts commit 9382f55b3f1c14c74e3bda229e277400743b11cc.

3 weeks agoRevert "Don't overwrite CFLAGS when adding -std=c11."
Guus Sliepen [Tue, 16 Jun 2020 18:06:59 +0000 (20:06 +0200)]
Revert "Don't overwrite CFLAGS when adding -std=c11."

This reverts commit 6d0820fda557de28c014b8ad4c40c385d23029a7.

3 weeks agoDon't overwrite CFLAGS when adding -std=c11.
Guus Sliepen [Mon, 15 Jun 2020 08:03:36 +0000 (10:03 +0200)]
Don't overwrite CFLAGS when adding -std=c11.

3 weeks agoReact faster to network changes, including point-to-point links.
Guus Sliepen [Sun, 14 Jun 2020 12:45:18 +0000 (14:45 +0200)]
React faster to network changes, including point-to-point links.

Tell Catta to also include point-to-point links, and when we get an
update from the Catta thread, wake up the main MeshLink thread so we
react to it immediately.

3 weeks agoOnly call setitimer if ITIMER_REAL is defined. fix/pthread-fixes
Guus Sliepen [Sat, 13 Jun 2020 19:45:08 +0000 (21:45 +0200)]
Only call setitimer if ITIMER_REAL is defined.

Musl doesn't implement setitimer().

3 weeks agoSet NOSIGPIPE on all sockets.
Guus Sliepen [Sat, 13 Jun 2020 19:39:39 +0000 (21:39 +0200)]
Set NOSIGPIPE on all sockets.

MacOS can raise a SIGPIPE when a local socket gets disconnected.

3 weeks agoFix warnings and missing mutex/cond initialization in the test suite.
Guus Sliepen [Fri, 12 Jun 2020 22:41:47 +0000 (00:41 +0200)]
Fix warnings and missing mutex/cond initialization in the test suite.

3 weeks agoInitialize the adns_done_queue.
Guus Sliepen [Fri, 12 Jun 2020 22:40:43 +0000 (00:40 +0200)]
Initialize the adns_done_queue.

3 weeks agoFix warnings caused by C-only flags passed to the C++ compiler.
Guus Sliepen [Fri, 12 Jun 2020 22:40:09 +0000 (00:40 +0200)]
Fix warnings caused by C-only flags passed to the C++ compiler.

3 weeks agoAdd missing initialization of a condition variable.
Guus Sliepen [Fri, 12 Jun 2020 07:09:52 +0000 (09:09 +0200)]
Add missing initialization of a condition variable.

4 weeks agoFix some test cases using the same configuration directory.
Guus Sliepen [Thu, 11 Jun 2020 20:31:25 +0000 (22:31 +0200)]
Fix some test cases using the same configuration directory.

4 weeks agoUse atomic operations to check whether to write to the signal pipe.
Guus Sliepen [Thu, 11 Jun 2020 19:52:00 +0000 (21:52 +0200)]
Use atomic operations to check whether to write to the signal pipe.

We need to do an atomic test-and-set operation to check whether we can
avoid writing to the signal pipe. Use C11 atomics to do this in a portable
way (hopefully).

4 weeks agoRemove gettimeofday() usage from test cases.
Guus Sliepen [Thu, 11 Jun 2020 20:22:37 +0000 (22:22 +0200)]
Remove gettimeofday() usage from test cases.

4 weeks agoAdd asserts() to all pthread related function calls.
Guus Sliepen [Thu, 11 Jun 2020 20:17:23 +0000 (22:17 +0200)]
Add asserts() to all pthread related function calls.

We normally expect all pthread-related functions to succeed, so in all
places where we didn't already explicitly check the return value, assert()
that the functions return 0.

4 weeks agoProperly initialize mutexes and condition variables.
Guus Sliepen [Wed, 10 Jun 2020 20:25:12 +0000 (22:25 +0200)]
Properly initialize mutexes and condition variables.

On Linux, zeroing a pthread_mutex_t or pthread_cond_t variable ensures
the mutex/cond is properly initialized, however this is not the case om
some other platforms. Ensure we always call pthread_mutex/cond_init().

4 weeks agoFix compiler warnings on macOS.
Guus Sliepen [Tue, 9 Jun 2020 21:18:04 +0000 (23:18 +0200)]
Fix compiler warnings on macOS.

4 weeks agoCheck whether IP_MTU is defined.
Guus Sliepen [Tue, 9 Jun 2020 21:12:44 +0000 (23:12 +0200)]
Check whether IP_MTU is defined.

4 weeks agoFix meshlink_join() failing on Android.
Guus Sliepen [Fri, 5 Jun 2020 16:09:38 +0000 (18:09 +0200)]
Fix meshlink_join() failing on Android.

The adns_blocking_request() function did not pass a hint to
getaddrinfo(). With glibc, the resulting struct addrinfo sets socktype
and protocol to SOCK_STREAM and IPPROTO_TCP, and the call to connect()
copied these values. However, bionic doesn't set the socktype and
protocol to those values if no hint was specified.

4 weeks agoEnsure utcp-test is compiled with the same flags as libmeshlink.
Guus Sliepen [Fri, 5 Jun 2020 07:40:26 +0000 (09:40 +0200)]
Ensure utcp-test is compiled with the same flags as libmeshlink.

5 weeks agoInclude "system.h" in the UTCP sources.
Guus Sliepen [Wed, 3 Jun 2020 19:23:33 +0000 (21:23 +0200)]
Include "system.h" in the UTCP sources.

The UTCP sources were not using the system.h header file like the rest
of the code, resulting in issues with some compilers.

5 weeks agoDon't crash when trying to connect a channel to port 0.
Guus Sliepen [Wed, 3 Jun 2020 19:19:09 +0000 (21:19 +0200)]
Don't crash when trying to connect a channel to port 0.

7 weeks agoExplicitly set the stack size for the MeshLink thread.
Guus Sliepen [Thu, 21 May 2020 12:48:02 +0000 (14:48 +0200)]
Explicitly set the stack size for the MeshLink thread.

Different libcs have different default sizes for newly created threads. In
particular, Musl defaults to 80 kB, which is too small for MeshLink. We now
request 1 MB, which should be more than enough to handle the deepest call

7 weeks agoLimit the size of the fd read buffer in channel_poll().
Guus Sliepen [Wed, 20 May 2020 22:13:50 +0000 (00:13 +0200)]
Limit the size of the fd read buffer in channel_poll().

7 weeks agoAdd a test for AIO callback cornercases.
Guus Sliepen [Mon, 18 May 2020 21:25:50 +0000 (23:25 +0200)]
Add a test for AIO callback cornercases.

7 weeks agoFix assert that could incorrectly be triggered when a peer closed the channel.
Guus Sliepen [Mon, 18 May 2020 21:24:56 +0000 (23:24 +0200)]
Fix assert that could incorrectly be triggered when a peer closed the channel.

If we are sending AIO data on a channel and the peer closed the connection,
we could trigger an assert incorrectly.

7 weeks agoReport the amount of actual data sent/received in AIO callbacks.
Guus Sliepen [Mon, 18 May 2020 21:23:32 +0000 (23:23 +0200)]
Report the amount of actual data sent/received in AIO callbacks.

We did this for fds but not for memory buffers.

7 weeks agoReset closed connections if there is incoming data.
Guus Sliepen [Mon, 18 May 2020 21:22:06 +0000 (23:22 +0200)]
Reset closed connections if there is incoming data.

7 weeks agoInclude our own key in REQ_PUBKEY requests.
Guus Sliepen [Fri, 15 May 2020 21:12:34 +0000 (23:12 +0200)]
Include our own key in REQ_PUBKEY requests.

If we don't know a peer's public key, it most likely means the peer
doesn't know our public key, so proactively send it along with the
REQ_PUBKEY request.

7 weeks agoHandle UTCP receive buffer wraparound corner cases.
Guus Sliepen [Fri, 15 May 2020 07:39:59 +0000 (09:39 +0200)]
Handle UTCP receive buffer wraparound corner cases.

Before we allowed buf->offset to be equal to buf->size. This caused an
issue where buffer_call() would call the callback twice, once for 0
bytes at the end of the buffer, and once for len bytes at the start of
the buffer.  This would cause the callback function to think the channel
had encountered an error.

If the data in the ringbuffer wraps around, and we call the receive
callback for the first part of the data, the callback function might
close the channel, so we must not call the callback for the second part
of the data.

8 weeks agoFix mismatch in supported compile flags tested for and added to CPPFLAGS.
Guus Sliepen [Wed, 13 May 2020 20:50:26 +0000 (22:50 +0200)]
Fix mismatch in supported compile flags tested for and added to CPPFLAGS.

8 weeks agoFix more compiler warnings.
Guus Sliepen [Wed, 13 May 2020 20:48:02 +0000 (22:48 +0200)]
Fix more compiler warnings.

This enables much more compiler warnings by default, and fixes all the
warnings we get from GCC 10 and Clang 10 in the library.

The blackbox test cases still produce a lot of warnings that have not
been fixed yet.

8 weeks agoFix make distcheck.
Guus Sliepen [Mon, 11 May 2020 20:04:22 +0000 (22:04 +0200)]
Fix make distcheck.

8 weeks agoAdd Doxygen support to the build system.
Guus Sliepen [Mon, 11 May 2020 19:34:50 +0000 (21:34 +0200)]
Add Doxygen support to the build system.

8 weeks agoMove UTCP into the MeshLink repository.
Guus Sliepen [Mon, 11 May 2020 17:52:00 +0000 (19:52 +0200)]
Move UTCP into the MeshLink repository.

UTCP is not used outside of MeshLink at the moment, and there is a tight
coupling between the two, so it makes more sense to have it as part of
MeshLink itself.

8 weeks agoHandle EINTR when reading/writing to AIO fds.
Guus Sliepen [Sat, 9 May 2020 20:41:23 +0000 (22:41 +0200)]
Handle EINTR when reading/writing to AIO fds.

2 months agoHandle meshlink_channel_close() being called in callbacks. fix/channel-close-in-callback
Guus Sliepen [Fri, 8 May 2020 10:48:44 +0000 (12:48 +0200)]
Handle meshlink_channel_close() being called in callbacks.

When it's called in a callback, we can't free the channel until the
function that called the callback has a chance to safely complete. This
is not a problem for regular receive and poll callbacks, but it is for AIO,
where there can be multiple outstanding AIO buffers that each need their
callback called to signal completion, and each of them could potentially
call meshlink_channel_close().

This also ensures that when the channel is explicitly closed by the
application, it will not receive any further callbacks.

2 months agoUpdate UTCP to fix retransmission of SYNACK packets.
Guus Sliepen [Mon, 4 May 2020 06:42:22 +0000 (08:42 +0200)]
Update UTCP to fix retransmission of SYNACK packets.

2 months agoAvoid a segfault when setting a timeout to 0.
Guus Sliepen [Tue, 28 Apr 2020 21:19:29 +0000 (23:19 +0200)]
Avoid a segfault when setting a timeout to 0.

The event loop was assuming that a timespec value of {0, 0} meant that the
timer was not added to the timer tree. However, it was possible for other
parts of the code to set the value to {0, 0}, which could result in a
segmentation fault. Use the splay_node_t data pointer to check whether a
timeout is linked into the tree instead.

2 months agoSeveral fixes for channel AIO send and receive functions.
Guus Sliepen [Tue, 28 Apr 2020 20:21:34 +0000 (22:21 +0200)]
Several fixes for channel AIO send and receive functions.

- Process multiple buffers if possible
- Better handling error conditions
  - fd errors now cancel the AIO buffer
  - channel errors cancel all outstanding AIO buffers
- Don't call the poll callback with a length larger than the remaining
  UTCP send buffer.

2 months agoFix a potential read from a freed buffer when sending data to a blacklisted node.
Guus Sliepen [Tue, 28 Apr 2020 18:20:45 +0000 (20:20 +0200)]
Fix a potential read from a freed buffer when sending data to a blacklisted node.

2 months agoAvoid a crash when graph() is called when the event loop is not running.
Guus Sliepen [Tue, 21 Apr 2020 21:33:47 +0000 (23:33 +0200)]
Avoid a crash when graph() is called when the event loop is not running.

2 months agoMake UTCP retranmissions trigger PMTU probes immediately.
Guus Sliepen [Sun, 19 Apr 2020 14:28:43 +0000 (16:28 +0200)]
Make UTCP retranmissions trigger PMTU probes immediately.

If there are network problems while data is being transferred over a
channel, we want to react to this as soon as possible. Set the retranmission
callback to trigger the next PMTU probe immediately if there as none in

2 months agoUse nanosleep() instead of clock_nanosleep().
Guus Sliepen [Thu, 16 Apr 2020 21:56:36 +0000 (23:56 +0200)]
Use nanosleep() instead of clock_nanosleep().

Mac OS X does not support the latter.

2 months agoUpdate UTCP to fix a potential segmentation fault.
Guus Sliepen [Thu, 16 Apr 2020 00:12:33 +0000 (02:12 +0200)]
Update UTCP to fix a potential segmentation fault.

2 months agoEnsure exported host files have a port in the canonical address.
Guus Sliepen [Thu, 16 Apr 2020 00:08:38 +0000 (02:08 +0200)]
Ensure exported host files have a port in the canonical address.

2 months agoUpdate UTCP.
Guus Sliepen [Sat, 11 Apr 2020 22:54:58 +0000 (00:54 +0200)]
Update UTCP.

2 months agoCheck that we can send up to 65536 bytes at a time on UDP-style channels.
Guus Sliepen [Sat, 11 Apr 2020 22:14:23 +0000 (00:14 +0200)]
Check that we can send up to 65536 bytes at a time on UDP-style channels.

2 months agoHave nodes remember in which submesh they live.
Guus Sliepen [Sat, 11 Apr 2020 22:06:13 +0000 (00:06 +0200)]
Have nodes remember in which submesh they live.

This exposes the submesh a node lives in to the node itself.

2 months agoAllow meshlink_open() to be called with a NULL name.
Guus Sliepen [Sat, 11 Apr 2020 16:15:50 +0000 (18:15 +0200)]
Allow meshlink_open() to be called with a NULL name.

This will use the name used last time the MeshLink instance was initialized.
If there is no initialized instance at the given confbase, it will return
an error.

Opening an instance with a different name than the one in the configuration
files will now also result in an error.

2 months agoWhen resetting timers that use CLOCK_MONOTONIC, use a negative value.
Guus Sliepen [Sat, 11 Apr 2020 15:43:18 +0000 (17:43 +0200)]
When resetting timers that use CLOCK_MONOTONIC, use a negative value.

CLOCK_MONOTONIC might be implemented as the time since the CPU booted, so
if MeshLink starts soon after booting, setting timers to "0" might not
actually be far enough in the past to trigger a timeout.

This has almost no effect in practice, since most timeouts are a minute or
less, but it might affect running tests in virtual machines.

2 months agoAdd a probe point for SPTPS renewal and devtool_force_sptps_renewal().
Guus Sliepen [Sat, 11 Apr 2020 15:27:39 +0000 (17:27 +0200)]
Add a probe point for SPTPS renewal and devtool_force_sptps_renewal().

The latter function just sets the timers so they should time out immediately.

2 months agoAlso renew SPTPS keys for meta-connections.
Guus Sliepen [Sat, 11 Apr 2020 15:25:53 +0000 (17:25 +0200)]
Also renew SPTPS keys for meta-connections.

2 months agoAdd a probe point for async DNS resolving.
Guus Sliepen [Sat, 11 Apr 2020 14:33:22 +0000 (16:33 +0200)]
Add a probe point for async DNS resolving.

2 months agoAdd UTCP UDP channel corner cases and test cases on channel get MSS length API
sairoop-elear [Fri, 10 Apr 2020 21:58:51 +0000 (03:28 +0530)]
Add UTCP UDP channel corner cases and test cases on channel get MSS length API

2 months agoAdd channel poll callback corner cases
sairoop-elear [Fri, 10 Apr 2020 11:45:22 +0000 (17:15 +0530)]
Add channel poll callback corner cases

2 months agoAdd missing atomic test cases to the APIs that affects disk writes
sairoop-elear [Tue, 7 Apr 2020 20:22:26 +0000 (01:52 +0530)]
Add missing atomic test cases to the APIs that affects disk writes

3 months agoUse blocking ADNS requests for most other hostname resolving. feature/async-dns
Guus Sliepen [Thu, 9 Apr 2020 22:06:15 +0000 (00:06 +0200)]
Use blocking ADNS requests for most other hostname resolving.

We keep calling getaddrinfo() directly if we know we only need to resolve
a numerical address.

3 months agoAdd "blocking" asynchronous DNS requests.
Guus Sliepen [Thu, 9 Apr 2020 21:39:19 +0000 (23:39 +0200)]
Add "blocking" asynchronous DNS requests.

These block for a limited amount of time, preventing lookups from taking
too long. Because these requests can be done without the main MeshLink
thread running, we don't use the request queue, but instead spawn a
thread for each blocking request.

3 months agoAdd asynchronous DNS lookups for outgoing connections.
Guus Sliepen [Tue, 7 Apr 2020 22:50:51 +0000 (00:50 +0200)]
Add asynchronous DNS lookups for outgoing connections.

3 months agoRemove unused support for proxies.
Guus Sliepen [Tue, 7 Apr 2020 21:17:38 +0000 (23:17 +0200)]
Remove unused support for proxies.

3 months agoAdd an asynchronous DNS thread.
Guus Sliepen [Thu, 23 May 2019 21:02:43 +0000 (23:02 +0200)]
Add an asynchronous DNS thread.

Add a thread dedicated to making DNS lookups. There are two queues, one
for pending DNS requests and one for done DNS requests. The async DNS
thread reads from the pending request queue, checks for each request if
the deadline has not been met yet, and if so calls getaddrinfo(). Once
the result is obtained, it adds that to the done request queue and
signals the main meshlink thread, which will then call the callback
function associated with the DNS request.

3 months agoAssume getaddrinfo() and IPv6 are supported.
Guus Sliepen [Thu, 23 May 2019 20:12:04 +0000 (22:12 +0200)]
Assume getaddrinfo() and IPv6 are supported.

All major operating systems of the last 10 years have supported IPv6 and
provide getaddrinfo().

3 months agoFix a debug message being logged incorrectly.
Guus Sliepen [Tue, 7 Apr 2020 22:46:26 +0000 (00:46 +0200)]
Fix a debug message being logged incorrectly.

3 months agoUpdate UTCP to fix retransmit timeout calculation.
Guus Sliepen [Mon, 6 Apr 2020 06:39:33 +0000 (08:39 +0200)]
Update UTCP to fix retransmit timeout calculation.

3 months agoUpdate UTCP to fix RTT measurements.
Guus Sliepen [Sun, 5 Apr 2020 23:59:28 +0000 (01:59 +0200)]
Update UTCP to fix RTT measurements.

3 months agoUpdate UTCP to support fragmenting packets on UDP style channels.
Guus Sliepen [Thu, 2 Apr 2020 22:23:11 +0000 (00:23 +0200)]
Update UTCP to support fragmenting packets on UDP style channels.

This allows the application to send packets of arbitrary size (up to 64 kiB)
without worrying about the path MTU to the destination node, which might
vary, especially at the start of a connection.

If the application doesn't want packets to fragment, it should use
meshlink_channel_get_mss() to query the maximum size for unfragmented

3 months agoUpdated test vectors for get node reachability
Roop [Thu, 13 Feb 2020 11:18:43 +0000 (16:48 +0530)]
Updated test vectors for get node reachability

3 months agoAdd meshlink_get_all_nodes_by_last_reachable API, meshlink_get_node_reachability...
Roop [Tue, 4 Feb 2020 10:46:29 +0000 (16:16 +0530)]
Add meshlink_get_all_nodes_by_last_reachable API, meshlink_get_node_reachability API and its test vectors

MeshLink now keeps track of when a node was last reachable. This can be
used by an application to detect nodes that were never reachable or which
have not been reachable for a certain amount of time.

3 months agoUpdate UTCP to fix a compile error.
Guus Sliepen [Thu, 2 Apr 2020 18:31:48 +0000 (20:31 +0200)]
Update UTCP to fix a compile error.

3 months agoAllow setting the UTCP clock granularity.
Guus Sliepen [Tue, 31 Mar 2020 09:22:35 +0000 (11:22 +0200)]
Allow setting the UTCP clock granularity.

This sets the granularity to 10 ms by default, and adds the function
meshlink_set_scheduling_granularity() to be able to change it.

3 months agoFix key renewal being called too often after the first renewal.
Guus Sliepen [Mon, 30 Mar 2020 06:21:24 +0000 (08:21 +0200)]
Fix key renewal being called too often after the first renewal.

3 months agoTry addresses found by Catta for UDP probes.
Guus Sliepen [Sun, 29 Mar 2020 22:42:32 +0000 (00:42 +0200)]
Try addresses found by Catta for UDP probes.

3 months agoRenew SPTPS keys every hour.
Guus Sliepen [Sun, 29 Mar 2020 22:24:30 +0000 (00:24 +0200)]
Renew SPTPS keys every hour.

We did do this in the past, but in some commit we stopped automatically
renewing keys every hour.

3 months agoAvoid allocating packet buffers unnecessarily.
Guus Sliepen [Sun, 29 Mar 2020 22:04:29 +0000 (00:04 +0200)]
Avoid allocating packet buffers unnecessarily.

Unless we have to queue a packet, we can avoid allocating and freeing
memory by keeping a permanently allocated packet buffer around.

3 months agoPropagate the discovered PMTU between nodes to UTCP.
Guus Sliepen [Sun, 29 Mar 2020 17:33:18 +0000 (19:33 +0200)]
Propagate the discovered PMTU between nodes to UTCP.

3 months agoUpdate UTCP and replace gettimeofday() with clock_gettime().
Guus Sliepen [Sun, 29 Mar 2020 19:52:24 +0000 (21:52 +0200)]
Update UTCP and replace gettimeofday() with clock_gettime().

3 months agoSend out channel data immediately, bypassing the packet queue.
Guus Sliepen [Fri, 27 Mar 2020 22:01:26 +0000 (23:01 +0100)]
Send out channel data immediately, bypassing the packet queue.

3 months agoReduce how often we have to poll the packet queue.
Guus Sliepen [Fri, 27 Mar 2020 21:52:46 +0000 (22:52 +0100)]
Reduce how often we have to poll the packet queue.

Packets are moved to the MeshLink thread via the packet queue. However,
each packet required a trigger byte to be sent to the event loop, requiring
more calls to select() than necessary. Now we make event loop signals level
triggered, and dequeue all enqueued packets at once.

This also adds debug log statements for the packet queue.

3 months agoRemove redundant call to add_local_addresses().
Guus Sliepen [Sun, 15 Mar 2020 15:33:46 +0000 (16:33 +0100)]
Remove redundant call to add_local_addresses().

3 months agoHave try_bind() reuse the setup_*_listen_socket() functions.
Guus Sliepen [Sun, 15 Mar 2020 15:24:34 +0000 (16:24 +0100)]
Have try_bind() reuse the setup_*_listen_socket() functions.

This ensures try_bind() configures sockets exactly the same as the actual
listening sockets.

3 months agoFix the order of socket operations when setting up listening sockets.
Guus Sliepen [Sun, 15 Mar 2020 15:08:44 +0000 (16:08 +0100)]
Fix the order of socket operations when setting up listening sockets.

Commit db8e6e4 caused calls to setsockopt() for setting up socket parameters
to be called after the call to bind().

3 months agoUse slashes internally to separate hostnames and ports in invitation addresses.
Guus Sliepen [Thu, 12 Mar 2020 20:32:41 +0000 (21:32 +0100)]
Use slashes internally to separate hostnames and ports in invitation addresses.

This avoids possible confusion when an IPv6 hostname is used without an
explicit port number.

3 months agoFix IPv6 address validation bug preventing IPv6 addresses that are added for invitati...
sairoop-elear [Thu, 12 Mar 2020 08:24:45 +0000 (13:54 +0530)]
Fix IPv6 address validation bug preventing IPv6 addresses that are added for invitation from getting added

3 months agoCorrectly remove all duplicates when having many hostnames in an invitation URL.
Guus Sliepen [Wed, 11 Mar 2020 22:12:08 +0000 (23:12 +0100)]
Correctly remove all duplicates when having many hostnames in an invitation URL.

Commit fbcf089 missed adjusting one call to

3 months agoFix some log messages being reported for the wrong log levels.
Guus Sliepen [Tue, 10 Mar 2020 21:54:45 +0000 (22:54 +0100)]
Fix some log messages being reported for the wrong log levels.

3 months agoAdd all recent addresses resolved from a hostname in meshlink_invite().
Guus Sliepen [Tue, 10 Mar 2020 21:42:33 +0000 (22:42 +0100)]
Add all recent addresses resolved from a hostname in meshlink_invite().

When a canonical hostname or an invitation address resolves to multiple
numeric addresses, add all of them as recent addresses for ourself, so
they are all part of the host config file we send to the invitee.

3 months agoUpdate the invite-join test.
Guus Sliepen [Tue, 10 Mar 2020 21:37:28 +0000 (22:37 +0100)]
Update the invite-join test.

- Check that duplicate addresses get culled correctly.
- Check that we can add lots of extra invitation addresses, and that
  they are in the expected order in the invitation URL.

3 months agoEnsure we process all hostnames for invitation URLs.
Guus Sliepen [Tue, 10 Mar 2020 21:33:42 +0000 (22:33 +0100)]
Ensure we process all hostnames for invitation URLs.

Commit 3febbb4 allowed more addresses to be added to invitation URLs, but
part of the still code assumed a maximum of 4 addresses in the URL.

3 months agoFix potential double free when using meshlink_add_invitation_address().
Guus Sliepen [Tue, 10 Mar 2020 21:05:57 +0000 (22:05 +0100)]
Fix potential double free when using meshlink_add_invitation_address().

4 months agoHandle not being able to bind to the configured port at startup.
Guus Sliepen [Fri, 6 Mar 2020 23:19:57 +0000 (00:19 +0100)]
Handle not being able to bind to the configured port at startup.

When starting a MeshLink node that has already been configured to run on a
certain port, but that port is in use (for one or more of the supported
address families), it would either ignore some address families, or would
try to bind to port 0 if all address families failed. However, this is
problematic, because it makes discovery and invitation URL generation much

Fix this by checking if any port binding fails for a supported address
family, and if so, try to find another port that does support binding on
all address families. If it fails to find any available port, it will fall
back to binding to port 0, so that outgoing connections are still possible.

4 months agoDon't abort on empty lines in receive_request().
Guus Sliepen [Fri, 6 Mar 2020 22:24:49 +0000 (23:24 +0100)]
Don't abort on empty lines in receive_request().

Remove the assertion that lines are not empty, since this could lead to
a DoS attack. Empty lines are already handled correctly by the rest of
the logic in receive_request().

4 months agoAdd meshlink_add_invitation_address(), deprecate meshlink_add_address().
Guus Sliepen [Fri, 6 Mar 2020 22:20:22 +0000 (23:20 +0100)]
Add meshlink_add_invitation_address(), deprecate meshlink_add_address().

This adds a function to add one or more application-controlled address and
port combinations to invitation URLs. It is meant to replace
meshlink_add_address(), which is too limited because it only allows one
address to be set, and doesn't allow a different port number to be set.

4 months agoAdd meshlink_set_external_address_discovery_url().
Guus Sliepen [Sat, 29 Feb 2020 15:19:44 +0000 (16:19 +0100)]
Add meshlink_set_external_address_discovery_url().

This function can be used to override the default service to
query a host's own externally visible address.

4 months agoUse the first working outgoing socket during meshlink_join().
Guus Sliepen [Tue, 3 Mar 2020 19:32:35 +0000 (20:32 +0100)]
Use the first working outgoing socket during meshlink_join().