init docs: go generated welcome dir + files
updated sharness hashes
Juan Batiz-Benet committed
Jan 19, 2015 at 17:26 UTC
73234479fa095f0a3fd01581ae1aee749d92f6bc
22 files changed
+601
-80
assets/assets.go
new
+14
@@ -0,0 +1,14 @@
1
+//go:generate doc2go -in=init-doc/readme -out=readme.go -package=assets
2
+//go:generate doc2go -in=init-doc/help -out=help.go -package=assets
3
+//go:generate doc2go -in=init-doc/contact -out=contact.go -package=assets
4
+//go:generate doc2go -in=init-doc/security-notes -out=security-notes.go -package=assets
5
+//go:generate doc2go -in=init-doc/quick-start -out=quick-start.go -package=assets
6
+package assets
7
+
8
+var Init_dir = map[string]string{
9
+ "readme": Init_doc_readme,
10
+ "help": Init_doc_help,
11
+ "contact": Init_doc_contact,
12
+ "security-notes": Init_doc_security_notes,
13
+ "quick-start": Init_doc_quick_start,
14
+}
assets/contact.go
new
+8
@@ -0,0 +1,8 @@
1
+package assets
2
+var Init_doc_contact = `Come hang out in our IRC chat room if you have any questions.
3
+
4
+Contact the ipfs dev team:
5
+- Bugs: https://github.com/jbenet/go-ipfs/issues
6
+- Help: irc.freenode.org/#ipfs
7
+- Email: dev@ipfs.io
8
+`
assets/help.go
new
+9
@@ -0,0 +1,9 @@
1
+package assets
2
+var Init_doc_help = `Some helpful resources for finding your way around ipfs:
3
+
4
+- quick-start: a quick show of various ipfs features.
5
+- ipfs commands: a list of all commands
6
+- ipfs --help: every command describes itself
7
+- https://github.com/jbenet/go-ipfs -- the src repository
8
+- #ipfs on irc.freenode.org -- the community irc channel
9
+`
assets/init-doc/about
new
+53
@@ -0,0 +1,53 @@
1
+
2
+ IPFS -- Inter-Planetary File system
3
+
4
+IPFS is a global, versioned, peer-to-peer filesystem. It combines good ideas
5
+from Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bit-
6
+torrent swarm, exchanging git objects. IPFS provides an interface as simple
7
+as the HTTP web, but with permanence built in. You can also mount the world
8
+at /ipfs.
9
+
10
+IPFS is a protocol:
11
+- defines a content-addressed file system
12
+- coordinates content delivery
13
+- combines Kademlia + BitTorrent + Git
14
+
15
+IPFS is a filesystem:
16
+- has directories and files
17
+- mountable filesystem (via FUSE)
18
+
19
+IPFS is a web:
20
+- can be used to view documents like the web
21
+- files accessible via HTTP at `http://ipfs.io/<path>`
22
+- browsers or extensions can learn to use `ipfs://` directly
23
+- hash-addressed content guarantees authenticity
24
+
25
+IPFS is modular:
26
+- connection layer over any network protocol
27
+- routing layer
28
+- uses a routing layer DHT (kademlia/coral)
29
+- uses a path-based naming service
30
+- uses bittorrent-inspired block exchange
31
+
32
+IPFS uses crypto:
33
+- cryptographic-hash content addressing
34
+- block-level deduplication
35
+- file integrity + versioning
36
+- filesystem-level encryption + signing support
37
+
38
+IPFS is p2p:
39
+- worldwide peer-to-peer file transfers
40
+- completely decentralized architecture
41
+- **no** central point of failure
42
+
43
+IPFS is a cdn:
44
+- add a file to the filesystem locally, and it's now available to the world
45
+- caching-friendly (content-hash naming)
46
+- bittorrent-based bandwidth distribution
47
+
48
+IPFS has a name service:
49
+- IPNS, an SFS inspired name system
50
+- global namespace based on PKI
51
+- serves to build trust chains
52
+- compatible with other NSes
53
+- can map DNS, .onion, .bit, etc to IPNS
assets/init-doc/contact
new
+6
@@ -0,0 +1,6 @@
1
+Come hang out in our IRC chat room if you have any questions.
2
+
3
+Contact the ipfs dev team:
4
+- Bugs: https://github.com/jbenet/go-ipfs/issues
5
+- Help: irc.freenode.org/#ipfs
6
+- Email: dev@ipfs.io
assets/init-doc/docs/index
new
+1
@@ -0,0 +1 @@
1
+Index
assets/init-doc/help
new
+7
@@ -0,0 +1,7 @@
1
+Some helpful resources for finding your way around ipfs:
2
+
3
+- quick-start: a quick show of various ipfs features.
4
+- ipfs commands: a list of all commands
5
+- ipfs --help: every command describes itself
6
+- https://github.com/jbenet/go-ipfs -- the src repository
7
+- #ipfs on irc.freenode.org -- the community irc channel
assets/init-doc/quick-start
new
+112
@@ -0,0 +1,112 @@
1
+# 0.1 - Quick Start
2
+
3
+This is a set of short examples with minmal explanation. It is meant as
4
+a "quick start". Soon, we'll write a longer tour :-)
5
+
6
+
7
+Add a file to ipfs:
8
+
9
+ echo "hello world" >hello
10
+ ipfs add hello
11
+
12
+
13
+View it:
14
+
15
+ ipfs cat <the-hash-you-got-here>
16
+
17
+
18
+Try a directory:
19
+
20
+ mkdir foo
21
+ mkdir foo/bar
22
+ echo "baz" > foo/baz
23
+ echo "baz" > foo/bar/baz
24
+ ipfs add -r foo
25
+
26
+
27
+View things:
28
+
29
+ ipfs ls <the-hash-here>
30
+ ipfs ls <the-hash-here>/bar
31
+ ipfs cat <the-hash-here>/baz
32
+ ipfs cat <the-hash-here>/bar/baz
33
+ ipfs cat <the-hash-here>/bar
34
+ ipfs ls <the-hash-here>/baz
35
+
36
+
37
+References:
38
+
39
+ ipfs refs <the-hash-here>
40
+ ipfs refs -r <the-hash-here>
41
+ ipfs refs --help
42
+
43
+
44
+Get:
45
+
46
+ ipfs get <the-hash-here> foo2
47
+ diff foo foo2
48
+
49
+
50
+Objects:
51
+
52
+ ipfs object get <the-hash-here>
53
+ ipfs object get <the-hash-here>/foo2
54
+ ipfs object --help
55
+
56
+
57
+Pin + GC:
58
+
59
+ ipfs pin -r <the-hash-here>
60
+ ipfs gc
61
+ ipfs ls <the-hash-here>
62
+ ipfs unpin -r <the-hash-here>
63
+ ipfs gc
64
+
65
+
66
+Daemon:
67
+
68
+ ipfs daemon (in another terminal)
69
+ ipfs id
70
+
71
+
72
+Network:
73
+
74
+ (must be online)
75
+ ipfs swarm peers
76
+ ipfs id
77
+ ipfs cat <hash-of-remote-object>
78
+
79
+
80
+Mount:
81
+
82
+ (warning: fuse is finicky!)
83
+ ipfs mount
84
+ cd /ipfs/<
85
+
86
+
87
+Tool:
88
+
89
+ ipfs version
90
+ ipfs update
91
+ ipfs commands
92
+ ipfs config --help
93
+ open http://localhost:5001/webui
94
+
95
+
96
+Browse:
97
+
98
+ webui:
99
+
100
+ http://localhost:5001/webui
101
+
102
+ video:
103
+
104
+ http://localhost:5001/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse
105
+
106
+ images:
107
+
108
+ http://localhost:5001/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs
109
+
110
+ markdown renderer app:
111
+
112
+ http://localhost:5001/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown
assets/init-doc/readme
new
+26
@@ -0,0 +1,26 @@
1
+Hello and Welcome to IPFS!
2
+
3
+██╗██████╗ ███████╗███████╗
4
+██║██╔══██╗██╔════╝██╔════╝
5
+██║██████╔╝█████╗ ███████╗
6
+██║██╔═══╝ ██╔══╝ ╚════██║
7
+██║██║ ██║ ███████║
8
+╚═╝╚═╝ ╚═╝ ╚══════╝
9
+
10
+If you're seeing this, you have successfully installed
11
+IPFS and are now interfacing with the ipfs merkledag!
12
+
13
+ -------------------------------------------------------
14
+| Warning: |
15
+| This is alpha software. use at your own discretion! |
16
+| Much is missing or lacking polish. There are bugs. |
17
+| Not yet secure. Read the security notes for more. |
18
+ -------------------------------------------------------
19
+
20
+Check out some of the other files in this directory:
21
+
22
+ ./about
23
+ ./help
24
+ ./quick-start <-- usage examples
25
+ ./readme <-- this file
26
+ ./security-notes
assets/init-doc/security-notes
new
+21
@@ -0,0 +1,21 @@
1
+ IPFS Alpha Security Notes
2
+
3
+We try hard to ensure our system is safe and robust, but all software
4
+has bugs, especially new software. This distribution is meant to be an
5
+alpha preview, don't use it for anything mission critical.
6
+
7
+Please note the following:
8
+
9
+- This is alpha software and has not been audited. It is our goal
10
+ to conduct a proper security audit once we close in on a 1.0 release.
11
+
12
+- ipfs is a networked program, and may have serious undiscovered
13
+ vulnerabilities. It is written in Go, and we do not execute any
14
+ user provided data. But please point any problems out to us in a
15
+ github issue, or email security@ipfs.io privately.
16
+
17
+- ipfs uses encryption for all communication, but it's NOT PROVEN SECURE
18
+ YET! It may be totally broken. For now, the code is included to make
19
+ sure we benchmark our operations with encryption in mind. In the future,
20
+ there will be an "unsafe" mode for high performance intranet apps.
21
+ If this is a blocking feature for you, please contact us.
assets/init-doc/tour/0.0-intro
new
+34
@@ -0,0 +1,34 @@
1
+WIP
2
+
3
+# 0.0 - Introduction
4
+
5
+Welcome to IPFS! This tour will guide you through a few of the
6
+features of this tool, and the most common commands. Then, it will
7
+immerse you into the world of merkledags and the amazing things
8
+you can do with them.
9
+
10
+
11
+This tour has many parts, and can be taken in different sequences.
12
+Different people learn different ways, so choose your own adventure:
13
+
14
+ To start with the concepts, try:
15
+ - The Merkle DAG
16
+ - Data Structures on the Merkle DAG
17
+ - Representing Files with unixfs
18
+ - add, cat, ls, refs
19
+ ...
20
+
21
+
22
+ To start with the examples, try:
23
+ - add, cat, ls, refs
24
+ - Representing Files with unixfs
25
+ - Data Structures on the Merkle DAG
26
+ - The Merkle DAG
27
+ ...
28
+
29
+
30
+ To start with the network, try:
31
+ - IPFS Nodes
32
+ - Running the daemon
33
+ - The Swarm
34
+ - The Web
assets/quick-start.go
new
+114
@@ -0,0 +1,114 @@
1
+package assets
2
+var Init_doc_quick_start = `# 0.1 - Quick Start
3
+
4
+This is a set of short examples with minmal explanation. It is meant as
5
+a "quick start". Soon, we'll write a longer tour :-)
6
+
7
+
8
+Add a file to ipfs:
9
+
10
+ echo "hello world" >hello
11
+ ipfs add hello
12
+
13
+
14
+View it:
15
+
16
+ ipfs cat <the-hash-you-got-here>
17
+
18
+
19
+Try a directory:
20
+
21
+ mkdir foo
22
+ mkdir foo/bar
23
+ echo "baz" > foo/baz
24
+ echo "baz" > foo/bar/baz
25
+ ipfs add -r foo
26
+
27
+
28
+View things:
29
+
30
+ ipfs ls <the-hash-here>
31
+ ipfs ls <the-hash-here>/bar
32
+ ipfs cat <the-hash-here>/baz
33
+ ipfs cat <the-hash-here>/bar/baz
34
+ ipfs cat <the-hash-here>/bar
35
+ ipfs ls <the-hash-here>/baz
36
+
37
+
38
+References:
39
+
40
+ ipfs refs <the-hash-here>
41
+ ipfs refs -r <the-hash-here>
42
+ ipfs refs --help
43
+
44
+
45
+Get:
46
+
47
+ ipfs get <the-hash-here> foo2
48
+ diff foo foo2
49
+
50
+
51
+Objects:
52
+
53
+ ipfs object get <the-hash-here>
54
+ ipfs object get <the-hash-here>/foo2
55
+ ipfs object --help
56
+
57
+
58
+Pin + GC:
59
+
60
+ ipfs pin -r <the-hash-here>
61
+ ipfs gc
62
+ ipfs ls <the-hash-here>
63
+ ipfs unpin -r <the-hash-here>
64
+ ipfs gc
65
+
66
+
67
+Daemon:
68
+
69
+ ipfs daemon (in another terminal)
70
+ ipfs id
71
+
72
+
73
+Network:
74
+
75
+ (must be online)
76
+ ipfs swarm peers
77
+ ipfs id
78
+ ipfs cat <hash-of-remote-object>
79
+
80
+
81
+Mount:
82
+
83
+ (warning: fuse is finicky!)
84
+ ipfs mount
85
+ cd /ipfs/<
86
+
87
+
88
+Tool:
89
+
90
+ ipfs version
91
+ ipfs update
92
+ ipfs commands
93
+ ipfs config --help
94
+ open http://localhost:5001/webui
95
+
96
+
97
+Browse:
98
+
99
+ webui:
100
+
101
+ http://localhost:5001/webui
102
+
103
+ video:
104
+
105
+ http://localhost:5001/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse
106
+
107
+ images:
108
+
109
+ http://localhost:5001/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs
110
+
111
+ markdown renderer app:
112
+
113
+ http://localhost:5001/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown
114
+`
assets/readme.go
new
+28
@@ -0,0 +1,28 @@
1
+package assets
2
+var Init_doc_readme = `Hello and Welcome to IPFS!
3
+
4
+██╗██████╗ ███████╗███████╗
5
+██║██╔══██╗██╔════╝██╔════╝
6
+██║██████╔╝█████╗ ███████╗
7
+██║██╔═══╝ ██╔══╝ ╚════██║
8
+██║██║ ██║ ███████║
9
+╚═╝╚═╝ ╚═╝ ╚══════╝
10
+
11
+If you're seeing this, you have successfully installed
12
+IPFS and are now interfacing with the ipfs merkledag!
13
+
14
+ -------------------------------------------------------
15
+| Warning: |
16
+| This is alpha software. use at your own discretion! |
17
+| Much is missing or lacking polish. There are bugs. |
18
+| Not yet secure. Read the security notes for more. |
19
+ -------------------------------------------------------
20
+
21
+Check out some of the other files in this directory:
22
+
23
+ ./about
24
+ ./help
25
+ ./quick-start <-- usage examples
26
+ ./readme <-- this file
27
+ ./security-notes
28
+`
assets/security-notes.go
new
+23
@@ -0,0 +1,23 @@
1
+package assets
2
+var Init_doc_security_notes = ` IPFS Alpha Security Notes
3
+
4
+We try hard to ensure our system is safe and robust, but all software
5
+has bugs, especially new software. This distribution is meant to be an
6
+alpha preview, don't use it for anything mission critical.
7
+
8
+Please note the following:
9
+
10
+- This is alpha software and has not been audited. It is our goal
11
+ to conduct a proper security audit once we close in on a 1.0 release.
12
+
13
+- ipfs is a networked program, and may have serious undiscovered
14
+ vulnerabilities. It is written in Go, and we do not execute any
15
+ user provided data. But please point any problems out to us in a
16
+ github issue, or email security@ipfs.io privately.
17
+
18
+- ipfs uses encryption for all communication, but it's NOT PROVEN SECURE
19
+ YET! It may be totally broken. For now, the code is included to make
20
+ sure we benchmark our operations with encryption in mind. In the future,
21
+ there will be an "unsafe" mode for high performance intranet apps.
22
+ If this is a blocking feature for you, please contact us.
23
+`
cmd/ipfs-gateway-fs/main.go
+1
-1
@@ -44,7 +44,7 @@ func run() error {
44
}
45
46
if !fsrepo.IsInitialized(repoPath) {
47
- conf, err := config.Init(*nBitsForKeypair)
47
+ conf, err := config.Init(os.Stdout, *nBitsForKeypair)
48
if err != nil {
49
return err
50
}
cmd/ipfs/daemon.go
+8
-5
@@ -1,7 +1,7 @@
1
package main
2
3
import (
4
- "fmt"
4
+ "bytes"
5
6
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
7
cmds "github.com/jbenet/go-ipfs/commands"
@@ -48,8 +48,10 @@ the daemon.
48
}
49
50
func daemonFunc(req cmds.Request, res cmds.Response) {
51
+ var out bytes.Buffer
52
+ res.SetOutput(&out)
53
+ writef(&out, "Initializing daemon...\n")
54
52
- fmt.Println("Initializing daemon...")
55
// first, whether user has provided the initialization flag. we may be
56
// running in an uninitialized state.
57
initialize, _, err := req.Option(initOptionKwd).Bool()
@@ -57,6 +59,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
59
res.SetError(err, cmds.ErrNormal)
60
return
61
}
62
+
63
if initialize {
64
65
// now, FileExists is our best method of detecting whether IPFS is
@@ -64,7 +67,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
67
// `IsInitialized` where the quality of the signal can be improved over
68
// time, and many call-sites can benefit.
69
if !util.FileExists(req.Context().ConfigRoot) {
67
- err := initWithDefaults(req.Context().ConfigRoot)
70
+ err := initWithDefaults(&out, req.Context().ConfigRoot)
71
if err != nil {
72
res.SetError(debugerror.Wrap(err), cmds.ErrNormal)
73
return
@@ -149,8 +152,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
152
res.SetError(err, cmds.ErrNormal)
153
return
154
}
152
- fmt.Printf("IPFS mounted at: %s\n", fsdir)
153
- fmt.Printf("IPNS mounted at: %s\n", nsdir)
155
+ writef(&out, "IPFS mounted at: %s\n", fsdir)
156
+ writef(&out, "IPNS mounted at: %s\n", nsdir)
157
}
158
159
var rootRedirect corehttp.ServeOption
cmd/ipfs/init.go
+60
-46
@@ -3,14 +3,17 @@ package main
3
import (
4
"bytes"
5
"fmt"
6
+ "io"
7
8
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
9
+ assets "github.com/jbenet/go-ipfs/assets"
10
cmds "github.com/jbenet/go-ipfs/commands"
11
core "github.com/jbenet/go-ipfs/core"
12
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
13
ipns "github.com/jbenet/go-ipfs/fuse/ipns"
14
config "github.com/jbenet/go-ipfs/repo/config"
15
fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
16
+ uio "github.com/jbenet/go-ipfs/unixfs/io"
17
u "github.com/jbenet/go-ipfs/util"
18
debugerror "github.com/jbenet/go-ipfs/util/debugerror"
19
)
@@ -50,12 +53,15 @@ var initCmd = &cmds.Command{
53
nBitsForKeypair = nBitsForKeypairDefault
54
}
55
53
- output, err := doInit(req.Context().ConfigRoot, force, nBitsForKeypair)
54
- if err != nil {
55
- res.SetError(err, cmds.ErrNormal)
56
- return
57
- }
58
- res.SetOutput(output)
56
+ rpipe, wpipe := io.Pipe()
57
+ go func() {
58
+ defer wpipe.Close()
59
+ if err := doInit(wpipe, req.Context().ConfigRoot, force, nBitsForKeypair); err != nil {
60
+ res.SetError(err, cmds.ErrNormal)
61
+ return
62
+ }
63
+ }()
64
+ res.SetOutput(rpipe)
65
},
66
}
67
@@ -64,58 +70,45 @@ Reinitializing would overwrite your keys.
70
(use -f to force overwrite)
71
`)
72
67
-var welcomeMsg = `Hello and Welcome to IPFS!
68
-
69
-██╗██████╗ ███████╗███████╗
70
-██║██╔══██╗██╔════╝██╔════╝
71
-██║██████╔╝█████╗ ███████╗
72
-██║██╔═══╝ ██╔══╝ ╚════██║
73
-██║██║ ██║ ███████║
74
-╚═╝╚═╝ ╚═╝ ╚══════╝
75
-
76
-If you're seeing this, you have successfully installed
77
-IPFS and are now interfacing with the ipfs merkledag!
78
-
79
-`
80
-
81
-func initWithDefaults(repoRoot string) error {
82
- _, err := doInit(repoRoot, false, nBitsForKeypairDefault)
73
+func initWithDefaults(out io.Writer, repoRoot string) error {
74
+ err := doInit(out, repoRoot, false, nBitsForKeypairDefault)
75
return debugerror.Wrap(err)
76
}
77
86
-func doInit(repoRoot string, force bool, nBitsForKeypair int) (interface{}, error) {
87
- u.POut("initializing ipfs node at %s\n", repoRoot)
78
+func writef(out io.Writer, format string, ifs ...interface{}) error {
79
+ _, err := out.Write([]byte(fmt.Sprintf(format, ifs...)))
80
+ return err
81
+}
82
+
83
+func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) error {
84
+ if err := writef(out, "initializing ipfs node at %s\n", repoRoot); err != nil {
85
+ return err
86
+ }
87
88
if fsrepo.IsInitialized(repoRoot) && !force {
90
- return nil, errRepoExists
89
+ return errRepoExists
90
}
92
- conf, err := config.Init(nBitsForKeypair)
91
+ conf, err := config.Init(out, nBitsForKeypair)
92
if err != nil {
94
- return nil, err
93
+ return err
94
}
95
if fsrepo.IsInitialized(repoRoot) {
96
if err := fsrepo.Remove(repoRoot); err != nil {
98
- return nil, err
97
+ return err
98
}
99
}
100
if err := fsrepo.Init(repoRoot, conf); err != nil {
102
- return nil, err
101
+ return err
102
}
103
105
- err = addTheWelcomeFile(repoRoot)
106
- if err != nil {
107
- return nil, err
108
- }
109
- err = initializeIpnsKeyspace(repoRoot)
110
- if err != nil {
111
- return nil, err
104
+ if err := addDefaultAssets(out, repoRoot); err != nil {
105
+ return err
106
}
113
- return nil, nil
107
+
108
+ return initializeIpnsKeyspace(repoRoot)
109
}
110
116
-// addTheWelcomeFile adds a file containing the welcome message to the newly
117
-// minted node.
118
-func addTheWelcomeFile(repoRoot string) error {
111
+func addDefaultAssets(out io.Writer, repoRoot string) error {
112
ctx, cancel := context.WithCancel(context.Background())
113
defer cancel()
114
r := fsrepo.At(repoRoot)
@@ -128,14 +121,35 @@ func addTheWelcomeFile(repoRoot string) error {
121
}
122
defer nd.Close()
123
131
- // Set up default file
132
- reader := bytes.NewBufferString(welcomeMsg)
133
- k, err := coreunix.Add(nd, reader)
124
+ dirb := uio.NewDirectory(nd.DAG)
125
+
126
+ // add every file in the assets pkg
127
+ for fname, file := range assets.Init_dir {
128
+ buf := bytes.NewBufferString(file)
129
+ s, err := coreunix.Add(nd, buf)
130
+ if err != nil {
131
+ return err
132
+ }
133
+ k := u.B58KeyDecode(s)
134
+ if err := dirb.AddChild(fname, k); err != nil {
135
+ return err
136
+ }
137
+ }
138
+
139
+ dir := dirb.GetNode()
140
+ dkey, err := nd.DAG.Add(dir)
141
if err != nil {
135
- return fmt.Errorf("failed to write test file: %s", err)
142
+ return err
143
+ }
144
+ if err := nd.Pinning.Pin(dir, true); err != nil {
145
+ return err
146
}
137
- fmt.Printf("\nto get started, enter: ipfs cat %s\n", k)
138
- return nil
147
+ if err := nd.Pinning.Flush(); err != nil {
148
+ return err
149
+ }
150
+
151
+ writef(out, "to get started, enter:\n")
152
+ return writef(out, "\n\tipfs cat /ipfs/%s/readme\n\n", dkey)
153
}
154
155
func initializeIpnsKeyspace(repoRoot string) error {
repo/config/init.go
+6
-5
@@ -3,19 +3,20 @@ package config
3
import (
4
"encoding/base64"
5
"fmt"
6
+ "io"
7
8
ci "github.com/jbenet/go-ipfs/p2p/crypto"
9
peer "github.com/jbenet/go-ipfs/p2p/peer"
10
errors "github.com/jbenet/go-ipfs/util/debugerror"
11
)
12
12
-func Init(nBitsForKeypair int) (*Config, error) {
13
+func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
14
ds, err := datastoreConfig()
15
if err != nil {
16
return nil, err
17
}
18
18
- identity, err := identityConfig(nBitsForKeypair)
19
+ identity, err := identityConfig(out, nBitsForKeypair)
20
if err != nil {
21
return nil, err
22
}
@@ -71,19 +72,19 @@ func datastoreConfig() (*Datastore, error) {
72
}
73
74
// identityConfig initializes a new identity.
74
-func identityConfig(nbits int) (Identity, error) {
75
+func identityConfig(out io.Writer, nbits int) (Identity, error) {
76
// TODO guard higher up
77
ident := Identity{}
78
if nbits < 1024 {
79
return ident, errors.New("Bitsize less than 1024 is considered unsafe.")
80
}
81
81
- fmt.Printf("generating %v-bit RSA keypair...", nbits)
82
+ out.Write([]byte(fmt.Sprintf("generating %v-bit RSA keypair...", nbits)))
83
sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits)
84
if err != nil {
85
return ident, err
86
}
86
- fmt.Printf("done\n")
87
+ out.Write([]byte(fmt.Sprintf("done\n")))
88
89
// currently storing key unencrypted. in the future we need to encrypt it.
90
// TODO(security)
test/sharness/lib/test-lib.sh
+4
-4
@@ -83,16 +83,16 @@ test_init_ipfs() {
83
test_launch_ipfs_daemon() {
84
85
test_expect_success "'ipfs daemon' succeeds" '
86
- ipfs daemon >actual 2>daemon_err &
86
+ ipfs daemon >actual_daemon 2>daemon_err &
87
'
88
89
test_expect_success "'ipfs daemon' output looks good" '
90
IPFS_PID=$! &&
91
- echo "Initializing daemon..." >expected &&
92
- echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected &&
93
- test_cmp_repeat_10_sec expected actual ||
91
+ echo "API server listening on /ip4/127.0.0.1/tcp/5001" >expected_daemon &&
92
+ test_cmp_repeat_10_sec expected_daemon actual_daemon ||
93
fsh cat daemon_err
94
'
95
+
96
}
97
98
test_mount_ipfs() {
test/sharness/t0020-init.sh
+10
-8
@@ -21,24 +21,26 @@ test_expect_success ".go-ipfs/ has been created" '
21
'
22
23
test_expect_success "ipfs config succeeds" '
24
- echo leveldb >expected &&
25
- ipfs config Datastore.Type >actual &&
26
- test_cmp expected actual
24
+ echo leveldb >expected_config &&
25
+ ipfs config Datastore.Type >actual_config &&
26
+ test_cmp expected_config actual_config
27
'
28
29
test_expect_success "ipfs peer id looks good" '
30
PEERID=$(ipfs config Identity.PeerID) &&
31
- echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual &&
32
- echo "46" >expected &&
33
- test_cmp expected actual
31
+ echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual_peerid &&
32
+ echo "46" >expected_peerid &&
33
+ test_cmp expected_peerid actual_peerid
34
'
35
36
test_expect_success "ipfs init output looks good" '
37
- STARTHASH="QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ" &&
37
+ STARTHASH="QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT" &&
38
+ STARTFILE="ipfs cat /ipfs/$STARTHASH/readme"
39
echo "initializing ipfs node at $IPFS_PATH" >expected &&
40
echo "generating 4096-bit RSA keypair...done" >>expected &&
41
echo "peer identity: $PEERID" >>expected &&
41
- printf "\\n%s\\n" "to get started, enter: ipfs cat $STARTHASH" >>expected &&
42
+ echo "to get started, enter:" >>expected &&
43
+ printf "\\n\\t$STARTFILE\\n\\n" >>expected &&
44
test_cmp expected actual_init
45
'
46
test/sharness/t0080-repo.sh
+18
-11
@@ -42,10 +42,12 @@ test_expect_success "'ipfs pin rm' succeeds" '
42
'
43
44
test_expect_success "file no longer pinned" '
45
- # we expect the welcome file to show up here
46
- echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >expected2
47
- ipfs pin ls -type=recursive >actual2
48
- test_cmp expected2 actual2
45
+ # we expect the welcome files to show up here
46
+ echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >expected2
47
+ ipfs refs -r QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected2
48
+ cat expected2 | sort >expected_sorted2
49
+ ipfs pin ls -type=recursive | sort >actual2
50
+ test_cmp expected_sorted2 actual2
51
'
52
53
test_expect_success "recursively pin afile" '
@@ -84,10 +86,12 @@ test_expect_success "'ipfs repo gc' removes file" '
86
'
87
88
test_expect_success "'ipfs refs local' no longer shows file" '
87
- echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >expected8
88
- echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>expected8
89
- ipfs refs local >actual8
90
- test_cmp expected8 actual8
89
+ echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >expected8
90
+ echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected8
91
+ ipfs refs -r QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected8
92
+ cat expected8 | sort >expected_sorted8
93
+ ipfs refs local | sort >actual8
94
+ test_cmp expected_sorted8 actual8
95
'
96
97
test_expect_success "adding multiblock random file succeeds" '
@@ -96,9 +100,11 @@ test_expect_success "adding multiblock random file succeeds" '
100
'
101
102
test_expect_success "'ipfs pin ls -type=indirect' is correct" '
99
- ipfs refs "$MBLOCKHASH" | sort >refsout
103
+ ipfs refs "$MBLOCKHASH" >refsout
104
+ ipfs refs -r "QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT" >>refsout
105
+ cat refsout | sort >refsout_sorted
106
ipfs pin ls -type=indirect | sort >indirectpins
101
- test_cmp refsout indirectpins
107
+ test_cmp refsout_sorted indirectpins
108
'
109
110
test_expect_success "pin something directly" '
@@ -123,7 +129,8 @@ test_expect_success "'ipfs pin ls -type=direct' is correct" '
129
130
test_expect_success "'ipfs pin ls -type=recursive' is correct" '
131
echo "$MBLOCKHASH" >rp_expected
126
- echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >>rp_expected
132
+ echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>rp_expected
133
+ ipfs refs -r "QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT" >>rp_expected
134
cat rp_expected | sort >rp_exp_sorted
135
ipfs pin ls -type=recursive | sort >rp_actual
136
test_cmp rp_exp_sorted rp_actual
unixfs/io/dirbuilder.go
new
+38
@@ -0,0 +1,38 @@
1
+package io
2
+
3
+import (
4
+ mdag "github.com/jbenet/go-ipfs/merkledag"
5
+ format "github.com/jbenet/go-ipfs/unixfs"
6
+ u "github.com/jbenet/go-ipfs/util"
7
+)
8
+
9
+type directoryBuilder struct {
10
+ dserv mdag.DAGService
11
+ dirnode *mdag.Node
12
+}
13
+
14
+func NewDirectory(dserv mdag.DAGService) *directoryBuilder {
15
+ db := new(directoryBuilder)
16
+ db.dserv = dserv
17
+ db.dirnode = new(mdag.Node)
18
+ db.dirnode.Data = format.FolderPBData()
19
+ return db
20
+}
21
+
22
+func (d *directoryBuilder) AddChild(name string, k u.Key) error {
23
+ cnode, err := d.dserv.Get(k)
24
+ if err != nil {
25
+ return err
26
+ }
27
+
28
+ err = d.dirnode.AddNodeLinkClean(name, cnode)
29
+ if err != nil {
30
+ return err
31
+ }
32
+
33
+ return nil
34
+}
35
+
36
+func (d *directoryBuilder) GetNode() *mdag.Node {
37
+ return d.dirnode
38
+}