From 071f4c0769e724b7bb3f54b3739ec3b283d217ef Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 1 Jul 2014 12:20:25 +0200 Subject: [PATCH] Remove reprecated st* utils --- .gitignore | 3 - build.sh | 2 - cmd/.gitignore | 1 - cmd/stcli/main.go | 146 --------------------------------------------- cmd/stcli/tls.go | 16 ----- cmd/stpidx/main.go | 56 ----------------- 6 files changed, 224 deletions(-) delete mode 100644 cmd/stcli/main.go delete mode 100644 cmd/stcli/tls.go delete mode 100644 cmd/stpidx/main.go diff --git a/.gitignore b/.gitignore index cfb24fbbf..aa33a09c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ syncthing syncthing.exe -stcli -stcli.exe *.tar.gz *.zip *.asc *.sublime* discosrv -stpidx .jshintrc coverage.out diff --git a/build.sh b/build.sh index 341858abc..a073c30b5 100755 --- a/build.sh +++ b/build.sh @@ -139,8 +139,6 @@ case "$1" in assets godep go build ./discover/cmd/discosrv - godep go build ./cmd/stpidx - godep go build ./cmd/stcli for os in darwin-amd64 linux-386 linux-amd64 freebsd-amd64 windows-amd64 windows-386 solaris-amd64 ; do export GOOS=${os%-*} diff --git a/cmd/.gitignore b/cmd/.gitignore index f80161a20..3e1db14fd 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 ee6d19bc3..000000000 --- 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 2be011238..000000000 --- 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 fd75ecfac..000000000 --- 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) - } - } - } -}