Demo app for chunking & SSH bytestream.

This commit is contained in:
Christian Schwarz 2017-04-15 17:08:01 +02:00
parent 69f8e7cfc3
commit 32f07c51c7
2 changed files with 83 additions and 0 deletions

1
scratchpad/chunker/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
chunker

View File

@ -0,0 +1,82 @@
package main
import (
"github.com/zrepl/zrepl/model"
"github.com/zrepl/zrepl/sshbytestream"
"github.com/zrepl/zrepl/util"
"flag"
// "bytes"
_ "bufio"
// "strings"
"io"
"fmt"
_ "time"
"os"
)
func main() {
mode := flag.String("mode", "", "incoming|outgoing")
incomingFile := flag.String("incoming.file", "", "file to deliver to callers")
outgoingHost := flag.String("outgoing.sshHost", "", "ssh host")
outgoingUser := flag.String("outgoing.sshUser", "", "ssh user")
outgoingPort := flag.Uint("outgoing.sshPort", 22, "ssh port")
flag.Parse()
switch {
case (*mode == "incoming"):
conn, err := sshbytestream.Incoming()
if err != nil {
panic(err)
}
file, err := os.Open(*incomingFile)
if err != nil {
panic(err)
}
chunker := chunking.NewChunker(file)
_, err = io.Copy(conn, &chunker)
if err != nil && err != io.EOF {
panic(err)
}
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount)
case *mode == "outgoing":
conn, err := sshbytestream.Outgoing("client", model.SSHTransport{
Host: *outgoingHost,
User: *outgoingUser,
Port: uint16(*outgoingPort),
Options: []string{"Compression=no"},
TransportOpenCommand: []string{"/tmp/sshwrap", "-mode", "incoming", "-incoming.file", "/random.img"},
})
if err != nil {
panic(err)
}
unchunker := chunking.NewUnchunker(conn)
_, err = io.Copy(os.Stdout, &unchunker)
if err != nil {
panic(err)
}
conn.Close()
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", unchunker.ChunkCount)
os.Exit(0)
default:
panic("unsupported mode!")
}
}