mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 02:48:59 +00:00
Remove reprecated st* utils
This commit is contained in:
parent
b57f4ed97e
commit
071f4c0769
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,12 +1,9 @@
|
||||
syncthing
|
||||
syncthing.exe
|
||||
stcli
|
||||
stcli.exe
|
||||
*.tar.gz
|
||||
*.zip
|
||||
*.asc
|
||||
*.sublime*
|
||||
discosrv
|
||||
stpidx
|
||||
.jshintrc
|
||||
coverage.out
|
||||
|
2
build.sh
2
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%-*}
|
||||
|
1
cmd/.gitignore
vendored
1
cmd/.gitignore
vendored
@ -1,2 +1 @@
|
||||
!syncthing
|
||||
!stcli
|
||||
|
@ -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")
|
||||
}
|
@ -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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user