Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 07d97fe

Browse files
haadcodedaviddias
authored andcommitted
docs(example): File Feed Example
1 parent 5078ddc commit 07d97fe

28 files changed

+1500
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
npm-debug.log
16+
17+
# orbit-db
18+
orbit-db
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Accessing go-ipfs files from the browser
2+
3+
**WIP**
4+
5+
InterPlanetary File Exchange enables you to share files with others via IPFS.
6+
7+
IPFE was built to demonstrate interoperability between the go-ipfs and js-ipfs (browser and Node.js) instances.
8+
9+
## TODO
10+
11+
- Need to merge https://github.com/ipfs/browserify-zlib-next/pull/23 and use the updated module. Otherwise the UI will error on zlib._transform.
12+
- Make sure go-ipfs and the UI connect to each other (last time I checked they didn't)
13+
- Use new signal server address everywhere (src/App.js, ipfe-daemon.js, ipfe-add.js)
14+
- ipfe-add currently uses js-ipf(node.js) daemon. But in order to add files from go-ipfs daemon, it would need to use js-ipfd-ctl. A quick way would be to use ipfs-daemon (I would *highly* recommend to do so), otherwise need to add the init dance for js-ipfsd-ctl much like `src/ipfs.js`.
15+
16+
## Requirements
17+
18+
- Node.js >= v4.x
19+
- Npm >= v3.x
20+
21+
## Step-by-step Instructions
22+
23+
### Start a go-ipfs daemon
24+
25+
1. Install go-ipfs from master (TODO: link).
26+
27+
2. Run `ipfs init`
28+
29+
3. Edit your IPFS config file, located at `~/.ipfs/config`
30+
31+
4. Add a Websocket listener address to `Addresses.Swarm`. It should look like this after editing:
32+
```
33+
"Addresses": {
34+
"API": "/ip4/127.0.0.1/tcp/5001",
35+
"Gateway": "/ip4/0.0.0.0/tcp/8080",
36+
"Swarm": [
37+
"/ip4/0.0.0.0/tcp/4001",
38+
"/ip4/0.0.0.0/tcp/9999/ws"
39+
]
40+
},
41+
```
42+
43+
5. Start the go-ipfs daemon with:
44+
```
45+
ipfs daemon
46+
```
47+
48+
6. You should see the Websocket address in the output:
49+
```
50+
Initializing daemon...
51+
Swarm listening on /ip4/127.0.0.1/tcp/4001
52+
Swarm listening on /ip4/127.0.0.1/tcp/9999/ws
53+
Swarm listening on /ip4/192.168.10.38/tcp/4001
54+
Swarm listening on /ip4/192.168.10.38/tcp/9999/ws
55+
API server listening on /ip4/127.0.0.1/tcp/5001
56+
Gateway (readonly) server listening on /ip4/0.0.0.0/tcp/8080
57+
Daemon is ready
58+
```
59+
60+
If you see address like `Swarm listening on /ip4/127.0.0.1/tcp/9999/ws`, it means all good!
61+
62+
### Start an InterPlanetary File Exchange daemon
63+
64+
1. Install the project's dependencies:
65+
```
66+
npm install
67+
```
68+
69+
2. Start the browser app with:
70+
```
71+
npm start
72+
```
73+
74+
This will open the app in your browser at http://localhost:3000/.
75+
76+
3. In the browser app, open a file exchange feed url, eg. http://localhost:3000/hello-world.
77+
78+
4. Start the Node.js ipfe-daemon with:
79+
```
80+
node ipfe-daemon hello-world
81+
```
82+
83+
The first argument after `ipfe-daemon` is the name of the file exchange feed.
84+
85+
5. In the browser app, open the Peers view by clicking on "Searching for peers..." or "1 peer". You will see which peers you're connected to.
86+
87+
6. Now go back to the terminal and find the Websocket multiaddress of your go-ipfs daemon by running:
88+
```
89+
ipfs id
90+
```
91+
92+
This will output all the address your go-ipfs daemon is listening at. Find the one with `ws` in it, and the port you added to the go-ipfs configuration file. It looks something like this:
93+
```
94+
/ip4/127.0.0.1/tcp/9999/ws/ipfs/QmZGH8GeASSkSZoNLPEBu1MqtzLTERNUEwh9yTHLEF5kcW
95+
```
96+
97+
7. Copy the address and paste it into the "Connect" input field in the browser app and press "Connect".
98+
99+
8. You should now see the two IPFS instances connected. You can verify it by observing the Peer view in the browser app and running the following command in the terminal:
100+
```
101+
ipfs swarm peers
102+
```
103+
104+
### Add files to InterPlanetary File Exchange
105+
106+
1. Add a file by running:
107+
```
108+
node ipfe-add hello-world ipfe-add.js
109+
```
110+
111+
You should see the following output:
112+
```
113+
Starting...
114+
Swarm listening on /libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmYRSN9BdRU5oYM1ryAWF518ogv8SkwZyux4aEWpxoaYZA
115+
IPFS node is ready
116+
New peers for 'hello-world':
117+
QmRNhXuS78LtUVLdJUJKmeLfE7K64CGBmwCiXY1sgJ6NaV
118+
------------------------------
119+
File | Hash | Size | Mime Type
120+
------------------------------
121+
ipfe-add.js | Qmdp8yhkyNGeqEYpkpqAm7duYqsEiJUi3KXfUFuUcyR2GR | 2588 | application/javascript
122+
```
123+
124+
Note that the multihash at the end of the swarm address will be different.
125+
126+
6. Once you see the output above, it means the file was added successfully!
127+
128+
7. Now go back to the browser app and observe the file in the list of files.
129+
130+
8. Click the file to open it.
131+
132+
9. You have successfully added a file in go-ipfs and downloaded it to the browser.
133+
134+
You can also add files to the browser app by dragging and dropping them. Once you do so, you should see the updated file list in the terminal running `ipfe-daemon`.

0 commit comments

Comments
 (0)