mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-21 16:03:32 +01:00
Demo app for chunking & SSH bytestream.
This commit is contained in:
parent
69f8e7cfc3
commit
32f07c51c7
1
scratchpad/chunker/.gitignore
vendored
Normal file
1
scratchpad/chunker/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
chunker
|
82
scratchpad/chunker/main.go
Normal file
82
scratchpad/chunker/main.go
Normal 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!")
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user