public class DtlsClusterConnector extends DTLSConnector
Forwards foreign cid records (tls_cid) to other connectors based on the
passed in DtlsClusterConnector.ClusterNodesProvider. Requires a
NodeConnectionIdGenerator in DtlsConnectorConfig in order to
extract the node-id from the record's CID and to retrieve the own node-id.
In order to preserve the original source address, the forwarded records are
prepended by a header, which contains that original address. The forwarded
records are exchange using a separate endpoint (port) to easier separate the
cluster internal traffic from external record traffic. That additional
endpoint is configured using DtlsClusterConnectorConfig.
Generally, if a forwarded tls_cid record is processed and a message is sent
back by that final destination connector, that sent message is backwarded to
the original receiving connector. That is required for the most network setup
in order to keep all NATs and load-balancers working. If your network permits
to send outgoing messages also from other endpoints,
DtlsClusterConnectorConfig can be used to configure that.
| Modifier and Type | Class and Description |
|---|---|
static interface |
DtlsClusterConnector.ClusterNodesProvider
Cluster nodes provider.
|
DTLSConnector.Worker| Modifier and Type | Field and Description |
|---|---|
protected static int |
CLUSTER_ADDRESS_LENGTH_OFFSET
Offset for address length of cluster records.
|
protected static int |
CLUSTER_ADDRESS_OFFSET
Offset for address of cluster records.
|
protected static int |
CLUSTER_MAC_LENGTH
Length of cluster Mac, if used.
|
protected static int |
CLUSTER_PORT_OFFSET
Offset for port of cluster records.
|
protected static int |
CLUSTER_RECORD_TYPE_OFFSET
Offset of cluster record type.
|
protected DtlsClusterHealth |
clusterHealth
DTLS cluster health statistic.
|
protected DatagramSocket |
clusterInternalSocket
Datagram socket for cluster internal communication.
|
protected static int |
MAX_ADDRESS_LENGTH
Maximum address length for cluster records.
|
protected static int |
MAX_DATAGRAM_OFFSET
Maximum datagram offset for cluster records.
|
protected static int |
MIN_ADDRESS_LENGTH
Maximum address length for cluster records.
|
static Byte |
RECORD_TYPE_INCOMING
Type of incoming forwarded messages.
|
static Byte |
RECORD_TYPE_OUTGOING
Type of outgoing forwarded messages.
|
config, connectionIdGenerator, health, inboundDatagramBufferSize, KEY_TLS_SERVER_HOST_NAME, timerDEFAULT_ETH_MTU, DEFAULT_IPV4_MTU, DEFAULT_IPV6_MTU, IPV4_HEADER_LENGTH, IPV6_HEADER_LENGTH, MAX_MTU| Modifier | Constructor and Description |
|---|---|
|
DtlsClusterConnector(DtlsConnectorConfig configuration,
DtlsClusterConnectorConfig clusterConfiguration,
DtlsClusterConnector.ClusterNodesProvider nodes)
Create dtls connector with cluster support.
|
|
DtlsClusterConnector(DtlsConnectorConfig configuration,
DtlsClusterConnectorConfig clusterConfiguration,
DtlsClusterConnector.ClusterNodesProvider nodes,
SessionCache sessionCache)
Create dtls connector with cluster support and session cache.
|
protected |
DtlsClusterConnector(DtlsConnectorConfig configuration,
DtlsClusterConnectorConfig clusterConfiguration,
ResumptionSupportingConnectionStore connectionStore,
boolean startReceiver)
Create dtls connector with cluster support and connection store.
|
| Modifier and Type | Method and Description |
|---|---|
protected DtlsHealth |
createDefaultHealthHandler(DtlsConnectorConfig configuration)
Create default health handler.
|
protected boolean |
ensureLength(Byte type,
DatagramPacket clusterPacket)
Ensure, that the packet is large enough for a valid cluster internal
message.
|
protected int |
getClusterMacLength()
Get cluster MAC length.
|
protected Byte |
getClusterRecordType(DatagramPacket clusterPacket)
Check, if internal message is forwarded or backwarded record.
|
int |
getNodeID()
Get connector's node-id.
|
protected void |
init(InetSocketAddress bindAddress,
DatagramSocket socket,
Integer mtu)
Initialize socket ad start connector.
|
protected void |
processDatagram(DatagramPacket packet,
InetSocketAddress router)
Process received datagram.
|
protected void |
processDatagramFromClusterNetwork(Byte type,
DatagramPacket clusterPacket)
Process received cluster internal message.
|
protected void |
processManagementDatagramFromClusterNetwork(DatagramPacket clusterPacket)
Process cluster internal management message.
|
protected void |
sendDatagramToClusterNetwork(DatagramPacket clusterPacket)
Send cluster internal message.
|
protected void |
sendRecord(Record record)
For
Record.getRouter() destinations, backwards massage to
original receiving connector (router). |
void |
setClusterNodesProvider(DtlsClusterConnector.ClusterNodesProvider nodes)
Set cluster nodes provider.
|
protected void |
startReceiver()
Start receiver threads for cluster internal communication.
|
void |
stop()
Stop also socket and threads for cluster internal communication.
|
clearConnectionState, close, createConnectionStore, destroy, dropReceivedRecord, forceResumeAllSessions, forceResumeSessionFor, getAddress, getMaxDatagramSize, getMaximumFragmentLength, getMaximumTransmissionUnit, getProtocol, getSessionByAddress, isRunning, onInitializeHandshaker, processDatagram, processRecord, receiveNextDatagramFromNetwork, send, sendFlight, sendNextDatagramOverNetwork, setAlertHandler, setEndpointContextMatcher, setExecutor, setRawDataReceiver, start, start, startDropConnectionsForPrincipal, startForEach, startTerminateConnectionsForPrincipal, startTerminateConnectionsForPrincipal, toStringprotected static final int CLUSTER_RECORD_TYPE_OFFSET
protected static final int CLUSTER_PORT_OFFSET
protected static final int CLUSTER_ADDRESS_LENGTH_OFFSET
protected static final int CLUSTER_ADDRESS_OFFSET
protected static final int MIN_ADDRESS_LENGTH
protected static final int MAX_ADDRESS_LENGTH
protected static final int CLUSTER_MAC_LENGTH
getClusterMacLength(),
Constant Field Valuesprotected static final int MAX_DATAGRAM_OFFSET
public static final Byte RECORD_TYPE_INCOMING
public static final Byte RECORD_TYPE_OUTGOING
protected final DtlsClusterHealth clusterHealth
protected volatile DatagramSocket clusterInternalSocket
public DtlsClusterConnector(DtlsConnectorConfig configuration, DtlsClusterConnectorConfig clusterConfiguration, DtlsClusterConnector.ClusterNodesProvider nodes)
configuration - dtls configurationclusterConfiguration - cluster internal connector configurationnodes - nodes providerIllegalArgumentException - if the configuration doesn't provide a
cid generator, or the cid generator only supports, but
doesn't use cids, or the cid generator is no
NodeConnectionIdGenerator.public DtlsClusterConnector(DtlsConnectorConfig configuration, DtlsClusterConnectorConfig clusterConfiguration, DtlsClusterConnector.ClusterNodesProvider nodes, SessionCache sessionCache)
configuration - dtls configurationclusterConfiguration - cluster internal connector configurationnodes - nodes providersessionCache - session cache. May be null.IllegalArgumentException - if the configuration doesn't provide a
cid generator, or the cid generator only supports, but
doesn't use cids, or the cid generator is no
NodeConnectionIdGenerator.protected DtlsClusterConnector(DtlsConnectorConfig configuration, DtlsClusterConnectorConfig clusterConfiguration, ResumptionSupportingConnectionStore connectionStore, boolean startReceiver)
configuration - dtls configurationclusterConfiguration - cluster internal connector configurationconnectionStore - connection storestartReceiver - true, start receiver threads for cluster
internal communication on
init(InetSocketAddress, DatagramSocket, Integer),
false, otherwise.IllegalArgumentException - if the configuration doesn't provide a
cid generator, or the cid generator only supports, but
doesn't use cids, or the cid generator is no
NodeConnectionIdGenerator.protected DtlsHealth createDefaultHealthHandler(DtlsConnectorConfig configuration)
DtlsClusterHealthLogger.createDefaultHealthHandler in class DTLSConnectorconfiguration - configurationprotected void init(InetSocketAddress bindAddress, DatagramSocket socket, Integer mtu) throws IOException
startReceiver is true.init in class DTLSConnectorbindAddress - address to bind socketsocket - socketmtu - mtu of socket, or null, if socket implementation
doesn't use a special mtu.IOException - I/O errorprotected void startReceiver()
clusterInternalSocket may be
locked by these threads calling
DatagramSocket.receive(DatagramPacket).public void stop()
stop in interface org.eclipse.californium.elements.Connectorstop in class DTLSConnectorprotected int getClusterMacLength()
0, if cluster MAC is not used.public void setClusterNodesProvider(DtlsClusterConnector.ClusterNodesProvider nodes)
nodes - cluster nodes providerpublic int getNodeID()
protected Byte getClusterRecordType(DatagramPacket clusterPacket)
clusterPacket - cluster internal messageRECORD_TYPE_INCOMING, if message is forwarded,
RECORD_TYPE_OUTGOING, if message is backwarded,
null, otherwise.protected boolean ensureLength(Byte type, DatagramPacket clusterPacket)
type - RECORD_TYPE_INCOMING or
RECORD_TYPE_OUTGOING.clusterPacket - the cluster internal message.true, if the cluster internal message is large enough,
false, if it is too short.protected void processDatagramFromClusterNetwork(Byte type, DatagramPacket clusterPacket) throws IOException
type - cluster record type. RECORD_TYPE_INCOMING or
RECORD_TYPE_OUTGOING.clusterPacket - cluster internal messageIOException - if an io-error occurred.protected void processManagementDatagramFromClusterNetwork(DatagramPacket clusterPacket) throws IOException
clusterPacket - cluster internal management message.IOException - if an i/o-error occurredprotected void sendDatagramToClusterNetwork(DatagramPacket clusterPacket) throws IOException
clusterPacket - cluster internal messageIOException - if an i/o-error occurred.protected void processDatagram(DatagramPacket packet, InetSocketAddress router)
NodeConnectionIdGenerator.processDatagram in class DTLSConnectorpacket - received messagerouter - router address, null, if no router is used.protected void sendRecord(Record record) throws IOException
Record.getRouter() destinations, backwards massage to
original receiving connector (router).sendRecord in class DTLSConnectorIOExceptionCopyright © 2023 Eclipse Foundation. All rights reserved.