summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-07 19:54:25 +0200
committerEdoardo La Greca2025-08-07 19:54:25 +0200
commit62db47bb6a6b2dbdff05d03a57c24cdf9e77d16c (patch)
tree141d7b704396f6b44ae790495f9d0c56be858f56 /src/main
parent60a9b89d01babe1d261d42a698ea906f4b293b59 (diff)
change version to use exceptions instead of error strings
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/Connection.kt16
-rw-r--r--src/main/kotlin/ProtocolTranslator.kt7
2 files changed, 10 insertions, 13 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 48394e0..a0923e8 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -72,7 +72,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
return imsg
}
- override fun version(msize: UInt, version: String): String? {
+ override fun version(msize: UInt, version: String) {
val omsg = OutMessage(NinePMessageType.TVERSION, this.NOTAG, listOf("msize", "version"),
mapOf(
"msize" to BigInteger(msize.toString())
@@ -84,25 +84,19 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
this.maxSize
)
omsg.write(this.tl)
- val imsg: InMessage
- try {
- imsg = InMessage(this.tl, msize, omsg.tag)
- } catch (ime: InvalidMessageException) {
- return ime.message
- }
+ val imsg = checkedInMessage(omsg.tag)
imsg.applySchema(listOf(
InMessage.Field("msize", InMessage.Field.Type.INTEGER, 4u),
InMessage.Field("version", InMessage.Field.Type.STRING, 0u)
))
val remoteMaxSize = imsg.fieldsInt["msize"]!!.toInt().toUInt()
if (remoteMaxSize > this.maxSize) {
- return "Invalid remote msize value (too big)."
+ throw MsizeValueTooBigException(msize, remoteMaxSize)
}
this.maxSize = remoteMaxSize
- if (imsg.fieldsStr["version"] == "unknown") {
- return "Unknown version."
+ if (!imsg.fieldsStr["version"]!!.startsWith("9P2000")) {
+ throw UnknownVersionException(imsg.fieldsStr["version"]!!)
}
- return null
}
override fun auth(afid: UInt, uname: String, aname: String) {
diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt
index eaa415f..f7b114f 100644
--- a/src/main/kotlin/ProtocolTranslator.kt
+++ b/src/main/kotlin/ProtocolTranslator.kt
@@ -27,9 +27,12 @@ interface ProtocolTranslator {
* @param msize The maximum length, in bytes, that the client will ever generate or expect to receive in a single
* 9P message.
* @param version Should be "9P2000", which is the only defined value.
- * @return a possible error.
+ * @throws InvalidMessageException if the received message is invalid.
+ * @throws RErrorException if the received message is an R-error message.
+ * @throws MsizeValueTooBigException if the received `msize` value is bigger than what the client requested.
+ * @throws UnknownVersionException if the version negotiation failed.
*/
- fun version(msize: UInt, version: String): String?
+ fun version(msize: UInt, version: String)
/**
* Perform authentication.