summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/src/main/kotlin/ConnectionOSLike.kt28
-rw-r--r--lib/src/main/kotlin/NinePMacros.kt8
-rw-r--r--lib/src/main/kotlin/ProtocolInitData.kt19
3 files changed, 47 insertions, 8 deletions
diff --git a/lib/src/main/kotlin/ConnectionOSLike.kt b/lib/src/main/kotlin/ConnectionOSLike.kt
new file mode 100644
index 0000000..a4719d7
--- /dev/null
+++ b/lib/src/main/kotlin/ConnectionOSLike.kt
@@ -0,0 +1,28 @@
+import java.time.Instant
+import kotlin.random.Random
+
+// TODO: Add throws for auth message
+/**
+ * A translator for 9P messages, similar to [Connection], which encapsulates bare 9P messages into a set of methods more
+ * similar to those provided by operating systems.
+ *
+ * Upon instantiation, this class initializes the 9P connection using [ProtocolTranslator.version],
+ * [ProtocolTranslator.auth], and [ProtocolTranslator.attach], up to the point in which the 9P connection can be used
+ * for any operation on remote files.
+ *
+ * @param pt An implementation for bare 9P messages.
+ * @throws except.InvalidMessageException if the received message is invalid.
+ * @throws except.RErrorException if the received message is an R-error message.
+ * @throws except.MsizeValueTooBigException if the received `msize` value is bigger than what the client requested.
+ * @throws except.UnknownVersionException if the version negotiation failed.
+ */
+class ConnectionOSLike(val pt: ProtocolTranslator, val initData: ProtocolInitData) {
+ init {
+ val afid = Random(Instant.now().epochSecond).nextInt().toUInt()
+ this.pt.version(this.initData.msize, this.initData.version)
+ this.pt.auth(afid, this.initData.uname, this.initData.aname)
+ val qid = this.pt.attach(this.initData.rootFid, afid, this.initData.uname, this.initData.aname)
+ }
+
+ // TODO: add methods
+} \ No newline at end of file
diff --git a/lib/src/main/kotlin/NinePMacros.kt b/lib/src/main/kotlin/NinePMacros.kt
deleted file mode 100644
index d5aa83e..0000000
--- a/lib/src/main/kotlin/NinePMacros.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * Handy function that initializes the 9P connection.
- */
-fun initNineP(npconn: Connection) {
- // TODO: implement
-}
-
-fun readAll(npconn: Connection, ) \ No newline at end of file
diff --git a/lib/src/main/kotlin/ProtocolInitData.kt b/lib/src/main/kotlin/ProtocolInitData.kt
new file mode 100644
index 0000000..351b289
--- /dev/null
+++ b/lib/src/main/kotlin/ProtocolInitData.kt
@@ -0,0 +1,19 @@
+/**
+ * Data for initializing the 9P protocol using [ProtocolTranslator.version], [ProtocolTranslator.auth], and
+ * [ProtocolTranslator.attach].
+ *
+ * @param msize A value for the `msize` field in the `version` message.
+ * @param version A value for the `version` field in the `version` message.
+ * @param uname A value for the `uname` field in the `auth` and `attach` messages.
+ * @param aname A value for the `aname` field in the `auth` and `attach` messages.
+ * @param rootFid A value for the root `fid` in the `attach` message.
+ * @param auth An [Authenticator] implementation used for authenticating the user.
+ */
+data class ProtocolInitData(
+ val msize: UInt,
+ val version: String,
+ val uname: String,
+ val aname: String,
+ val rootFid: UInt,
+ val auth: Authenticator
+) \ No newline at end of file