summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-01 19:19:15 +0200
committerEdoardo La Greca2025-08-01 19:20:25 +0200
commiteec68974cabb51e1a8136772e0cad38eaa7d3620 (patch)
tree73e1e2d0e1df015e36aa0e9211c10541ccb074d1 /src
parent756db579d92270ca7cce13f3eda8e4b17ac0039f (diff)
change class names and do some refactoring
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/Message.kt (renamed from src/main/kotlin/NinePMessage.kt)36
-rw-r--r--src/main/kotlin/ProtocolTranslator.kt (renamed from src/main/kotlin/NinePTranslator.kt)4
-rw-r--r--src/main/kotlin/TransportLayer.kt (renamed from src/main/kotlin/NetworkPacketTransporter.kt)6
-rw-r--r--src/main/kotlin/TransportLayerJavaNet.kt (renamed from src/main/kotlin/NetworkPacketTransporterJavaNet.kt)4
4 files changed, 25 insertions, 25 deletions
diff --git a/src/main/kotlin/NinePMessage.kt b/src/main/kotlin/Message.kt
index 1d77807..5007c26 100644
--- a/src/main/kotlin/NinePMessage.kt
+++ b/src/main/kotlin/Message.kt
@@ -14,7 +14,7 @@ import kotlin.math.pow
* @param fieldValuesInt A map of each field name into its value. This map only stores integer values.
* @param fieldValuesStr A map of each field name into its value. This map only stores string values.
*/
-class NinePMessage(val type: NinePMessageType, val tag: UShort, val fieldNames: List<String>, val fieldValuesInt: Map<String, BigInteger>, val fieldValuesStr: Map<String, String>, val maxSize: UInt) {
+class Message(val type: NinePMessageType, val tag: UShort, val fieldNames: List<String>, val fieldValuesInt: Map<String, BigInteger>, val fieldValuesStr: Map<String, String>, val maxSize: UInt) {
/**
* Intersection between [fieldNames] and [fieldValuesInt]. In other words: the amount of integer fields that are
* going to be used when writing the message.
@@ -29,11 +29,11 @@ class NinePMessage(val type: NinePMessageType, val tag: UShort, val fieldNames:
/**
* Send the message using the given networking API.
*
- * @param npt The networking API.
+ * @param tl The networking API.
* @throws IllegalArgumentException if [fieldNames], [fieldValuesInt], and [fieldValuesStr] are incoherent or the
* final size of the message exceeds the negotiated value.
*/
- fun write(npt: NetworkPacketTransporter) {
+ fun write(tl: TransportLayer) {
// check that names in fieldNames exist as keys in either fieldValuesInt or fieldValuesStr but not both
require(insecInts.size == fieldNames.size - insecStrs.size)
@@ -41,13 +41,13 @@ class NinePMessage(val type: NinePMessageType, val tag: UShort, val fieldNames:
if (totalSize > this.maxSize) {
throw IllegalArgumentException("Message size exceeded.")
}
- writeMessageSizeType(npt, totalSize, type)
- writeInteger(npt, tag.toInt().toBigInteger())
+ writeMessageSizeType(tl, totalSize, type)
+ writeInteger(tl, tag.toInt().toBigInteger())
for (field in fieldNames) {
if (field in insecInts) {
- writeInteger(npt, fieldValuesInt[field]!!)
+ writeInteger(tl, fieldValuesInt[field]!!)
} else {
- writeString(npt, fieldValuesStr[field]!!)
+ writeString(tl, fieldValuesStr[field]!!)
}
}
}
@@ -58,12 +58,12 @@ class NinePMessage(val type: NinePMessageType, val tag: UShort, val fieldNames:
*
* In 9P, binary numbers (non-textual) are specified in little-endian order (least significant byte first).
*
- * @param npt The networking API.
+ * @param tl The networking API.
* @param value The number's value.
*/
- private fun writeInteger(npt: NetworkPacketTransporter, value: BigInteger) {
+ private fun writeInteger(tl: TransportLayer, value: BigInteger) {
val bytes = value.toByteArray()
- npt.transmit(Array(bytes.size) { i -> bytes[i].toUByte() })
+ tl.transmit(Array(bytes.size) { i -> bytes[i].toUByte() })
}
/**
@@ -72,27 +72,27 @@ class NinePMessage(val type: NinePMessageType, val tag: UShort, val fieldNames:
* In 9P, strings are represented as a 2-byte integer (the string's size) followed by the actual UTF-8 string. The
* null terminator is forbidden in 9P messages.
*
- * @param npt The networking API.
+ * @param tl The networking API.
* @param value The string.
* @throws IllegalArgumentException if the value of the string's size does not fit into 2 bytes.
*/
- private fun writeString(npt: NetworkPacketTransporter, value: String) {
+ private fun writeString(tl: TransportLayer, value: String) {
require(value.length <= 2.0.pow(16.0) - 1)
- writeInteger(npt, value.length.toBigInteger())
+ writeInteger(tl, value.length.toBigInteger())
val bytes = value.toByteArray()
- npt.transmit(Array(bytes.size) { i -> bytes[i].toUByte() })
+ tl.transmit(Array(bytes.size) { i -> bytes[i].toUByte() })
}
/**
* Write the message size and type.
*
- * @param npt The networking API.
+ * @param tl The networking API.
* @param size The total message size, including the 4 bytes of this parameter and the type's byte.
* @param type The 9P message type as a [NinePMessageType] constant.
*/
- private fun writeMessageSizeType(npt: NetworkPacketTransporter, size: UInt, type: NinePMessageType) {
- writeInteger(npt, size.toInt().toBigInteger())
- writeInteger(npt, type.value.toInt().toBigInteger())
+ private fun writeMessageSizeType(tl: TransportLayer, size: UInt, type: NinePMessageType) {
+ writeInteger(tl, size.toInt().toBigInteger())
+ writeInteger(tl, type.value.toInt().toBigInteger())
}
/**
diff --git a/src/main/kotlin/NinePTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt
index ef76cc6..bc64002 100644
--- a/src/main/kotlin/NinePTranslator.kt
+++ b/src/main/kotlin/ProtocolTranslator.kt
@@ -4,7 +4,7 @@ TODO:
*/
/**
- * The [NinePTranslator] interface provides methods that coincide 1:1 with each request type in the 9P protocol. Every
+ * The [ProtocolTranslator] interface provides methods that coincide 1:1 with each request type in the 9P protocol. Every
* method that can fail, that is, every request that can receive a response with `Rerror` type instead of the same type
* as itself, returns a non-null `String` that contains the error message received in the response.
*
@@ -12,7 +12,7 @@ TODO:
*
* Trivia: comments for each method are taken from each message type's manual page in section 5.
*/
-interface NinePTranslator {
+interface ProtocolTranslator {
/**
* Negotiate protocol version.
*
diff --git a/src/main/kotlin/NetworkPacketTransporter.kt b/src/main/kotlin/TransportLayer.kt
index eef0aea..514f78b 100644
--- a/src/main/kotlin/NetworkPacketTransporter.kt
+++ b/src/main/kotlin/TransportLayer.kt
@@ -1,7 +1,7 @@
import java.io.Closeable
/**
- * [NetworkPacketTransporter] is an abstract class for network transport-layer operations. A class that implements this
+ * [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").
*
@@ -10,9 +10,9 @@ import java.io.Closeable
* if the remote address is a domain name, but it cannot be resolved.
*
* Depending on the specific given implementation, the constructor of this class might throw other exceptions (e.g. the
- * [java.net.Socket] constructor in [NetworkPacketTransporterJavaNet]).
+ * [java.net.Socket] constructor in [TransportLayerJavaNet]).
*/
-abstract class NetworkPacketTransporter : Closeable {
+abstract class TransportLayer : Closeable {
val address: String
val port: UShort
diff --git a/src/main/kotlin/NetworkPacketTransporterJavaNet.kt b/src/main/kotlin/TransportLayerJavaNet.kt
index fe2c87c..c40b72b 100644
--- a/src/main/kotlin/NetworkPacketTransporterJavaNet.kt
+++ b/src/main/kotlin/TransportLayerJavaNet.kt
@@ -9,9 +9,9 @@ TODO:
*/
/**
- * An implementation of [NetworkPacketTransporter] written using the [java.net] package.
+ * An implementation of [TransportLayer] written using the [java.net] package.
*/
-class NetworkPacketTransporterJavaNet : NetworkPacketTransporter {
+class TransportLayerJavaNet : TransportLayer {
/**
* The connection's socket.
*/