blob: a4719d72306e1eb0df8b290529f2a2071ec48bcb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
}
|