@cryptotaxi247 / kubo / commits / 8d05fa47e

cmd: remove dead ipfs_routingd and ipfs_bootstrapd

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Jun 15, 2015 at 22:16 UTC 8d05fa47e8f5a1eef05ef2b2c4b8ffe8172c82fe
2 files changed -317
cmd/ipfs_bootstrapd/main.go deleted
-167
@@ -1,167 +0,0 @@
1 -package main
2 -
3 -import (
4 - "bufio"
5 - "errors"
6 - "flag"
7 - "log"
8 - "os"
9 - "time"
10 -
11 - context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
12 - core "github.com/ipfs/go-ipfs/core"
13 - corehttp "github.com/ipfs/go-ipfs/core/corehttp"
14 - corerepo "github.com/ipfs/go-ipfs/core/corerepo"
15 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
16 - config "github.com/ipfs/go-ipfs/repo/config"
17 - fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18 -)
19 -
20 -var (
21 - blocklistFilepath = flag.String("blocklist", "", "keys that should not be served by the gateway")
22 - writable = flag.Bool("writable", false, "enable writing objects (with POST, PUT and DELETE)")
23 - refreshBlockListInterval = flag.Duration("refresh-blocklist-interval", 30*time.Second, "refresh blocklist")
24 - refreshAssetsInterval = flag.Duration("refresh-assets-interval", 30*time.Second, "refresh assets")
25 - garbageCollectInterval = flag.Duration("gc-interval", 24*time.Hour, "frequency of repo garbage collection")
26 - assetsPath = flag.String("assets-path", "", "if provided, periodically adds contents of path to IPFS")
27 - host = flag.String("host", "/ip4/0.0.0.0/tcp/8080", "override the HTTP host listening address")
28 - performGC = flag.Bool("gc", false, "perform garbage collection")
29 - nBitsForKeypair = flag.Int("b", 1024, "number of bits for keypair (if repo is uninitialized)")
30 -)
31 -
32 -func main() {
33 - flag.Parse()
34 - if *assetsPath == "" {
35 - log.Println("asset-path not provided. hosting gateway without file server functionality...")
36 - }
37 - if err := run(); err != nil {
38 - log.Println(err)
39 - }
40 -}
41 -
42 -func run() error {
43 - ctx, cancel := context.WithCancel(context.Background())
44 - defer cancel()
45 - repoPath, err := fsrepo.BestKnownPath()
46 - if err != nil {
47 - return err
48 - }
49 -
50 - if !fsrepo.IsInitialized(repoPath) {
51 - conf, err := config.Init(os.Stdout, *nBitsForKeypair)
52 - if err != nil {
53 - return err
54 - }
55 - if err := fsrepo.Init(repoPath, conf); err != nil {
56 - return err
57 - }
58 - }
59 -
60 - repo, err := fsrepo.Open(repoPath)
61 - if err != nil { // owned by node
62 - return err
63 - }
64 -
65 - node, err := core.NewIPFSNode(ctx, core.Online(repo))
66 - if err != nil {
67 - return err
68 - }
69 - defer node.Close()
70 -
71 - if *performGC {
72 - if err := runGarbageCollectorWorker(ctx, node); err != nil {
73 - return err
74 - }
75 - }
76 -
77 - if *assetsPath != "" {
78 - if err := runFileServerWorker(ctx, node); err != nil {
79 - return err
80 - }
81 - }
82 -
83 - blocklist := &corehttp.BlockList{}
84 - gateway := corehttp.NewGateway(corehttp.GatewayConfig{
85 - Writable: *writable,
86 - BlockList: blocklist,
87 - })
88 -
89 - if err := runBlockListWorker(blocklist, *blocklistFilepath); err != nil {
90 - return err
91 - }
92 -
93 - opts := []corehttp.ServeOption{
94 - corehttp.VersionOption(),
95 - corehttp.IPNSHostnameOption(),
96 - gateway.ServeOption(),
97 - }
98 - return corehttp.ListenAndServe(node, *host, opts...)
99 -}
100 -
101 -func runGarbageCollectorWorker(ctx context.Context, node *core.IpfsNode) error {
102 - go func() {
103 - for _ = range time.Tick(*garbageCollectInterval) {
104 - if err := corerepo.GarbageCollect(node, ctx); err != nil {
105 - log.Println("failed to run garbage collection", err)
106 - }
107 - }
108 - }()
109 - return nil
110 -}
111 -
112 -func runFileServerWorker(ctx context.Context, node *core.IpfsNode) error {
113 - fi, err := os.Stat(*assetsPath)
114 - if err != nil {
115 - return err
116 - }
117 - if !fi.IsDir() {
118 - return errors.New("asset path must be a directory")
119 - }
120 - go func() {
121 - for _ = range time.Tick(*refreshAssetsInterval) {
122 - _, err := coreunix.AddR(node, *assetsPath)
123 - if err != nil {
124 - log.Println(err)
125 - }
126 - }
127 - }()
128 - return nil
129 -}
130 -
131 -func runBlockListWorker(blocklist *corehttp.BlockList, filepath string) error {
132 - if filepath == "" {
133 - return nil
134 - }
135 - go func() {
136 - for _ = range time.Tick(*refreshBlockListInterval) {
137 - log.Println("updating the blocklist...")
138 - func() { // in a func to allow defer f.Close()
139 - f, err := os.Open(filepath)
140 - if err != nil {
141 - log.Println(err)
142 - }
143 - defer f.Close()
144 - scanner := bufio.NewScanner(f)
145 - blocked := make(map[string]struct{}) // Implement using Bloom Filter hybrid if blocklist gets large
146 - for scanner.Scan() {
147 - t := scanner.Text()
148 - blocked[t] = struct{}{}
149 - }
150 -
151 - // If an error occurred, do not change the existing decider. This
152 - // is to avoid accidentally clearing the list if the deploy is
153 - // botched.
154 - if err := scanner.Err(); err != nil {
155 - log.Println(err)
156 - } else {
157 - blocklist.SetDecider(func(s string) bool {
158 - _, ok := blocked[s]
159 - return !ok
160 - })
161 - log.Printf("updated the blocklist (%d entries)", len(blocked))
162 - }
163 - }()
164 - }
165 - }()
166 - return nil
167 -}
cmd/ipfs_routingd/main.go deleted
-150
@@ -1,150 +0,0 @@
1 -package main
2 -
3 -import (
4 - "errors"
5 - "flag"
6 - "fmt"
7 - "log"
8 - "os"
9 - "os/signal"
10 - "time"
11 -
12 - aws "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/aws"
13 - s3 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
14 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/fzzy/radix/redis"
15 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
16 - context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
17 - core "github.com/ipfs/go-ipfs/core"
18 - corerouting "github.com/ipfs/go-ipfs/core/corerouting"
19 - config "github.com/ipfs/go-ipfs/repo/config"
20 - fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
21 - redisds "github.com/ipfs/go-ipfs/thirdparty/redis-datastore"
22 - s3datastore "github.com/ipfs/go-ipfs/thirdparty/s3-datastore"
23 - ds2 "github.com/ipfs/go-ipfs/util/datastore2"
24 -)
25 -
26 -var (
27 - ttl = flag.Duration("ttl", 12*time.Hour, "period after which routing keys expire")
28 - redisHost = flag.String("redis-host", "localhost:6379", "redis tcp host address:port")
29 - redisPassword = flag.String("redis-pass", "", "redis password if required")
30 - datastoreOption = flag.String("datastore", "redis", "routing datastore (also available: aws)")
31 - s3bucket = flag.String("aws-bucket", "", "S3 bucket for aws routing datastore")
32 - s3region = flag.String("aws-region", aws.USWest2.Name, "S3 region")
33 - nBitsForKeypair = flag.Int("b", 1024, "number of bits for keypair (if repo is uninitialized)")
34 -)
35 -
36 -func main() {
37 - flag.Parse()
38 - if err := run(); err != nil {
39 - log.Println(err)
40 - }
41 -}
42 -
43 -func run() error {
44 - ctx, cancel := context.WithCancel(context.Background())
45 - defer cancel()
46 - repoPath, err := fsrepo.BestKnownPath()
47 - if err != nil {
48 - return err
49 - }
50 -
51 - if !fsrepo.IsInitialized(repoPath) {
52 - conf, err := config.Init(os.Stdout, *nBitsForKeypair)
53 - if err != nil {
54 - return err
55 - }
56 - if err := fsrepo.Init(repoPath, conf); err != nil {
57 - return err
58 - }
59 - }
60 - repo, err := fsrepo.Open(repoPath)
61 - if err != nil { // owned by node
62 - return err
63 - }
64 -
65 - var ds datastore.ThreadSafeDatastore
66 - switch *datastoreOption {
67 - case "redis":
68 - redisClient, err := redis.Dial("tcp", *redisHost)
69 - if err != nil {
70 - return fmt.Errorf("could not connect to redis: %s", err)
71 - }
72 - if *redisPassword != "" {
73 - if err := redisClient.Cmd("AUTH", *redisPassword).Err; err != nil {
74 - return err
75 - }
76 - }
77 - redisds, err := redisds.NewExpiringDatastore(redisClient, *ttl)
78 - if err != nil {
79 - return err
80 - }
81 - ds = redisds
82 - case "aws":
83 - s3raw, err := makeS3Datastore()
84 - if err != nil {
85 - return err
86 - }
87 - s3, err := enhanceDatastore(s3raw)
88 - if err != nil {
89 - return err
90 - }
91 - ds = s3
92 - default:
93 - return errors.New("unsupported datastore type")
94 - }
95 - node, err := core.NewIPFSNode(ctx,
96 - core.OnlineWithOptions(
97 - repo,
98 - corerouting.SupernodeServer(ds),
99 - core.DefaultHostOption),
100 - )
101 - if err != nil {
102 - return err
103 - }
104 - defer node.Close()
105 -
106 - interrupt := make(chan os.Signal)
107 - signal.Notify(interrupt, os.Kill, os.Interrupt)
108 - <-interrupt
109 - return nil
110 -}
111 -
112 -func makeS3Datastore() (*s3datastore.S3Datastore, error) {
113 -
114 - // FIXME get ENV through flags?
115 -
116 - auth, err := aws.EnvAuth()
117 - if err != nil {
118 - return nil, err
119 - }
120 -
121 - s3c := s3.New(auth, aws.Regions[*s3region])
122 - b := s3c.Bucket(*s3bucket)
123 - exists, err := b.Exists("initialized") // TODO lazily instantiate
124 - if err != nil {
125 - return nil, err
126 - }
127 -
128 - if !exists {
129 - if err := b.PutBucket(s3.PublicRead); err != nil {
130 - switch e := err.(type) {
131 - case *s3.Error:
132 - log.Println(e.Code)
133 - default:
134 - return nil, err
135 - }
136 - }
137 -
138 - // TODO create the initial value
139 - }
140 -
141 - return &s3datastore.S3Datastore{
142 - Bucket: *s3bucket,
143 - Client: s3c,
144 - }, nil
145 -}
146 -
147 -func enhanceDatastore(d datastore.ThreadSafeDatastore) (datastore.ThreadSafeDatastore, error) {
148 - // TODO cache
149 - return ds2.CloserWrap(d), nil
150 -}