From 32f07c51c75e8b00bbdae866b0b92c01d96b5253 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 15 Apr 2017 17:08:01 +0200 Subject: [PATCH] Demo app for chunking & SSH bytestream. --- scratchpad/chunker/.gitignore | 1 + scratchpad/chunker/main.go | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 scratchpad/chunker/.gitignore create mode 100644 scratchpad/chunker/main.go diff --git a/scratchpad/chunker/.gitignore b/scratchpad/chunker/.gitignore new file mode 100644 index 0000000..e633497 --- /dev/null +++ b/scratchpad/chunker/.gitignore @@ -0,0 +1 @@ +chunker diff --git a/scratchpad/chunker/main.go b/scratchpad/chunker/main.go new file mode 100644 index 0000000..def0518 --- /dev/null +++ b/scratchpad/chunker/main.go @@ -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!") + + } + +} \ No newline at end of file