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 }