removed old commands files
https://www.youtube.com/watch?v=kyFyAqLtHq8
Juan Batiz-Benet committed
Nov 18, 2014 at 02:35 UTC
ad3f3e003f21ad783cd72842f9883815a6dbc685
46 files changed
-3168
cmd/ipfs/.gitignore
deleted
-1
@@ -1 +0,0 @@
1
-./ipfs
cmd/ipfs/Makefile
deleted
-15
@@ -1,15 +0,0 @@
1
-all: install
2
-
3
-build:
4
- go build
5
-
6
-install: build
7
- go install
8
-
9
-# cpu profiling: `go tool pprof ipfs cpu.prof`
10
-# mem profiling: `go tool pprof ipfs ipfs.mprof`
11
-
12
-clean:
13
- rm -f cpu.prof
14
- rm -f ipfs.mprof
15
- rm -f ipfs
cmd/ipfs/README.md
deleted
-29
@@ -1,29 +0,0 @@
1
-# go-ipfs/cmd/ipfs
2
-
3
-This is the ipfs commandline tool. For now, it's the main entry point to using IPFS. Use it.
4
-
5
-```
6
-> go build
7
-> go install
8
-> ipfs
9
-ipfs - global versioned p2p merkledag file system
10
-
11
-Basic commands:
12
-
13
- add <path> Add an object to ipfs.
14
- cat <ref> Show ipfs object data.
15
- ls <ref> List links from an object.
16
- refs <ref> List link hashes from an object.
17
-
18
-Tool commands:
19
-
20
- config Manage configuration.
21
- version Show ipfs version information.
22
- commands List all available commands.
23
-
24
-Advanced Commands:
25
-
26
- mount Mount an ipfs read-only mountpoint.
27
-
28
-Use "ipfs help <command>" for more information about a command.
29
-```
cmd/ipfs/add.go
deleted
-39
@@ -1,39 +0,0 @@
1
-package main
2
-
3
-import (
4
- "fmt"
5
- "path/filepath"
6
-
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
8
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
9
- "github.com/jbenet/go-ipfs/core/commands"
10
-)
11
-
12
-// Error indicating the max depth has been exceded.
13
-var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
14
-
15
-var cmdIpfsAdd = &commander.Command{
16
- UsageLine: "add",
17
- Short: "Add an object to ipfs.",
18
- Long: `ipfs add <path>... - Add objects to ipfs.
19
-
20
- Adds contents of <path> to ipfs. Use -r to add directories.
21
- Note that directories are added recursively, to form the ipfs
22
- MerkleDAG. A smarter partial add with a staging area (like git)
23
- remains to be implemented.
24
-`,
25
- Run: addCmd,
26
- Flag: *flag.NewFlagSet("ipfs-add", flag.ExitOnError),
27
-}
28
-
29
-func init() {
30
- cmdIpfsAdd.Flag.Bool("r", false, "add objects recursively")
31
-}
32
-
33
-var addCmd = makeCommand(command{
34
- name: "add",
35
- args: 1,
36
- flags: []string{"r"},
37
- cmdFn: commands.Add,
38
- argFilter: filepath.Abs,
39
-})
cmd/ipfs/block.go
deleted
-58
@@ -1,58 +0,0 @@
1
-package main
2
-
3
-import (
4
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsBlock = &commander.Command{
10
- UsageLine: "block",
11
- Short: "manipulate raw ipfs blocks",
12
- Long: `ipfs block - manipulate raw ipfs blocks
13
-
14
- ipfs block get <key> - get and output block named by <key>
15
- ipfs block put - store stdin as a block, outputs <key>
16
-
17
-ipfs block is a plumbing command used to manipulate raw ipfs blocks.
18
-Reads from stdin or writes to stdout, and <key> is a base58 encoded
19
-multihash.`,
20
- // Run: blockGetCmd,
21
- Subcommands: []*commander.Command{
22
- cmdIpfsBlockGet,
23
- cmdIpfsBlockPut,
24
- },
25
- Flag: *flag.NewFlagSet("ipfs-block", flag.ExitOnError),
26
-}
27
-
28
-var cmdIpfsBlockGet = &commander.Command{
29
- UsageLine: "get <key>",
30
- Short: "get and output block named by <key>",
31
- Long: `ipfs get <key> - get and output block named by <key>
32
-
33
-ipfs block get is a plumbing command for retreiving raw ipfs blocks.
34
-It outputs to stdout, and <key> is a base58 encoded multihash.`,
35
- Run: makeCommand(command{
36
- name: "blockGet",
37
- args: 1,
38
- flags: nil,
39
- online: true,
40
- cmdFn: commands.BlockGet,
41
- }),
42
-}
43
-
44
-var cmdIpfsBlockPut = &commander.Command{
45
- UsageLine: "put",
46
- Short: "store stdin as a block, outputs <key>",
47
- Long: `ipfs put - store stdin as a block, outputs <key>
48
-
49
-ipfs block put is a plumbing command for storing raw ipfs blocks.
50
-It reads from stding, and <key> is a base58 encoded multihash.`,
51
- Run: makeCommand(command{
52
- name: "blockPut",
53
- args: 0,
54
- flags: nil,
55
- online: true,
56
- cmdFn: commands.BlockPut,
57
- }),
58
-}
cmd/ipfs/bootstrap.go
deleted
-236
@@ -1,236 +0,0 @@
1
-package main
2
-
3
-import (
4
- "errors"
5
- "strings"
6
-
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
8
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
9
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
10
- mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
11
-
12
- config "github.com/jbenet/go-ipfs/config"
13
- peer "github.com/jbenet/go-ipfs/peer"
14
- u "github.com/jbenet/go-ipfs/util"
15
-)
16
-
17
-var cmdIpfsBootstrap = &commander.Command{
18
- UsageLine: "bootstrap",
19
- Short: "Show a list of bootstrapped addresses.",
20
- Long: `ipfs bootstrap - show, or manipulate bootstrap node addresses
21
-
22
-Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'.
23
-
24
-Commands:
25
-
26
- list Show the boostrap list.
27
- add <address> Add a node's address to the bootstrap list.
28
- remove <address> Remove an address from the bootstrap list.
29
-
30
-` + bootstrapSecurityWarning,
31
- Run: bootstrapListCmd,
32
- Subcommands: []*commander.Command{
33
- cmdIpfsBootstrapRemove,
34
- cmdIpfsBootstrapAdd,
35
- cmdIpfsBootstrapList,
36
- },
37
- Flag: *flag.NewFlagSet("ipfs-bootstrap", flag.ExitOnError),
38
-}
39
-
40
-var cmdIpfsBootstrapRemove = &commander.Command{
41
- UsageLine: "remove <address | peerid>",
42
- Short: "Remove addresses from the bootstrap list.",
43
- Long: `ipfs bootstrap remove - remove addresses from the bootstrap list
44
-` + bootstrapSecurityWarning,
45
- Run: bootstrapRemoveCmd,
46
- Flag: *flag.NewFlagSet("ipfs-bootstrap-remove", flag.ExitOnError),
47
-}
48
-
49
-var cmdIpfsBootstrapAdd = &commander.Command{
50
- UsageLine: "add <address | peerid>",
51
- Short: "Add addresses to the bootstrap list.",
52
- Long: `ipfs bootstrap add - add addresses to the bootstrap list
53
-` + bootstrapSecurityWarning,
54
- Run: bootstrapAddCmd,
55
- Flag: *flag.NewFlagSet("ipfs-bootstrap-add", flag.ExitOnError),
56
-}
57
-
58
-var cmdIpfsBootstrapList = &commander.Command{
59
- UsageLine: "list",
60
- Short: "Show addresses in the bootstrap list.",
61
- Run: bootstrapListCmd,
62
- Flag: *flag.NewFlagSet("ipfs-bootstrap-list", flag.ExitOnError),
63
-}
64
-
65
-func bootstrapRemoveCmd(c *commander.Command, inp []string) error {
66
-
67
- if len(inp) == 0 {
68
- return errors.New("remove: no address or peerid specified")
69
- }
70
-
71
- toRemove, err := bootstrapInputToPeers(inp)
72
- if err != nil {
73
- return err
74
- }
75
-
76
- cfg, err := getConfig(c)
77
- if err != nil {
78
- return err
79
- }
80
-
81
- keep := []*config.BootstrapPeer{}
82
- remove := []*config.BootstrapPeer{}
83
-
84
- // function to filer what to keep
85
- shouldKeep := func(bp *config.BootstrapPeer) bool {
86
- for _, skipBP := range toRemove {
87
-
88
- // IDs must match to skip.
89
- if bp.PeerID != skipBP.PeerID {
90
- continue
91
- }
92
-
93
- // if Addresses match, or skipBP has no addr (wildcard)
94
- if skipBP.Address == bp.Address || skipBP.Address == "" {
95
- return false
96
- }
97
- }
98
- return true
99
- }
100
-
101
- // filter all the existing peers
102
- for _, currBP := range cfg.Bootstrap {
103
- if shouldKeep(currBP) {
104
- keep = append(keep, currBP)
105
- } else {
106
- remove = append(remove, currBP)
107
- }
108
- }
109
-
110
- // if didn't remove anyone, bail.
111
- if len(keep) == len(cfg.Bootstrap) {
112
- return errors.New("remove: peer given did not match any in list")
113
- }
114
-
115
- // write new config
116
- cfg.Bootstrap = keep
117
- if err := writeConfig(c, cfg); err != nil {
118
- return err
119
- }
120
-
121
- for _, bp := range remove {
122
- u.POut("removed %s\n", bp)
123
- }
124
- return nil
125
-}
126
-
127
-func bootstrapAddCmd(c *commander.Command, inp []string) error {
128
-
129
- if len(inp) == 0 {
130
- return errors.New("add: no address specified")
131
- }
132
-
133
- toAdd, err := bootstrapInputToPeers(inp)
134
- if err != nil {
135
- return err
136
- }
137
-
138
- cfg, err := getConfig(c)
139
- if err != nil {
140
- return err
141
- }
142
-
143
- // function to check whether a peer is already in the list.
144
- combine := func(lists ...[]*config.BootstrapPeer) []*config.BootstrapPeer {
145
-
146
- set := map[string]struct{}{}
147
- final := []*config.BootstrapPeer{}
148
-
149
- for _, list := range lists {
150
- for _, peer := range list {
151
- // if already in the set, continue
152
- _, found := set[peer.String()]
153
- if found {
154
- continue
155
- }
156
-
157
- set[peer.String()] = struct{}{}
158
- final = append(final, peer)
159
- }
160
- }
161
- return final
162
- }
163
-
164
- // combine both lists, removing dups.
165
- cfg.Bootstrap = combine(cfg.Bootstrap, toAdd)
166
- if err := writeConfig(c, cfg); err != nil {
167
- return err
168
- }
169
-
170
- for _, bp := range toAdd {
171
- u.POut("added %s\n", bp)
172
- }
173
- return nil
174
-}
175
-
176
-func bootstrapListCmd(c *commander.Command, inp []string) error {
177
-
178
- cfg, err := getConfig(c)
179
- if err != nil {
180
- return err
181
- }
182
-
183
- for _, bp := range cfg.Bootstrap {
184
- u.POut("%s\n", bp)
185
- }
186
-
187
- return nil
188
-}
189
-
190
-func bootstrapInputToPeers(input []string) ([]*config.BootstrapPeer, error) {
191
- split := func(addr string) (string, string) {
192
- idx := strings.LastIndex(addr, "/")
193
- if idx == -1 {
194
- return "", addr
195
- }
196
- return addr[:idx], addr[idx+1:]
197
- }
198
-
199
- peers := []*config.BootstrapPeer{}
200
- for _, addr := range input {
201
- addrS, peeridS := split(addr)
202
-
203
- // make sure addrS parses as a multiaddr.
204
- if len(addrS) > 0 {
205
- maddr, err := ma.NewMultiaddr(addrS)
206
- if err != nil {
207
- return nil, err
208
- }
209
-
210
- addrS = maddr.String()
211
- }
212
-
213
- // make sure idS parses as a peer.ID
214
- peerid, err := mh.FromB58String(peeridS)
215
- if err != nil {
216
- return nil, err
217
- }
218
-
219
- // construct config entry
220
- peers = append(peers, &config.BootstrapPeer{
221
- Address: addrS,
222
- PeerID: peer.ID(peerid).Pretty(),
223
- })
224
- }
225
- return peers, nil
226
-}
227
-
228
-const bootstrapSecurityWarning = `
229
-SECURITY WARNING:
230
-
231
-The bootstrap command manipulates the "bootstrap list", which contains
232
-the addresses of bootstrap nodes. These are the *trusted peers* from
233
-which to learn about other peers in the network. Only edit this list
234
-if you understand the risks of adding or removing nodes from this list.
235
-
236
-`
cmd/ipfs/cat.go
deleted
-26
@@ -1,26 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsCat = &commander.Command{
10
- UsageLine: "cat",
11
- Short: "Show ipfs object data.",
12
- Long: `ipfs cat <ipfs-path> - Show ipfs object data.
13
-
14
- Retrieves the object named by <ipfs-path> and displays the Data
15
- it contains.
16
-`,
17
- Run: catCmd,
18
- Flag: *flag.NewFlagSet("ipfs-cat", flag.ExitOnError),
19
-}
20
-
21
-var catCmd = makeCommand(command{
22
- name: "cat",
23
- args: 1,
24
- flags: nil,
25
- cmdFn: commands.Cat,
26
-})
cmd/ipfs/commands.go
deleted
-74
@@ -1,74 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
5
- u "github.com/jbenet/go-ipfs/util"
6
- "strings"
7
- "time"
8
-)
9
-
10
-var cmdIpfsCommands = &commander.Command{
11
- UsageLine: "commands",
12
- Short: "List all available commands.",
13
- Long: `ipfs commands - List all available commands.
14
-
15
- Lists all available commands (and sub-commands) and exits.
16
- `,
17
- Run: commandsCmd,
18
- Subcommands: []*commander.Command{
19
- cmdIpfsCommandsHelp,
20
- },
21
-}
22
-
23
-func commandsCmd(c *commander.Command, args []string) error {
24
- var listCmds func(c *commander.Command)
25
- listCmds = func(c *commander.Command) {
26
- u.POut("%s\n", c.FullSpacedName())
27
- for _, sc := range c.Subcommands {
28
- listCmds(sc)
29
- }
30
- }
31
-
32
- listCmds(c.Parent)
33
- return nil
34
-}
35
-
36
-var cmdIpfsCommandsHelp = &commander.Command{
37
- UsageLine: "help",
38
- Short: "List all available commands' help pages.",
39
- Long: `ipfs commands help - List all available commands's help pages.
40
-
41
- Shows the pages of all available commands (and sub-commands) and exits.
42
- Outputs a markdown document.
43
- `,
44
- Run: commandsHelpCmd,
45
-}
46
-
47
-func commandsHelpCmd(c *commander.Command, args []string) error {
48
- u.POut(referenceHeaderMsg)
49
- u.POut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))
50
-
51
- var printCmds func(*commander.Command, int)
52
- printCmds = func(c *commander.Command, level int) {
53
- u.POut("%s ", strings.Repeat("#", level))
54
- u.POut("%s\n\n", c.FullSpacedName())
55
- u.POut("```\n")
56
- u.POut("%s\n", c.Long)
57
- u.POut("```\n\n")
58
-
59
- for _, sc := range c.Subcommands {
60
- printCmds(sc, level+1)
61
- }
62
- }
63
-
64
- printCmds(c.Parent.Parent, 1)
65
- return nil
66
-}
67
-
68
-const referenceHeaderMsg = `
69
-# ipfs command reference
70
-
71
-This document lists every ipfs command (including subcommands), along with
72
-its help page. It can be viewed by running 'ipfs commands help'.
73
-
74
-`
cmd/ipfs/config.go
deleted
-143
@@ -1,143 +0,0 @@
1
-package main
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "io"
7
- "os"
8
- "os/exec"
9
-
10
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
11
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
12
- config "github.com/jbenet/go-ipfs/config"
13
- u "github.com/jbenet/go-ipfs/util"
14
-)
15
-
16
-var cmdIpfsConfig = &commander.Command{
17
- UsageLine: "config",
18
- Short: "Get/Set ipfs config values",
19
- Long: `ipfs config [<key>] [<value>] - Get/Set ipfs config values.
20
-
21
- ipfs config <key> - Get value of <key>
22
- ipfs config <key> <value> - Set value of <key> to <value>
23
- ipfs config --show - Show config file
24
- ipfs config --edit - Edit config file in $EDITOR
25
-
26
-Examples:
27
-
28
- Get the value of the 'datastore.path' key:
29
-
30
- ipfs config datastore.path
31
-
32
- Set the value of the 'datastore.path' key:
33
-
34
- ipfs config datastore.path ~/.go-ipfs/datastore
35
-
36
-`,
37
- Run: configCmd,
38
- Flag: *flag.NewFlagSet("ipfs-config", flag.ExitOnError),
39
-}
40
-
41
-func init() {
42
- cmdIpfsConfig.Flag.Bool("edit", false, "Edit config file in $EDITOR")
43
- cmdIpfsConfig.Flag.Bool("show", false, "Show config file")
44
-}
45
-
46
-func configCmd(c *commander.Command, inp []string) error {
47
-
48
- confdir, err := getConfigDir(c.Parent)
49
- if err != nil {
50
- return err
51
- }
52
-
53
- filename, err := config.Filename(confdir)
54
- if err != nil {
55
- return err
56
- }
57
-
58
- // if editing, open the editor
59
- if c.Flag.Lookup("edit").Value.Get().(bool) {
60
- return configEditor(filename)
61
- }
62
-
63
- // if showing, cat the file
64
- if c.Flag.Lookup("show").Value.Get().(bool) {
65
- return configCat(filename)
66
- }
67
-
68
- if len(inp) == 0 {
69
- // "ipfs config" run without parameters
70
- u.POut(c.Long)
71
- return nil
72
- }
73
-
74
- // Getter (1 param)
75
- if len(inp) == 1 {
76
- value, err := config.ReadConfigKey(filename, inp[0])
77
- if err != nil {
78
- return fmt.Errorf("Failed to get config value: %s", err)
79
- }
80
-
81
- strval, ok := value.(string)
82
- if ok {
83
- u.POut("%s\n", strval)
84
- return nil
85
- }
86
-
87
- if err := config.Encode(os.Stdout, value); err != nil {
88
- return fmt.Errorf("Failed to encode config value: %s", err)
89
- }
90
- u.POut("\n")
91
- return nil
92
- }
93
-
94
- // Setter (>1 params)
95
- err = config.WriteConfigKey(filename, inp[0], inp[1])
96
- if err != nil {
97
- return fmt.Errorf("Failed to set config value: %s", err)
98
- }
99
-
100
- return nil
101
-}
102
-
103
-func configCat(filename string) error {
104
-
105
- file, err := os.Open(filename)
106
- if err != nil {
107
- return err
108
- }
109
- defer file.Close()
110
-
111
- if _, err = io.Copy(os.Stdout, file); err != nil {
112
- return err
113
- }
114
- u.POut("\n")
115
- return nil
116
-}
117
-
118
-func configEditor(filename string) error {
119
-
120
- editor := os.Getenv("EDITOR")
121
- if editor == "" {
122
- return errors.New("ENV variable $EDITOR not set")
123
- }
124
-
125
- cmd := exec.Command("sh", "-c", editor+" "+filename)
126
- cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
127
- return cmd.Run()
128
-}
129
-
130
-func writeConfig(c *commander.Command, cfg *config.Config) error {
131
-
132
- confdir, err := getConfigDir(c)
133
- if err != nil {
134
- return err
135
- }
136
-
137
- filename, err := config.Filename(confdir)
138
- if err != nil {
139
- return err
140
- }
141
-
142
- return config.WriteConfigFile(filename, cfg)
143
-}
cmd/ipfs/diag.go
deleted
-32
@@ -1,32 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
-
6
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
7
- "github.com/jbenet/go-ipfs/core/commands"
8
-)
9
-
10
-var cmdIpfsDiag = &commander.Command{
11
- UsageLine: "net-diag",
12
- Short: "Generate a diagnostics report",
13
- Long: `ipfs net-diag - Generate a diagnostics report.
14
-
15
- Sends out a message to each node in the network recursively
16
- requesting a listing of data about them including number of
17
- connected peers and latencies between them.
18
-`,
19
- Run: diagCmd,
20
- Flag: *flag.NewFlagSet("ipfs-net-diag", flag.ExitOnError),
21
-}
22
-
23
-func init() {
24
- cmdIpfsDiag.Flag.Bool("raw", false, "print raw json output")
25
-}
26
-
27
-var diagCmd = makeCommand(command{
28
- name: "diag",
29
- args: 0,
30
- flags: []string{"raw"},
31
- cmdFn: commands.Diag,
32
-})
cmd/ipfs/equinox.yaml
deleted
-6
@@ -1,6 +0,0 @@
1
----
2
-equinox-account: CHANGEME
3
-equinox-secret: CHANGEME
4
-equinox-app: CHANGEME
5
-channel: stable
6
-private-key: equinox-priv
cmd/ipfs/gen.go
deleted
-72
@@ -1,72 +0,0 @@
1
-package main
2
-
3
-import (
4
- "fmt"
5
- "os"
6
-
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
- "github.com/jbenet/go-ipfs/core/commands"
9
- "github.com/jbenet/go-ipfs/daemon"
10
- u "github.com/jbenet/go-ipfs/util"
11
-)
12
-
13
-// command is the descriptor of an ipfs daemon command.
14
-// Used with makeCommand to proxy over commands via the daemon.
15
-type command struct {
16
- name string
17
- args int
18
- flags []string
19
- online bool
20
- cmdFn commands.CmdFunc
21
- argFilter func(string) (string, error)
22
-}
23
-
24
-// commanderFunc is a function that can be passed into the Commander library as
25
-// a command handler. Defined here because commander lacks this definition.
26
-type commanderFunc func(*commander.Command, []string) error
27
-
28
-// makeCommand Wraps a commands.CmdFunc so that it may be safely run by the
29
-// commander library
30
-func makeCommand(cmdDesc command) commanderFunc {
31
- return func(c *commander.Command, inp []string) error {
32
- if len(inp) < cmdDesc.args {
33
- u.POut(c.Long)
34
- return nil
35
- }
36
- confdir, err := getConfigDir(c)
37
- if err != nil {
38
- return err
39
- }
40
-
41
- cmd := daemon.NewCommand()
42
- cmd.Command = cmdDesc.name
43
- if cmdDesc.argFilter != nil {
44
- for _, a := range inp {
45
- s, err := cmdDesc.argFilter(a)
46
- if err != nil {
47
- return err
48
- }
49
- cmd.Args = append(cmd.Args, s)
50
- }
51
- } else {
52
- cmd.Args = inp
53
- }
54
-
55
- for _, a := range cmdDesc.flags {
56
- cmd.Opts[a] = c.Flag.Lookup(a).Value.Get()
57
- }
58
-
59
- err = daemon.SendCommand(cmd, confdir)
60
- if err != nil {
61
- log.Info("Executing command locally: %s", err)
62
- // Do locally
63
- n, err := localNode(confdir, cmdDesc.online)
64
- if err != nil {
65
- return fmt.Errorf("Local node creation failed: %v", err)
66
- }
67
-
68
- return cmdDesc.cmdFn(n, cmd.Args, cmd.Opts, os.Stdout)
69
- }
70
- return nil
71
- }
72
-}
cmd/ipfs/init.go
deleted
-200
@@ -1,200 +0,0 @@
1
-package main
2
-
3
-import (
4
- "bytes"
5
- "encoding/base64"
6
- "errors"
7
- "fmt"
8
- "os"
9
- "path/filepath"
10
-
11
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
12
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
13
- config "github.com/jbenet/go-ipfs/config"
14
- core "github.com/jbenet/go-ipfs/core"
15
- ci "github.com/jbenet/go-ipfs/crypto"
16
- imp "github.com/jbenet/go-ipfs/importer"
17
- chunk "github.com/jbenet/go-ipfs/importer/chunk"
18
- peer "github.com/jbenet/go-ipfs/peer"
19
- updates "github.com/jbenet/go-ipfs/updates"
20
- u "github.com/jbenet/go-ipfs/util"
21
-)
22
-
23
-var cmdIpfsInit = &commander.Command{
24
- UsageLine: "init",
25
- Short: "Initialize ipfs local configuration",
26
- Long: `ipfs init
27
-
28
- Initializes ipfs configuration files and generates a
29
- new keypair.
30
-`,
31
- Run: initCmd,
32
- Flag: *flag.NewFlagSet("ipfs-init", flag.ExitOnError),
33
-}
34
-
35
-func init() {
36
- cmdIpfsInit.Flag.Int("b", 4096, "number of bits for keypair")
37
- cmdIpfsInit.Flag.String("p", "", "passphrase for encrypting keys")
38
- cmdIpfsInit.Flag.Bool("f", false, "force overwrite of existing config")
39
- cmdIpfsInit.Flag.String("d", "", "Change default datastore location")
40
-}
41
-
42
-var defaultPeers = []*config.BootstrapPeer{
43
- &config.BootstrapPeer{
44
- // mars.i.ipfs.io
45
- PeerID: "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
46
- Address: "/ip4/104.131.131.82/tcp/4001",
47
- },
48
-}
49
-
50
-func datastoreConfig(dspath string) (config.Datastore, error) {
51
- ds := config.Datastore{}
52
- if len(dspath) == 0 {
53
- var err error
54
- dspath, err = config.DataStorePath("")
55
- if err != nil {
56
- return ds, err
57
- }
58
- }
59
- ds.Path = dspath
60
- ds.Type = "leveldb"
61
-
62
- // Construct the data store if missing
63
- if err := os.MkdirAll(dspath, os.ModePerm); err != nil {
64
- return ds, err
65
- }
66
-
67
- // Check the directory is writeable
68
- if f, err := os.Create(filepath.Join(dspath, "._check_writeable")); err == nil {
69
- os.Remove(f.Name())
70
- } else {
71
- return ds, errors.New("Datastore '" + dspath + "' is not writeable")
72
- }
73
-
74
- return ds, nil
75
-}
76
-
77
-func identityConfig(nbits int) (config.Identity, error) {
78
- ident := config.Identity{}
79
- fmt.Println("generating key pair...")
80
- sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits)
81
- if err != nil {
82
- return ident, err
83
- }
84
-
85
- // currently storing key unencrypted. in the future we need to encrypt it.
86
- // TODO(security)
87
- skbytes, err := sk.Bytes()
88
- if err != nil {
89
- return ident, err
90
- }
91
- ident.PrivKey = base64.StdEncoding.EncodeToString(skbytes)
92
-
93
- id, err := peer.IDFromPubKey(pk)
94
- if err != nil {
95
- return ident, err
96
- }
97
- ident.PeerID = id.Pretty()
98
-
99
- return ident, nil
100
-}
101
-
102
-func initCmd(c *commander.Command, inp []string) error {
103
- configpath, err := getConfigDir(c.Parent)
104
- if err != nil {
105
- return err
106
- }
107
-
108
- u.POut("initializing ipfs node at %s\n", configpath)
109
- filename, err := config.Filename(configpath)
110
- if err != nil {
111
- return errors.New("Couldn't get home directory path")
112
- }
113
-
114
- dspath, ok := c.Flag.Lookup("d").Value.Get().(string)
115
- if !ok {
116
- return errors.New("failed to parse datastore flag")
117
- }
118
-
119
- fi, err := os.Lstat(filename)
120
- force, ok := c.Flag.Lookup("f").Value.Get().(bool)
121
- if !ok {
122
- return errors.New("failed to parse force flag")
123
- }
124
- if fi != nil || (err != nil && !os.IsNotExist(err)) {
125
- if !force {
126
- return errors.New("ipfs configuration file already exists!\nReinitializing would overwrite your keys.\n(use -f to force overwrite)")
127
- }
128
- }
129
- cfg := new(config.Config)
130
-
131
- // setup the datastore
132
- cfg.Datastore, err = datastoreConfig(dspath)
133
- if err != nil {
134
- return err
135
- }
136
-
137
- // setup the node addresses.
138
- cfg.Addresses = config.Addresses{
139
- Swarm: "/ip4/0.0.0.0/tcp/4001",
140
- API: "/ip4/127.0.0.1/tcp/5001",
141
- }
142
-
143
- // setup the node mount points.
144
- cfg.Mounts = config.Mounts{
145
- IPFS: "/ipfs",
146
- IPNS: "/ipns",
147
- }
148
-
149
- nbits, ok := c.Flag.Lookup("b").Value.Get().(int)
150
- if !ok {
151
- return errors.New("failed to get bits flag")
152
- }
153
- if nbits < 1024 {
154
- return errors.New("Bitsize less than 1024 is considered unsafe.")
155
- }
156
-
157
- cfg.Identity, err = identityConfig(nbits)
158
- if err != nil {
159
- return err
160
- }
161
-
162
- // Use these hardcoded bootstrap peers for now.
163
- cfg.Bootstrap = defaultPeers
164
-
165
- // tracking ipfs version used to generate the init folder
166
- // and adding update checker default setting.
167
- cfg.Version = config.Version{
168
- Check: "error",
169
- Current: updates.Version,
170
- }
171
-
172
- err = config.WriteConfigFile(filename, cfg)
173
- if err != nil {
174
- return err
175
- }
176
-
177
- nd, err := core.NewIpfsNode(cfg, false)
178
- if err != nil {
179
- return err
180
- }
181
- defer nd.Close()
182
-
183
- // Set up default file
184
- msg := `Hello and Welcome to IPFS!
185
-If you're seeing this, that means that you have successfully
186
-installed ipfs and are now interfacing with the wonderful
187
-world of DAGs and hashes!
188
-`
189
- reader := bytes.NewBufferString(msg)
190
-
191
- defnd, err := imp.BuildDagFromReader(reader, nd.DAG, nd.Pinning.GetManual(), chunk.DefaultSplitter)
192
- if err != nil {
193
- return err
194
- }
195
-
196
- k, _ := defnd.Key()
197
- fmt.Printf("Default file key: %s\n", k)
198
-
199
- return nil
200
-}
cmd/ipfs/ipfs.go
deleted
-240
@@ -1,240 +0,0 @@
1
-package main
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "os"
7
- "runtime/pprof"
8
-
9
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
10
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
11
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
12
-
13
- config "github.com/jbenet/go-ipfs/config"
14
- core "github.com/jbenet/go-ipfs/core"
15
- daemon "github.com/jbenet/go-ipfs/daemon"
16
- updates "github.com/jbenet/go-ipfs/updates"
17
- u "github.com/jbenet/go-ipfs/util"
18
-)
19
-
20
-const heapProfile = "ipfs.mprof"
21
-
22
-// The IPFS command tree. It is an instance of `commander.Command`.
23
-var CmdIpfs = &commander.Command{
24
- UsageLine: "ipfs [<flags>] <command> [<args>]",
25
- Short: "global versioned p2p merkledag file system",
26
- Long: `ipfs - global versioned p2p merkledag file system
27
-
28
-Basic commands:
29
-
30
- init Initialize ipfs local configuration.
31
- add <path> Add an object to ipfs.
32
- cat <ref> Show ipfs object data.
33
- ls <ref> List links from an object.
34
- refs <ref> List link hashes from an object.
35
-
36
-Tool commands:
37
-
38
- config Manage configuration.
39
- update Download and apply go-ipfs updates.
40
- version Show ipfs version information.
41
- commands List all available commands.
42
-
43
-Advanced Commands:
44
-
45
- mount Mount an ipfs read-only mountpoint.
46
- serve Serve an interface to ipfs.
47
- net-diag Print network diagnostic
48
-
49
-Plumbing commands:
50
-
51
- block Interact with raw blocks in the datastore
52
- object Interact with raw dag nodes
53
-
54
-
55
-Use "ipfs help <command>" for more information about a command.
56
-`,
57
- Run: ipfsCmd,
58
- Subcommands: []*commander.Command{
59
- cmdIpfsAdd,
60
- cmdIpfsCat,
61
- cmdIpfsLs,
62
- cmdIpfsRefs,
63
- cmdIpfsConfig,
64
- cmdIpfsVersion,
65
- cmdIpfsCommands,
66
- cmdIpfsMount,
67
- cmdIpfsInit,
68
- cmdIpfsServe,
69
- cmdIpfsRun,
70
- cmdIpfsName,
71
- cmdIpfsBootstrap,
72
- cmdIpfsDiag,
73
- cmdIpfsBlock,
74
- cmdIpfsObject,
75
- cmdIpfsUpdate,
76
- cmdIpfsLog,
77
- cmdIpfsPin,
78
- cmdIpfsTour,
79
- },
80
- Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
81
-}
82
-
83
-// log is the command logger
84
-var log = u.Logger("cmd/ipfs")
85
-
86
-func init() {
87
- config, err := config.PathRoot()
88
- if err != nil {
89
- fmt.Fprintln(os.Stderr, "Failure initializing the default Config Directory: ", err)
90
- os.Exit(1)
91
- }
92
- CmdIpfs.Flag.String("c", config, "specify config directory")
93
-}
94
-
95
-func ipfsCmd(c *commander.Command, args []string) error {
96
- u.POut(c.Long)
97
- return nil
98
-}
99
-
100
-func main() {
101
- // if debugging, setup profiling.
102
- if u.Debug {
103
- ofi, err := os.Create("cpu.prof")
104
- defer ofi.Close()
105
-
106
- if err != nil {
107
- fmt.Println(err)
108
- return
109
- }
110
-
111
- pprof.StartCPUProfile(ofi)
112
- defer pprof.StopCPUProfile()
113
- }
114
-
115
- err := CmdIpfs.Dispatch(os.Args[1:])
116
- if err != nil {
117
- if len(err.Error()) > 0 {
118
- fmt.Fprintf(os.Stderr, "ipfs %s: %v\n", os.Args[1], err)
119
- }
120
- os.Exit(1)
121
- }
122
-
123
- if u.Debug {
124
- err := writeHeapProfileToFile()
125
- if err != nil {
126
- log.Critical(err)
127
- }
128
- }
129
- return
130
-}
131
-
132
-// localNode constructs a node
133
-func localNode(confdir string, online bool) (*core.IpfsNode, error) {
134
- filename, err := config.Filename(confdir)
135
- if err != nil {
136
- return nil, err
137
- }
138
-
139
- cfg, err := config.Load(filename)
140
- if err != nil {
141
- return nil, err
142
- }
143
-
144
- if err := updates.CliCheckForUpdates(cfg, filename); err != nil {
145
- return nil, err
146
- }
147
-
148
- return core.NewIpfsNode(cfg, online)
149
-}
150
-
151
-// Gets the config "-c" flag from the command, or returns
152
-// the default configuration root directory
153
-func getConfigDir(c *commander.Command) (string, error) {
154
-
155
- // use the root cmd (that's where config is specified)
156
- for ; c.Parent != nil; c = c.Parent {
157
- }
158
-
159
- // flag should be defined on root.
160
- param := c.Flag.Lookup("c").Value.Get().(string)
161
- if param != "" {
162
- return u.TildeExpansion(param)
163
- }
164
-
165
- return config.PathRoot()
166
-}
167
-
168
-func getConfig(c *commander.Command) (*config.Config, error) {
169
- confdir, err := getConfigDir(c)
170
- if err != nil {
171
- return nil, err
172
- }
173
-
174
- filename, err := config.Filename(confdir)
175
- if err != nil {
176
- return nil, err
177
- }
178
-
179
- return config.Load(filename)
180
-}
181
-
182
-// cmdContext is a wrapper structure that keeps a node, a daemonlistener, and
183
-// a config directory together. These three are needed for most commands.
184
-type cmdContext struct {
185
- node *core.IpfsNode
186
- daemon *daemon.DaemonListener
187
- configDir string
188
-}
189
-
190
-// setupCmdContext initializes a cmdContext structure from a given command.
191
-func setupCmdContext(c *commander.Command, online bool) (cc cmdContext, err error) {
192
- rootCmd := c
193
- for ; rootCmd.Parent != nil; rootCmd = rootCmd.Parent {
194
- }
195
-
196
- cc.configDir, err = getConfigDir(rootCmd)
197
- if err != nil {
198
- return
199
- }
200
-
201
- cc.node, err = localNode(cc.configDir, online)
202
- if err != nil {
203
- return
204
- }
205
-
206
- cc.daemon, err = setupDaemon(cc.configDir, cc.node)
207
- if err != nil {
208
- return
209
- }
210
-
211
- return
212
-}
213
-
214
-// setupDaemon sets up the daemon corresponding to given node.
215
-func setupDaemon(confdir string, node *core.IpfsNode) (*daemon.DaemonListener, error) {
216
- if node.Config.Addresses.API == "" {
217
- return nil, errors.New("no config.Addresses.API endpoint supplied")
218
- }
219
-
220
- maddr, err := ma.NewMultiaddr(node.Config.Addresses.API)
221
- if err != nil {
222
- return nil, err
223
- }
224
-
225
- dl, err := daemon.NewDaemonListener(node, maddr, confdir)
226
- if err != nil {
227
- return nil, err
228
- }
229
- go dl.Listen()
230
- return dl, nil
231
-}
232
-
233
-func writeHeapProfileToFile() error {
234
- mprof, err := os.Create(heapProfile)
235
- if err != nil {
236
- log.Fatal(err)
237
- }
238
- defer mprof.Close()
239
- return pprof.WriteHeapProfile(mprof)
240
-}
cmd/ipfs/log.go
deleted
-29
@@ -1,29 +0,0 @@
1
-package main
2
-
3
-import (
4
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsLog = &commander.Command{
10
- UsageLine: "log <name> <level> ",
11
- Short: "switch logging levels of a running daemon",
12
- Long: `ipfs log <name> <level> - switch logging levels of a running daemon
13
-
14
- <name> is a the subsystem logging identifier. Use * for all subsystems.
15
- <level> is one of: debug, info, notice, warning, error, critical
16
-
17
-ipfs log is a utility command used to change the logging output of a running daemon.
18
-`,
19
- Run: logCmd,
20
- Flag: *flag.NewFlagSet("ipfs-log", flag.ExitOnError),
21
-}
22
-
23
-var logCmd = makeCommand(command{
24
- name: "log",
25
- args: 2,
26
- flags: nil,
27
- online: true,
28
- cmdFn: commands.Log,
29
-})
cmd/ipfs/ls.go
deleted
-29
@@ -1,29 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsLs = &commander.Command{
10
- UsageLine: "ls",
11
- Short: "List links from an object.",
12
- Long: `ipfs ls <ipfs-path> - List links from an object.
13
-
14
- Retrieves the object named by <ipfs-path> and displays the links
15
- it contains, with the following format:
16
-
17
- <link base58 hash> <link size in bytes> <link name>
18
-
19
-`,
20
- Run: lsCmd,
21
- Flag: *flag.NewFlagSet("ipfs-ls", flag.ExitOnError),
22
-}
23
-
24
-var lsCmd = makeCommand(command{
25
- name: "ls",
26
- args: 1,
27
- flags: nil,
28
- cmdFn: commands.Ls,
29
-})
cmd/ipfs/mount_darwin.go
deleted
-33
@@ -1,33 +0,0 @@
1
-package main
2
-
3
-import (
4
- "fmt"
5
- "runtime"
6
- "strings"
7
- "syscall"
8
-)
9
-
10
-func init() {
11
- // this is a hack, but until we need to do it another way, this works.
12
- platformFuseChecks = darwinFuseCheckVersion
13
-}
14
-
15
-func darwinFuseCheckVersion() error {
16
- // on OSX, check FUSE version.
17
- if runtime.GOOS != "darwin" {
18
- return nil
19
- }
20
-
21
- ov, err := syscall.Sysctl("osxfuse.version.number")
22
- if err != nil {
23
- return err
24
- }
25
-
26
- if strings.HasPrefix(ov, "2.7.") || strings.HasPrefix(ov, "2.8.") {
27
- return nil
28
- }
29
-
30
- return fmt.Errorf("osxfuse version %s not supported.\n%s\n%s", ov,
31
- "Older versions of osxfuse have kernel panic bugs; please upgrade!",
32
- "https://github.com/jbenet/go-ipfs/issues/177")
33
-}
cmd/ipfs/mount_unix.go
deleted
-118
@@ -1,118 +0,0 @@
1
-// +build linux darwin freebsd
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
- "os"
8
- "os/signal"
9
- "syscall"
10
-
11
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
12
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
13
-
14
- core "github.com/jbenet/go-ipfs/core"
15
- ipns "github.com/jbenet/go-ipfs/fuse/ipns"
16
- mount "github.com/jbenet/go-ipfs/fuse/mount"
17
- rofs "github.com/jbenet/go-ipfs/fuse/readonly"
18
-)
19
-
20
-var cmdIpfsMount = &commander.Command{
21
- UsageLine: "mount",
22
- Short: "Mount an ipfs read-only mountpoint.",
23
- Long: `ipfs mount <os-path> - Mount an ipfs read-only mountpoint.
24
-
25
- Mount ipfs at a read-only mountpoint on the OS. All ipfs objects
26
- will be accessible under that directory. Note that the root will
27
- not be listable, as it is virtual. Accessing known paths directly.
28
-
29
-`,
30
- Run: mountCmd,
31
- Flag: *flag.NewFlagSet("ipfs-mount", flag.ExitOnError),
32
-}
33
-
34
-func init() {
35
- cmdIpfsMount.Flag.String("f", "", "specify a mountpoint for ipfs")
36
- cmdIpfsMount.Flag.String("n", "", "specify a mountpoint for ipns")
37
-}
38
-
39
-func mountCmd(c *commander.Command, inp []string) error {
40
- if err := platformFuseChecks(); err != nil {
41
- return err
42
- }
43
-
44
- cc, err := setupCmdContext(c, true)
45
- if err != nil {
46
- return err
47
- }
48
- defer cc.daemon.Close()
49
-
50
- // update fsdir with flag.
51
- fsdir := cc.node.Config.Mounts.IPFS
52
- if val, ok := c.Flag.Lookup("f").Value.Get().(string); ok && val != "" {
53
- fsdir = val
54
- }
55
-
56
- // get default mount points
57
- nsdir := cc.node.Config.Mounts.IPNS
58
- if val, ok := c.Flag.Lookup("n").Value.Get().(string); ok && val != "" {
59
- nsdir = val
60
- }
61
-
62
- return doMount(cc.node, fsdir, nsdir)
63
-}
64
-
65
-func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
66
-
67
- // this sync stuff is so that both can be mounted simultaneously.
68
- var fsmount mount.Mount
69
- var nsmount mount.Mount
70
- var err1 error
71
- var err2 error
72
-
73
- done := make(chan struct{})
74
-
75
- go func() {
76
- fsmount, err1 = rofs.Mount(node, fsdir)
77
- done <- struct{}{}
78
- }()
79
-
80
- go func() {
81
- nsmount, err2 = ipns.Mount(node, nsdir, fsdir)
82
- done <- struct{}{}
83
- }()
84
-
85
- <-done
86
- <-done
87
-
88
- if err1 != nil || err2 != nil {
89
- fsmount.Close()
90
- nsmount.Close()
91
- if err1 != nil {
92
- return err1
93
- } else {
94
- return err2
95
- }
96
- }
97
-
98
- fmt.Printf("mounted ipfs at %s\n", fsdir)
99
- fmt.Printf("mounted ipns at %s\n", nsdir)
100
-
101
- // setup node state, so that it can be cancelled
102
- node.Mounts.Ipfs = fsmount
103
- node.Mounts.Ipns = nsmount
104
-
105
- // wait until we kill
106
- sigc := make(chan os.Signal, 1)
107
- signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT,
108
- syscall.SIGTERM, syscall.SIGQUIT)
109
- <-sigc
110
-
111
- fmt.Println("unmounting...")
112
- node.Close()
113
- return nil
114
-}
115
-
116
-var platformFuseChecks = func() error {
117
- return nil
118
-}
cmd/ipfs/mount_windows.go
deleted
-19
@@ -1,19 +0,0 @@
1
-package main
2
-
3
-import (
4
- "errors"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
6
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
7
-)
8
-
9
-var cmdIpfsMount = &commander.Command{
10
- UsageLine: "mount",
11
- Short: "Mount an ipfs read-only mountpoint.",
12
- Long: `Not yet implemented on windows.`,
13
- Run: mountCmd,
14
- Flag: *flag.NewFlagSet("ipfs-mount", flag.ExitOnError),
15
-}
16
-
17
-func mountCmd(c *commander.Command, inp []string) error {
18
- return errors.New("mount not yet implemented on windows")
19
-}
cmd/ipfs/name.go
deleted
-57
@@ -1,57 +0,0 @@
1
-package main
2
-
3
-import (
4
- "fmt"
5
-
6
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
7
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
-)
9
-
10
-var cmdIpfsName = &commander.Command{
11
- UsageLine: "name [publish | resolve]",
12
- Short: "ipfs namespace (ipns) tool",
13
- Long: `ipfs name - Get/Set ipfs config values.
14
-
15
- ipfs name publish [<name>] <ref> - Assign the <ref> to <name>
16
- ipfs name resolve [<name>] - Resolve the <ref> value of <name>
17
-
18
-IPNS is a PKI namespace, where names are the hashes of public keys, and
19
-the private key enables publishing new (signed) values. In both publish
20
-and resolve, the default value of <name> is your own identity public key.
21
-
22
-
23
-Examples:
24
-
25
-Publish a <ref> to your identity name:
26
-
27
- > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
28
- published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
29
-
30
-Publish a <ref> to another public key:
31
-
32
- > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
33
- published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
34
-
35
-Resolve the value of your identity:
36
-
37
- > ipfs name resolve
38
- QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
39
-
40
-Resolve te value of another name:
41
-
42
- > ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
43
- QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
44
-
45
-`,
46
- Run: nameCmd,
47
- Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
48
- Subcommands: []*commander.Command{
49
- cmdIpfsPub,
50
- cmdIpfsResolve,
51
- },
52
-}
53
-
54
-func nameCmd(c *commander.Command, args []string) error {
55
- fmt.Println(c.Long)
56
- return nil
57
-}
cmd/ipfs/objects.go
deleted
-112
@@ -1,112 +0,0 @@
1
-package main
2
-
3
-import (
4
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsObject = &commander.Command{
10
- UsageLine: "object",
11
- Short: "interact with ipfs objects",
12
- Long: `ipfs object - interact with ipfs objects
13
-
14
- ipfs object data <key> - return the data for this key as raw bytes
15
- ipfs object links <key> - lists (the keys of ?) the links this key points to
16
- ipfs object get <key> - output dag object to stdout
17
- ipfs object put - add dag object from stdin
18
-
19
-ipfs object is a plumbing command used to manipulate dag objects directly.
20
-- <key> is a base58 encoded multihash.
21
-- It reads from stdin or writes to stdout.
22
-- It accepts multiple encodings: --encoding=[ protobuf, json, ... ]`,
23
- Subcommands: []*commander.Command{
24
- cmdIpfsObjectData,
25
- cmdIpfsObjectLinks,
26
- cmdIpfsObjectGet,
27
- cmdIpfsObjectPut,
28
- },
29
- Flag: *flag.NewFlagSet("ipfs-object", flag.ExitOnError),
30
-}
31
-
32
-var cmdIpfsObjectData = &commander.Command{
33
- UsageLine: "data <key>",
34
- Short: "data outputs the raw bytes named by <key>",
35
- Long: `ipfs data <key> - data outputs the raw bytes named by <key>
36
-
37
-ipfs data is a plumbing command for retreiving the raw bytes stored in a dag node.
38
-It outputs to stdout, and <key> is a base58 encoded multihash.`,
39
- Run: makeCommand(command{
40
- name: "objectData",
41
- args: 1,
42
- flags: nil,
43
- online: true,
44
- cmdFn: commands.ObjectData,
45
- }),
46
-}
47
-
48
-var cmdIpfsObjectLinks = &commander.Command{
49
- UsageLine: "links <key>",
50
- Short: "outputs the links pointed to by <key>",
51
- Long: `ipfs links <key> - outputs the links pointed to by <key>
52
-
53
-ipfs block get is a plumbing command for retreiving raw ipfs blocks.
54
-It outputs to stdout, and <key> is a base58 encoded multihash.`,
55
- Run: makeCommand(command{
56
- name: "objectLinks",
57
- args: 1,
58
- flags: nil,
59
- online: true,
60
- cmdFn: commands.ObjectLinks,
61
- }),
62
-}
63
-
64
-func init() {
65
- cmdIpfsObjectGet.Flag.String("encoding", "json", "the encoding to use..")
66
- cmdIpfsObjectPut.Flag.String("encoding", "json", "the encoding to use..")
67
-}
68
-
69
-var cmdIpfsObjectGet = &commander.Command{
70
- UsageLine: "get <key>",
71
- Short: "get and serialize the dag node named by <key>",
72
- Long: `ipfs get <key> - get and output the dag node named by <key>
73
-
74
-ipfs object get is a plumbing command for retreiving dag nodes.
75
-It serialize the dag node to the format specified by the format flag.
76
-It outputs to stdout, and <key> is a base58 encoded multihash.
77
-
78
-Formats:
79
-
80
-This command outputs and accepts data in a variety of encodings: protobuf, json, etc.
81
-Use the --encoding flag
82
-`,
83
- Run: makeCommand(command{
84
- name: "blockGet",
85
- args: 1,
86
- flags: []string{"encoding"},
87
- online: true,
88
- cmdFn: commands.ObjectGet,
89
- }),
90
-}
91
-
92
-var cmdIpfsObjectPut = &commander.Command{
93
- UsageLine: "put",
94
- Short: "store stdin as a dag object, outputs <key>",
95
- Long: `ipfs put - store stdin as a dag object, outputs <key>
96
-
97
-ipfs object put is a plumbing command for storing dag nodes.
98
-It serialize the dag node to the format specified by the format flag.
99
-It reads from stding, and <key> is a base58 encoded multihash.
100
-
101
-Formats:
102
-
103
-This command outputs and accepts data in a variety of encodings: protobuf, json, etc.
104
-Use the --encoding flag`,
105
- Run: makeCommand(command{
106
- name: "blockPut",
107
- args: 0,
108
- flags: []string{"encoding"},
109
- online: true,
110
- cmdFn: commands.ObjectPut,
111
- }),
112
-}
cmd/ipfs/pin.go
deleted
-62
@@ -1,62 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsPin = &commander.Command{
10
- UsageLine: "pin",
11
- Short: "",
12
- Long: `ipfs pin [add|rm] - object pinning commands
13
-`,
14
- Subcommands: []*commander.Command{
15
- cmdIpfsSubPin,
16
- cmdIpfsSubUnpin,
17
- },
18
-}
19
-
20
-var cmdIpfsSubPin = &commander.Command{
21
- UsageLine: "add",
22
- Short: "pin an ipfs object to local storage.",
23
- Long: `ipfs pin add <ipfs-path> - pin ipfs object to local storage.
24
-
25
- Retrieves the object named by <ipfs-path> and stores it locally
26
- on disk.
27
-`,
28
- Run: pinSubCmd,
29
- Flag: *flag.NewFlagSet("ipfs-pin", flag.ExitOnError),
30
-}
31
-
32
-var pinSubCmd = makeCommand(command{
33
- name: "pin",
34
- args: 1,
35
- flags: []string{"r", "d"},
36
- cmdFn: commands.Pin,
37
-})
38
-
39
-var cmdIpfsSubUnpin = &commander.Command{
40
- UsageLine: "rm",
41
- Short: "unpin an ipfs object from local storage.",
42
- Long: `ipfs pin rm <ipfs-path> - unpin ipfs object from local storage.
43
-
44
- Removes the pin from the given object allowing it to be garbage
45
- collected if needed.
46
-`,
47
- Run: unpinSubCmd,
48
- Flag: *flag.NewFlagSet("ipfs-unpin", flag.ExitOnError),
49
-}
50
-
51
-var unpinSubCmd = makeCommand(command{
52
- name: "unpin",
53
- args: 1,
54
- flags: []string{"r"},
55
- cmdFn: commands.Unpin,
56
-})
57
-
58
-func init() {
59
- cmdIpfsSubPin.Flag.Bool("r", false, "pin objects recursively")
60
- cmdIpfsSubPin.Flag.Int("d", 1, "recursive depth")
61
- cmdIpfsSubUnpin.Flag.Bool("r", false, "unpin objects recursively")
62
-}
cmd/ipfs/publish.go
deleted
-41
@@ -1,41 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsPub = &commander.Command{
10
- UsageLine: "publish",
11
- Short: "publish a <ref> to ipns.",
12
- Long: `ipfs publish [<name>] <ref> - publish a <ref> to ipns.
13
-
14
-IPNS is a PKI namespace, where names are the hashes of public keys, and
15
-the private key enables publishing new (signed) values. In publish, the
16
-default value of <name> is your own identity public key.
17
-
18
-Examples:
19
-
20
-Publish a <ref> to your identity name:
21
-
22
- > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
23
- published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
24
-
25
-Publish a <ref> to another public key:
26
-
27
- > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
28
- published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
29
-
30
-`,
31
- Run: pubCmd,
32
- Flag: *flag.NewFlagSet("ipfs-publish", flag.ExitOnError),
33
-}
34
-
35
-var pubCmd = makeCommand(command{
36
- name: "publish",
37
- args: 1,
38
- flags: nil,
39
- online: true,
40
- cmdFn: commands.Publish,
41
-})
cmd/ipfs/refs.go
deleted
-36
@@ -1,36 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- commands "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsRefs = &commander.Command{
10
- UsageLine: "refs",
11
- Short: "List link hashes from an object.",
12
- Long: `ipfs refs <ipfs-path> - List link hashes from an object..
13
-
14
- Retrieves the object named by <ipfs-path> and displays the link
15
- hashes it contains, with the following format:
16
-
17
- <link base58 hash>
18
-
19
- Note: list all refs recursively with -r.
20
-
21
-`,
22
- Run: refCmd,
23
- Flag: *flag.NewFlagSet("ipfs-refs", flag.ExitOnError),
24
-}
25
-
26
-func init() {
27
- cmdIpfsRefs.Flag.Bool("r", false, "recursive: list refs recursively")
28
- cmdIpfsRefs.Flag.Bool("u", false, "unique: list each ref only once")
29
-}
30
-
31
-var refCmd = makeCommand(command{
32
- name: "refs",
33
- args: 1,
34
- flags: []string{"r", "u"},
35
- cmdFn: commands.Refs,
36
-})
cmd/ipfs/resolve.go
deleted
-42
@@ -1,42 +0,0 @@
1
-package main
2
-
3
-import (
4
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-var cmdIpfsResolve = &commander.Command{
10
- UsageLine: "resolve",
11
- Short: "resolve an ipns name to a <ref>",
12
- Long: `ipfs resolve [<name>] - Resolve an ipns name to a <ref>.
13
-
14
-IPNS is a PKI namespace, where names are the hashes of public keys, and
15
-the private key enables publishing new (signed) values. In resolve, the
16
-default value of <name> is your own identity public key.
17
-
18
-
19
-Examples:
20
-
21
-Resolve the value of your identity:
22
-
23
- > ipfs name resolve
24
- QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
25
-
26
-Resolve te value of another name:
27
-
28
- > ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
29
- QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
30
-
31
-`,
32
- Run: resolveCmd,
33
- Flag: *flag.NewFlagSet("ipfs-resolve", flag.ExitOnError),
34
-}
35
-
36
-var resolveCmd = makeCommand(command{
37
- name: "resolve",
38
- args: 0,
39
- flags: nil,
40
- online: true,
41
- cmdFn: commands.Resolve,
42
-})
cmd/ipfs/run.go
deleted
-36
@@ -1,36 +0,0 @@
1
-package main
2
-
3
-import (
4
- "os"
5
- "os/signal"
6
- "syscall"
7
-
8
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
9
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
10
-)
11
-
12
-var cmdIpfsRun = &commander.Command{
13
- UsageLine: "run",
14
- Short: "run local ifps node.",
15
- Long: `run a local ipfs node with no other interface.
16
-`,
17
- Run: runCmd,
18
- Flag: *flag.NewFlagSet("ipfs-run", flag.ExitOnError),
19
-}
20
-
21
-func runCmd(c *commander.Command, inp []string) error {
22
- cc, err := setupCmdContext(c, true)
23
- if err != nil {
24
- return err
25
- }
26
-
27
- sigc := make(chan os.Signal, 1)
28
- signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT,
29
- syscall.SIGTERM, syscall.SIGQUIT)
30
-
31
- // wait until we get a signal to exit.
32
- <-sigc
33
-
34
- cc.daemon.Close()
35
- return nil
36
-}
cmd/ipfs/serve.go
deleted
-49
@@ -1,49 +0,0 @@
1
-package main
2
-
3
-import (
4
- "fmt"
5
-
6
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
-
10
- h "github.com/jbenet/go-ipfs/server/http"
11
-)
12
-
13
-var cmdIpfsServe = &commander.Command{
14
- UsageLine: "serve",
15
- Short: "Serve an interface to ipfs",
16
- Subcommands: []*commander.Command{
17
- cmdIpfsServeHTTP,
18
- },
19
- Flag: *flag.NewFlagSet("ipfs-serve", flag.ExitOnError),
20
-}
21
-
22
-var cmdIpfsServeHTTP = &commander.Command{
23
- UsageLine: "http",
24
- Short: "Serve an HTTP API",
25
- Long: `ipfs serve http - Serve an http gateway into ipfs.`,
26
- Run: serveHTTPCmd,
27
- Flag: *flag.NewFlagSet("ipfs-serve-http", flag.ExitOnError),
28
-}
29
-
30
-func init() {
31
- cmdIpfsServeHTTP.Flag.String("address", "/ip4/127.0.0.1/tcp/8080", "Listen Address")
32
-}
33
-
34
-func serveHTTPCmd(c *commander.Command, _ []string) error {
35
- cc, err := setupCmdContext(c, true)
36
- if err != nil {
37
- return err
38
- }
39
- defer cc.daemon.Close()
40
-
41
- address := c.Flag.Lookup("address").Value.Get().(string)
42
- maddr, err := ma.NewMultiaddr(address)
43
- if err != nil {
44
- return err
45
- }
46
-
47
- fmt.Printf("Serving on %s\n", address)
48
- return h.Serve(maddr, cc.node)
49
-}
cmd/ipfs/tour.go
deleted
-134
@@ -1,134 +0,0 @@
1
-// +build linux darwin freebsd
2
-
3
-package main
4
-
5
-import (
6
- "fmt"
7
-
8
- config "github.com/jbenet/go-ipfs/config"
9
- tour "github.com/jbenet/go-ipfs/tour"
10
-
11
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
12
-)
13
-
14
-var cmdIpfsTour = &commander.Command{
15
- UsageLine: "tour [<number>]",
16
- Short: "Take the IPFS Tour.",
17
- Long: `ipfs tour - Take the IPFS Tour.
18
-
19
- ipfs tour [<number>] - Show tour topic. Default to current.
20
- ipfs tour next - Show the next tour topic.
21
- ipfs tour list - Show a list of topics.
22
- ipfs tour restart - Restart the tour.
23
-
24
-This is a tour that takes you through various IPFS concepts,
25
-features, and tools to make sure you get up to speed with
26
-IPFS very quickly. To start, run:
27
-
28
- ipfs tour
29
-`,
30
- Run: tourCmd,
31
- Subcommands: []*commander.Command{
32
- cmdIpfsTourNext,
33
- cmdIpfsTourList,
34
- cmdIpfsTourRestart,
35
- },
36
-}
37
-
38
-var cmdIpfsTourNext = &commander.Command{
39
- UsageLine: "next",
40
- Short: "Show the next IPFS Tour topic.",
41
- Run: tourNextCmd,
42
-}
43
-
44
-var cmdIpfsTourList = &commander.Command{
45
- UsageLine: "list",
46
- Short: "Show a list of IPFS Tour topics.",
47
- Run: tourListCmd,
48
-}
49
-
50
-var cmdIpfsTourRestart = &commander.Command{
51
- UsageLine: "restart",
52
- Short: "Restart the IPFS Tour.",
53
- Run: tourRestartCmd,
54
-}
55
-
56
-func tourCmd(c *commander.Command, inp []string) error {
57
- cfg, err := getConfig(c)
58
- if err != nil {
59
- return err
60
- }
61
-
62
- topic := tour.TopicID(cfg.Tour.Last)
63
- if len(inp) > 0 {
64
- topic = tour.TopicID(inp[0])
65
- }
66
- return tourShow(topic)
67
-}
68
-
69
-func tourNextCmd(c *commander.Command, _ []string) error {
70
- cfg, err := getConfig(c)
71
- if err != nil {
72
- return err
73
- }
74
-
75
- topic := tour.NextTopic(tour.TopicID(cfg.Tour.Last))
76
- if err := tourShow(topic); err != nil {
77
- return err
78
- }
79
-
80
- // if topic didn't change (last) done
81
- if string(topic) == cfg.Tour.Last {
82
- return nil
83
- }
84
-
85
- // topic changed, not last. write it out.
86
- cfg.Tour.Last = string(topic)
87
- return writeConfig(c, cfg)
88
-}
89
-
90
-func tourListCmd(c *commander.Command, _ []string) error {
91
- cfg, err := getConfig(c)
92
- if err != nil {
93
- return err
94
- }
95
- lastid := tour.TopicID(cfg.Tour.Last)
96
-
97
- for _, id := range tour.IDs {
98
- c := ' '
99
- switch {
100
- case id == lastid:
101
- c = '*'
102
- case id.LessThan(lastid):
103
- c = '✓'
104
- }
105
-
106
- t := tour.Topics[id]
107
- fmt.Printf("- %c %-5.5s %s\n", c, id, t.Title)
108
- }
109
- return nil
110
-}
111
-
112
-func tourRestartCmd(c *commander.Command, _ []string) error {
113
- cfg, err := getConfig(c)
114
- if err != nil {
115
- return err
116
- }
117
-
118
- cfg.Tour.Last = ""
119
- return writeConfig(c, cfg)
120
-}
121
-
122
-func tourShow(id tour.ID) error {
123
- t, found := tour.Topics[id]
124
- if !found {
125
- return fmt.Errorf("no topic with id: %s", id)
126
- }
127
-
128
- fmt.Printf("Tour %s - %s\n\n%s\n", t.ID, t.Title, t.Text)
129
- return nil
130
-}
131
-
132
-func lastTour(cfg *config.Config) string {
133
- return ""
134
-}
cmd/ipfs/update.go
deleted
-62
@@ -1,62 +0,0 @@
1
-package main
2
-
3
-import (
4
- flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5
- commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6
- "github.com/jbenet/go-ipfs/core/commands"
7
-)
8
-
9
-func init() {
10
- cmdIpfsUpdate.Flag.Bool("force", false, "force shutdown of daemon when updating")
11
-}
12
-
13
-var cmdIpfsUpdate = &commander.Command{
14
- UsageLine: "update",
15
- Short: "check for updates and apply them",
16
- Long: `ipfs update - check for updates and apply them
17
-
18
- ipfs update <version> - apply
19
- ipfs update check - just check
20
- ipfs update log - list the changelogs
21
-
22
-ipfs update is a utility command used to check for updates and apply them.
23
-I wont even try, @jbenet. You do this much better :)`,
24
- Run: makeCommand(command{
25
- name: "updateApply",
26
- args: 0,
27
- flags: []string{"force"},
28
- online: true,
29
- cmdFn: commands.UpdateApply,
30
- }),
31
- Subcommands: []*commander.Command{
32
- cmdIpfsUpdateCheck,
33
- cmdIpfsUpdateLog,
34
- },
35
- Flag: *flag.NewFlagSet("ipfs-update", flag.ExitOnError),
36
-}
37
-
38
-var cmdIpfsUpdateCheck = &commander.Command{
39
- UsageLine: "check",
40
- Short: "",
41
- Long: `ipfs update check <key>`,
42
- Run: makeCommand(command{
43
- name: "updateCheck",
44
- args: 0,
45
- flags: nil,
46
- online: false,
47
- cmdFn: commands.UpdateCheck,
48
- }),
49
-}
50
-
51
-var cmdIpfsUpdateLog = &commander.Command{
52
- UsageLine: "log",
53
- Short: "list the last versions and their changelog",
54
- Long: `ipfs updage log - list the last versions and their changelog`,
55
- Run: makeCommand(command{
56
- name: "updateLog",
57
- args: 0,
58
- flags: nil,
59
- online: false,
60
- cmdFn: commands.UpdateCheck,
61
- }),
62
-}
cmd/ipfs/version.go
deleted
-31
@@ -1,31 +0,0 @@
1
-package main
2
-
3
-import (
4
- config "github.com/jbenet/go-ipfs/config"
5
- u "github.com/jbenet/go-ipfs/util"
6
-
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
8
-)
9
-
10
-var cmdIpfsVersion = &commander.Command{
11
- UsageLine: "version",
12
- Short: "Show ipfs version information.",
13
- Long: `ipfs version - Show ipfs version information.
14
-
15
- Returns the current version of ipfs and exits.
16
- `,
17
- Run: versionCmd,
18
-}
19
-
20
-func init() {
21
- cmdIpfsVersion.Flag.Bool("number", false, "show only the number")
22
-}
23
-
24
-func versionCmd(c *commander.Command, _ []string) error {
25
- number := c.Flag.Lookup("number").Value.Get().(bool)
26
- if !number {
27
- u.POut("ipfs version ")
28
- }
29
- u.POut("%s\n", config.CurrentVersionNumber)
30
- return nil
31
-}
core/commands/add.go
deleted
-136
@@ -1,136 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "io"
7
- "io/ioutil"
8
- "os"
9
- "path/filepath"
10
-
11
- "github.com/jbenet/go-ipfs/core"
12
- "github.com/jbenet/go-ipfs/importer"
13
- dag "github.com/jbenet/go-ipfs/merkledag"
14
- "github.com/jbenet/go-ipfs/pin"
15
- ft "github.com/jbenet/go-ipfs/unixfs"
16
-)
17
-
18
-// Error indicating the max depth has been exceded.
19
-var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
20
-
21
-// Add is a command that imports files and directories -- given as arguments -- into ipfs.
22
-func Add(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
23
- depth := 1
24
-
25
- // if recursive, set depth to reflect so
26
- if r, ok := opts["r"].(bool); r && ok {
27
- depth = -1
28
- }
29
-
30
- // add every path in args
31
- for _, path := range args {
32
-
33
- // Add the file
34
- _, err := AddPath(n, path, depth, out)
35
- if err != nil {
36
- if err == ErrDepthLimitExceeded && depth == 1 {
37
- err = errors.New("use -r to recursively add directories")
38
- }
39
- return fmt.Errorf("addFile error: %v", err)
40
- }
41
-
42
- }
43
- return nil
44
-}
45
-
46
-// AddPath adds a particular path to ipfs.
47
-func AddPath(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
48
- if depth == 0 {
49
- return nil, ErrDepthLimitExceeded
50
- }
51
-
52
- fi, err := os.Stat(fpath)
53
- if err != nil {
54
- return nil, err
55
- }
56
-
57
- if fi.IsDir() {
58
- return addDir(n, fpath, depth, out)
59
- }
60
-
61
- return addFile(n, fpath, depth, out)
62
-}
63
-
64
-func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
65
- tree := &dag.Node{Data: ft.FolderPBData()}
66
-
67
- files, err := ioutil.ReadDir(fpath)
68
- if err != nil {
69
- return nil, err
70
- }
71
-
72
- // construct nodes for containing files.
73
- for _, f := range files {
74
- fp := filepath.Join(fpath, f.Name())
75
- nd, err := AddPath(n, fp, depth-1, out)
76
- if err != nil {
77
- return nil, err
78
- }
79
-
80
- if err = tree.AddNodeLink(f.Name(), nd); err != nil {
81
- return nil, err
82
- }
83
- }
84
-
85
- log.Infof("adding dir: %s", fpath)
86
-
87
- return tree, addNode(n, tree, fpath, out)
88
-}
89
-
90
-func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
91
- mp, ok := n.Pinning.(pin.ManualPinner)
92
- if !ok {
93
- return nil, errors.New("invalid pinner type! expected manual pinner")
94
- }
95
-
96
- root, err := importer.BuildDagFromFile(fpath, n.DAG, mp)
97
- if err != nil {
98
- return nil, err
99
- }
100
-
101
- log.Infof("adding file: %s", fpath)
102
-
103
- for _, l := range root.Links {
104
- log.Infof("adding subblock: '%s' %s", l.Name, l.Hash.B58String())
105
- }
106
-
107
- k, err := root.Key()
108
- if err != nil {
109
- return nil, err
110
- }
111
-
112
- // output that we've added this node
113
- fmt.Fprintf(out, "added %s %s\n", k, fpath)
114
-
115
- return root, nil
116
-}
117
-
118
-// addNode adds the node to the graph + local storage
119
-func addNode(n *core.IpfsNode, nd *dag.Node, fpath string, out io.Writer) error {
120
- // add the file to the graph + local storage
121
- err := n.DAG.AddRecursive(nd)
122
- if err != nil {
123
- return err
124
- }
125
-
126
- k, err := nd.Key()
127
- if err != nil {
128
- return err
129
- }
130
-
131
- // output that we've added this node
132
- fmt.Fprintf(out, "added %s %s\n", k, fpath)
133
-
134
- // ensure we keep it
135
- return n.Pinning.Pin(nd, true)
136
-}
core/commands/block.go
deleted
-60
@@ -1,60 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "fmt"
5
- "io"
6
- "io/ioutil"
7
- "os"
8
- "time"
9
-
10
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11
-
12
- mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
13
- "github.com/jbenet/go-ipfs/blocks"
14
- "github.com/jbenet/go-ipfs/core"
15
- u "github.com/jbenet/go-ipfs/util"
16
-)
17
-
18
-// BlockGet retrives a raw ipfs block from the node's BlockService
19
-func BlockGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
20
-
21
- if !u.IsValidHash(args[0]) {
22
- return fmt.Errorf("block get: not a valid hash")
23
- }
24
-
25
- h, err := mh.FromB58String(args[0])
26
- if err != nil {
27
- return fmt.Errorf("block get: %v", err)
28
- }
29
-
30
- k := u.Key(h)
31
- log.Debugf("BlockGet key: '%q'", k)
32
- ctx, _ := context.WithTimeout(context.TODO(), time.Second*5)
33
- b, err := n.Blocks.GetBlock(ctx, k)
34
- if err != nil {
35
- return fmt.Errorf("block get: %v", err)
36
- }
37
-
38
- _, err = out.Write(b.Data)
39
- return err
40
-}
41
-
42
-// BlockPut reads everything from conn and saves the data to the nodes BlockService
43
-func BlockPut(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
44
- // TODO: this should read from an io.Reader arg
45
- data, err := ioutil.ReadAll(os.Stdin)
46
- if err != nil {
47
- return err
48
- }
49
-
50
- b := blocks.NewBlock(data)
51
- log.Debugf("BlockPut key: '%q'", b.Key())
52
-
53
- k, err := n.Blocks.AddBlock(b)
54
- if err != nil {
55
- return err
56
- }
57
- fmt.Fprintf(out, "added as '%s'\n", k)
58
-
59
- return nil
60
-}
core/commands/cat.go
deleted
-29
@@ -1,29 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "fmt"
5
- "io"
6
-
7
- "github.com/jbenet/go-ipfs/core"
8
- uio "github.com/jbenet/go-ipfs/unixfs/io"
9
-)
10
-
11
-func Cat(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12
- for _, fn := range args {
13
- dagnode, err := n.Resolver.ResolvePath(fn)
14
- if err != nil {
15
- return fmt.Errorf("catFile error: %v", err)
16
- }
17
-
18
- read, err := uio.NewDagReader(dagnode, n.DAG)
19
- if err != nil {
20
- return fmt.Errorf("cat error: %v", err)
21
- }
22
-
23
- _, err = io.Copy(out, read)
24
- if err != nil {
25
- return fmt.Errorf("cat error: %v", err)
26
- }
27
- }
28
- return nil
29
-}
core/commands/commands.go
deleted
-12
@@ -1,12 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "io"
5
-
6
- "github.com/jbenet/go-ipfs/core"
7
- u "github.com/jbenet/go-ipfs/util"
8
-)
9
-
10
-var log = u.Logger("commands")
11
-
12
-type CmdFunc func(*core.IpfsNode, []string, map[string]interface{}, io.Writer) error
core/commands/diag.go
deleted
-49
@@ -1,49 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "encoding/json"
5
- "errors"
6
- "fmt"
7
- "io"
8
- "time"
9
-
10
- "github.com/jbenet/go-ipfs/core"
11
- diagn "github.com/jbenet/go-ipfs/diagnostics"
12
-)
13
-
14
-func PrintDiagnostics(info []*diagn.DiagInfo, out io.Writer) {
15
- for _, i := range info {
16
- fmt.Fprintf(out, "Peer: %s\n", i.ID)
17
- fmt.Fprintf(out, "\tUp for: %s\n", i.LifeSpan.String())
18
- fmt.Fprintf(out, "\tConnected To:\n")
19
- for _, c := range i.Connections {
20
- fmt.Fprintf(out, "\t%s\n\t\tLatency = %s\n", c.ID, c.Latency.String())
21
- }
22
- fmt.Fprintln(out)
23
- }
24
-
25
-}
26
-
27
-func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
28
- if n.Diagnostics == nil {
29
- return errors.New("Cannot run diagnostic in offline mode!")
30
- }
31
- info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
32
- if err != nil {
33
- return err
34
- }
35
- raw, ok := opts["raw"].(bool)
36
- if !ok {
37
- return errors.New("incorrect value to parameter 'raw'")
38
- }
39
- if raw {
40
- enc := json.NewEncoder(out)
41
- err = enc.Encode(info)
42
- if err != nil {
43
- return err
44
- }
45
- } else {
46
- PrintDiagnostics(info, out)
47
- }
48
- return nil
49
-}
core/commands/log.go
deleted
-18
@@ -1,18 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "io"
5
-
6
- "github.com/jbenet/go-ipfs/core"
7
- u "github.com/jbenet/go-ipfs/util"
8
-)
9
-
10
-// Log changes the log level of a subsystem
11
-func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12
- if err := u.SetLogLevel(args[0], args[1]); err != nil {
13
- return err
14
- }
15
-
16
- log.Info("Changed LogLevel of %q to %q", args[0], args[1])
17
- return nil
18
-}
core/commands/ls.go
deleted
-22
@@ -1,22 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "fmt"
5
- "io"
6
-
7
- "github.com/jbenet/go-ipfs/core"
8
-)
9
-
10
-func Ls(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11
- for _, fn := range args {
12
- dagnode, err := n.Resolver.ResolvePath(fn)
13
- if err != nil {
14
- return fmt.Errorf("ls error: %v", err)
15
- }
16
-
17
- for _, link := range dagnode.Links {
18
- fmt.Fprintf(out, "%s %d %s\n", link.Hash.B58String(), link.Size, link.Name)
19
- }
20
- }
21
- return nil
22
-}
core/commands/object.go
deleted
-135
@@ -1,135 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "bytes"
5
- "encoding/json"
6
- "errors"
7
- "fmt"
8
- "io"
9
- "io/ioutil"
10
- "os"
11
-
12
- "github.com/jbenet/go-ipfs/core"
13
- dag "github.com/jbenet/go-ipfs/merkledag"
14
-)
15
-
16
-// ObjectData takes a key string from args and writes out the raw bytes of that node (if there is one)
17
-func ObjectData(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
18
- dagnode, err := n.Resolver.ResolvePath(args[0])
19
- if err != nil {
20
- return fmt.Errorf("objectData error: %v", err)
21
- }
22
- log.Debugf("objectData: found dagnode %q (# of bytes: %d - # links: %d)", args[0], len(dagnode.Data), len(dagnode.Links))
23
-
24
- _, err = io.Copy(out, bytes.NewReader(dagnode.Data))
25
- return err
26
-}
27
-
28
-// ObjectLinks takes a key string from args and lists the links it points to
29
-func ObjectLinks(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
30
- dagnode, err := n.Resolver.ResolvePath(args[0])
31
- if err != nil {
32
- return fmt.Errorf("objectLinks error: %v", err)
33
- }
34
- log.Debugf("ObjectLinks: found dagnode %q (# of bytes: %d - # links: %d)", args[0], len(dagnode.Data), len(dagnode.Links))
35
-
36
- for _, link := range dagnode.Links {
37
- _, err = fmt.Fprintf(out, "%s %d %q\n", link.Hash.B58String(), link.Size, link.Name)
38
- if err != nil {
39
- break
40
- }
41
- }
42
-
43
- return err
44
-}
45
-
46
-// ErrUnknownObjectEnc is returned if a invalid encoding is supplied
47
-var ErrUnknownObjectEnc = errors.New("unknown object encoding")
48
-
49
-type objectEncoding string
50
-
51
-const (
52
- objectEncodingJSON objectEncoding = "json"
53
- objectEncodingProtobuf = "protobuf"
54
-)
55
-
56
-func getObjectEnc(o interface{}) objectEncoding {
57
- v, ok := o.(string)
58
- if !ok {
59
- // chosen as default because it's human readable
60
- log.Warning("option is not a string - falling back to json")
61
- return objectEncodingJSON
62
- }
63
-
64
- return objectEncoding(v)
65
-}
66
-
67
-// ObjectGet takes a key string from args and a format option and serializes the dagnode to that format
68
-func ObjectGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
69
- dagnode, err := n.Resolver.ResolvePath(args[0])
70
- if err != nil {
71
- return fmt.Errorf("ObjectGet error: %v", err)
72
- }
73
- log.Debugf("objectGet: found dagnode %q (# of bytes: %d - # links: %d)", args[0], len(dagnode.Data), len(dagnode.Links))
74
-
75
- // sadly all encodings dont implement a common interface
76
- var data []byte
77
- switch getObjectEnc(opts["encoding"]) {
78
- case objectEncodingJSON:
79
- data, err = json.MarshalIndent(dagnode, "", " ")
80
-
81
- case objectEncodingProtobuf:
82
- data, err = dagnode.Marshal()
83
-
84
- default:
85
- return ErrUnknownObjectEnc
86
- }
87
-
88
- if err != nil {
89
- return fmt.Errorf("ObjectGet error: %v", err)
90
- }
91
-
92
- _, err = io.Copy(out, bytes.NewReader(data))
93
- return err
94
-}
95
-
96
-// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 512k
97
-var ErrObjectTooLarge = errors.New("input object was too large. limit is 512kbytes")
98
-
99
-const inputLimit = 512 * 1024
100
-
101
-// ObjectPut takes a format option, serilizes bytes from stdin and updates the dag with that data
102
-func ObjectPut(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
103
- var (
104
- dagnode *dag.Node
105
- data []byte
106
- err error
107
- )
108
-
109
- data, err = ioutil.ReadAll(io.LimitReader(os.Stdin, inputLimit+10))
110
- if err != nil {
111
- return fmt.Errorf("ObjectPut error: %v", err)
112
- }
113
-
114
- if len(data) >= inputLimit {
115
- return ErrObjectTooLarge
116
- }
117
-
118
- switch getObjectEnc(opts["encoding"]) {
119
- case objectEncodingJSON:
120
- dagnode = new(dag.Node)
121
- err = json.Unmarshal(data, dagnode)
122
-
123
- case objectEncodingProtobuf:
124
- dagnode, err = dag.Decoded(data)
125
-
126
- default:
127
- return ErrUnknownObjectEnc
128
- }
129
-
130
- if err != nil {
131
- return fmt.Errorf("ObjectPut error: %v", err)
132
- }
133
-
134
- return addNode(n, dagnode, "stdin", out)
135
-}
core/commands/pin.go
deleted
-58
@@ -1,58 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "fmt"
5
- "io"
6
-
7
- "github.com/jbenet/go-ipfs/core"
8
-)
9
-
10
-func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11
-
12
- // set recursive flag
13
- recursive, _ := opts["r"].(bool) // false if cast fails.
14
-
15
- // if recursive, set depth flag
16
- depth := 1 // default (non recursive)
17
- if d, ok := opts["d"].(int); recursive && ok {
18
- depth = d
19
- }
20
- if depth < -1 {
21
- return fmt.Errorf("ipfs pin: called with invalid depth: %v", depth)
22
- }
23
-
24
- fmt.Printf("recursive, depth: %v, %v\n", recursive, depth)
25
-
26
- for _, fn := range args {
27
- dagnode, err := n.Resolver.ResolvePath(fn)
28
- if err != nil {
29
- return fmt.Errorf("pin error: %v", err)
30
- }
31
-
32
- err = n.Pinning.Pin(dagnode, recursive)
33
- if err != nil {
34
- return fmt.Errorf("pin: %v", err)
35
- }
36
- }
37
- return n.Pinning.Flush()
38
-}
39
-
40
-func Unpin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
41
-
42
- // set recursive flag
43
- recursive, _ := opts["r"].(bool) // false if cast fails.
44
-
45
- for _, fn := range args {
46
- dagnode, err := n.Resolver.ResolvePath(fn)
47
- if err != nil {
48
- return fmt.Errorf("pin error: %v", err)
49
- }
50
-
51
- k, _ := dagnode.Key()
52
- err = n.Pinning.Unpin(k, recursive)
53
- if err != nil {
54
- return fmt.Errorf("pin: %v", err)
55
- }
56
- }
57
- return n.Pinning.Flush()
58
-}
core/commands/publish.go
deleted
-53
@@ -1,53 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "io"
7
-
8
- "github.com/jbenet/go-ipfs/core"
9
- u "github.com/jbenet/go-ipfs/util"
10
-
11
- nsys "github.com/jbenet/go-ipfs/namesys"
12
-)
13
-
14
-func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
15
- log.Debug("Begin Publish")
16
-
17
- if n.Identity == nil {
18
- return errors.New("Identity not loaded!")
19
- }
20
-
21
- // name := ""
22
- ref := ""
23
-
24
- switch len(args) {
25
- case 2:
26
- // name = args[0]
27
- ref = args[1]
28
- return errors.New("keychains not yet implemented")
29
- case 1:
30
- // name = n.Identity.ID.String()
31
- ref = args[0]
32
-
33
- default:
34
- return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
35
- }
36
-
37
- // later, n.Keychain.Get(name).PrivKey
38
- k := n.Identity.PrivKey()
39
-
40
- pub := nsys.NewRoutingPublisher(n.Routing)
41
- err := pub.Publish(k, ref)
42
- if err != nil {
43
- return err
44
- }
45
-
46
- hash, err := k.GetPublic().Hash()
47
- if err != nil {
48
- return err
49
- }
50
- fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
51
-
52
- return nil
53
-}
core/commands/refs.go
deleted
-65
@@ -1,65 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "io"
5
-
6
- mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
7
- "github.com/jbenet/go-ipfs/core"
8
- mdag "github.com/jbenet/go-ipfs/merkledag"
9
- u "github.com/jbenet/go-ipfs/util"
10
-)
11
-
12
-func Refs(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
13
- unique, ok := opts["u"].(bool)
14
- if !ok {
15
- unique = false
16
- }
17
-
18
- recursive, ok := opts["r"].(bool)
19
- if !ok {
20
- recursive = false
21
- }
22
-
23
- var refsSeen map[u.Key]bool
24
- if unique {
25
- refsSeen = make(map[u.Key]bool)
26
- }
27
-
28
- for _, fn := range args {
29
- nd, err := n.Resolver.ResolvePath(fn)
30
- if err != nil {
31
- return err
32
- }
33
-
34
- printRefs(n, nd, refsSeen, recursive)
35
- }
36
- return nil
37
-}
38
-
39
-func printRefs(n *core.IpfsNode, nd *mdag.Node, refSeen map[u.Key]bool, recursive bool) {
40
- for _, link := range nd.Links {
41
- printRef(link.Hash, refSeen)
42
-
43
- if recursive {
44
- nd, err := n.DAG.Get(u.Key(link.Hash))
45
- if err != nil {
46
- log.Errorf("error: cannot retrieve %s (%s)", link.Hash.B58String(), err)
47
- return
48
- }
49
-
50
- printRefs(n, nd, refSeen, recursive)
51
- }
52
- }
53
-}
54
-
55
-func printRef(h mh.Multihash, refsSeen map[u.Key]bool) {
56
- if refsSeen != nil {
57
- _, found := refsSeen[u.Key(h)]
58
- if found {
59
- return
60
- }
61
- refsSeen[u.Key(h)] = true
62
- }
63
-
64
- u.POut("%s\n", h.B58String())
65
-}
core/commands/resolve.go
deleted
-35
@@ -1,35 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "io"
7
-
8
- "github.com/jbenet/go-ipfs/core"
9
-)
10
-
11
-func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12
-
13
- name := ""
14
-
15
- switch len(args) {
16
- case 1:
17
- name = args[0]
18
- case 0:
19
- if n.Identity == nil {
20
- return errors.New("Identity not loaded!")
21
- }
22
- name = n.Identity.ID().String()
23
-
24
- default:
25
- return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
26
- }
27
-
28
- res, err := n.Namesys.Resolve(name)
29
- if err != nil {
30
- return err
31
- }
32
-
33
- fmt.Fprintf(out, "%s\n", res)
34
- return nil
35
-}
core/commands/update.go
deleted
-76
@@ -1,76 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "io"
7
- "os"
8
-
9
- "github.com/jbenet/go-ipfs/core"
10
- "github.com/jbenet/go-ipfs/updates"
11
-)
12
-
13
-// UpdateApply applys an update of the ipfs binary and shuts down the node if successful
14
-func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
15
- fmt.Fprintln(out, "Current Version:", updates.Version)
16
- u, err := updates.CheckForUpdate()
17
- if err != nil {
18
- return err
19
- }
20
-
21
- if u == nil {
22
- fmt.Fprintln(out, "No update available")
23
- return nil
24
- }
25
- fmt.Fprintln(out, "New Version:", u.Version)
26
-
27
- _, onDaemon := opts["onDaemon"]
28
- force := opts["force"].(bool)
29
- if onDaemon && !force {
30
- return fmt.Errorf(`Error: update must stop running ipfs service.
31
-You may want to abort the update, or shut the service down manually.
32
-To shut it down automatically, run:
33
-
34
- ipfs update --force
35
-`)
36
- }
37
-
38
- if err = updates.Apply(u); err != nil {
39
- fmt.Fprint(out, err.Error())
40
- return fmt.Errorf("Couldn't apply update: %v", err)
41
- }
42
-
43
- fmt.Fprintln(out, "Updated applied!")
44
- if onDaemon {
45
- if force {
46
- fmt.Fprintln(out, "Shutting down ipfs service.")
47
- os.Exit(1) // is there a cleaner shutdown routine?
48
- } else {
49
- fmt.Fprintln(out, "You can now restart the ipfs service.")
50
- }
51
- }
52
-
53
- return nil
54
-}
55
-
56
-// UpdateCheck checks wether there is an update available
57
-func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
58
- fmt.Fprintln(out, "Current Version:", updates.Version)
59
- u, err := updates.CheckForUpdate()
60
- if err != nil {
61
- return err
62
- }
63
-
64
- if u == nil {
65
- fmt.Fprintln(out, "No update available")
66
- return nil
67
- }
68
-
69
- fmt.Fprintln(out, "New Version:", u.Version)
70
- return nil
71
-}
72
-
73
-// UpdateLog lists the version available online
74
-func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
75
- return errors.New("Not yet implemented")
76
-}
daemon/daemon.go
deleted
-166
@@ -1,166 +0,0 @@
1
-package daemon
2
-
3
-import (
4
- "encoding/json"
5
- "fmt"
6
- "io"
7
- "os"
8
- "path"
9
- "sync"
10
-
11
- core "github.com/jbenet/go-ipfs/core"
12
- "github.com/jbenet/go-ipfs/core/commands"
13
- u "github.com/jbenet/go-ipfs/util"
14
-
15
- lock "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
16
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
17
- manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
18
-)
19
-
20
-var log = u.Logger("daemon")
21
-
22
-// LockFile is the filename of the daemon lock, relative to config dir
23
-const LockFile = "daemon.lock"
24
-
25
-// DaemonListener listens to an initialized IPFS node and can send it commands instead of
26
-// starting up a new set of connections
27
-type DaemonListener struct {
28
- node *core.IpfsNode
29
- list manet.Listener
30
- closed bool
31
- wg sync.WaitGroup
32
- lk io.Closer
33
-}
34
-
35
-//Command accepts user input and can be sent to the running IPFS node
36
-type Command struct {
37
- Command string
38
- Args []string
39
- Opts map[string]interface{}
40
-}
41
-
42
-func NewDaemonListener(ipfsnode *core.IpfsNode, addr ma.Multiaddr, confdir string) (*DaemonListener, error) {
43
- var err error
44
- confdir, err = u.TildeExpansion(confdir)
45
- if err != nil {
46
- return nil, err
47
- }
48
-
49
- lk, err := daemonLock(confdir)
50
- if err != nil {
51
- return nil, err
52
- }
53
-
54
- ofi, err := os.Create(confdir + "/rpcaddress")
55
- if err != nil {
56
- log.Warningf("Could not create rpcaddress file: %s", err)
57
- return nil, err
58
- }
59
-
60
- _, err = ofi.Write([]byte(addr.String()))
61
- if err != nil {
62
- log.Warningf("Could not write to rpcaddress file: %s", err)
63
- return nil, err
64
- }
65
- ofi.Close()
66
-
67
- list, err := manet.Listen(addr)
68
- if err != nil {
69
- return nil, err
70
- }
71
- log.Info("New daemon listener initialized.")
72
-
73
- return &DaemonListener{
74
- node: ipfsnode,
75
- list: list,
76
- lk: lk,
77
- }, nil
78
-}
79
-
80
-func NewCommand() *Command {
81
- return &Command{
82
- Opts: make(map[string]interface{}),
83
- }
84
-}
85
-
86
-func (dl *DaemonListener) Listen() {
87
- if dl.closed {
88
- panic("attempting to listen on a closed daemon Listener")
89
- }
90
-
91
- // add ourselves to workgroup. and remove ourselves when done.
92
- dl.wg.Add(1)
93
- defer dl.wg.Done()
94
-
95
- log.Info("daemon listening")
96
- for {
97
- conn, err := dl.list.Accept()
98
- if err != nil {
99
- if !dl.closed {
100
- log.Warning("DaemonListener Accept: %v", err)
101
- }
102
- return
103
- }
104
- go dl.handleConnection(conn)
105
- }
106
-}
107
-
108
-func (dl *DaemonListener) handleConnection(conn manet.Conn) {
109
- defer conn.Close()
110
-
111
- dec := json.NewDecoder(conn)
112
-
113
- var command Command
114
- err := dec.Decode(&command)
115
- if err != nil {
116
- fmt.Fprintln(conn, err)
117
- return
118
- }
119
-
120
- log.Debugf("Got command: %v", command)
121
- switch command.Command {
122
- case "add":
123
- err = commands.Add(dl.node, command.Args, command.Opts, conn)
124
- case "cat":
125
- err = commands.Cat(dl.node, command.Args, command.Opts, conn)
126
- case "ls":
127
- err = commands.Ls(dl.node, command.Args, command.Opts, conn)
128
- case "pin":
129
- err = commands.Pin(dl.node, command.Args, command.Opts, conn)
130
- case "publish":
131
- err = commands.Publish(dl.node, command.Args, command.Opts, conn)
132
- case "resolve":
133
- err = commands.Resolve(dl.node, command.Args, command.Opts, conn)
134
- case "diag":
135
- err = commands.Diag(dl.node, command.Args, command.Opts, conn)
136
- case "blockGet":
137
- err = commands.BlockGet(dl.node, command.Args, command.Opts, conn)
138
- case "blockPut":
139
- err = commands.BlockPut(dl.node, command.Args, command.Opts, conn)
140
- case "log":
141
- err = commands.Log(dl.node, command.Args, command.Opts, conn)
142
- case "unpin":
143
- err = commands.Unpin(dl.node, command.Args, command.Opts, conn)
144
- case "updateApply":
145
- command.Opts["onDaemon"] = true
146
- err = commands.UpdateApply(dl.node, command.Args, command.Opts, conn)
147
- default:
148
- err = fmt.Errorf("Invalid Command: '%s'", command.Command)
149
- }
150
- if err != nil {
151
- log.Errorf("%s: %s", command.Command, err)
152
- fmt.Fprintln(conn, err)
153
- }
154
-}
155
-
156
-func (dl *DaemonListener) Close() error {
157
- dl.closed = true
158
- err := dl.list.Close()
159
- dl.wg.Wait() // wait till done before releasing lock.
160
- dl.lk.Close()
161
- return err
162
-}
163
-
164
-func daemonLock(confdir string) (io.Closer, error) {
165
- return lock.Lock(path.Join(confdir, LockFile))
166
-}
daemon/daemon_client.go
deleted
-107
@@ -1,107 +0,0 @@
1
-package daemon
2
-
3
-import (
4
- "bufio"
5
- "encoding/json"
6
- "errors"
7
- "io"
8
- "os"
9
-
10
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
11
- manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
12
-
13
- u "github.com/jbenet/go-ipfs/util"
14
-)
15
-
16
-// ErrDaemonNotRunning is returned when attempting to retrieve the daemon's
17
-// address and the daemon is not actually running.
18
-var ErrDaemonNotRunning = errors.New("daemon not running")
19
-
20
-func getDaemonAddr(confdir string) (string, error) {
21
- var err error
22
- confdir, err = u.TildeExpansion(confdir)
23
- if err != nil {
24
- return "", err
25
- }
26
- fi, err := os.Open(confdir + "/rpcaddress")
27
- if err != nil {
28
- log.Debugf("getDaemonAddr failed: %s", err)
29
- if err == os.ErrNotExist {
30
- return "", ErrDaemonNotRunning
31
- }
32
- return "", err
33
- }
34
-
35
- read := bufio.NewReader(fi)
36
-
37
- // TODO: operating system agostic line delim
38
- line, err := read.ReadBytes('\n')
39
- if err != nil && err != io.EOF {
40
- return "", err
41
- }
42
- return string(line), nil
43
-}
44
-
45
-// SendCommand attempts to run the command over a currently-running daemon.
46
-// If there is no running daemon, returns ErrDaemonNotRunning. This is done
47
-// over network RPC API. The address of the daemon is retrieved from the config
48
-// directory, where live daemons write their addresses to special files.
49
-func SendCommand(command *Command, confdir string) error {
50
- server := os.Getenv("IPFS_ADDRESS_RPC")
51
-
52
- if server == "" {
53
- //check if daemon is running
54
- log.Info("Checking if daemon is running...")
55
- if !serverIsRunning(confdir) {
56
- return ErrDaemonNotRunning
57
- }
58
-
59
- log.Info("Daemon is running!")
60
-
61
- var err error
62
- server, err = getDaemonAddr(confdir)
63
- if err != nil {
64
- return err
65
- }
66
- }
67
-
68
- return serverComm(server, command)
69
-}
70
-
71
-func serverIsRunning(confdir string) bool {
72
- var err error
73
- confdir, err = u.TildeExpansion(confdir)
74
- if err != nil {
75
- log.Errorf("Tilde Expansion Failed: %s", err)
76
- return false
77
- }
78
- lk, err := daemonLock(confdir)
79
- if err == nil {
80
- lk.Close()
81
- return false
82
- }
83
- return true
84
-}
85
-
86
-func serverComm(server string, command *Command) error {
87
- log.Info("Daemon address: %s", server)
88
- maddr, err := ma.NewMultiaddr(server)
89
- if err != nil {
90
- return err
91
- }
92
-
93
- conn, err := manet.Dial(maddr)
94
- if err != nil {
95
- return err
96
- }
97
-
98
- enc := json.NewEncoder(conn)
99
- err = enc.Encode(command)
100
- if err != nil {
101
- return err
102
- }
103
-
104
- io.Copy(os.Stdout, conn)
105
-
106
- return nil
107
-}
daemon/daemon_test.go
deleted
-86
@@ -1,86 +0,0 @@
1
-package daemon
2
-
3
-import (
4
- "encoding/base64"
5
- "os"
6
- "testing"
7
-
8
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
- config "github.com/jbenet/go-ipfs/config"
10
- core "github.com/jbenet/go-ipfs/core"
11
- ci "github.com/jbenet/go-ipfs/crypto"
12
- peer "github.com/jbenet/go-ipfs/peer"
13
-)
14
-
15
-func TestInitializeDaemonListener(t *testing.T) {
16
-
17
- priv, pub, err := ci.GenerateKeyPair(ci.RSA, 512)
18
- if err != nil {
19
- t.Fatal(err)
20
- }
21
- prbytes, err := priv.Bytes()
22
- if err != nil {
23
- t.Fatal(err)
24
- }
25
-
26
- ident, _ := peer.IDFromPubKey(pub)
27
- privKey := base64.StdEncoding.EncodeToString(prbytes)
28
- pID := ident.Pretty()
29
-
30
- id := config.Identity{
31
- PeerID: pID,
32
- PrivKey: privKey,
33
- }
34
-
35
- nodeConfigs := []*config.Config{
36
- &config.Config{
37
- Identity: id,
38
- Datastore: config.Datastore{
39
- Type: "memory",
40
- },
41
- Addresses: config.Addresses{
42
- Swarm: "/ip4/0.0.0.0/tcp/4001",
43
- API: "/ip4/127.0.0.1/tcp/8000",
44
- },
45
- },
46
-
47
- &config.Config{
48
- Identity: id,
49
- Datastore: config.Datastore{
50
- Type: "leveldb",
51
- Path: ".test/datastore",
52
- },
53
- Addresses: config.Addresses{
54
- Swarm: "/ip4/0.0.0.0/tcp/4001",
55
- API: "/ip4/127.0.0.1/tcp/8000",
56
- },
57
- },
58
- }
59
-
60
- var tempConfigDir = ".test"
61
- err = os.MkdirAll(tempConfigDir, os.ModeDir|0777)
62
- if err != nil {
63
- t.Fatalf("error making temp config dir: %v", err)
64
- }
65
-
66
- for _, c := range nodeConfigs {
67
-
68
- node, _ := core.NewIpfsNode(c, false)
69
- addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/1327")
70
- if err != nil {
71
- t.Fatal(err)
72
- }
73
-
74
- dl, initErr := NewDaemonListener(node, addr, tempConfigDir)
75
- if initErr != nil {
76
- t.Fatal(initErr)
77
- }
78
-
79
- closeErr := dl.Close()
80
- if closeErr != nil {
81
- t.Fatal(closeErr)
82
- }
83
-
84
- }
85
-
86
-}