]> git.meshlink.io Git - meshlink/log
meshlink
5 years agoSync the host config directory after accepting an invitee.
Guus Sliepen [Tue, 5 Nov 2019 19:57:31 +0000 (20:57 +0100)]
Sync the host config directory after accepting an invitee.

5 years agoRefuse invitees if we can't delete the invitation file.
Guus Sliepen [Tue, 5 Nov 2019 19:46:58 +0000 (20:46 +0100)]
Refuse invitees if we can't delete the invitation file.

If the call to unlink() or a subsequent sync of the invitation directory
fails, don't allow the invitee access, to prevent an invitation from
being used twice.

5 years agoSync invitation directory when calling meshlink_invite().
Guus Sliepen [Tue, 5 Nov 2019 19:41:50 +0000 (20:41 +0100)]
Sync invitation directory when calling meshlink_invite().

5 years agoDon't fail to start MeshLink if some host config files couldn't be read.
Guus Sliepen [Tue, 5 Nov 2019 18:33:04 +0000 (19:33 +0100)]
Don't fail to start MeshLink if some host config files couldn't be read.

5 years agoHandle host config files without a public key.
Guus Sliepen [Tue, 5 Nov 2019 18:27:11 +0000 (19:27 +0100)]
Handle host config files without a public key.

Commit fa05f996c5500c056a36c1d43e33a407f876643c broke reading config
files for hosts for which no public key is known.

5 years agoAdd missing calls to fflush().
Guus Sliepen [Tue, 5 Nov 2019 18:22:09 +0000 (19:22 +0100)]
Add missing calls to fflush().

We need to ensure file handles have flushed the stream buffer to disk
before calling fsync().

Also remove redundant calls to fsync(), config_write_file() already
takes care of it.

5 years agoAllow nodes to learn their own reflexive UDP address.
Guus Sliepen [Thu, 31 Oct 2019 21:26:25 +0000 (22:26 +0100)]
Allow nodes to learn their own reflexive UDP address.

When a node gets a succesful UDP probe reply, it informs the peer of the
UDP address and port that it has. The peer can then use this information to
inform other nodes it wants to communicate with.

Currently, this is only done to close the time window where two nodes have
established an SPTPS session via a third node, while the third node hasn't
learned of the two nodes' UDP addresses, in which case it was too late for
the third node to assist with hole punching.

5 years agoTry to get a new reflexive UDP address if UDP probes failed.
Guus Sliepen [Thu, 31 Oct 2019 19:46:36 +0000 (20:46 +0100)]
Try to get a new reflexive UDP address if UDP probes failed.

If we are sending data to a node, but we don't have working UDP, it could
be because we don't have a good reflexive UDP address. Send a dummy ANS_KEY
once in a while as long as we still want to exchange data.

5 years agoAvoid compiler warnings when compiling with -DNDEBUG.
Guus Sliepen [Thu, 31 Oct 2019 19:42:10 +0000 (20:42 +0100)]
Avoid compiler warnings when compiling with -DNDEBUG.

5 years agoOnly add confirmed reflexive UDP addresses to ANS_KEY messages.
Guus Sliepen [Thu, 31 Oct 2019 18:44:27 +0000 (19:44 +0100)]
Only add confirmed reflexive UDP addresses to ANS_KEY messages.

5 years agoEnsure NDEBUG is not set in the test suite.
Guus Sliepen [Wed, 30 Oct 2019 18:45:30 +0000 (19:45 +0100)]
Ensure NDEBUG is not set in the test suite.

We rely on assert() in the test suite, so it should not be compiled out
when doing a release build with -DNDEBUG.

5 years agoFix another case of assert() with side-effects.
Guus Sliepen [Wed, 30 Oct 2019 18:21:09 +0000 (19:21 +0100)]
Fix another case of assert() with side-effects.

5 years agoFix signal pipe creation when compiling with -DNDEBUG.
Guus Sliepen [Wed, 30 Oct 2019 17:19:31 +0000 (18:19 +0100)]
Fix signal pipe creation when compiling with -DNDEBUG.

Argument of a call to assert() should never have side effects.

5 years agoDon't call terminate_connection() from meshlink_blacklist().
Guus Sliepen [Mon, 28 Oct 2019 20:14:17 +0000 (21:14 +0100)]
Don't call terminate_connection() from meshlink_blacklist().

If meshlink_blacklist() is called from a callback function, this can result
in a use-after-free bug. Instead, shut down the socket, so the event loop
will take care of it.

5 years agoSet meshlink_errno when trying to create a channel to a blacklisted node.
Guus Sliepen [Mon, 28 Oct 2019 20:12:14 +0000 (21:12 +0100)]
Set meshlink_errno when trying to create a channel to a blacklisted node.

Create a new errno value MESHLINK_EBLACKLISTED, which is used when trying
to send something or create a channel to a blacklisted node. Also improve
some log messages.

5 years agoEnsure an invitation timeout of 0 means no invitations are valid.
Guus Sliepen [Sun, 27 Oct 2019 13:47:38 +0000 (14:47 +0100)]
Ensure an invitation timeout of 0 means no invitations are valid.

5 years agoDon't close active connections when a node is discovered via Catta.
Guus Sliepen [Sun, 27 Oct 2019 13:38:18 +0000 (14:38 +0100)]
Don't close active connections when a node is discovered via Catta.

When a node was discovered by Catta, but we already had an active
meta-connection with it, it would erroneously close that connection.

5 years agoDon't call graph() twice when a new connection replaces an older one.
Guus Sliepen [Sun, 27 Oct 2019 13:04:29 +0000 (14:04 +0100)]
Don't call graph() twice when a new connection replaces an older one.

This prevents a node from being considered unreachable for just a small
moment, even though we know it is reachable.

5 years agoRestart UDP SPTPS when a node reconnects with a new session ID.
Guus Sliepen [Sun, 27 Oct 2019 13:02:47 +0000 (14:02 +0100)]
Restart UDP SPTPS when a node reconnects with a new session ID.

If a node restarts, but its old connection was not considered closed
yet, the graph algorithm never saw it go down. We still want to ensure
we restart UDP SPTPS in this case.

5 years agoDrop severity of log messages regarding ADD/DEL_EDGE messages.
Guus Sliepen [Sun, 27 Oct 2019 12:47:38 +0000 (13:47 +0100)]
Drop severity of log messages regarding ADD/DEL_EDGE messages.

5 years agoFix retransmission timeout calculation in UTCP.
Guus Sliepen [Mon, 14 Oct 2019 20:36:04 +0000 (22:36 +0200)]
Fix retransmission timeout calculation in UTCP.

This could result in unnecessary retransmissions and lower throughput of
channels.

5 years agoRemove support for broadcast packets.
Guus Sliepen [Mon, 14 Oct 2019 19:34:54 +0000 (21:34 +0200)]
Remove support for broadcast packets.

This is not used in MeshLink. Removing support for this also means we no
longer have to calculate a minimum spanning tree whenever the graph is
updated.

5 years agoAllow the mesh to detect when a node has completely restarted. features/detect-restarted-nodes
Guus Sliepen [Sun, 13 Oct 2019 21:32:03 +0000 (23:32 +0200)]
Allow the mesh to detect when a node has completely restarted.

When calling meshlink_open(), a node creates a unique ID that is passed
along ADD_EDGE messages. When a node becomes unreachable and then reachable
again, this allows other nodes to detect whether it was just a temporary
network issue, or whether the node completely restarted (either because
meshlink_close() was called or because it crashed).

At the moment, when this is detected, other nodes close all open channels
with the restarted node.

5 years agoSet the priv pointer at channel open time in the channels-cornercases test.
Guus Sliepen [Sun, 13 Oct 2019 19:46:01 +0000 (21:46 +0200)]
Set the priv pointer at channel open time in the channels-cornercases test.

5 years agoAdd a way to set the channel's priv pointer when opening it.
Guus Sliepen [Sun, 13 Oct 2019 19:39:11 +0000 (21:39 +0200)]
Add a way to set the channel's priv pointer when opening it.

This prevents a race condition where between opening a channel and
setting the priv pointer, the receive callback is called.

5 years agoSet a very small channel timeout in channels-failure test.
Guus Sliepen [Sun, 13 Oct 2019 12:31:14 +0000 (14:31 +0200)]
Set a very small channel timeout in channels-failure test.

This tests both the meshlink_set_node_channel_timeout() function and greatly
speeds up the test.

5 years agoRemove some more superfluous parentheses.
Guus Sliepen [Sun, 13 Oct 2019 12:24:03 +0000 (14:24 +0200)]
Remove some more superfluous parentheses.

5 years agoRename mesh_mutex to mutex.
Guus Sliepen [Sun, 13 Oct 2019 12:16:52 +0000 (14:16 +0200)]
Rename mesh_mutex to mutex.

5 years agoAdd meshlink_set_node_channel_timeout().
Guus Sliepen [Sun, 13 Oct 2019 12:05:07 +0000 (14:05 +0200)]
Add meshlink_set_node_channel_timeout().

This function allows setting the user timeout for UTCP connections.

5 years agoFix waiting for two nodes to become reachable in the test suite.
Guus Sliepen [Thu, 10 Oct 2019 20:16:20 +0000 (22:16 +0200)]
Fix waiting for two nodes to become reachable in the test suite.

5 years agoCorrectly handle incoming retransmissions of SYN packets.
Guus Sliepen [Thu, 10 Oct 2019 20:12:36 +0000 (22:12 +0200)]
Correctly handle incoming retransmissions of SYN packets.

If the SYNACK got lost, the peer that initiated a channel would retransmit
the SYN packet. However, the responder would ignore the retransmitted SYN
packet, causing the channel to stall and eventually time out.

5 years agoDon't load config files partially.
Guus Sliepen [Thu, 10 Oct 2019 19:23:58 +0000 (21:23 +0200)]
Don't load config files partially.

There are various points where we update node information and store a new
host config file to disk. However, at startup we read only part of the host
config files. This allowed a corner case where we never read the full host
config file, but did write it to disk, losing information in the process.

5 years agoFix spurious channel closures after meshlink_stop()+meshlink_start().
Guus Sliepen [Thu, 10 Oct 2019 18:50:43 +0000 (20:50 +0200)]
Fix spurious channel closures after meshlink_stop()+meshlink_start().

When restarting the mesh without fully closing the handle, channels should
continue to work MeshLink was only stopped briefly. However, we were
accidentily always setting the connection timeout when a node's UDP status
changed, which would cause channels that didn't have any unsent data to
time out.

5 years agoCheck the return value of node_write_config() while handling invitations.
Guus Sliepen [Thu, 10 Oct 2019 05:58:21 +0000 (07:58 +0200)]
Check the return value of node_write_config() while handling invitations.

5 years agoAdd an error callback.
Guus Sliepen [Mon, 7 Oct 2019 19:00:01 +0000 (21:00 +0200)]
Add an error callback.

Normally, API functions report potential errors. However, it might happen
that the background thread runs into a serious error that prevents
MeshLink from operating as expected. Add a callback that is called in those
cases.

Currently, the only time it is called is when it can not create or modify
config files in the background thread.

5 years agoFix a double call to pthread_mutex_unlock().
Guus Sliepen [Mon, 7 Oct 2019 12:23:15 +0000 (14:23 +0200)]
Fix a double call to pthread_mutex_unlock().

Found by ThreadSanitizer.

5 years agoDon't use static variables when choosing a broadcast address.
Guus Sliepen [Mon, 7 Oct 2019 12:13:42 +0000 (14:13 +0200)]
Don't use static variables when choosing a broadcast address.

Found by ThreadSanitizer.

5 years agoUnlock the mesh_mutex before destroying it.
Guus Sliepen [Mon, 7 Oct 2019 11:38:37 +0000 (13:38 +0200)]
Unlock the mesh_mutex before destroying it.

Found by ThreadSanitizer.

5 years agoRefactor the non-blackbox test suite.
Guus Sliepen [Mon, 7 Oct 2019 10:53:18 +0000 (12:53 +0200)]
Refactor the non-blackbox test suite.

- Add a default log callback function to utils.[ch]
- Use the functions from utils.[ch] where appropriate.
- Use assert() where possible.
- Make functions and variables static where possible.
- Remove the need for wrapper scripts.

5 years agoReplace rand() by xoshiro256** with per-mesh state.
Guus Sliepen [Sat, 5 Oct 2019 17:40:15 +0000 (19:40 +0200)]
Replace rand() by xoshiro256** with per-mesh state.

We need a reasonable fast PRNG that doesn't have to be secure, for things
like timer randomization, port number generation and so on. Already some
platforms warn about the use of rand(). Also, when calling fork(), both
parent and child have the same PRNG seed, which causes some inefficiencies
in the test suite.

5 years agoAdd the /whitelist command to the chat examples.
Guus Sliepen [Sat, 5 Oct 2019 12:34:40 +0000 (14:34 +0200)]
Add the /whitelist command to the chat examples.

This allows undoing a /kick.

5 years agoFix the channels-no-partial test case.
Guus Sliepen [Sat, 5 Oct 2019 12:32:19 +0000 (14:32 +0200)]
Fix the channels-no-partial test case.

5 years agoRemove unused functions, and make more functions static.
Guus Sliepen [Sat, 5 Oct 2019 12:16:43 +0000 (14:16 +0200)]
Remove unused functions, and make more functions static.

5 years agoAdd assert() calls to the library.
Guus Sliepen [Sat, 5 Oct 2019 12:15:35 +0000 (14:15 +0200)]
Add assert() calls to the library.

To aid in debugging, start using assert() to ensure preconditions hold.
At the moment, we assume that NULL-pointer dereferences will always cause
segfaults, so we don't add assert(ptr) statements in those cases, but that
might change in the future.

5 years agoClean up resources in the test cases.
Guus Sliepen [Fri, 4 Oct 2019 19:10:10 +0000 (21:10 +0200)]
Clean up resources in the test cases.

Not doing so prevents tools such as AddressSanitizer and Valgrind from
declaring the tests free of memory leaks.

5 years agoFix potential memory leaks in the autoconnect algorithm.
Guus Sliepen [Fri, 4 Oct 2019 19:08:59 +0000 (21:08 +0200)]
Fix potential memory leaks in the autoconnect algorithm.

5 years agoAvoid casting function pointers.
Guus Sliepen [Fri, 4 Oct 2019 19:08:34 +0000 (21:08 +0200)]
Avoid casting function pointers.

5 years agoFix memory leaks from timers.
Guus Sliepen [Fri, 4 Oct 2019 19:06:33 +0000 (21:06 +0200)]
Fix memory leaks from timers.

5 years agoHave meshlink_get_node() and _submesh() set MESHLINK_ENOENT when appropriate.
Guus Sliepen [Fri, 4 Oct 2019 14:55:48 +0000 (16:55 +0200)]
Have meshlink_get_node() and _submesh() set MESHLINK_ENOENT when appropriate.

These functions can return NULL both when the parameters are invalid or if
the node or submesh does not exist, meshlink_errno must be set correctly
to distinguish between the two cases.

5 years agoFix memory leaks in the outgoing packet queue.
Guus Sliepen [Fri, 4 Oct 2019 14:53:51 +0000 (16:53 +0200)]
Fix memory leaks in the outgoing packet queue.

Found by AddressSanitizer.

5 years agoFix several memory leaks found by AddressSanitizer.
Guus Sliepen [Fri, 4 Oct 2019 14:08:51 +0000 (16:08 +0200)]
Fix several memory leaks found by AddressSanitizer.

5 years agoEnsure only valid hostnames end up in the invitation URL.
Guus Sliepen [Sun, 29 Sep 2019 09:38:09 +0000 (11:38 +0200)]
Ensure only valid hostnames end up in the invitation URL.

5 years agoFix errors found by Clang's static analyzer.
Guus Sliepen [Thu, 26 Sep 2019 20:43:45 +0000 (22:43 +0200)]
Fix errors found by Clang's static analyzer.

5 years agoFix winerror() returning a pointer to a stack-allocated array.
Guus Sliepen [Thu, 26 Sep 2019 20:01:24 +0000 (22:01 +0200)]
Fix winerror() returning a pointer to a stack-allocated array.

Found by cppcheck.

5 years agoFix potential double fclose().
Guus Sliepen [Thu, 26 Sep 2019 18:50:11 +0000 (20:50 +0200)]
Fix potential double fclose().

We were calling fclose() inside config_read_file(), which never called
fopen() itself. It is the caller's responsibility to close the file on
error. Also fix two error cases where the caller forgot to close fclose().

5 years agoUpdate mesh->loop.now right after select() returns.
Guus Sliepen [Wed, 25 Sep 2019 19:47:44 +0000 (21:47 +0200)]
Update mesh->loop.now right after select() returns.

It can be that select() waits for a few seconds before an event or
timeout arives. We didn't update mesh->loop.now before calling any of
the callback functions, which meant they could use a time a few seconds
in the past. In particular, the last_ping_time of connections could be
set to a value such that they would immediately be considered timed out.

5 years agoAdd missing mutex locks.
Guus Sliepen [Wed, 25 Sep 2019 19:09:51 +0000 (21:09 +0200)]
Add missing mutex locks.

5 years agoAdd missing mutex locks.
Guus Sliepen [Wed, 25 Sep 2019 05:42:00 +0000 (07:42 +0200)]
Add missing mutex locks.

meshlink_channel_close() and meshlink_channel_shutdown() did not lock
the mutex, which could cause some race conditions.

5 years agoAvoid using typedefs in meshlink.h.
Guus Sliepen [Mon, 23 Sep 2019 20:08:00 +0000 (22:08 +0200)]
Avoid using typedefs in meshlink.h.

Use struct meshlink_foo instead of meshlink_foo_t in meshlink.h, so
links to function parameter types go to the struct definitions.

5 years agoAdd \memberof annotations to the C API documentation.
Guus Sliepen [Mon, 23 Sep 2019 19:44:03 +0000 (21:44 +0200)]
Add \memberof annotations to the C API documentation.

5 years agoFix doxygen warnings.
Guus Sliepen [Mon, 23 Sep 2019 19:17:43 +0000 (21:17 +0200)]
Fix doxygen warnings.

5 years agoAdd missing parts of meshlink_set_node_pmtu_cb().
Guus Sliepen [Mon, 23 Sep 2019 19:15:31 +0000 (21:15 +0200)]
Add missing parts of meshlink_set_node_pmtu_cb().

5 years agoAdd a callback for PMTU changes.
Guus Sliepen [Mon, 23 Sep 2019 18:54:16 +0000 (20:54 +0200)]
Add a callback for PMTU changes.

This can be used to detect changes in UDP reachability of peers, and
allows the application to change the maximum packet size for UDP
channels.

5 years agoReset UTCP timers when learning a node's public key.
Guus Sliepen [Sun, 15 Sep 2019 11:22:17 +0000 (13:22 +0200)]
Reset UTCP timers when learning a node's public key.

If we try to open a channel to a node whose public key we do not yet
have, a REQ_KEY request is sent out. When the answer comes back we know
the key, but we have to tell UTCP to reset the timers, otherwise we have
to wait for a retransmission timeout to occur before resending the SYN
packet.

5 years agoFix compiler warnings from Clang 10 and GCC 9.
Guus Sliepen [Mon, 23 Sep 2019 10:40:17 +0000 (12:40 +0200)]
Fix compiler warnings from Clang 10 and GCC 9.

5 years agoTest UDP channels.
Guus Sliepen [Sun, 22 Sep 2019 20:26:00 +0000 (22:26 +0200)]
Test UDP channels.

Simulate three simultaneous UDP channels transmitting 40 Mbps. Check that
>95% of the packets arrive, and that there is no TCP-like merging or
splitting of packets. This also checks that channels can be opened and
closed like regular TCP channels.

5 years agoEnsure Catta gets a valid service name.
Guus Sliepen [Sun, 22 Sep 2019 14:08:48 +0000 (16:08 +0200)]
Ensure Catta gets a valid service name.

Normally the appname is used as the service name as well. However,
Catta's rules are that the service name must be at least two characters,
and only contain alphanumeric characters, dashses and underscores.

5 years agoEnsure the channel poll callback is called with len 0 on error.
Guus Sliepen [Tue, 17 Sep 2019 19:50:38 +0000 (21:50 +0200)]
Ensure the channel poll callback is called with len 0 on error.

5 years agoCorrectly update our own host config file after meshlink_set_port().
Guus Sliepen [Mon, 9 Sep 2019 19:35:14 +0000 (21:35 +0200)]
Correctly update our own host config file after meshlink_set_port().

We wrote the host config file before we updated mesh->self, causing the
old port number to remain in the host config file. This would cause
subsequent calls to meshlink_invite() to have the wrong port number in
the invitation.

5 years agoFix deadlock during discovery failure
sairoop-elear [Fri, 6 Sep 2019 10:36:16 +0000 (16:06 +0530)]
Fix deadlock during discovery failure

5 years agoFix starting the channels-fork test.
Guus Sliepen [Thu, 5 Sep 2019 17:57:57 +0000 (19:57 +0200)]
Fix starting the channels-fork test.

The test started by cleaning the wrong config files, and could potentially
fail when started at the same time as the non-forking channels test.

5 years agoCall fsync() on the configuration directories where appropriate.
Guus Sliepen [Thu, 5 Sep 2019 17:56:29 +0000 (19:56 +0200)]
Call fsync() on the configuration directories where appropriate.

Just ensuring individual config files are written atomically is good enough
to keep internal consistency, but we want to make sure directory metadata
is also synced to disk when returning from functions that expect the changes
to have been made permanent, such as meshlink_import() and
meshlink_blacklist(). Also do this when we create the initial directory
structure.

We already took care of syncing directory metadata when rotating keys for
encrypted storage.

5 years agoWrite config files atomically.
Guus Sliepen [Thu, 5 Sep 2019 17:33:53 +0000 (19:33 +0200)]
Write config files atomically.

5 years agoWhen opening a mesh handle, inherit the global log callback.
Guus Sliepen [Thu, 5 Sep 2019 17:32:42 +0000 (19:32 +0200)]
When opening a mesh handle, inherit the global log callback.

This prevents losing log messages halfway during meshlink_open().

5 years agoFix a potential crash when restarting the mesh.
Guus Sliepen [Thu, 5 Sep 2019 15:55:41 +0000 (17:55 +0200)]
Fix a potential crash when restarting the mesh.

The tv value must not be changed for a timeout that is still linked into the
tree of timeouts, otherwise the tree can get corrupted.

5 years agoMake ping intervals and timeouts configurable for each device class.
Guus Sliepen [Thu, 5 Sep 2019 15:53:12 +0000 (17:53 +0200)]
Make ping intervals and timeouts configurable for each device class.

5 years agoBetter use of enum dev_class_t.
Guus Sliepen [Thu, 5 Sep 2019 13:14:45 +0000 (15:14 +0200)]
Better use of enum dev_class_t.

5 years agoAdd support for AIO using filedescriptors.
Guus Sliepen [Thu, 29 Aug 2019 21:26:29 +0000 (23:26 +0200)]
Add support for AIO using filedescriptors.

This adds support to enqueue transmits between channels and filedescriptors.
Currently, it requires that read() and write() calls on the filedescriptors
are non-blocking and always succeed, which limits it to reading from and
writing to files.

5 years agoUse relative URLs for the submodules.
Guus Sliepen [Wed, 21 Aug 2019 19:29:37 +0000 (21:29 +0200)]
Use relative URLs for the submodules.

5 years agoIgnore REQ_KEY only if we very recently sent one ourselves.
Guus Sliepen [Sun, 18 Aug 2019 14:58:29 +0000 (16:58 +0200)]
Ignore REQ_KEY only if we very recently sent one ourselves.

In case the SPTPS state between two nodes becomes desynchronized, we must
allow a new SPTPS connection to be set up eventually.

5 years agoRemove redundant call to graph().
Guus Sliepen [Sun, 18 Aug 2019 14:54:58 +0000 (16:54 +0200)]
Remove redundant call to graph().

When we receive an ADD_EDGE for an existing edge but with new information,
don't call graph() between removing the old edge and adding the new one.
This prevents a node from temporarily being considered unreachable, which
in turn would cause the SPTPS state to that node being reset.

5 years agoSend REQ_KEY after a successful meta-connection only from the initiator.
Guus Sliepen [Sun, 18 Aug 2019 14:51:31 +0000 (16:51 +0200)]
Send REQ_KEY after a successful meta-connection only from the initiator.

5 years agoTest concurrent AIO and non-AIO transfers.
Guus Sliepen [Thu, 15 Aug 2019 20:41:15 +0000 (22:41 +0200)]
Test concurrent AIO and non-AIO transfers.

Create 5 channels; 4 transfer a large amount of data via AIO, the 5th does
a regular meshlink_channel_send(). Verify that there is concurrency between
all channels.

5 years agoAllow the channel send and receive buffer size to be changed.
Guus Sliepen [Tue, 13 Aug 2019 19:03:42 +0000 (21:03 +0200)]
Allow the channel send and receive buffer size to be changed.

This also adds a test to see if this works in combination with
MESHLINK_CHANNEL_NO_PARTIAL.

5 years agoAdd meshlink_channel_aio_receive().
Guus Sliepen [Mon, 12 Aug 2019 14:46:02 +0000 (16:46 +0200)]
Add meshlink_channel_aio_receive().

This function allows handing over a large buffer to MeshLink which will be
used to receive data without needing intervention from the application.
A callback is called when MeshLink has filled the buffer with the data.

5 years agoAdd a test case for meshlink_channel_aio_send().
Guus Sliepen [Mon, 12 Aug 2019 12:01:52 +0000 (14:01 +0200)]
Add a test case for meshlink_channel_aio_send().

5 years agoAdd meshlink_channel_aio_send().
Guus Sliepen [Mon, 12 Aug 2019 11:43:01 +0000 (13:43 +0200)]
Add meshlink_channel_aio_send().

This function allows handing over a large amount of data to MeshLink
which will be sent without needing intervention from the application.
A callback is called when MeshLink is done with the data, so the
application can call any cleanup function it needs to call.

5 years agoAdd the MESHLINK_CHANNEL_NO_PARTIAL flag.
Guus Sliepen [Thu, 8 Aug 2019 13:20:42 +0000 (15:20 +0200)]
Add the MESHLINK_CHANNEL_NO_PARTIAL flag.

This ensures that calls to meshlink_channel_send() either succeed with all
data sent, or no data sent at all.

5 years agoUse condition variables to wait for threads to finish initializing.
Guus Sliepen [Sun, 4 Aug 2019 20:22:10 +0000 (22:22 +0200)]
Use condition variables to wait for threads to finish initializing.

To prevent a race condition when calling meshlink_stop() right after
meshlink_start(), we need to wait for the MeshLink and Catta threads to
finish initializing before we can return from meshlink_start().

5 years agoRemove global variables.
Guus Sliepen [Sun, 4 Aug 2019 10:58:27 +0000 (12:58 +0200)]
Remove global variables.

There still were some global variables and buffers that were either unused
or should be local to a MeshLink instance.

5 years agoAvoid unnecessary calls to time().
Guus Sliepen [Sun, 4 Aug 2019 10:22:52 +0000 (12:22 +0200)]
Avoid unnecessary calls to time().

We already have the current time from the event loop.

5 years agoCorrectly set device class after joining if the server didn't specify one.
Guus Sliepen [Sat, 3 Aug 2019 21:32:04 +0000 (23:32 +0200)]
Correctly set device class after joining if the server didn't specify one.

5 years agoCorrectly update device class when receiving an ADD_EDGE message.
Guus Sliepen [Sat, 3 Aug 2019 20:56:40 +0000 (22:56 +0200)]
Correctly update device class when receiving an ADD_EDGE message.

In some cases we didn't update the device class information when receiving
an ADD_EDGE message. This could cause autoconnect to fail to work as
expected.

5 years agoRun Catta in the same network namespace as MeshLink.
Guus Sliepen [Sat, 3 Aug 2019 20:54:34 +0000 (22:54 +0200)]
Run Catta in the same network namespace as MeshLink.

5 years agoIgnore online/offline state from Catta.
Guus Sliepen [Fri, 26 Jul 2019 22:49:40 +0000 (00:49 +0200)]
Ignore online/offline state from Catta.

Catta only works on Ethernet interfaces. However, if there is a
non-Ethernet interface, MeshLink might still be able to connect to
peers. So just rely on getifaddrs() for checking whether to terminate
connections or not.

5 years agoClose connections if the local address is no longer valid.
Guus Sliepen [Fri, 26 Jul 2019 22:44:06 +0000 (00:44 +0200)]
Close connections if the local address is no longer valid.

When we detect that there are changes on the network interfaces, check for
each active connection whether the local side of the connection has an
address that exists on at least one network interface. If not, then
communication via that connection is not possible. Instead of waiting for
a timeout, immediately terminate those connections.

5 years agoRemove unused member variables.
Guus Sliepen [Fri, 19 Jul 2019 16:54:40 +0000 (18:54 +0200)]
Remove unused member variables.

In MeshLink, we are not using node/edge options, and we don't support
compression or setting a custom local discovery broadcast address.

Keep the internal support for meta-connections via proxies for now, even
though it currently isn't exposed via the API.

5 years agoReorganize structs for better packing and access patterns.
Guus Sliepen [Fri, 19 Jul 2019 16:23:37 +0000 (18:23 +0200)]
Reorganize structs for better packing and access patterns.

Used the pahole tool to find gaps in structs. Move the lesser accessed
members to the end of the struct.

5 years agoSpeed up reconnections on network interface changes.
Guus Sliepen [Fri, 19 Jul 2019 12:50:25 +0000 (14:50 +0200)]
Speed up reconnections on network interface changes.

Catta informs us whenever an interface comes online or goes offline. If we
detect that there are no online interfaces, immediately terminate all meta-
connections. Otherwise, reset the ping timers and reconnection timers for
outgoing connections.

5 years agoFix a small memory leak.
Guus Sliepen [Fri, 19 Jul 2019 12:44:29 +0000 (14:44 +0200)]
Fix a small memory leak.

When registering ourselves to Catta, we called meshlink_get_fingerprint()
without freeing the returned string afterwards.