Skip to content

Commit

Permalink
Add cause to handshake failure.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@bosch-si.com>
  • Loading branch information
Achim Kraus committed Oct 2, 2018
1 parent 573f63c commit 35a2d12
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
* one.
* Achim Kraus (Bosch Software Innovations GmbH) - add multiple receiver threads.
* move default thread numbers to configuration.
* Achim Kraus (Bosch Software Innovations GmbH) - add cause to handshake failure.
******************************************************************************/
package org.eclipse.californium.scandium;

Expand Down Expand Up @@ -1753,38 +1754,46 @@ private void handleTimeout(DTLSFlight flight, boolean resend) {
if (null != connection) {
Handshaker handshaker = connection.getOngoingHandshake();
if (null != handshaker) {

Exception cause = null;
if (resend) {
// set DTLS retransmission maximum
// set DTLS retransmission maximum
final int max = config.getMaxRetransmissions();

// check if limit of retransmissions reached
if (flight.getTries() < max) {
LOGGER.debug("Re-transmitting flight for [{}], [{}] retransmissions left",
flight.getPeerAddress(), max - flight.getTries() - 1);

try {
flight.incrementTries();
flight.setNewSequenceNumbers();
sendFlight(flight);

// schedule next retransmission
scheduleRetransmission(flight);
handshaker.handshakeFlightRetransmitted(flight.getFlightNumber());
return;
} catch (IOException e) {
// stop retransmission on IOExceptions
cause = e;
LOGGER.info("Cannot retransmit flight to peer [{}]", flight.getPeerAddress(), e);
} catch (GeneralSecurityException e) {
LOGGER.info("Cannot retransmit flight to peer [{}]", flight.getPeerAddress(), e);
cause = e;
}
} else {
LOGGER.debug("Flight for [{}] has reached maximum no. [{}] of retransmissions, discarding ...",
flight.getPeerAddress(), max);
}
}
if (cause == null) {
cause = new Exception("handshake flight " + flight.getFlightNumber() + " timeout!");
} else {
cause = new Exception("handshake flight " + flight.getFlightNumber() + " failed!", cause);
}

// inform handshaker
handshaker.handshakeFailed(new Exception("handshake flight " + flight.getFlightNumber() + " timeout!"));
handshaker.handshakeFailed(cause);
}
}
}
Expand Down

0 comments on commit 35a2d12

Please sign in to comment.