Skip to content

Commit

Permalink
Mitigate side effects of connection status when there are 2 locations
Browse files Browse the repository at this point in the history
We are connected to location A and B which have the same profile. We connect to both, then connection B drops. What is the profile status? We keep it at Available as long as there's at least one location connected. It previously would mark it as offline.

Also remove the stack trace for disconnection, unless we're in 'dev' profile.
  • Loading branch information
zapek committed Nov 14, 2024
1 parent 93b122d commit aaa4a9e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/io/xeres/app/net/peer/pipeline/PeerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,26 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)

if (cause instanceof TooLongFrameException || cause instanceof IOException)
{
log.error("Error in channel of {} (closing connection): ", remote, cause);
if (log.isDebugEnabled())
{
log.debug("Error in channel of {} (closing connection): ", remote, cause);
}
else
{
log.error("Error in channel of {} (closing connection): {}", remote, cause.getMessage());
}
ctx.close();
}
else
{
log.error("Error in channel of {}:", remote, cause);
if (log.isDebugEnabled())
{
log.debug("Error in channel of {}:", remote, cause);
}
else
{
log.error("Error in channel of {}: {}", remote, cause.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,18 @@ private void updateContactConnection(long profileId, long locationId, Availabili

if (existing.getValue().availability() != availability) // Avoid useless refreshes
{
existing.setValue(Contact.withAvailability(existing.getValue(), availability));
if (existing.isLeaf())
{
existing.setValue(Contact.withAvailability(existing.getValue(), availability));
}
else
{
// There are children, we need to use a different algorithm then.
profileClient.findById(profileId)
.doOnSuccess(profile -> existing.setValue(Contact.withAvailability(existing.getValue(), profile.getLocations().stream()
.anyMatch(Location::isConnected) ? Availability.AVAILABLE : Availability.OFFLINE)))
.subscribe();
}
}
}

Expand Down

0 comments on commit aaa4a9e

Please sign in to comment.