diff options
author | Jakob Borg <jakob@nym.se> | 2014-07-01 12:20:25 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-07-01 12:20:25 +0200 |
commit | 071f4c0769e724b7bb3f54b3739ec3b283d217ef (patch) | |
tree | 9772f31f5a449e94846374a61c111abb79c173ef /cmd | |
parent | b57f4ed97e0ae054d4a2327dc01b637217750d58 (diff) |
Remove reprecated st* utils
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/.gitignore | 1 | ||||
-rw-r--r-- | cmd/stcli/main.go | 146 | ||||
-rw-r--r-- | cmd/stcli/tls.go | 16 | ||||
-rw-r--r-- | cmd/stpidx/main.go | 56 |
4 files changed, 0 insertions, 219 deletions
diff --git a/cmd/.gitignore b/cmd/.gitignore index f80161a20f..3e1db14fd3 100644 --- a/cmd/.gitignore +++ b/cmd/.gitignore @@ -1,2 +1 @@ !syncthing -!stcli diff --git a/cmd/stcli/main.go b/cmd/stcli/main.go deleted file mode 100644 index ee6d19bc3c..0000000000 --- a/cmd/stcli/main.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved. -// Use of this source code is governed by an MIT-style license that can be -// found in the LICENSE file. - -package main - -import ( - "crypto/tls" - "flag" - "io" - "log" - "os" - "path/filepath" - - "github.com/calmh/syncthing/protocol" -) - -var ( - exit bool - cmd string - confDir string - target string - get string - pc protocol.Connection -) - -func main() { - log.SetFlags(0) - log.SetOutput(os.Stdout) - - flag.StringVar(&cmd, "cmd", "idx", "Command") - flag.StringVar(&confDir, "home", ".", "Certificates directory") - flag.StringVar(&target, "target", "127.0.0.1:22000", "Target node") - flag.StringVar(&get, "get", "", "Get file") - flag.BoolVar(&exit, "exit", false, "Exit after command") - flag.Parse() - - connect(target) - - select {} -} - -func connect(target string) { - cert, err := loadCert(confDir) - if err != nil { - log.Fatal(err) - } - - myID := protocol.NewNodeID(cert.Certificate[0]) - - tlsCfg := &tls.Config{ - Certificates: []tls.Certificate{cert}, - NextProtos: []string{"bep/1.0"}, - ServerName: myID.String(), - ClientAuth: tls.RequestClientCert, - SessionTicketsDisabled: true, - InsecureSkipVerify: true, - MinVersion: tls.VersionTLS12, - } - - conn, err := tls.Dial("tcp", target, tlsCfg) - if err != nil { - log.Fatal(err) - } - - remoteID := protocol.NewNodeID(conn.ConnectionState().PeerCertificates[0].Raw) - - pc = protocol.NewConnection(remoteID, conn, conn, Model{}) - - select {} -} - -type Model struct { -} - -func prtIndex(files []protocol.FileInfo) { - for _, f := range files { - log.Printf("%q (v:%d mod:%d flags:0%o nblocks:%d)", f.Name, f.Version, f.Modified, f.Flags, len(f.Blocks)) - for _, b := range f.Blocks { - log.Printf(" %6d %x", b.Size, b.Hash) - } - } -} - -func (m Model) Index(nodeID protocol.NodeID, repo string, files []protocol.FileInfo) { - log.Printf("Received index for repo %q", repo) - if cmd == "idx" { - prtIndex(files) - if get != "" { - for _, f := range files { - if f.Name == get { - go getFile(f) - break - } - } - } else if exit { - os.Exit(0) - } - } -} - -func getFile(f protocol.FileInfo) { - fn := filepath.Base(f.Name) - fd, err := os.Create(fn) - if err != nil { - log.Fatal(err) - } - - var offset int64 - for _, b := range f.Blocks { - log.Printf("Request %q %d - %d", f.Name, offset, offset+int64(b.Size)) - bs, err := pc.Request("default", f.Name, offset, int(b.Size)) - log.Printf(" - got %d bytes", len(bs)) - if err != nil { - log.Fatal(err) - } - offset += int64(b.Size) - fd.Write(bs) - } - - fd.Close() -} - -func (m Model) IndexUpdate(nodeID protocol.NodeID, repo string, files []protocol.FileInfo) { - log.Printf("Received index update for repo %q", repo) - if cmd == "idx" { - prtIndex(files) - if exit { - os.Exit(0) - } - } -} - -func (m Model) ClusterConfig(nodeID protocol.NodeID, config protocol.ClusterConfigMessage) { - log.Println("Received cluster config") - log.Printf("%#v", config) -} - -func (m Model) Request(nodeID protocol.NodeID, repo string, name string, offset int64, size int) ([]byte, error) { - log.Println("Received request") - return nil, io.EOF -} - -func (m Model) Close(nodeID protocol.NodeID, err error) { - log.Println("Received close") -} diff --git a/cmd/stcli/tls.go b/cmd/stcli/tls.go deleted file mode 100644 index 2be011238e..0000000000 --- a/cmd/stcli/tls.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved. -// Use of this source code is governed by an MIT-style license that can be -// found in the LICENSE file. - -package main - -import ( - "crypto/tls" - "path/filepath" -) - -func loadCert(dir string) (tls.Certificate, error) { - cf := filepath.Join(dir, "cert.pem") - kf := filepath.Join(dir, "key.pem") - return tls.LoadX509KeyPair(cf, kf) -} diff --git a/cmd/stpidx/main.go b/cmd/stpidx/main.go deleted file mode 100644 index fd75ecface..0000000000 --- a/cmd/stpidx/main.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved. -// Use of this source code is governed by an MIT-style license that can be -// found in the LICENSE file. - -package main - -import ( - "compress/gzip" - "flag" - "log" - "os" - - "github.com/calmh/syncthing/protocol" -) - -func main() { - log.SetFlags(0) - log.SetOutput(os.Stdout) - - showBlocks := flag.Bool("b", false, "Show blocks") - flag.Parse() - name := flag.Arg(0) - - idxf, err := os.Open(name) - if err != nil { - log.Fatal(err) - } - defer idxf.Close() - - gzr, err := gzip.NewReader(idxf) - if err != nil { - log.Fatal(err) - } - defer gzr.Close() - - var im protocol.IndexMessage - err = im.DecodeXDR(gzr) - if err != nil { - log.Fatal(err) - } - - log.Printf("Repo: %q, Files: %d", im.Repository, len(im.Files)) - for _, file := range im.Files { - del := file.Flags&protocol.FlagDeleted != 0 - inv := file.Flags&protocol.FlagInvalid != 0 - dir := file.Flags&protocol.FlagDirectory != 0 - prm := file.Flags & 0777 - log.Printf("File: %q, Ver:%d, Del: %v, Inv: %v, Dir: %v, Perm: 0%03o, Modified: %d, Blocks: %d", - file.Name, file.Version, del, inv, dir, prm, file.Modified, len(file.Blocks)) - if *showBlocks { - for _, block := range file.Blocks { - log.Printf(" Size: %6d, Hash: %x", block.Size, block.Hash) - } - } - } -} |