Skip to content

Commit

Permalink
Merge ReadWriteLockConnectionStore into
Browse files Browse the repository at this point in the history
ResumptionSupportingConnectionStore.

Remove obsolete ReadWriteLockConnectionStore.

Signed-off-by: Achim Kraus <[email protected]>
  • Loading branch information
boaks committed Dec 13, 2024
1 parent daff8aa commit 799b08a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 161 deletions.
2 changes: 2 additions & 0 deletions MIGRATION_HINTS_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Change scope of `DTLSFlight.wrapMessage` to `private`.

The names `CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA378`, and `CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA378` are corrected into `CipherSuite.TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384`, and `CipherSuite.TLS_PSK_WITH_AES_256_GCM_SHA384`.

Merged `ReadWriteLockConnectionStore` into `ResumptionSupportingConnectionStore` and remove obsolete `ReadWriteLockConnectionStore`.

### Californium-Core:

The functions of the obsolete and removed `ExtendedCoapStack` are moved into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
import org.eclipse.californium.scandium.dtls.InMemoryReadWriteLockConnectionStore;
import org.eclipse.californium.scandium.dtls.MaxFragmentLengthExtension;
import org.eclipse.californium.scandium.dtls.ProtocolVersion;
import org.eclipse.californium.scandium.dtls.ReadWriteLockConnectionStore;
import org.eclipse.californium.scandium.dtls.Record;
import org.eclipse.californium.scandium.dtls.RecordLayer;
import org.eclipse.californium.scandium.dtls.ResumingClientHandshaker;
Expand Down Expand Up @@ -934,8 +933,8 @@ private void cleanupRecentHandshakes(int calls) {
LOGGER.error("{} recent handshakes, cleanup failed after {} in {}ms{}!", size, count,
TimeUnit.NANOSECONDS.toMillis(time), qualifier, ex);
}
if (running.get() && connectionStore instanceof ReadWriteLockConnectionStore) {
((ReadWriteLockConnectionStore) connectionStore).shrink(calls, running);
if (running.get() ) {
connectionStore.shrink(calls, running);
}
}

Expand Down Expand Up @@ -979,8 +978,8 @@ public final void setExecutor(ExecutorService executor) {
}
}
}
if (change && connectionStore instanceof ReadWriteLockConnectionStore) {
((ReadWriteLockConnectionStore) connectionStore).setExecutor(null);
if (change ) {
connectionStore.setExecutor(null);
}
}

Expand Down Expand Up @@ -1183,9 +1182,7 @@ protected void init(InetSocketAddress bindAddress, DatagramSocket socket, Intege
} else {
executorService = timer;
}
if (connectionStore instanceof ReadWriteLockConnectionStore) {
((ReadWriteLockConnectionStore) connectionStore).setExecutor(executorService);
}
connectionStore.setExecutor(executorService);
this.hasInternalExecutor = true;
}
// prepare restored connections.
Expand Down Expand Up @@ -1401,9 +1398,7 @@ public void stop() {
shutdown = executorService;
executorService = null;
hasInternalExecutor = false;
if (connectionStore instanceof ReadWriteLockConnectionStore) {
((ReadWriteLockConnectionStore) connectionStore).setExecutor(null);
}
connectionStore.setExecutor(null);
}
for (Thread t : receiverThreads) {
t.interrupt();
Expand Down Expand Up @@ -1655,61 +1650,26 @@ public void run() {
*/
private final Connection getConnection(InetSocketAddress peerAddress, ConnectionId cid, boolean create) {
ExecutorService executor = getExecutorService();
Connection connection;
if (connectionStore instanceof ReadWriteLockConnectionStore) {
ReadWriteLockConnectionStore store = (ReadWriteLockConnectionStore) connectionStore;
if (cid != null) {
connection = connectionStore.get(cid);
} else {
Connection connection = (cid != null) ? connectionStore.get(cid) : connectionStore.get(peerAddress);
if (create && connection == null && cid == null) {
connectionStore.writeLock().lock();
try {
// check again, now with write-lock
connection = connectionStore.get(peerAddress);
}
if (create && connection == null && cid == null) {
store.writeLock().lock();
try {
// check again, now with write-lock
connection = connectionStore.get(peerAddress);
if (connection == null) {
LOGGER.trace("create new connection for {}", peerAddress);
Connection newConnection = new Connection(peerAddress);
newConnection.setConnectorContext(executor, connectionListener);
if (running.get()) {
// only add, if connector is running!
if (!connectionStore.put(newConnection)) {
return null;
}
}
return newConnection;
}
} finally {
store.writeLock().unlock();
}
}
} else {
synchronized (connectionStore) {
if (cid != null) {
connection = connectionStore.get(cid);
} else {
connection = connectionStore.get(peerAddress);
if (connection == null && create) {
LOGGER.trace("create new connection for {}", peerAddress);
Connection newConnection = new Connection(peerAddress);
newConnection.setConnectorContext(executor, connectionListener);
if (running.get()) {
// only add, if connector is running!
if (!connectionStore.put(newConnection)) {
return null;
}
if (connection == null) {
LOGGER.trace("create new connection for {}", peerAddress);
Connection newConnection = new Connection(peerAddress);
newConnection.setConnectorContext(executor, connectionListener);
if (running.get()) {
// only add, if connector is running!
if (!connectionStore.put(newConnection)) {
return null;
}
return newConnection;
}
return newConnection;
}
if (running.get() && connection != null && !connection.isExecuting()) {
// reviving is only required for none
// ShrinkingConnectionStore
connection.setConnectorContext(executor, connectionListener);
LOGGER.trace("revive connection for {},{}", peerAddress, cid);
return connection;
}
} finally {
connectionStore.writeLock().unlock();
}
}
if (connection == null) {
Expand Down Expand Up @@ -2463,18 +2423,11 @@ private void processNewClientHello(final Record record) {
if (addressVerified) {
final Connection connection;
ExecutorService executor = getExecutorService();
if (connectionStore instanceof ReadWriteLockConnectionStore) {
ReadWriteLockConnectionStore store = (ReadWriteLockConnectionStore) connectionStore;
store.writeLock().lock();
try {
connection = getConnectionForNewClientHello(peerAddress, clientHello, executor);
} finally {
store.writeLock().unlock();
}
} else {
synchronized (connectionStore) {
connection = getConnectionForNewClientHello(peerAddress, clientHello, executor);
}
connectionStore.writeLock().lock();
try {
connection = getConnectionForNewClientHello(peerAddress, clientHello, executor);
} finally {
connectionStore.writeLock().unlock();
}
if (connection != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
*
* @since 3.5
*/
public class InMemoryReadWriteLockConnectionStore implements ReadWriteLockConnectionStore {
public class InMemoryReadWriteLockConnectionStore implements ResumptionSupportingConnectionStore {

private static final Logger LOGGER = LoggerFactory.getLogger(InMemoryReadWriteLockConnectionStore.class);
private static final FilteredLogger WARN_FILTER = new FilteredLogger(LOGGER.getName(), 3, TimeUnit.SECONDS.toNanos(10));
Expand Down

This file was deleted.

Loading

0 comments on commit 799b08a

Please sign in to comment.