@cryptotaxi247 / kubo / commits / 857fce168

Replace existing iptb dependencies with the gx one

Now that iptb has been added as a gx dependency, we can replace existing dependencies with the one from gx. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Apr 11, 2016 at 10:56 UTC 857fce168a679c5c2a51e6a00b8260f9ccefe6b7
6 files changed +1 -910
Godeps/_workspace/src/github.com/whyrusleeping/iptb/util/proc_unix.go deleted
-13
@@ -1,13 +0,0 @@
1 -// +build !windows
2 -package iptbutil
3 -
4 -import (
5 - "os/exec"
6 - "syscall"
7 -)
8 -
9 -func init() {
10 - setupOpt = func(cmd *exec.Cmd) {
11 - cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
12 - }
13 -}
Godeps/_workspace/src/github.com/whyrusleeping/iptb/util/util.go deleted
-542
@@ -1,542 +0,0 @@
1 -package iptbutil
2 -
3 -import (
4 - "encoding/json"
5 - "errors"
6 - "fmt"
7 - "io/ioutil"
8 - "log"
9 - "net/http"
10 - "os"
11 - "os/exec"
12 - "path"
13 - "strconv"
14 - "strings"
15 - "sync"
16 - "syscall"
17 - "time"
18 -
19 - serial "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
20 -
21 - manet "gx/ipfs/QmTrxSBY8Wqd5aBB4MeizeSzS5xFbK8dQBrYaMsiGnCBhb/go-multiaddr-net"
22 - ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr"
23 -)
24 -
25 -var setupOpt = func(cmd *exec.Cmd) {}
26 -
27 -// GetNumNodes returns the number of testbed nodes configured in the testbed directory
28 -func GetNumNodes() int {
29 - for i := 0; i < 2000; i++ {
30 - _, err := os.Stat(IpfsDirN(i))
31 - if os.IsNotExist(err) {
32 - return i
33 - }
34 - }
35 - panic("i dont know whats going on")
36 -}
37 -
38 -func TestBedDir() string {
39 - tbd := os.Getenv("IPTB_ROOT")
40 - if len(tbd) != 0 {
41 - return tbd
42 - }
43 -
44 - home := os.Getenv("HOME")
45 - if len(home) == 0 {
46 - panic("could not find home")
47 - }
48 -
49 - return path.Join(home, "testbed")
50 -}
51 -
52 -func IpfsDirN(n int) string {
53 - return path.Join(TestBedDir(), fmt.Sprint(n))
54 -}
55 -
56 -type InitCfg struct {
57 - Count int
58 - Force bool
59 - Bootstrap string
60 - PortStart int
61 - Mdns bool
62 - Utp bool
63 - Override string
64 -}
65 -
66 -func (c *InitCfg) swarmAddrForPeer(i int) string {
67 - str := "/ip4/0.0.0.0/tcp/%d"
68 - if c.Utp {
69 - str = "/ip4/0.0.0.0/udp/%d/utp"
70 - }
71 -
72 - if c.PortStart == 0 {
73 - return fmt.Sprintf(str, 0)
74 - }
75 - return fmt.Sprintf(str, c.PortStart+i)
76 -}
77 -
78 -func (c *InitCfg) apiAddrForPeer(i int) string {
79 - if c.PortStart == 0 {
80 - return "/ip4/127.0.0.1/tcp/0"
81 - }
82 - return fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", c.PortStart+1000+i)
83 -}
84 -
85 -func YesNoPrompt(prompt string) bool {
86 - var s string
87 - for {
88 - fmt.Println(prompt)
89 - fmt.Scanf("%s", &s)
90 - switch s {
91 - case "y", "Y":
92 - return true
93 - case "n", "N":
94 - return false
95 - }
96 - fmt.Println("Please press either 'y' or 'n'")
97 - }
98 -}
99 -
100 -func IpfsInit(cfg *InitCfg) error {
101 - p := IpfsDirN(0)
102 - if _, err := os.Stat(p); !os.IsNotExist(err) {
103 - if !cfg.Force && !YesNoPrompt("testbed nodes already exist, overwrite? [y/n]") {
104 - return nil
105 - }
106 - err := os.RemoveAll(TestBedDir())
107 - if err != nil {
108 - return err
109 - }
110 - }
111 - wait := sync.WaitGroup{}
112 - for i := 0; i < cfg.Count; i++ {
113 - wait.Add(1)
114 - go func(v int) {
115 - defer wait.Done()
116 - dir := IpfsDirN(v)
117 - err := os.MkdirAll(dir, 0777)
118 - if err != nil {
119 - log.Println("ERROR: ", err)
120 - return
121 - }
122 -
123 - cmd := exec.Command("ipfs", "init", "-b=1024")
124 - cmd.Env = append(cmd.Env, "IPFS_PATH="+dir)
125 - out, err := cmd.CombinedOutput()
126 - if err != nil {
127 - log.Println("ERROR: ", err)
128 - log.Println(string(out))
129 - }
130 - }(i)
131 - }
132 - wait.Wait()
133 -
134 - // Now setup bootstrapping
135 - switch cfg.Bootstrap {
136 - case "star":
137 - err := starBootstrap(cfg)
138 - if err != nil {
139 - return err
140 - }
141 - case "none":
142 - err := clearBootstrapping(cfg)
143 - if err != nil {
144 - return err
145 - }
146 - default:
147 - return fmt.Errorf("unrecognized bootstrapping option: %s", cfg.Bootstrap)
148 - }
149 -
150 - /*
151 - if cfg.Override != "" {
152 - err := ApplyConfigOverride(cfg)
153 - if err != nil {
154 - return err
155 - }
156 - }
157 - */
158 -
159 - return nil
160 -}
161 -
162 -func ApplyConfigOverride(cfg *InitCfg) error {
163 - fir, err := os.Open(cfg.Override)
164 - if err != nil {
165 - return err
166 - }
167 - defer fir.Close()
168 -
169 - var configs map[string]interface{}
170 - err = json.NewDecoder(fir).Decode(&configs)
171 - if err != nil {
172 - return err
173 - }
174 -
175 - for i := 0; i < cfg.Count; i++ {
176 - err := applyOverrideToNode(configs, i)
177 - if err != nil {
178 - return err
179 - }
180 - }
181 -
182 - return nil
183 -}
184 -
185 -func applyOverrideToNode(ovr map[string]interface{}, node int) error {
186 - for k, v := range ovr {
187 - _ = k
188 - switch v.(type) {
189 - case map[string]interface{}:
190 - default:
191 - }
192 -
193 - }
194 -
195 - panic("not implemented")
196 -}
197 -
198 -func starBootstrap(icfg *InitCfg) error {
199 - // '0' node is the bootstrap node
200 - cfgpath := path.Join(IpfsDirN(0), "config")
201 - bcfg, err := serial.Load(cfgpath)
202 - if err != nil {
203 - return err
204 - }
205 - bcfg.Bootstrap = nil
206 - bcfg.Addresses.Swarm = []string{icfg.swarmAddrForPeer(0)}
207 - bcfg.Addresses.API = icfg.apiAddrForPeer(0)
208 - bcfg.Addresses.Gateway = ""
209 - bcfg.Discovery.MDNS.Enabled = icfg.Mdns
210 - err = serial.WriteConfigFile(cfgpath, bcfg)
211 - if err != nil {
212 - return err
213 - }
214 -
215 - for i := 1; i < icfg.Count; i++ {
216 - cfgpath := path.Join(IpfsDirN(i), "config")
217 - cfg, err := serial.Load(cfgpath)
218 - if err != nil {
219 - return err
220 - }
221 -
222 - ba := fmt.Sprintf("%s/ipfs/%s", bcfg.Addresses.Swarm[0], bcfg.Identity.PeerID)
223 - ba = strings.Replace(ba, "0.0.0.0", "127.0.0.1", -1)
224 - cfg.Bootstrap = []string{ba}
225 - cfg.Addresses.Gateway = ""
226 - cfg.Discovery.MDNS.Enabled = icfg.Mdns
227 - cfg.Addresses.Swarm = []string{
228 - icfg.swarmAddrForPeer(i),
229 - }
230 - cfg.Addresses.API = icfg.apiAddrForPeer(i)
231 - err = serial.WriteConfigFile(cfgpath, cfg)
232 - if err != nil {
233 - return err
234 - }
235 - }
236 - return nil
237 -}
238 -
239 -func clearBootstrapping(icfg *InitCfg) error {
240 - for i := 0; i < icfg.Count; i++ {
241 - cfgpath := path.Join(IpfsDirN(i), "config")
242 - cfg, err := serial.Load(cfgpath)
243 - if err != nil {
244 - return err
245 - }
246 -
247 - cfg.Bootstrap = nil
248 - cfg.Addresses.Gateway = ""
249 - cfg.Addresses.Swarm = []string{icfg.swarmAddrForPeer(i)}
250 - cfg.Addresses.API = icfg.apiAddrForPeer(i)
251 - cfg.Discovery.MDNS.Enabled = icfg.Mdns
252 - err = serial.WriteConfigFile(cfgpath, cfg)
253 - if err != nil {
254 - return err
255 - }
256 - }
257 - return nil
258 -}
259 -
260 -func IpfsPidOf(n int) (int, error) {
261 - dir := IpfsDirN(n)
262 - b, err := ioutil.ReadFile(path.Join(dir, "daemon.pid"))
263 - if err != nil {
264 - return -1, err
265 - }
266 -
267 - return strconv.Atoi(string(b))
268 -}
269 -
270 -func KillNode(i int) error {
271 - pid, err := IpfsPidOf(i)
272 - if err != nil {
273 - return fmt.Errorf("error killing daemon %d: %s", i, err)
274 - }
275 -
276 - p, err := os.FindProcess(pid)
277 - if err != nil {
278 - return fmt.Errorf("error killing daemon %d: %s", i, err)
279 - }
280 - err = p.Kill()
281 - if err != nil {
282 - return fmt.Errorf("error killing daemon %d: %s\n", i, err)
283 - }
284 -
285 - p.Wait()
286 -
287 - err = os.Remove(path.Join(IpfsDirN(i), "daemon.pid"))
288 - if err != nil {
289 - return fmt.Errorf("error removing pid file for daemon %d: %s\n", i, err)
290 - }
291 -
292 - return nil
293 -}
294 -
295 -func IpfsKillAll() error {
296 - n := GetNumNodes()
297 - for i := 0; i < n; i++ {
298 - err := KillNode(i)
299 - if err != nil {
300 - return err
301 - }
302 - }
303 - return nil
304 -}
305 -
306 -func envForDaemon(n int) []string {
307 - envs := os.Environ()
308 - npath := "IPFS_PATH=" + IpfsDirN(n)
309 - for i, e := range envs {
310 - p := strings.Split(e, "=")
311 - if p[0] == "IPFS_PATH" {
312 - envs[i] = npath
313 - return envs
314 - }
315 - }
316 -
317 - return append(envs, npath)
318 -}
319 -
320 -func IpfsStart(waitall bool) error {
321 - var addrs []string
322 - n := GetNumNodes()
323 - for i := 0; i < n; i++ {
324 - dir := IpfsDirN(i)
325 - cmd := exec.Command("ipfs", "daemon")
326 - cmd.Dir = dir
327 - cmd.Env = envForDaemon(i)
328 -
329 - setupOpt(cmd)
330 -
331 - stdout, err := os.Create(path.Join(dir, "daemon.stdout"))
332 - if err != nil {
333 - return err
334 - }
335 -
336 - stderr, err := os.Create(path.Join(dir, "daemon.stderr"))
337 - if err != nil {
338 - return err
339 - }
340 -
341 - cmd.Stdout = stdout
342 - cmd.Stderr = stderr
343 -
344 - err = cmd.Start()
345 - if err != nil {
346 - return err
347 - }
348 - pid := cmd.Process.Pid
349 -
350 - fmt.Printf("Started daemon %d, pid = %d\n", i, pid)
351 - err = ioutil.WriteFile(path.Join(dir, "daemon.pid"), []byte(fmt.Sprint(pid)), 0666)
352 - if err != nil {
353 - return err
354 - }
355 -
356 - // Make sure node 0 is up before starting the rest so
357 - // bootstrapping works properly
358 - cfg, err := serial.Load(path.Join(IpfsDirN(i), "config"))
359 - if err != nil {
360 - return err
361 - }
362 -
363 - maddr := ma.StringCast(cfg.Addresses.API)
364 - _, addr, err := manet.DialArgs(maddr)
365 - if err != nil {
366 - return err
367 - }
368 -
369 - addrs = append(addrs, addr)
370 -
371 - err = waitOnAPI(cfg.Identity.PeerID, i)
372 - if err != nil {
373 - return err
374 - }
375 - }
376 - if waitall {
377 - for i := 0; i < n; i++ {
378 - err := waitOnSwarmPeers(i)
379 - if err != nil {
380 - return err
381 - }
382 - }
383 -
384 - }
385 - return nil
386 -}
387 -
388 -func waitOnAPI(peerid string, nnum int) error {
389 - for i := 0; i < 50; i++ {
390 - err := tryAPICheck(peerid, nnum)
391 - if err == nil {
392 - return nil
393 - }
394 - time.Sleep(time.Millisecond * 200)
395 - }
396 - return fmt.Errorf("node %d failed to come online in given time period", nnum)
397 -}
398 -
399 -func GetNodesAPIAddr(nnum int) (string, error) {
400 - addrb, err := ioutil.ReadFile(path.Join(IpfsDirN(nnum), "api"))
401 - if err != nil {
402 - return "", err
403 - }
404 -
405 - maddr, err := ma.NewMultiaddr(string(addrb))
406 - if err != nil {
407 - fmt.Println("error parsing multiaddr: ", err)
408 - return "", err
409 - }
410 -
411 - _, addr, err := manet.DialArgs(maddr)
412 - if err != nil {
413 - fmt.Println("error on multiaddr dialargs: ", err)
414 - return "", err
415 - }
416 - return addr, nil
417 -}
418 -
419 -func tryAPICheck(peerid string, nnum int) error {
420 - addr, err := GetNodesAPIAddr(nnum)
421 - if err != nil {
422 - return err
423 - }
424 -
425 - resp, err := http.Get("http://" + addr + "/api/v0/id")
426 - if err != nil {
427 - return err
428 - }
429 -
430 - out := make(map[string]interface{})
431 - err = json.NewDecoder(resp.Body).Decode(&out)
432 - if err != nil {
433 - return fmt.Errorf("liveness check failed: %s", err)
434 - }
435 -
436 - id, ok := out["ID"]
437 - if !ok {
438 - return fmt.Errorf("liveness check failed: ID field not present in output")
439 - }
440 -
441 - idstr := id.(string)
442 - if idstr != peerid {
443 - return fmt.Errorf("liveness check failed: unexpected peer at endpoint")
444 - }
445 -
446 - return nil
447 -}
448 -
449 -func waitOnSwarmPeers(nnum int) error {
450 - addr, err := GetNodesAPIAddr(nnum)
451 - if err != nil {
452 - return err
453 - }
454 -
455 - for i := 0; i < 50; i++ {
456 - resp, err := http.Get("http://" + addr + "/api/v0/swarm/peers")
457 - if err == nil {
458 - out := make(map[string]interface{})
459 - err := json.NewDecoder(resp.Body).Decode(&out)
460 - if err != nil {
461 - return fmt.Errorf("liveness check failed: %s", err)
462 - }
463 -
464 - peers := out["Strings"].([]interface{})
465 - if len(peers) == 0 {
466 - time.Sleep(time.Millisecond * 200)
467 - continue
468 - }
469 -
470 - return nil
471 - }
472 - time.Sleep(time.Millisecond * 200)
473 - }
474 - return fmt.Errorf("node at %s failed to bootstrap in given time period", addr)
475 -}
476 -
477 -// GetPeerID reads the config of node 'n' and returns its peer ID
478 -func GetPeerID(n int) (string, error) {
479 - cfg, err := serial.Load(path.Join(IpfsDirN(n), "config"))
480 - if err != nil {
481 - return "", err
482 - }
483 - return cfg.Identity.PeerID, nil
484 -}
485 -
486 -// IpfsShell sets up environment variables for a new shell to more easily
487 -// control the given daemon
488 -func IpfsShell(n int) error {
489 - shell := os.Getenv("SHELL")
490 - if shell == "" {
491 - return fmt.Errorf("couldnt find shell!")
492 - }
493 -
494 - dir := IpfsDirN(n)
495 - nenvs := []string{"IPFS_PATH=" + dir}
496 -
497 - nnodes := GetNumNodes()
498 - for i := 0; i < nnodes; i++ {
499 - peerid, err := GetPeerID(i)
500 - if err != nil {
501 - return err
502 - }
503 - nenvs = append(nenvs, fmt.Sprintf("NODE%d=%s", i, peerid))
504 - }
505 - nenvs = append(os.Environ(), nenvs...)
506 -
507 - return syscall.Exec(shell, []string{shell}, nenvs)
508 -}
509 -
510 -func ConnectNodes(from, to int) error {
511 - if from == to {
512 - // skip connecting to self..
513 - return nil
514 - }
515 - fmt.Printf("connecting %d -> %d\n", from, to)
516 - cmd := exec.Command("ipfs", "id", "-f", "<addrs>")
517 - cmd.Env = []string{"IPFS_PATH=" + IpfsDirN(to)}
518 - out, err := cmd.Output()
519 - if err != nil {
520 - fmt.Println("ERR: ", string(out))
521 - return err
522 - }
523 - addr := strings.Split(string(out), "\n")[0]
524 -
525 - connectcmd := exec.Command("ipfs", "swarm", "connect", addr)
526 - connectcmd.Env = []string{"IPFS_PATH=" + IpfsDirN(from)}
527 - out, err = connectcmd.CombinedOutput()
528 - if err != nil {
529 - fmt.Println(string(out))
530 - return err
531 - }
532 - return nil
533 -}
534 -
535 -func GetAttr(attr string, node int) (string, error) {
536 - switch attr {
537 - case "id":
538 - return GetPeerID(node)
539 - default:
540 - return "", errors.New("unrecognized attribute")
541 - }
542 -}
test/Makefile
+1 -1
@@ -5,7 +5,7 @@ IPFS_CMD = ../cmd/ipfs
5 RANDOM_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random
6 RANDOM_FILES_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random-files
7 MULTIHASH_SRC = ../../../../gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash
8 -IPTB_SRC = ./dependencies/iptb
8 +IPTB_SRC = ../../../../gx/ipfs/QmccSTNEUYSJsDSHZj3uKS3pPYCRXCNxr4X8Ub1TQyKPsZ/iptb
9 POLLENDPOINT_SRC= ../thirdparty/pollEndpoint
10 GOSLEEP_SRC = ./dependencies/go-sleep
11
test/dependencies/iptb/LICENSE deleted
-21
@@ -1,21 +0,0 @@
1 -The MIT License (MIT)
2 -
3 -Copyright (c) 2015 Jeromy Johnson
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining a copy
6 -of this software and associated documentation files (the "Software"), to deal
7 -in the Software without restriction, including without limitation the rights
8 -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 -copies of the Software, and to permit persons to whom the Software is
10 -furnished to do so, subject to the following conditions:
11 -
12 -The above copyright notice and this permission notice shall be included in
13 -all copies or substantial portions of the Software.
14 -
15 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 -THE SOFTWARE.
test/dependencies/iptb/README.md deleted
-40
@@ -1,40 +0,0 @@
1 -# IPTB
2 -iptb is a program used to manage a cluster of ipfs nodes locally on your
3 -computer. It allows the creation of up to 1000 (limited by poor port choice)
4 -nodes, and allows for various other setup options to be selected such as
5 -different bootstrapping patterns. iptb makes testing networks in ipfs
6 -easy!
7 -
8 -### Commands:
9 -- init
10 - - creates and initializes 'n' repos
11 - - Options:
12 - - -n=[number of nodes]
13 - - -f : force overwriting of existing nodes
14 - - -bootstrap : select bootstrapping style for cluster choices: star, none
15 - - -mdns=[true||false] : defaults to false
16 - - -p=[start port] : port to start allocations from
17 -- start
18 - - starts up all testbed nodes
19 - - Options:
20 - - -wait : wait until daemons are fully initialized
21 -- stop
22 - - kills all testbed nodes
23 -- restart
24 - - kills and then restarts all testbed nodes
25 -
26 -- shell [n]
27 - - execs your shell with environment variables set as follows:
28 - - IPFS_PATH - set to testbed node n's IPFS_PATH
29 - - NODE[x] - set to the peer ID of node x
30 -
31 -- get [attr] [n]
32 - - gets the specified attribute from then given node
33 - - available attributes: id
34 -
35 -### Configuration
36 -By default, iptb uses `$HOME/testbed` to store created nodes. This path is
37 -configurable via the environment variables `IPTB_ROOT`.
38 -
39 -
40 -
test/dependencies/iptb/main.go deleted
-293
@@ -1,293 +0,0 @@
1 -package main
2 -
3 -import (
4 - "fmt"
5 - "io"
6 - "net/http"
7 - "os"
8 - "strconv"
9 - "strings"
10 -
11 - cli "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/codegangsta/cli"
12 - util "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/iptb/util"
13 -)
14 -
15 -func parseRange(s string) ([]int, error) {
16 - if strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]") {
17 - ranges := strings.Split(s[1:len(s)-1], ",")
18 - var out []int
19 - for _, r := range ranges {
20 - rng, err := expandDashRange(r)
21 - if err != nil {
22 - return nil, err
23 - }
24 -
25 - out = append(out, rng...)
26 - }
27 - return out, nil
28 - } else {
29 - i, err := strconv.Atoi(s)
30 - if err != nil {
31 - return nil, err
32 - }
33 -
34 - return []int{i}, nil
35 - }
36 -}
37 -
38 -func expandDashRange(s string) ([]int, error) {
39 - parts := strings.Split(s, "-")
40 - if len(parts) == 0 {
41 - i, err := strconv.Atoi(s)
42 - if err != nil {
43 - return nil, err
44 - }
45 - return []int{i}, nil
46 - }
47 - low, err := strconv.Atoi(parts[0])
48 - if err != nil {
49 - return nil, err
50 - }
51 -
52 - hi, err := strconv.Atoi(parts[1])
53 - if err != nil {
54 - return nil, err
55 - }
56 -
57 - var out []int
58 - for i := low; i <= hi; i++ {
59 - out = append(out, i)
60 - }
61 - return out, nil
62 -}
63 -
64 -func handleErr(s string, err error) {
65 - if err != nil {
66 - fmt.Fprintln(os.Stderr, s, err)
67 - os.Exit(1)
68 - }
69 -}
70 -
71 -func main() {
72 - app := cli.NewApp()
73 - app.Commands = []cli.Command{
74 - initCmd,
75 - startCmd,
76 - killCmd,
77 - restartCmd,
78 - shellCmd,
79 - getCmd,
80 - connectCmd,
81 - dumpStacksCmd,
82 - }
83 -
84 - err := app.Run(os.Args)
85 - if err != nil {
86 - fmt.Println(err)
87 - os.Exit(1)
88 - }
89 -}
90 -
91 -var initCmd = cli.Command{
92 - Name: "init",
93 - Usage: "create and initialize testbed nodes",
94 - Flags: []cli.Flag{
95 - cli.IntFlag{
96 - Name: "count, n",
97 - Usage: "number of ipfs nodes to initialize",
98 - },
99 - cli.IntFlag{
100 - Name: "port, p",
101 - Usage: "port to start allocations from",
102 - },
103 - cli.BoolFlag{
104 - Name: "force, f",
105 - Usage: "force initialization (overwrite existing configs)",
106 - },
107 - cli.BoolFlag{
108 - Name: "mdns",
109 - Usage: "turn on mdns for nodes",
110 - },
111 - cli.StringFlag{
112 - Name: "bootstrap",
113 - Usage: "select bootstrapping style for cluster",
114 - Value: "star",
115 - },
116 - cli.BoolFlag{
117 - Name: "utp",
118 - Usage: "use utp for addresses",
119 - },
120 - cli.StringFlag{
121 - Name: "cfg",
122 - Usage: "override default config with values from the given file",
123 - },
124 - },
125 - Action: func(c *cli.Context) {
126 - if c.Int("count") == 0 {
127 - fmt.Printf("please specify number of nodes: '%s init -n 10'\n", os.Args[0])
128 - os.Exit(1)
129 - }
130 - cfg := &util.InitCfg{
131 - Bootstrap: c.String("bootstrap"),
132 - Force: c.Bool("f"),
133 - Count: c.Int("count"),
134 - Mdns: c.Bool("mdns"),
135 - Utp: c.Bool("utp"),
136 - PortStart: c.Int("port"),
137 - Override: c.String("cfg"),
138 - }
139 -
140 - err := util.IpfsInit(cfg)
141 - handleErr("ipfs init err: ", err)
142 - },
143 -}
144 -
145 -var startCmd = cli.Command{
146 - Name: "start",
147 - Usage: "starts up all testbed nodes",
148 - Flags: []cli.Flag{
149 - cli.BoolFlag{
150 - Name: "wait",
151 - Usage: "wait for nodes to fully come online before returning",
152 - },
153 - },
154 - Action: func(c *cli.Context) {
155 - err := util.IpfsStart(c.Bool("wait"))
156 - handleErr("ipfs start err: ", err)
157 - },
158 -}
159 -
160 -var killCmd = cli.Command{
161 - Name: "kill",
162 - Usage: "kill a given node (or all nodes if none specified)",
163 - Aliases: []string{"stop"},
164 - Action: func(c *cli.Context) {
165 - if c.Args().Present() {
166 - i, err := strconv.Atoi(c.Args()[0])
167 - if err != nil {
168 - fmt.Println("failed to parse node number: ", err)
169 - os.Exit(1)
170 - }
171 - err = util.KillNode(i)
172 - if err != nil {
173 - fmt.Println("failed to kill node: ", err)
174 - }
175 - return
176 - }
177 - err := util.IpfsKillAll()
178 - handleErr("ipfs kill err: ", err)
179 - },
180 -}
181 -
182 -var restartCmd = cli.Command{
183 - Name: "restart",
184 - Usage: "kill all nodes, then restart",
185 - Flags: []cli.Flag{
186 - cli.BoolFlag{
187 - Name: "wait",
188 - Usage: "wait for nodes to come online before returning",
189 - },
190 - },
191 - Action: func(c *cli.Context) {
192 - err := util.IpfsKillAll()
193 - handleErr("ipfs kill err: ", err)
194 -
195 - err = util.IpfsStart(c.Bool("wait"))
196 - handleErr("ipfs start err: ", err)
197 - },
198 -}
199 -
200 -var shellCmd = cli.Command{
201 - Name: "shell",
202 - Usage: "execs your shell with certain environment variables set",
203 - Description: `Starts a new shell and sets some environment variables for you:
204 -
205 -IPFS_PATH - set to testbed node 'n's IPFS_PATH
206 -NODE[x] - set to the peer ID of node x
207 -`,
208 - Action: func(c *cli.Context) {
209 - if !c.Args().Present() {
210 - fmt.Println("please specify which node you want a shell for")
211 - os.Exit(1)
212 - }
213 - n, err := strconv.Atoi(c.Args()[0])
214 - handleErr("parse err: ", err)
215 -
216 - err = util.IpfsShell(n)
217 - handleErr("ipfs shell err: ", err)
218 - },
219 -}
220 -
221 -var connectCmd = cli.Command{
222 - Name: "connect",
223 - Usage: "connect two nodes together",
224 - Action: func(c *cli.Context) {
225 - if len(c.Args()) < 2 {
226 - fmt.Println("iptb connect [node] [node]")
227 - os.Exit(1)
228 - }
229 -
230 - from, err := parseRange(c.Args()[0])
231 - if err != nil {
232 - fmt.Printf("failed to parse: %s\n", err)
233 - return
234 - }
235 -
236 - to, err := parseRange(c.Args()[1])
237 - if err != nil {
238 - fmt.Printf("failed to parse: %s\n", err)
239 - return
240 - }
241 -
242 - for _, f := range from {
243 - for _, t := range to {
244 - err = util.ConnectNodes(f, t)
245 - if err != nil {
246 - fmt.Printf("failed to connect: %s\n", err)
247 - return
248 - }
249 - }
250 - }
251 - },
252 -}
253 -
254 -var getCmd = cli.Command{
255 - Name: "get",
256 - Usage: "get an attribute of the given node",
257 - Action: func(c *cli.Context) {
258 - if len(c.Args()) < 2 {
259 - fmt.Println("iptb get [attr] [node]")
260 - os.Exit(1)
261 - }
262 - attr := c.Args().First()
263 - num, err := strconv.Atoi(c.Args()[1])
264 - handleErr("error parsing node number: ", err)
265 -
266 - val, err := util.GetAttr(attr, num)
267 - handleErr("error getting attribute: ", err)
268 - fmt.Println(val)
269 - },
270 -}
271 -
272 -var dumpStacksCmd = cli.Command{
273 - Name: "dump-stack",
274 - Usage: "get a stack dump from the given daemon",
275 - Action: func(c *cli.Context) {
276 - if len(c.Args()) < 1 {
277 - fmt.Println("iptb dump-stack [node]")
278 - os.Exit(1)
279 - }
280 -
281 - num, err := strconv.Atoi(c.Args()[0])
282 - handleErr("error parsing node number: ", err)
283 -
284 - addr, err := util.GetNodesAPIAddr(num)
285 - handleErr("failed to get api addr: ", err)
286 -
287 - resp, err := http.Get("http://" + addr + "/debug/pprof/goroutine?debug=2")
288 - handleErr("GET stack dump failed: ", err)
289 - defer resp.Body.Close()
290 -
291 - io.Copy(os.Stdout, resp.Body)
292 - },
293 -}