diff options
author | Edoardo La Greca | 2025-08-29 19:28:27 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-29 19:28:27 +0200 |
commit | b32a4f6511171ebfc64811471c7a2fa61bf17961 (patch) | |
tree | f2d0e31ef584fbbd9ff921adcbab3cfc01deddfe /lib/src/main/kotlin/ConnectionOSLike.kt | |
parent | 3ab30c0fc3a7d6744908812284b168b57729b4ce (diff) |
delete NinePMacros.kt and replace it with ConnectionOSLike and ProtocolInitData
Diffstat (limited to 'lib/src/main/kotlin/ConnectionOSLike.kt')
-rw-r--r-- | lib/src/main/kotlin/ConnectionOSLike.kt | 28 |
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 |