提交 f1df72b1 作者: Jeromy Johnson

Merge pull request #2545 from chriscool/use-gx-for-iptb

Use gx for iptb
// +build !windows
package iptbutil
import (
"os/exec"
"syscall"
)
func init() {
setupOpt = func(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
}
}
......@@ -59,6 +59,16 @@
"hash": "QmdhsRK1EK2fvAz2i2SH5DEfkL6seDuyMYEsxKa9Braim3",
"name": "client_golang",
"version": "0.0.0"
},
{
"hash": "QmSx5xkktduyo1hBL7kZxdiZq1P9TrgeGkNW8qtoY14bSk",
"name": "iptb",
"version": "0.0.0"
},
{
"hash": "QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku",
"name": "go-multihash",
"version": "0.0.0"
}
],
"gxVersion": "0.4.0",
......@@ -66,4 +76,4 @@
"license": "MIT",
"name": "go-ipfs",
"version": "0.4.0"
}
\ No newline at end of file
}
......@@ -4,17 +4,20 @@ IPFS_ROOT = ../
IPFS_CMD = ../cmd/ipfs
RANDOM_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random
RANDOM_FILES_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random-files
MULTIHASH_SRC = ../../../../gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash
IPTB_SRC = ./dependencies/iptb
POLLENDPOINT_SRC= ../thirdparty/pollEndpoint
GOSLEEP_SRC = ./dependencies/go-sleep
GX_RELATIVE_PATH = ../../../../gx/ipfs
# User might want to override those on the command line
GOFLAGS =
all: deps
deps: bins
global-deps:
make -C .. deps
deps: global-deps bins
clean:
rm $(BINS)
......@@ -23,6 +26,8 @@ bins: $(BINS)
find_go_files = $(shell find $(1) -name "*.go")
# Non gx dependencies
bin/random: $(call find_go_files, $(RANDOM_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/random $(RANDOM_SRC)/random
......@@ -31,10 +36,6 @@ bin/random-files:
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/random-files $(RANDOM_FILES_SRC)/random-files
bin/multihash: $(call find_go_files, $(MULTIHASH_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/multihash $(MULTIHASH_SRC)/multihash
bin/ipfs: $(call find_go_files, $(IPFS_ROOT)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/ipfs $(IPFS_CMD)
......@@ -43,14 +44,30 @@ bin/pollEndpoint: $(call find_go_files, $(POLLENDPOINT_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/pollEndpoint $(POLLENDPOINT_SRC)
bin/iptb: $(call find_go_files, $(IPTB_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/iptb $(IPTB_SRC)
bin/go-sleep: $(call find_go_files, $(GOSLEEP_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/go-sleep $(GOSLEEP_SRC)
# gx dependencies
multihash_src:
$(eval MULTIHASH_HASH := $(shell cd .. && gx deps find go-multihash))
$(eval MULTIHASH_SRC := $(GX_RELATIVE_PATH)/$(MULTIHASH_HASH)/go-multihash)
bin/multihash: multihash_src $(call find_go_files, $(MULTIHASH_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/multihash $(MULTIHASH_SRC)/multihash
iptb_src:
$(eval IPTB_HASH := $(shell cd .. && gx deps find iptb))
$(eval IPTB_SRC := $(GX_RELATIVE_PATH)/$(IPTB_HASH)/iptb)
bin/iptb: iptb_src $(call find_go_files, $(IPTB_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/iptb $(IPTB_SRC)
# Tests
test: test_expensive
test_expensive: verify_gofmt
......@@ -67,6 +84,8 @@ test_race: verify_gofmt
cd 3nodetest && make GOFLAGS=-race
cd dependencies && make GOFLAGS=-race
# Misc
coverage: coverage_sharness
coverage_sharness:
......
The MIT License (MIT)
Copyright (c) 2015 Jeromy Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# IPTB
iptb is a program used to manage a cluster of ipfs nodes locally on your
computer. It allows the creation of up to 1000 (limited by poor port choice)
nodes, and allows for various other setup options to be selected such as
different bootstrapping patterns. iptb makes testing networks in ipfs
easy!
### Commands:
- init
- creates and initializes 'n' repos
- Options:
- -n=[number of nodes]
- -f : force overwriting of existing nodes
- -bootstrap : select bootstrapping style for cluster choices: star, none
- -mdns=[true||false] : defaults to false
- -p=[start port] : port to start allocations from
- start
- starts up all testbed nodes
- Options:
- -wait : wait until daemons are fully initialized
- stop
- kills all testbed nodes
- restart
- kills and then restarts all testbed nodes
- shell [n]
- execs your shell with environment variables set as follows:
- IPFS_PATH - set to testbed node n's IPFS_PATH
- NODE[x] - set to the peer ID of node x
- get [attr] [n]
- gets the specified attribute from then given node
- available attributes: id
### Configuration
By default, iptb uses `$HOME/testbed` to store created nodes. This path is
configurable via the environment variables `IPTB_ROOT`.
package main
import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
cli "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/codegangsta/cli"
util "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/iptb/util"
)
func parseRange(s string) ([]int, error) {
if strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]") {
ranges := strings.Split(s[1:len(s)-1], ",")
var out []int
for _, r := range ranges {
rng, err := expandDashRange(r)
if err != nil {
return nil, err
}
out = append(out, rng...)
}
return out, nil
} else {
i, err := strconv.Atoi(s)
if err != nil {
return nil, err
}
return []int{i}, nil
}
}
func expandDashRange(s string) ([]int, error) {
parts := strings.Split(s, "-")
if len(parts) == 0 {
i, err := strconv.Atoi(s)
if err != nil {
return nil, err
}
return []int{i}, nil
}
low, err := strconv.Atoi(parts[0])
if err != nil {
return nil, err
}
hi, err := strconv.Atoi(parts[1])
if err != nil {
return nil, err
}
var out []int
for i := low; i <= hi; i++ {
out = append(out, i)
}
return out, nil
}
func handleErr(s string, err error) {
if err != nil {
fmt.Fprintln(os.Stderr, s, err)
os.Exit(1)
}
}
func main() {
app := cli.NewApp()
app.Commands = []cli.Command{
initCmd,
startCmd,
killCmd,
restartCmd,
shellCmd,
getCmd,
connectCmd,
dumpStacksCmd,
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
var initCmd = cli.Command{
Name: "init",
Usage: "create and initialize testbed nodes",
Flags: []cli.Flag{
cli.IntFlag{
Name: "count, n",
Usage: "number of ipfs nodes to initialize",
},
cli.IntFlag{
Name: "port, p",
Usage: "port to start allocations from",
},
cli.BoolFlag{
Name: "force, f",
Usage: "force initialization (overwrite existing configs)",
},
cli.BoolFlag{
Name: "mdns",
Usage: "turn on mdns for nodes",
},
cli.StringFlag{
Name: "bootstrap",
Usage: "select bootstrapping style for cluster",
Value: "star",
},
cli.BoolFlag{
Name: "utp",
Usage: "use utp for addresses",
},
cli.StringFlag{
Name: "cfg",
Usage: "override default config with values from the given file",
},
},
Action: func(c *cli.Context) {
if c.Int("count") == 0 {
fmt.Printf("please specify number of nodes: '%s init -n 10'\n", os.Args[0])
os.Exit(1)
}
cfg := &util.InitCfg{
Bootstrap: c.String("bootstrap"),
Force: c.Bool("f"),
Count: c.Int("count"),
Mdns: c.Bool("mdns"),
Utp: c.Bool("utp"),
PortStart: c.Int("port"),
Override: c.String("cfg"),
}
err := util.IpfsInit(cfg)
handleErr("ipfs init err: ", err)
},
}
var startCmd = cli.Command{
Name: "start",
Usage: "starts up all testbed nodes",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "wait",
Usage: "wait for nodes to fully come online before returning",
},
},
Action: func(c *cli.Context) {
err := util.IpfsStart(c.Bool("wait"))
handleErr("ipfs start err: ", err)
},
}
var killCmd = cli.Command{
Name: "kill",
Usage: "kill a given node (or all nodes if none specified)",
Aliases: []string{"stop"},
Action: func(c *cli.Context) {
if c.Args().Present() {
i, err := strconv.Atoi(c.Args()[0])
if err != nil {
fmt.Println("failed to parse node number: ", err)
os.Exit(1)
}
err = util.KillNode(i)
if err != nil {
fmt.Println("failed to kill node: ", err)
}
return
}
err := util.IpfsKillAll()
handleErr("ipfs kill err: ", err)
},
}
var restartCmd = cli.Command{
Name: "restart",
Usage: "kill all nodes, then restart",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "wait",
Usage: "wait for nodes to come online before returning",
},
},
Action: func(c *cli.Context) {
err := util.IpfsKillAll()
handleErr("ipfs kill err: ", err)
err = util.IpfsStart(c.Bool("wait"))
handleErr("ipfs start err: ", err)
},
}
var shellCmd = cli.Command{
Name: "shell",
Usage: "execs your shell with certain environment variables set",
Description: `Starts a new shell and sets some environment variables for you:
IPFS_PATH - set to testbed node 'n's IPFS_PATH
NODE[x] - set to the peer ID of node x
`,
Action: func(c *cli.Context) {
if !c.Args().Present() {
fmt.Println("please specify which node you want a shell for")
os.Exit(1)
}
n, err := strconv.Atoi(c.Args()[0])
handleErr("parse err: ", err)
err = util.IpfsShell(n)
handleErr("ipfs shell err: ", err)
},
}
var connectCmd = cli.Command{
Name: "connect",
Usage: "connect two nodes together",
Action: func(c *cli.Context) {
if len(c.Args()) < 2 {
fmt.Println("iptb connect [node] [node]")
os.Exit(1)
}
from, err := parseRange(c.Args()[0])
if err != nil {
fmt.Printf("failed to parse: %s\n", err)
return
}
to, err := parseRange(c.Args()[1])
if err != nil {
fmt.Printf("failed to parse: %s\n", err)
return
}
for _, f := range from {
for _, t := range to {
err = util.ConnectNodes(f, t)
if err != nil {
fmt.Printf("failed to connect: %s\n", err)
return
}
}
}
},
}
var getCmd = cli.Command{
Name: "get",
Usage: "get an attribute of the given node",
Action: func(c *cli.Context) {
if len(c.Args()) < 2 {
fmt.Println("iptb get [attr] [node]")
os.Exit(1)
}
attr := c.Args().First()
num, err := strconv.Atoi(c.Args()[1])
handleErr("error parsing node number: ", err)
val, err := util.GetAttr(attr, num)
handleErr("error getting attribute: ", err)
fmt.Println(val)
},
}
var dumpStacksCmd = cli.Command{
Name: "dump-stack",
Usage: "get a stack dump from the given daemon",
Action: func(c *cli.Context) {
if len(c.Args()) < 1 {
fmt.Println("iptb dump-stack [node]")
os.Exit(1)
}
num, err := strconv.Atoi(c.Args()[0])
handleErr("error parsing node number: ", err)
addr, err := util.GetNodesAPIAddr(num)
handleErr("failed to get api addr: ", err)
resp, err := http.Get("http://" + addr + "/debug/pprof/goroutine?debug=2")
handleErr("GET stack dump failed: ", err)
defer resp.Body.Close()
io.Copy(os.Stdout, resp.Body)
},
}
......@@ -33,7 +33,10 @@ aggregate: clean-test-results $(T)
@echo "*** $@ ***"
lib/test-aggregate-results.sh
deps: $(SHARNESS) $(BINS) curl
global-deps:
make -C ../.. deps
deps: global-deps $(SHARNESS) $(BINS) curl
$(SHARNESS): FORCE
@echo "*** checking $@ ***"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论