diff options
author | Edoardo La Greca | 2025-08-02 18:33:48 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-02 18:33:48 +0200 |
commit | 451f327d034f27aef470abfd67eaa4ea70f1a33c (patch) | |
tree | 2d48c14b416599f0514891cbb6237c6e60eb8115 | |
parent | 3581fd9db46893cefad747c25ec599b5d4aa7418 (diff) |
turn TransportLayer into an interface
-rw-r--r-- | src/main/kotlin/TransportLayer.kt | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/src/main/kotlin/TransportLayer.kt b/src/main/kotlin/TransportLayer.kt index 514f78b..d4a9b12 100644 --- a/src/main/kotlin/TransportLayer.kt +++ b/src/main/kotlin/TransportLayer.kt @@ -1,43 +1,19 @@ import java.io.Closeable /** - * [TransportLayer] is an abstract class for network transport-layer operations. A class that implements this - * class' abstract methods, once instantiated, establishes and manages a connection with a remote endpoint defined by an - * address and a port and allows to send and receive network messages (also called "payloads"). + * [TransportLayer] is an interface for network transport-layer operations. A class that implements these methods, once + * instantiated, establishes and manages a connection with a remote endpoint defined by an address and a port and allows + * to send and receive network messages (also called "payloads"). * * The address of the remote endpoint can be an IP address (v4 or v6) or a domain name, in which case it is resolved to * an IP address right before initializing the connection. Every constructor should throw an [UnresolvableHostException] - * if the remote address is a domain name, but it cannot be resolved. + * if the remote address is formatted as an actual domain name, but it cannot be resolved (e.g. it doesn't exist, or it + * contains forbidden characters). * * Depending on the specific given implementation, the constructor of this class might throw other exceptions (e.g. the * [java.net.Socket] constructor in [TransportLayerJavaNet]). */ -abstract class TransportLayer : Closeable { - val address: String - val port: UShort - - /** - * Classic constructor. - * - * @throws UnresolvableHostException if the remote address is a domain name, but it cannot be resolved. - */ - constructor(address: String, port: UShort) { - this.address = address - this.port = port - } - - /** - * This constructor allows addresses specified using one of the styles specified in dial(2). See - * [nineAddressToValues]. - * - * @throws UnresolvableHostException if the remote address is a domain name, but it cannot be resolved. - */ - constructor(fullAddress: String) { - val ap = nineAddressToValues(fullAddress) - this.address = ap.first - this.port = ap.second - } - +interface TransportLayer : Closeable { /** * Close the connection. */ @@ -48,7 +24,7 @@ abstract class TransportLayer : Closeable { * * @throws java.io.IOException if the message could not be correctly transmitted. */ - abstract fun transmit(payload: Array<UByte>) + fun transmit(payload: Array<UByte>) /* /** * Receive a payload until a byte occurs, which marks the end of the message. The byte is discarded after being read @@ -70,5 +46,5 @@ abstract class TransportLayer : Closeable { * @return the received payload. * @throws java.io.IOException if the message could not be correctly received. */ - abstract fun receive(length: ULong): Array<UByte> + fun receive(length: ULong): Array<UByte> }
\ No newline at end of file |