diff --git a/src/dorkbox/network/connection/connectionType/ConnectionProperties.kt b/src/dorkbox/network/connection/connectionType/ConnectionProperties.kt new file mode 100644 index 00000000..3702c317 --- /dev/null +++ b/src/dorkbox/network/connection/connectionType/ConnectionProperties.kt @@ -0,0 +1,24 @@ +package dorkbox.network.connection.connectionType + +import dorkbox.network.handshake.UpgradeType + +/** + * Used in [IpConnectionTypeRule] to decide what kind of connection a matching IP Address should have. + */ +enum class ConnectionProperties(val type: Byte) { + /** + * No compression, no encryption + */ + NOTHING(UpgradeType.NONE), + + /** + * Only compression + */ + COMPRESS(UpgradeType.COMPRESS), + + /** + * Compression + encryption + */ + COMPRESS_AND_ENCRYPT(UpgradeType.ENCRYPT); + +} diff --git a/src/dorkbox/network/connection/ping/PingCanceledException.kt b/src/dorkbox/network/connection/ping/PingCanceledException.kt index 6541e45f..9d5d7f5c 100644 --- a/src/dorkbox/network/connection/ping/PingCanceledException.kt +++ b/src/dorkbox/network/connection/ping/PingCanceledException.kt @@ -13,17 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dorkbox.network.connection.ping; +package dorkbox.network.connection.ping -import java.io.IOException; +import java.io.IOException -public -class PingCanceledException extends IOException { - - private static final long serialVersionUID = 9045461384091038605L; - - public - PingCanceledException() { - super("Ping request has been canceled."); - } +object PingCanceledException : IOException() { + private const val serialVersionUID = 9045461384091038605L } diff --git a/src/dorkbox/network/connection/ping/PingFuture.kt b/src/dorkbox/network/connection/ping/PingFuture.kt index 75bf5072..80f05934 100644 --- a/src/dorkbox/network/connection/ping/PingFuture.kt +++ b/src/dorkbox/network/connection/ping/PingFuture.kt @@ -13,34 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dorkbox.network.connection.ping; +package dorkbox.network.connection.ping -import java.util.concurrent.atomic.AtomicInteger; - -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Ping; -import dorkbox.network.connection.PingListener; - -public -class PingFuture implements Ping { - - private static final AtomicInteger pingCounter = new AtomicInteger(0); - - // private final Promise> promise; - - private final int id; - private final long sentTime; +import dorkbox.network.connection.Connection +import dorkbox.network.connection.Ping +import dorkbox.network.connection.PingListener +import java.util.concurrent.atomic.AtomicInteger +class PingFuture internal constructor() : Ping { /** - * Protected constructor for when we are completely overriding this class. (Used by the "local" connection for instant pings) + * @return the ID of this ping future */ - @SuppressWarnings("unused") - PingFuture() { - // this(null); - id = -1; - sentTime = -2; - } - + // private final Promise> promise; + val id: Int + private val sentTime: Long // public // PingFuture(Promise> promise) { // this.promise = promise; @@ -50,15 +36,20 @@ class PingFuture implements Ping { // if (this.id == Integer.MAX_VALUE) { // pingCounter.set(0); // } + // }// try { + // PingTuple entry = this.promise.syncUninterruptibly() + // .get(); + // if (entry != null) { + // return entry.responseTime; + // } + // } catch (InterruptedException e) { + // } catch (ExecutionException e) { // } - /** * Wait for the ping to return, and returns the ping response time in MS or -1 if it failed. */ - @Override - public - int getResponse() { - // try { + override val response: Int + get() =// try { // PingTuple entry = this.promise.syncUninterruptibly() // .get(); // if (entry != null) { @@ -66,18 +57,14 @@ class PingFuture implements Ping { // } // } catch (InterruptedException e) { // } catch (ExecutionException e) { - // } - return -1; - } + // } + -1 /** * Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already * completed, the specified listener is notified immediately. */ - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public - void add(PingListener listener) { + override fun add(listener: PingListener) { // this.promise.addListener((GenericFutureListener) listener); } @@ -85,27 +72,21 @@ class PingFuture implements Ping { * Removes the specified listener from this future. The specified listener is no longer notified when this future is done. If the * specified listener is not associated with this future, this method does nothing and returns silently. */ - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public - void remove(PingListener listener) { + override fun remove(listener: PingListener) { // this.promise.removeListener((GenericFutureListener) listener); } /** * Cancel this Ping. */ - @Override - public - void cancel() { + override fun cancel() { // this.promise.tryFailure(new PingCanceledException()); } /** * This is when the endpoint that ORIGINALLY sent the ping, finally receives a response. */ - public - void setSuccess(C connection, PingMessage ping) { + fun setSuccess(connection: C, ping: PingMessage?) { // if (ping.id == this.id) { // long longTime = System.currentTimeMillis() - this.sentTime; // if (longTime < Integer.MAX_VALUE) { @@ -117,17 +98,21 @@ class PingFuture implements Ping { // } } - public - boolean isSuccess() { - // return this.promise.isSuccess(); - return false; + // return this.promise.isSuccess(); + val isSuccess: Boolean + get() =// return this.promise.isSuccess(); + false + + companion object { + private val pingCounter = AtomicInteger(0) } /** - * @return the ID of this ping future + * Protected constructor for when we are completely overriding this class. (Used by the "local" connection for instant pings) */ - public - int getId() { - return this.id; + init { + // this(null); + id = -1 + sentTime = -2 } } diff --git a/src/dorkbox/network/connection/ping/PingMessage.kt b/src/dorkbox/network/connection/ping/PingMessage.kt index 776820e0..7b0ad647 100644 --- a/src/dorkbox/network/connection/ping/PingMessage.kt +++ b/src/dorkbox/network/connection/ping/PingMessage.kt @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dorkbox.network.connection.ping; +package dorkbox.network.connection.ping /** * Internal message to determine round trip time. */ -public class PingMessage { - public int id; - public boolean isReply; + var id = 0 + var isReply = false } diff --git a/src/dorkbox/network/connection/ping/PingTuple.kt b/src/dorkbox/network/connection/ping/PingTuple.kt index f54f19ea..2e81f5c9 100644 --- a/src/dorkbox/network/connection/ping/PingTuple.kt +++ b/src/dorkbox/network/connection/ping/PingTuple.kt @@ -13,17 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dorkbox.network.connection.ping; +package dorkbox.network.connection.ping +import dorkbox.network.connection.Connection -import dorkbox.network.connection.Connection; - -public class PingTuple { - public C connection; - public int responseTime; - - public PingTuple(C connection, int responseTime) { - this.connection = connection; - this.responseTime = responseTime; - } -} +class PingTuple(var connection: C, var responseTime: Int)