You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
# Tutorial - Synchronize and distribute folders with files.
1
+
# Example - Exchange files between Desktop and Browser
2
2
3
3
**WIP**
4
4
5
-
## Run
5
+
## Run - TEMP INSTRUCTIONS
6
6
7
7
1. Run a go-ipfs daemon with a WS address and --enable-pubsub-experiment flag, with API at port 5001
8
8
2. Run `node src/ff-cli/bin.js add hello package.json`
@@ -14,17 +14,18 @@ Note that the run order is important, running the ff-cli other way round won't w
14
14
15
15
## Coming up
16
16
17
-
> Welcome! This tutorial will guide you through building a web application for file distribution, using React, OrbitDB (a distributed key-value store) and libp2p PubSub. You will learn how to distribute content and how to synchronize state in a distributed way.
17
+
> Welcome! This example will guide you through building a web application for file distribution, using React, OrbitDB (a serverless, distributed database) and libp2p PubSub. You will learn how to distribute content and how to synchronize state in a distributed way.
18
18
19
19
There are a couple of caveats:
20
20
21
21
- js-ipfs currently doesn't support DHT peer discovery, the peer from which you are fetching data should be within the reach (local or in public IP) of the browser node.
22
22
- We need to use a signalling server to establish the WebRTC connections, this won't be necessary as soon as libp2p-relay gets developed
23
23
-[full go-ipfs interop is not complete yet, blocked by an interop stream multiplexer](https://github.com/ipfs/js-ipfs/issues/721). You can, however, fetch content from go-ipfs through js-ipfs.
24
+
- This app was created with create-react-app which provides its own build script. The caveat is that it doesn't allow us to use custom webpack config files which we need to shim `zlib` with `browserify-zlib-next`. As a workaround, we copy a custom webpack config file to `node_modules/react-scripts/config/` in a postinstall step.
24
25
25
26
That being said, we will explain throughout this tutorial to circunvent the caveats and once they are fixed, we will update the tutorial as well.
26
27
27
-
# Application diagram
28
+
##Application diagram
28
29
29
30
```sh
30
31
@@ -66,53 +67,35 @@ That being said, we will explain throughout this tutorial to circunvent the cave
66
67
└───────────┘
67
68
```
68
69
69
-
This app, file feed, will use OrbitDB over IPFS/libp2p PubSub to synchronize the latest state of feed, then using IPFS primitives to fetch and distribute the files. IPFS is using libp2p, the networking stack of IPFS, that enables IPFS to work in the Browser and in Node.js by swapping its building blocks, supporting multiple transports while keeping the same API.
70
+
This app, file exchange, will use OrbitDB, IPFS and libp2p PubSub to synchronize the latest state of a file feed, then using IPFS primitives it fetched and distributes the files. IPFS is using libp2p, the networking stack of IPFS, that enables IPFS to work in the Browser and in Node.js by swapping its building blocks, supporting multiple transports while keeping the same API.
70
71
71
-
## Check out the final state
72
+
## Quick Start
72
73
73
-
If you just want to check out what is the final state of how this application will look like, go to the complete folder, install the dependencies and run it.
74
+
If you just want to check out the app, go to the complete folder, install the dependencies and run it.
74
75
75
76
```sh
76
-
>cdcomplete
77
-
>npm install
78
-
>npm start
79
-
# open your browser (Chrome or Firefox) in http://localhost:12345
77
+
cdcomplete
78
+
npm install
79
+
npm start
80
+
# open your browser (Chrome or Firefox) in http://localhost:3000
80
81
```
81
82
82
83
You should get something like this:
83
84
84
85
`TODO: Insert final screenshot here`
85
86
86
-
## Step-by-step instructions
87
87
88
-
`TODO`
88
+
## Step-by-step instructions
89
89
90
-
--------------------------------------
91
-
`needs refactor`
92
90
### Start a go-ipfs daemon
93
91
94
-
1. Install go-ipfs from master (TODO: link).
92
+
1. Install go-ipfs from [master](https://github.com/ipfs/go-ipfs#build-from-source).
95
93
96
-
2. Run `ipfs init`
94
+
2. Run `IPFS_PATH=$HOME/.file-exchange ipfs init`
97
95
98
-
3.Edit your IPFS config file, located at `~/.ipfs/config`
4. Add a Websocket listener address to `Addresses.Swarm`. It should look like this after editing:
101
-
```
102
-
"Addresses": {
103
-
"API": "/ip4/127.0.0.1/tcp/5001",
104
-
"Gateway": "/ip4/0.0.0.0/tcp/8080",
105
-
"Swarm": [
106
-
"/ip4/0.0.0.0/tcp/4001",
107
-
"/ip4/0.0.0.0/tcp/9999/ws"
108
-
]
109
-
},
110
-
```
111
-
112
-
5. Start the go-ipfs daemon with:
113
-
```
114
-
ipfs daemon
115
-
```
98
+
5. Start the go-ipfs daemon: `IPFS_PATH=$HOME/.file-exchange ipfs daemon --enable-pubsub-experiment`
116
99
117
100
6. You should see the Websocket address in the output:
118
101
```
@@ -126,78 +109,36 @@ Gateway (readonly) server listening on /ip4/0.0.0.0/tcp/8080
126
109
Daemon is ready
127
110
```
128
111
129
-
If you see address like `Swarm listening on /ip4/127.0.0.1/tcp/9999/ws`, it means all good!
112
+
If you see an address like `Swarm listening on /ip4/127.0.0.1/tcp/9999/ws`, it means **all good**!
130
113
131
-
### Start an InterPlanetary File Exchange daemon
132
-
133
-
1. Install the project's dependencies:
134
-
```
135
-
npm install
136
-
```
137
-
138
-
2. Start the browser app with:
139
-
```
140
-
npm start
141
-
```
114
+
In a new terminal window, run `IPFS_PATH=$HOME/.file-exchange ipfs id` and note the first address in the `Addresses` field. It should look something like this: `/ip4/127.0.0.1/tcp/9999/ws/ipfs/QmZGH8GeASSkSZoNLPEBu1MqtzLTERNUEwh9yTHLEF5kcW`. **You'll need this address later**.
142
115
143
-
This will open the app in your browser at http://localhost:3000/.
116
+
### Run File Exchange App
144
117
145
-
3. In the browser app, open a file exchange feed url, eg. http://localhost:3000/hello-world.
118
+
**NOTE!**
119
+
Before running the following command, you'll need to go to the root directory of `js-ipfs/` and run `npm install` to install all the dependencies. After you've done that, continue with the steps here.
146
120
147
-
4. Start the Node.js ipfe-daemon with:
121
+
Install the project's dependencies:
148
122
```
149
-
node ipfe-daemon hello-world
150
-
```
151
-
152
-
The first argument after `ipfe-daemon` is the name of the file exchange feed.
153
-
154
-
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.
155
-
156
-
6. Now go back to the terminal and find the Websocket multiaddress of your go-ipfs daemon by running:
157
-
```
158
-
ipfs id
159
-
```
160
-
161
-
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:
7. Copy the address and paste it into the "Connect" input field in the browser app and press "Connect".
167
-
168
-
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:
126
+
Start the browser app with:
169
127
```
170
-
ipfs swarm peers
128
+
npm start
171
129
```
172
130
173
-
### Add files to InterPlanetary File Exchange
131
+
This will open the app in your browser at http://localhost:3000/. Open a file exchange feed by appending the feed name to the url, eg. http://localhost:3000/hello-world.
174
132
175
-
1. Add a file by running:
176
-
```
177
-
node ipfe-add hello-world ipfe-add.js
178
-
```
133
+
In the browser app, open the Peers view by clicking on "Searching for peers..." and enter the go-ipfs address you got fom `ipfs id` earlier into the input field and press connect. You should now see that address in the list of peers.
179
134
180
-
You should see the following output:
135
+
Go back to the terminal and run the file exchange CLI tool:
181
136
```
182
-
Starting...
183
-
Swarm listening on /libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmYRSN9BdRU5oYM1ryAWF518ogv8SkwZyux4aEWpxoaYZA
Note that the multihash at the end of the swarm address will be different.
194
-
195
-
6. Once you see the output above, it means the file was added successfully!
196
-
197
-
7. Now go back to the browser app and observe the file in the list of files.
198
-
199
-
8. Click the file to open it.
140
+
You should now see `package.json` in the browser app! Click it to view its contents.
200
141
201
-
9. You have successfully added a file in go-ipfs and downloaded it to the browser.
142
+
**That's it!**
202
143
203
-
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`.
144
+
Play around with the browser app, drag and drop files into it, run `node src/cli/bin` to see what else you can do with the CLI tool and have fun!
0 commit comments