examples: remove rarely used code

Currently the examples are rarely used and either should belong to a
different repository, be part of documentation or deleted entirely.

Change-Id: I125a0860f9a1d475d384882c0e7edf64ee0f371f
This commit is contained in:
Egon Elbre 2020-10-14 13:28:09 +03:00
parent 2f4bb114d4
commit c54dd45755
6 changed files with 0 additions and 421 deletions

View File

@ -1,96 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"crypto/sha256"
"flag"
"fmt"
"net/http"
"os"
"time"
"github.com/vivint/infectious"
"go.uber.org/zap"
"storj.io/common/encryption"
"storj.io/common/ranger"
"storj.io/common/ranger/httpranger"
"storj.io/common/storj"
"storj.io/uplink/private/eestream"
)
var (
addr = flag.String("addr", "localhost:8080", "address to serve from")
erasureShareSize = flag.Int("erasure_share_size", 4*1024, "block size of pieces")
key = flag.String("key", "a key", "the secret key")
rsk = flag.Int("required", 20, "rs required")
rsn = flag.Int("total", 40, "rs total")
)
func main() {
err := Main()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
// Main is the exported CLI executable function.
func Main() error {
ctx := context.Background()
encKey := storj.Key(sha256.Sum256([]byte(*key)))
fc, err := infectious.NewFEC(*rsk, *rsn)
if err != nil {
return err
}
es := eestream.NewRSScheme(fc, *erasureShareSize)
var firstNonce storj.Nonce
decrypter, err := encryption.NewDecrypter(storj.EncAESGCM, &encKey, &firstNonce, es.StripeSize())
if err != nil {
return err
}
// initialize http rangers in parallel to save from network latency
rrs := map[int]ranger.Ranger{}
type indexRangerError struct {
i int
rr ranger.Ranger
err error
}
result := make(chan indexRangerError, *rsn)
for i := 0; i < *rsn; i++ {
go func(i int) {
url := fmt.Sprintf("http://18.184.133.99:%d", 10000+i)
rr, err := httpranger.HTTPRanger(ctx, url)
result <- indexRangerError{i: i, rr: rr, err: err}
}(i)
}
// wait for all goroutines to finish and save result in rrs map
for i := 0; i < *rsn; i++ {
res := <-result
if res.err != nil {
// return on the first failure
return err
}
rrs[res.i] = res.rr
}
rc, err := eestream.Decode(zap.L(), rrs, es, 4*1024*1024, false)
if err != nil {
return err
}
rr, err := encryption.Transform(rc, decrypter)
if err != nil {
return err
}
rr, err = encryption.UnpadSlow(ctx, rr)
if err != nil {
return err
}
return http.ListenAndServe(*addr, http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
httpranger.ServeContent(ctx, w, r, flag.Arg(0), time.Time{}, rr)
}))
}

View File

@ -1,52 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
)
func main() {
flag.Parse()
if flag.Arg(0) == "" {
fmt.Printf("usage: %s <targetdir>\n", os.Args[0])
os.Exit(1)
}
err := Main()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
// Main is the exported CLI executable function.
func Main() error {
pieces, err := ioutil.ReadDir(flag.Arg(0))
if err != nil {
return err
}
for _, piece := range pieces {
pieceNum, err := strconv.Atoi(strings.TrimSuffix(piece.Name(), ".piece"))
if err != nil {
return err
}
pieceAddr := "localhost:" + strconv.Itoa(10000+pieceNum)
piecePath := filepath.Join(flag.Arg(0), piece.Name())
go fmt.Println(
http.ListenAndServe(pieceAddr, http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, piecePath)
})))
}
select {} // sleep forever
}

View File

@ -1,97 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"crypto/sha256"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/vivint/infectious"
"go.uber.org/zap"
"storj.io/common/encryption"
"storj.io/common/ranger"
"storj.io/common/ranger/httpranger"
"storj.io/common/storj"
"storj.io/uplink/private/eestream"
)
var (
addr = flag.String("addr", "localhost:8080", "address to serve from")
erasureShareSize = flag.Int("erasure_share_size", 4*1024, "block size of pieces")
key = flag.String("key", "a key", "the secret key")
rsk = flag.Int("required", 20, "rs required")
rsn = flag.Int("total", 40, "rs total")
)
func main() {
flag.Parse()
if flag.Arg(0) == "" {
fmt.Printf("usage: %s <targetdir>\n", os.Args[0])
os.Exit(1)
}
err := Main()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
// Main is the exported CLI executable function.
func Main() error {
encKey := storj.Key(sha256.Sum256([]byte(*key)))
fc, err := infectious.NewFEC(*rsk, *rsn)
if err != nil {
return err
}
es := eestream.NewRSScheme(fc, *erasureShareSize)
var firstNonce storj.Nonce
decrypter, err := encryption.NewDecrypter(storj.EncAESGCM, &encKey, &firstNonce, es.StripeSize())
if err != nil {
return err
}
pieces, err := ioutil.ReadDir(flag.Arg(0))
if err != nil {
return err
}
rrs := map[int]ranger.Ranger{}
for _, piece := range pieces {
piecenum, err := strconv.Atoi(strings.TrimSuffix(piece.Name(), ".piece"))
if err != nil {
return err
}
r, err := ranger.FileRanger(filepath.Join(flag.Arg(0), piece.Name()))
if err != nil {
return err
}
rrs[piecenum] = r
}
rc, err := eestream.Decode(zap.L(), rrs, es, 4*1024*1024, false)
if err != nil {
return err
}
rr, err := encryption.Transform(rc, decrypter)
if err != nil {
return err
}
ctx := context.Background()
rr, err = encryption.UnpadSlow(ctx, rr)
if err != nil {
return err
}
return http.ListenAndServe(*addr, http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
httpranger.ServeContent(ctx, w, r, flag.Arg(0), time.Time{}, rr)
}))
}

View File

@ -1,101 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"crypto/sha256"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"github.com/vivint/infectious"
"go.uber.org/zap"
"storj.io/common/encryption"
"storj.io/common/storj"
"storj.io/uplink/private/eestream"
)
var (
erasureShareSize = flag.Int("erasure_share_size", 4*1024, "block size of pieces")
key = flag.String("key", "a key", "the secret key")
rsk = flag.Int("required", 20, "rs required")
rsn = flag.Int("total", 40, "rs total")
)
func main() {
flag.Parse()
if flag.Arg(0) == "" {
fmt.Printf("usage: cat data | %s <targetdir>\n", os.Args[0])
os.Exit(1)
}
err := Main()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
// Main is the exported CLI executable function.
func Main() error {
err := os.MkdirAll(flag.Arg(0), 0755)
if err != nil {
return err
}
fc, err := infectious.NewFEC(*rsk, *rsn)
if err != nil {
return err
}
es := eestream.NewRSScheme(fc, *erasureShareSize)
rs, err := eestream.NewRedundancyStrategy(es, 0, 0)
if err != nil {
return err
}
encKey := storj.Key(sha256.Sum256([]byte(*key)))
var firstNonce storj.Nonce
encrypter, err := encryption.NewEncrypter(storj.EncAESGCM, &encKey, &firstNonce, es.StripeSize())
if err != nil {
return err
}
readers, err := eestream.EncodeReader(context.Background(), zap.L(),
encryption.TransformReader(encryption.PadReader(os.Stdin,
encrypter.InBlockSize()), encrypter, 0), rs)
if err != nil {
return err
}
errs := make(chan error, len(readers))
for i := range readers {
go func(i int) {
pieceFile := filepath.Join(flag.Arg(0), fmt.Sprintf("%d.piece", i))
fh, err := os.Create(pieceFile)
if err != nil {
errs <- err
return
}
defer printError(fh.Close)
defer printError(readers[i].Close)
_, err = io.Copy(fh, readers[i])
errs <- err
}(i)
}
for range readers {
err := <-errs
if err != nil {
return err
}
}
return nil
}
func printError(fn func() error) {
err := fn()
if err != nil {
fmt.Println(err)
}
}

View File

@ -1,49 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"flag"
"fmt"
"github.com/spf13/cobra"
"storj.io/common/telemetry"
"storj.io/private/process"
)
var (
addr = flag.String("addr", ":9000", "address to listen for metrics on")
)
func main() {
process.Exec(&cobra.Command{
Use: "metric-receiver",
Short: "receive metrics",
RunE: run,
})
}
func run(cmd *cobra.Command, args []string) (err error) {
ctx, _ := process.Ctx(cmd)
s, err := telemetry.Listen(*addr)
if err != nil {
return err
}
defer printError(s.Close)
fmt.Printf("listening on %s\n", s.Addr())
return s.Serve(ctx, telemetry.HandlerFunc(handle))
}
func handle(application, instance string, key []byte, val float64) {
fmt.Printf("%s %s %s %v\n", application, instance, string(key), val)
}
func printError(fn func() error) {
err := fn()
if err != nil {
fmt.Println(err)
}
}

View File

@ -1,26 +0,0 @@
# This is a SystemD unit file for the Storage Node
# To configure:
# - Update the user and group that the service will run as (User & Group below)
# - Ensure that the Storage Node binary is in /usr/local/bin and is named storagenode (or edit the ExecStart line
# below to reflect the name and location of your binary
# - Ensure that you've run setup and have edited the configuration appropriately prior to starting the
# service with this script
# To use:
# - Place this file in /etc/systemd/system/ or wherever your SystemD unit files are stored
# - Run systemctl daemon-reload
# - To start run systemctl start storagenode
[Unit]
Description = Storage Node service
After = syslog.target
[Service]
User = storj
Group = storj
ExecStart = /usr/local/bin/storagenode run
Restart = always
Type = simple
NotifyAccess = main
[Install]
WantedBy = multi-user.target