Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 1b07ed4

Browse files
Merge #420
420: docs(http): initial draft of tutorial r=koivunej a=niklaslong This is a first draft of the tutorial mentioned in #402. It currently covers: - installing rust - configuration of the `IPFS_PATH` - `-- init` - `-- daemon` - `ipfs id` from the go-ipfs CLI Co-authored-by: Niklas Long <[email protected]>
2 parents 73409a8 + ad2d93b commit 1b07ed4

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

http/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,102 @@ HTTP specs:
1616

1717
Status: Pre-alpha, most of the functionality is missing or `501 Not
1818
Implemented`. See the repository level README for more information.
19+
20+
## Getting started
21+
22+
This tutorial will demonstrate how to run a rust-ipfs node using the ipfs-http
23+
crate. If you haven't already, you'll need to [install
24+
Rust](https://doc.rust-lang.org/stable/book/ch01-01-installation.html). You
25+
should also [install the go-ipfs
26+
CLI](https://docs.ipfs.io/install/command-line/) as this will make it easier to
27+
interact with the node.
28+
29+
By default ipfs-http stores the configuration for the node in the `.rust-ipfs`
30+
directory. Should you want to override this, you can do so by setting the
31+
`IPFS_PATH` environment variable. For this example it's a good idea to set the
32+
path to `.rust-ipfs` so that the go-ipfs CLI knows to use that directory as
33+
well (default is `.ipfs`).
34+
35+
You can initialise the directory with:
36+
37+
```
38+
cargo run -p ipfs-http -- init --profile test --bits 2048
39+
```
40+
41+
The `--profile` option allows the user to use a set of defaults. Currently two
42+
profiles are supported:
43+
44+
- `test`: runs the daemon using ephemeral ports
45+
- `default` runs the daemon on port `4004`
46+
47+
The `--bits` option specifies the length of the RSA keys to be used. The output
48+
should return a peer id and confirm the path of the newly initialised node is
49+
either the default or the `IPFS_PATH`.
50+
51+
The `.rust-ipfs` directory now contains a configuration file, `config`:
52+
53+
```
54+
{
55+
"Identity": {
56+
"PeerID": "QmTETy4bmL44fwkvbkMzXMVmiUDTvEcupsfpM8BCgNERUe",
57+
"PrivKey": "CAASpgkwggSiAgEAAoIBAQCyFR6pKSRt62WLJ6fi2MeG0pn [...]"
58+
},
59+
"Addresses": {
60+
"Swarm": [
61+
"/ip4/127.0.0.1/tcp/0"
62+
]
63+
}
64+
}
65+
```
66+
67+
It stores the peer id, private key (shortened for brevity) and swarm addresses
68+
for the node. Let's run the node as a daemon:
69+
70+
```
71+
cargo run -p ipfs-http -- daemon
72+
```
73+
74+
This exposes the node as an HTTP API. The config directory has also grown to
75+
include a `blockstore`, a `datastore` and an `api` file:
76+
77+
```
78+
.rust-ipfs
79+
├── api
80+
├── blockstore
81+
├── config
82+
└── datastore
83+
└── pins
84+
```
85+
86+
The `blockstore` and `datastore` are empty, as we haven't yet added any data to
87+
the ipfs node. The `api` file keeps track of the node's address.
88+
89+
The node can now be queried using the go-ipfs CLI. In another terminal window
90+
run:
91+
92+
```
93+
ipfs id
94+
```
95+
96+
This returns the information about the node.
97+
98+
```
99+
{
100+
"ID": "QmTETy4bmL44fwkvbkMzXMVmiUDTvEcupsfpM8BCgNERUe",
101+
"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3D [...]",
102+
"Addresses": [
103+
"/ip4/127.0.0.1/tcp/58807/p2p/QmTETy4bmL44fwkvbkMzXMVmiUDTvEcupsfpM8BCgNERUe"
104+
],
105+
"AgentVersion": "rust-ipfs/version",
106+
"ProtocolVersion": "ipfs/version",
107+
"Protocols": null
108+
}
109+
```
110+
111+
The query is logged by the node and shows the `/api/v0/id` endpoint handled the request:
112+
113+
```
114+
INFO ipfs-http: 127.0.0.1:58811 "POST /api/v0/id HTTP/1.1" 200 "-" "go-ipfs-cmds/http" 2.795971ms
115+
```
116+
117+

0 commit comments

Comments
 (0)