]> git.meshlink.io Git - meshlink/log
meshlink
4 years 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.

4 years 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.

4 years 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().

4 years 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.

4 years 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().

4 years 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.

4 years 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

4 years 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
remove_duplicate_hostnames().

4 years 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.

4 years 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.

4 years 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.

4 years 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.

4 years 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 years 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
harder.

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 years 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 years 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 years 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 meshlink.io service to
query a host's own externally visible address.

4 years 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().

4 years agoAvoid ports that are in use by not all address families.
Guus Sliepen [Fri, 28 Feb 2020 19:09:11 +0000 (20:09 +0100)]
Avoid ports that are in use by not all address families.

It could happen that a port is bound by another application, but only
for some of the supported address families (ie, only IPv4 but not IPv6).
We don't want MeshLink to then bind to the other address familie(s), but
rather have it try another port altogether.

4 years agoFurther improve try_bind().
Guus Sliepen [Fri, 28 Feb 2020 18:25:52 +0000 (19:25 +0100)]
Further improve try_bind().

Make try_bind() do the same checks as add_listen_address() does: try to
create both a TCP and UDP socket on a given port for all address
families. If one address family succeeds for both TCP and UDP, consider
this a valid port.

4 years agoFix logic in try_bind().
Guus Sliepen [Tue, 25 Feb 2020 19:39:48 +0000 (20:39 +0100)]
Fix logic in try_bind().

Fix the check for successful socket creation. Also make sure we only
return success if we can bind to IPv4 and IPv6, but ignore other
network protocols.

4 years agoCheck that importing the same data twice is fine, but importing garbage is not.
Guus Sliepen [Sun, 23 Feb 2020 00:47:11 +0000 (01:47 +0100)]
Check that importing the same data twice is fine, but importing garbage is not.

4 years agoMove assert()s that dereference a pointer to after the pointer NULL check.
Guus Sliepen [Sun, 23 Feb 2020 00:41:56 +0000 (01:41 +0100)]
Move assert()s that dereference a pointer to after the pointer NULL check.

4 years agoAdd missing NULL-check in meshlink_verify().
Guus Sliepen [Sun, 23 Feb 2020 00:40:26 +0000 (01:40 +0100)]
Add missing NULL-check in meshlink_verify().

4 years agoUpdate the blackbox join test cases.
Guus Sliepen [Sun, 23 Feb 2020 00:38:24 +0000 (01:38 +0100)]
Update the blackbox join test cases.

4 years agoFix compilation error caused by ACX_THREAD
Guus Sliepen [Sat, 22 Feb 2020 22:40:04 +0000 (23:40 +0100)]
Fix compilation error caused by ACX_THREAD

4 years agoMake the join commit order configurable. feature/join-commit-order
Guus Sliepen [Tue, 11 Feb 2020 21:28:24 +0000 (22:28 +0100)]
Make the join commit order configurable.

By default, when an invitee joins a mesh, it will commit its configuration
to disk first, then the inviter. This adds a function to reverse that order.

4 years agoFix a memory leak when an invitation file contains an invalid submesh name.
Guus Sliepen [Tue, 11 Feb 2020 20:39:36 +0000 (21:39 +0100)]
Fix a memory leak when an invitation file contains an invalid submesh name.

Found by Clang's static analyzer.

4 years agoMove join state out of meshlink_handle_t, and ensure proper cleanup on errors.
Guus Sliepen [Tue, 11 Feb 2020 20:37:33 +0000 (21:37 +0100)]
Move join state out of meshlink_handle_t, and ensure proper cleanup on errors.

Move the state we keep when calling meshlink_join() out of meshlink_handle_t
and just put it on the stack of meshlink_join(). Also make sure we properly
release allocated resources in all error conditions during a join.

4 years agoFix garbage being sent at start of a UDP channel.
Guus Sliepen [Sat, 8 Feb 2020 15:04:42 +0000 (16:04 +0100)]
Fix garbage being sent at start of a UDP channel.

If meshlink_channel_send() was called before a UDP channel had finished
the handshake, it caused UTCP to send garbage data.

4 years agoFall back to getifaddrs() to get an interface address if there is no default route.
Guus Sliepen [Sat, 8 Feb 2020 13:55:21 +0000 (14:55 +0100)]
Fall back to getifaddrs() to get an interface address if there is no default route.

When generating invitations, we try to find a suitable local interface
address by faking an outgoing connection to the Internet. However,
that doesn't work if there is no default route. In this case, fall back
to using getifaddrs() if that function is available, and filter out any
link-local and loopback addresses.

4 years agoUse bind() to check if a local address is still valid.
Guus Sliepen [Thu, 6 Feb 2020 20:34:43 +0000 (21:34 +0100)]
Use bind() to check if a local address is still valid.

Some platforms don't support getifaddrs(). We use this to check if the
local address of a socket is still available on any network interface.
Instead, try to bind() a new socket to the same address (but port 0) as
existing sockets. If it returns EADDRNOTAVAIL, we know that this address
is no longer valid.

4 years agoFix android (Android 6 or before) compilation issue around getifaddr
Roop [Fri, 7 Feb 2020 05:31:45 +0000 (11:01 +0530)]
Fix android (Android 6 or before) compilation issue around getifaddr

4 years agoClear reachability times in imported host config files.
Guus Sliepen [Tue, 4 Feb 2020 22:11:34 +0000 (23:11 +0100)]
Clear reachability times in imported host config files.

This mirrors what we do with host config files received during a join.

4 years agoForce -fPIC when compiling libcatta.
Guus Sliepen [Mon, 3 Feb 2020 20:24:50 +0000 (21:24 +0100)]
Force -fPIC when compiling libcatta.

4 years agoClear reachability times in host config files received during a join.
Guus Sliepen [Mon, 3 Feb 2020 16:43:50 +0000 (17:43 +0100)]
Clear reachability times in host config files received during a join.

When a node joins an existing mesh, it gets passed one or more host config
files from the inviter. However, these might contain non-zero reachability
times, but the invitee has never seen those nodes, so clear them before
storing the host config files.

4 years agoPrevent meshlink_errno from being set incorrectly by meshlink_invite()
Guus Sliepen [Mon, 3 Feb 2020 16:03:07 +0000 (17:03 +0100)]
Prevent meshlink_errno from being set incorrectly by meshlink_invite()

We called a public API function inside meshlink_invite() to check that we
don't try to invite a node that's already known. That causes it to set
meshlink_errno to MESHLINK_ENOENT. Fix this by calling lookup_node()
instead.

4 years agoFix spelling errors.
Guus Sliepen [Mon, 3 Feb 2020 15:24:41 +0000 (16:24 +0100)]
Fix spelling errors.

Found by codespell.

4 years agoFix reachability queries for blacklisted nodes.
Guus Sliepen [Mon, 3 Feb 2020 15:11:36 +0000 (16:11 +0100)]
Fix reachability queries for blacklisted nodes.

4 years agoFix compiling with GCC 10.
Guus Sliepen [Mon, 3 Feb 2020 15:10:26 +0000 (16:10 +0100)]
Fix compiling with GCC 10.

4 years agoFix potential segmentation fault on iOS.
Guus Sliepen [Wed, 29 Jan 2020 08:28:25 +0000 (09:28 +0100)]
Fix potential segmentation fault on iOS.

The PONG handler could call freeaddrinfo() on a struct that was not
allocated with getaddrinfo(). On most platforms this apparently works
fine, but on iOS it will try to free memory that wasn't allocated. Fix
this by moving the code to reset an outgoing_t to a separate function,
and calling that from the PONG handler.

4 years agoOnly let mesh->self be reachable when the mesh is started.
Guus Sliepen [Mon, 27 Jan 2020 14:07:35 +0000 (15:07 +0100)]
Only let mesh->self be reachable when the mesh is started.

This ensures meshlink_node_get_reachability(mesh->self) returns true only
if the mesh has been started. It also handles reachability of self in
graph.c just like any other node. This means there will now also be a
node status callback generated when the mesh is started and stopped.

4 years agoSync host config file immediately after initial connect.
Guus Sliepen [Fri, 24 Jan 2020 20:08:01 +0000 (21:08 +0100)]
Sync host config file immediately after initial connect.

4 years agoAdd meshlink_get_node_reachability().
Guus Sliepen [Sun, 19 Jan 2020 23:45:09 +0000 (00:45 +0100)]
Add meshlink_get_node_reachability().

This function returns the current state of a node's reachability, as
well as the last time the node became reachable and the last time it
became unreachable.

4 years agoAdd a configurable fast connection retry period.
Guus Sliepen [Mon, 13 Jan 2020 13:23:15 +0000 (14:23 +0100)]
Add a configurable fast connection retry period.

If no nodes are reachable, allow connections to retry once every second for a
per device-class configurable amount of time.

4 years agoRemember the address used by an invitee.
Guus Sliepen [Fri, 6 Dec 2019 22:01:46 +0000 (23:01 +0100)]
Remember the address used by an invitee.

When a new node uses an invitation succesfully, store the address it
used to connect.

4 years agoRemember the address used when connecting to an inviting node.
Guus Sliepen [Fri, 6 Dec 2019 21:58:29 +0000 (22:58 +0100)]
Remember the address used when connecting to an inviting node.

The inviter sends us its own host config file, which should be populated
with its known addresses. However, if a symbolic hostname is in the
invitation URL and it can resolve to multiple IP addresses, or if the IP
address associated with it is currently different from when the invitation
was generated, the address used to connect to the inviter might not be
present in its host config file. This could cause the invitation to succeed,
but then the nodes would fail to make a regular MeshLink connection.

4 years agoEnsure all addresses in the invitation URL are also in the invitation file.
Guus Sliepen [Fri, 6 Dec 2019 21:42:59 +0000 (22:42 +0100)]
Ensure all addresses in the invitation URL are also in the invitation file.

4 years agoPrefer sockaddr_t over struct sockaddr_*.
Guus Sliepen [Fri, 6 Dec 2019 20:50:02 +0000 (21:50 +0100)]
Prefer sockaddr_t over struct sockaddr_*.

This avoids a lot of pointer casts, and also fixes some problems with the
sockaddr length potentially being smaller than necessary.

4 years agoDon't add duplicates to the list of recently seen addresses.
Guus Sliepen [Fri, 6 Dec 2019 20:47:11 +0000 (21:47 +0100)]
Don't add duplicates to the list of recently seen addresses.

Duplicate addresses would be appended to the list, and could push out other
addresses. If the address already exists, only move it to the top if it is
not already there.

Also don't force an immediate write of the host config file when trying to
add an address that already exists.

4 years agoDestroy new/ and old/ subdirectories when creating a new instance.
Guus Sliepen [Sun, 1 Dec 2019 23:32:57 +0000 (00:32 +0100)]
Destroy new/ and old/ subdirectories when creating a new instance.

4 years agoAdd meshlink_get_all_nodes_by_last_reachable().
Guus Sliepen [Sun, 1 Dec 2019 22:56:10 +0000 (23:56 +0100)]
Add meshlink_get_all_nodes_by_last_reachable().

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.

4 years agoAdd a #define for the maximum number of tracked recently seen addresses.
Guus Sliepen [Sun, 1 Dec 2019 22:29:39 +0000 (23:29 +0100)]
Add a #define for the maximum number of tracked recently seen addresses.

4 years agoSync the base configuration directory at the end of meshlink_join().
Guus Sliepen [Thu, 28 Nov 2019 21:24:05 +0000 (22:24 +0100)]
Sync the base configuration directory at the end of meshlink_join().

While joining a mesh, we create a new current/ subdirectory. While the
contents were already synced to disk, we need to ensure the subdirectory
itself is also synced before returning.

4 years agoSync the base configuration directory after each subdirectory rename operation.
Guus Sliepen [Thu, 28 Nov 2019 21:21:19 +0000 (22:21 +0100)]
Sync the base configuration directory after each subdirectory rename operation.

This ensures the proper ordering of the renames in the event of a crash.

4 years agoSync the base configuration directory after each call to config_destroy().
Guus Sliepen [Thu, 28 Nov 2019 21:20:05 +0000 (22:20 +0100)]
Sync the base configuration directory after each call to config_destroy().

This guarantees proper ordering when deleting the current/, new/ and old/
subdirectories.

5 years agoFix logic error preventing fast update of reflexive address.
Guus Sliepen [Thu, 14 Nov 2019 20:48:02 +0000 (21:48 +0100)]
Fix logic error preventing fast update of reflexive address.

When we are trying to communicate with peers that don't know our
reflexive address, and we just learned our own one, we want to inform
those peers of it immediately, so they can send PMTU probes to the right
address. A logic error prevented this from happening in the common case.

5 years agoAssert that nodes black/whitelisted by name persist after closing the mesh.
Guus Sliepen [Mon, 11 Nov 2019 21:54:46 +0000 (22:54 +0100)]
Assert that nodes black/whitelisted by name persist after closing the mesh.

5 years agoAdd support for black/whitelisting by name, and forgetting nodes.
Guus Sliepen [Mon, 11 Nov 2019 21:49:05 +0000 (22:49 +0100)]
Add support for black/whitelisting by name, and forgetting nodes.

5 years agoFix __warn_unused_result__, add more of it and fix the resulting warnings.
Guus Sliepen [Sat, 9 Nov 2019 16:57:55 +0000 (17:57 +0100)]
Fix __warn_unused_result__, add more of it and fix the resulting warnings.

Due to a bug in the autoconf test for function attributes, we were always
disabling __warn_unused_result__. Fix this, and add this function attribute
to a lot more functions whose results are definitely important.

This change makes it clear where we ignore the results of a function that
might fail. The proper fix in most cases is to propagate the result to the
caller. For meshlink_blacklist() and meshlink_whitelist(), we were not
return an error condition, even if we might fail to commit the blacklist
operation to permanent storage. So we now make these functions return a
bool.

5 years agoUse a separate lockfile to lock the configuration directory.
Guus Sliepen [Sat, 9 Nov 2019 16:52:19 +0000 (17:52 +0100)]
Use a separate lockfile to lock the configuration directory.

We can't use meshlink.conf as the lock file, since it can move around.
Instead, create meshlink.lock right below confbase, and keep it always
locked while a meshlink handle is valid.

meshlink_destroy() will also use this lockfile to ensure we don't destroy
a directory that is still in use, and prevent race conditions between
meshlink_destroy() and meshlink_open().

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.