org.bouncycastle.tls.DefaultTlsHeartbeat Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bctls-jdk18on Show documentation
Show all versions of bctls-jdk18on Show documentation
The Bouncy Castle Java APIs for TLS and DTLS, including a provider for the JSSE.
The newest version!
package org.bouncycastle.tls;
import org.bouncycastle.util.Pack;
public class DefaultTlsHeartbeat
implements TlsHeartbeat
{
private final int idleMillis, timeoutMillis;
private int counter = 0;
public DefaultTlsHeartbeat(int idleMillis, int timeoutMillis)
{
if (idleMillis <= 0)
{
throw new IllegalArgumentException("'idleMillis' must be > 0");
}
if (timeoutMillis <= 0)
{
throw new IllegalArgumentException("'timeoutMillis' must be > 0");
}
this.idleMillis = idleMillis;
this.timeoutMillis = timeoutMillis;
}
public synchronized byte[] generatePayload()
{
// NOTE: The counter naturally wraps back to 0
return Pack.intToBigEndian(++counter);
}
public int getIdleMillis()
{
return idleMillis;
}
public int getTimeoutMillis()
{
return timeoutMillis;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy