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