Interface wireframe

This commit is contained in:
Christian Schwarz
2017-04-14 19:26:32 +02:00
parent 8f11874a6e
commit 123becbd22
7 changed files with 278 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package rpc
struct Unchunker {
In io.Reader
internalBuffer []byte
remainingChunkSize uint
}
func NewUnchunker(conn io.Reader) {
return Unchunker{In: conn} // TODO
}
func (c Unchunker) Read(b []byte) (n int, error) {
// read min(c.internalBuffer.len, b.len) from c.internalBuffer into b
// fill up internalBuffer
// 1 read up to max(remainingChunkSize,internalBuffer.len) from In
// 2 if remainingChunkSize == 0, read next chunk size, update remainingChunkSize
// 3 goto 1
}
struct Chunker {
In io.Reader
MaxChunkSize uint
ChunkBuf []byte // length of buf determines chunk size? --> would be fixed then
}
+76
View File
@@ -0,0 +1,76 @@
package rpc
type RPCRequester interface {
FilesystemRequest(r FilesystemRequest) (root model.Filesystem, err error)
InitialTransferRequest(r InitialTransferRequest) (io.Read, error)
IncrementalTransferRequest(r IncrementalTransferRequest) (io.Read, error)
}
type RPCHandler interface {
HandleFilesystemRequest(r FilesystemRequest) (root model.Filesystem, err error)
HandleInitialTransferRequest(r InitialTransferRequest) (io.Read, error)
HandleIncrementalTransferRequestRequest(r IncrementalTransferRequest) (io.Read, error)
}
type ByteStreamRPC struct {
conn io.ReadWriteCloser
}
func ConnectByteStreamRPC(conn io.ReadWriteCloser) (ByteStreamRPC, error) {
// TODO do ssh connection to transport, establish TCP-like communication channel
conn := sshtransport.New()
rpc := ByteStreamRPC{
conn: conn,
}
return conn, nil
}
func ListenByteStreamRPC(conn io.ReadWriteCloser, handler RPCHandler) (error) {
// Read from connection, decode wire protocol, route requests to handler
return nil
}
func (c ByteStreamRPC) FilesystemRequest(r FilesystemRequest) (roots []model.Filesystem, err error) {
encodedReader := protobuf.Encode(r)
c.conn.Write(NewChunker(encodedReader))
encodedResponseReader := NewUnchunker(c.conn.Read())
roots = protobuf.Decode(encodedResponse)
return
}
func (c ByteStreamRPC) InitialTransferRequest(r InitialTransferRequest) (io.Read, error) {
// send request header using protobuf or similar
encodedReader := protobuf.Encode(r)
c.conn.Write(NewChunker(encodedReader))
// expect chunked response -> use unchunker on c.conn to read snapshot stream
return NewUmainnchunker(c.conn.Read())
}
func (c ByteStreamRPC) IncrementalTransferRequest(r IncrementalTransferRequest) (io.Read, error) {
}
type LocalRPC struct {
handler RPCHandler
}
func ConnectLocalRPC(handler RPCHandler) LocalRPC {
return LocalRPC{handler}
}
func (c LocalRPC) FilesystemRequest(r FilesystemRequest) (root model.Filesystem, err error) {
return c.handler.HandleFilesystemRequest(r)
}
func (c LocalRPC) InitialTransferRequest(r InitialTransferRequest) (io.Read, error) {
return c.handler.HandleInitialTransferRequest(r)
}
func (c LocalRPC) IncrementalTransferRequest(r IncrementalTransferRequest) (io.Read, error) {
return c.handler.HandleIncrementalTransferRequest(r)
}
+29
View File
@@ -0,0 +1,29 @@
package protocol
type RequestId uint8
type Request struct {
RequestType RequestType
RequestId [16]byte // UUID
}
type FilesystemRequest struct {
Request
Roots []string
}
type InitialTransferRequest struct {
Request
Snapshot string // tank/my/db@ljlsdjflksdf
}
func (r InitialTransferRequest) Respond(snapshotReader io.Reader) {
}
type IncrementalTransferRequest struct {
Request
FromSnapshot string
ToSnapshot string
}
func (r IncrementalTransferRequest) Respond(snapshotReader io.Reader) {
}