summaryrefslogtreecommitdiff
path: root/lib/src/main/kotlin/ConnectionOSLike.kt
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/main/kotlin/ConnectionOSLike.kt')
-rw-r--r--lib/src/main/kotlin/ConnectionOSLike.kt28
1 files changed, 28 insertions, 0 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