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

tutorial: Transfer Files #714

Closed
wants to merge 10 commits into from
Closed

tutorial: Transfer Files #714

wants to merge 10 commits into from

Conversation

haadcode
Copy link
Member

@haadcode haadcode commented Jan 16, 2017

This PR will add a basic interop example as per #711.

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demo available here is not an interop demo, in fact, it doesn't touch go-ipfs at all, I know you wanted first to do js-ipfs to js-ipfs, but that is not the purpose.

The demo must be (as discussed during prep session):

  • User adds content using go-ipfs CLI
  • User accesses that content from a browser.

To overcome the challenge of not being blocked by the stream muxing issue, you can write the whole tutorial using js-ipfs CLI + js-ipfs in the Browser, then when muxed is fixed (cc @victorbjelkholm), we will just need to s/jsipfs/ipfs.

@@ -0,0 +1,102 @@
# interop examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/interop examples/fetch content added by go-ipfs

npm start
```

Open http://127.0.0.1:8080 in your favorite browser.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome or Firefox

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both should work, thus "your favorite" :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also Safari, Edge, Internet Explorer and Opera, not everyone's favourite is Chrome or Firefox :)

Steps
1. create IPFS instance

First, we need an IPFS instance that we'll use throughout the tutorial. For the sake of convinience, we'll use `ipfs-daemon` module to create and IPFS instance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be recommending ipfs-daemon in order to instantiate js-ipfs, it just means that js-ipfs needs to improve its init process.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rework this in a way that the init dance is in its own file and we include js-ipfs instead of ipfs-daemon.

I don't think we'll get to merge ipfs-daemon to js-ipfs within two weeks given how massive public API change that is. Let me know if you think we can.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'll get to merge ipfs-daemon to js-ipfs within two weeks given how massive public API change that is. Let me know if you think we can.

We totally can, it is not actually that big of a change, really, just requires putting in the hours, it is pretty clear what we want out of it and we have a ton of tests creating js-ipfs daemons with different configurations and in Node.js + Browser, those that will ensure that the new API works.

It is, however, a low priority compared to the rest of the tasks for this Sprint, so, if we get to finish all the others, we will want ot tackle this.

Until then, the demo should be without an external module to create an instance of this module.

})
```

2. listen for file drop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this demo is to "access files from go-ipfs", and not adding files inside the browser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Somewhere we discussed, and decided, that we do go-ipfs -> js-ipfs-browser -> js-ipfs-browser (stream a video or smth). I believe adding the support for adding files to the browser version is not that much out of scope in terms of work and it adds another important step to the tutorial for one of the most asked questions for someone who's starting with ipfs "how do I add files to IPFS?". So having that functionality gives a more fully fledged tutorial than just catting files from go-ipfs. Don't worry, we're still going for the same goal: access files from go-ipfs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@haadcode
Copy link
Member Author

The demo available here is not an interop demo, in fact, it doesn't touch go-ipfs at all, I know you wanted first to do js-ipfs to js-ipfs, but that is not the purpose.

All of this is what the example will be. Perhaps the intent was dropped in the communication. If you take a look at my sprint updates, you'll see the progress being described (ie. it's WIP).

See this comment #714 (comment) for details to why there's browser-to-browser functionality too.

@haadcode
Copy link
Member Author

To clarify, this PR will (eventually) implement the example as designed here: #711 (comment)

@daviddias
Copy link
Member

@haadcode thank you for clarifying! :)

@daviddias daviddias changed the title (WIP) Add basic interop example (WIP) Example: cat a go-ipfs added file from the browser Jan 19, 2017
Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haadcode just tried the example and worked like a charm.

But I didn't really run through the Tutorial, because the example is the full blown thing already and I understand why, we need to have the thing done once, in order to know it works, so here is my suggestion to improve the UX.

  • create a folder called tutorials at the root of the project and move this example there
  • rename the folder to 'access-go-ipfs-files'
  • inside the folder have README.md, final/, start
  • inside the folder final, have the full built thing
  • inside the folder start, have just the starting files (package.json, http server step up, etc)
  • in the README, explain the purpose of this tutorial, how people can run the real deal and that they can do this as a tutorial.
  • Important to add to gitignore the files from the startfolder, with the exceptions of the ones you leave there :)

Apply this to other example as well.

Note that, things that are still missing from the goal of this example (which you are probably well aware, but just listing them now to keep track):

  • right now, it is still just doing browser to browser
  • There is no reference as to explain that a file should be added with js-ipfs/go-ipfs CLI
  • It needs to explain that a WebSockets address needs to added to go-ipfs/js-ipfs
  • or a webrtc-star address to js-ipfs


## Run
```
cd examples/interop-examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, people will be inside this folder already

"author": "",
"license": "ISC",
"dependencies": {
"ipfs-daemon": "^0.3.0-beta.16"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ipfs-daemon is out of the equation, it will be so much faster to get this example to work because one less npm install of the whole thing is needed.

"start": "http-server -c-1"
},
"author": "",
"license": "ISC",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ISC/MIT

This was referenced Jan 20, 2017
@daviddias daviddias changed the title (WIP) Example: cat a go-ipfs added file from the browser (WIP) Tutorial: cat a go-ipfs added file from the browser Jan 20, 2017
@daviddias
Copy link
Member

@haadcode I was going to review this example again, but I see there hasn't been any other commit since my last review, so I will avoid listing out the points of feedback again.

I received a notification through IRC that you were preparing some handoff guide for the next person to take on this examples, however, I'm being unable to find it, I've scanned the IRC logs and opened all the related github issues, could you point me to it? Thank you.

@haadcode
Copy link
Member Author

you were preparing some handoff guide for the next person to take on this examples

Working on it.

@haadcode
Copy link
Member Author

Updated everything, fixed a bunch of stuff. This should be now ready to be picked up by others. What remains to be done is listed in: https://github.com/ipfs/js-ipfs/blob/e916a5d1d0c654a6111e5a4861aafb79b72b3e62/examples/access-go-ipfs-files/cat-a-file/README.md#todo. There's also the new signal server address that needs to be fixed as per libp2p/js-libp2p-webrtc-star#87.

The short is: add the UI for connecting to a go-ipfs address manually and make sure catting the file from go-ipfs-->js-ipfs(-browser) works.

@daviddias
Copy link
Member

Seems that it is assumed that the user has ran npm run build before hand.

» npm i

> cat-a-file@1.0.0 postinstall /Users/koruza/code/js-ipfs/examples/access-go-ipfs-files/cat-a-file
> cp ../../../dist/index.js ./public/ipfs.js

cp: ../../../dist/index.js: No such file or directory

npm WARN cat-a-file@1.0.0 No repository field.
npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i"
npm ERR! node v6.9.1

@daviddias
Copy link
Member

daviddias commented Jan 25, 2017

The example doesn't have a way to signal a want to dial to any other node, assumes that webrtc is used. The purpose was to offer to the user a way to dial through websockets.

I rebased the commits

@daviddias
Copy link
Member

working on this example today

@daviddias daviddias force-pushed the docs/interop-examples branch 2 times, most recently from af0ff7a to 06aa615 Compare January 25, 2017 17:05
@daviddias
Copy link
Member

Todo notes left by @haadcode for @RichardLitt

@victorb victorb assigned victorb and unassigned haadcode Jan 26, 2017
@victorb
Copy link
Member

victorb commented Jan 26, 2017

Taking over this for now

@daviddias daviddias changed the title (WIP) Tutorial: cat a go-ipfs added file from the browser (WIP) Tutorial: Transfer Files Jan 27, 2017
@victorb
Copy link
Member

victorb commented Jan 29, 2017

Sorry @haadcode missed your comments before, reply inline:

It's better to use dynamic sizes (for fonts, margins, widths, etc.) instead of pixels, ie. px --> em / rem / etc.

I would like the layout to stay the same no matter the viewport so I'll go with px here.

When changing CSS, make sure to test the changes at least with Firefox and Chrome to make sure they both work (usually they don't quite render the same), and make sure to try it on a mobile browser(s) too to make sure the layouts and fonts scale.

Sure, no problem. I'm not gonna spend any time on trying it on mobile though, if people want it to work on mobile, they'll have to solve any issues themselves (or we can do another example for mobile in the future)

I believe that you're still working on this, but make sure the picture is actually shown: ea48e5b#diff-6db58e31a051cfc7a871d0fd2444b037R100 :)

Not really, I've removed the picture since I didn't see how it tied into the example. I think it's not necessary to show a picture inline in the webpage but rather when people add files, we show them in a download list.

@victorb
Copy link
Member

victorb commented Jan 29, 2017

Last update before weekend

Still missing some refactor, mainly splitting up the ipfs and UI logic, right now it's all wrapped together. Made just one quick pass for comments so probably there are things that can be better explained. I have not looked at the tutorial and I'm pretty sure it's unfinished. Did some improvements with the drag-and-drop but still there is a bug left.

Biggest one is that .get doesn't actually work at the moment. Purpose is to fetch the content of the file and set as an octet-stream as the download when clicking the link, but something is crashing with the wrong cid version. @diasdavid is working on fixing this.

  • Refactor code + add valuable comments
  • Have .get actually work with just one file and also maybe directories
  • Fix drag-and-drop not closing popup when ending up not dropping file in UI
  • Finish tutorial in readme.md

@daviddias daviddias mentioned this pull request Jan 29, 2017
daviddias and others added 7 commits January 30, 2017 09:24
- refactor: reorg + fix lint
- fix: build step, no longer fail on postinstall
- docs: add diagram
- docs: add the instructions steps
- lint: fix all the things
- note about signalling server
- nicer colors
- include logo
- fancier buttons
- easier flow to start daemon
- less information after starting daemon
- use dns signal server
- larger font size
- removal of unused features
- removal of duplicated script references
- more explanation
- and probably something more I forgot
@daviddias
Copy link
Member

daviddias commented Jan 30, 2017

@victorbjelkholm I just fresh git cloned and fresh install both package.json and this is what I'm getting:

image

Updated: fixed in #31c6383

@victorb
Copy link
Member

victorb commented Jan 30, 2017

Final pass-through before leaving this move on to the CI/CD sprint

  • cd into /complete directory of the transfer files example

  • Run npm install

  • Run npm start

  • cd ../../../

  • run npm run build

  • cd examples/transfer-files/complete

  • npm start

  • navigate to localhost:12345

  • in js-ipfs, run IPFS_PATH=$HOME/.examples-test node src/cli/bin.js init

  • run IPFS_PATH=$HOME/.examples-test node src/cli/bin.js daemon

  • run IPFS_PATH=$HOME/.examples-test node src/cli/bin.js id

  • grab the address containing /ws

  • connect directly to it by putting /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmPs14AG8igTwHKvZ2deVDrkYTtczghHTeyivUNsSydhpH in the multiaddr input and pressing "Connect to peer"

  • Address shows up in list of remote peers

  • Run IPFS_PATH=$HOME/.examples-test node src/cli/bin.js add package.json, save the hash

  • Paste the hash into multihash input field, press "Fetch file"

  • Date - Hash and size appears in the list of fetched files

  • Clicking on the item for the file triggers download

  • File finished downloading, opening up shows content of file being "content of file" since the .get is not fully working yet... See TODO comment in function catFile in app.js

  • Dragging a file into the UI shows wonky "drop file popup" that appears and disappears when moving the mouse around

  • Dropping the file shows "Added antigen.sh as Qm[...]" and changes the hash in the multihash input

  • Clicking "Fetch file" adds the file to the list of files with it's size and the date

  • Clicking on the added file item downloads the file but still with the file contents being "content of file"

  • Let's try with a go-ipfs node. Kill the current running nodejs node

  • Peer disappears from the UI in the complete example

  • Pull down latest master of go-ipfs and install it

  • Run IPFS_PATH=$HOME/.examples-test-go ipfs init

  • Run IPFS_PATH=$HOME/.examples-test-go ipfs daemon

  • No /ws address, need to add it to the configuration

  • Open $HOME/.examples-test-go/config and add /ip4/127.0.0.1/tcp/4004/ws to the list of swarm addresses

  • Run IPFS_PATH=$HOME/.examples-test-go ipfs daemon

  • Run IPFS_PATH=$HOME/.examples-test-go ipfs id, save the /ws address

  • Paste /ws address into multiaddr input and press "Connect to peer"

  • Peer address shows up in UI

  • Run IPFS_PATH=$HOME/.examples-test-go ipfs add appveyor.yml in go-ipfs repository

  • Save hash

  • Paste hash into multihash input and press "Fetch file"

  • Receive stream with files but it doesn't have any .content field as the response from nodejs process has

Conclusion

  • "content of file" is currently being set as the content of the file since we haven't fully got .get to work yet
  • Communication with go-ipfs nodes does not work the same way as when communicating with nodejs nodes
  • When connecting with the go-ipfs daemon, peer is listed in the browser node but not in the go-ipfs node

@victorb
Copy link
Member

victorb commented Jan 30, 2017

Discovered via @diasdavid doing a demo today with this.

  • Peers list have a comma between every peer that is not supposed to be there
  • Multiaddr input is too wide and goes outside the containing box

@daviddias daviddias changed the title (WIP) Tutorial: Transfer Files tutorial: Transfer Files Jan 31, 2017
@daviddias
Copy link
Member

@victorbjelkholm fixed the get problem. The stream was never resumed :)

843e227

@daviddias
Copy link
Member

Follow here: #774 (comment)

@daviddias daviddias closed this Mar 7, 2017
@daviddias daviddias deleted the docs/interop-examples branch March 7, 2017 16:21
@daviddias daviddias removed the status/in-progress In progress label Mar 7, 2017
daviddias pushed a commit that referenced this pull request Mar 15, 2017
daviddias pushed a commit that referenced this pull request Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants