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

tutorial: File Exchange - Transfer files between desktop and browser using go-ipfs, js-ipfs and orbit-db #716

Closed
wants to merge 26 commits into from

Conversation

haadcode
Copy link
Member

This is a WIP PR for the second interop example. A File Manager in the browser, which eventually will be able to display files added in go-ipfs. It currently works only between browser js-ipfs nodes.

No need to review it yet, still working on it.

@haadcode haadcode added the status/in-progress In progress label Jan 18, 2017
@daviddias daviddias changed the title (WIP) Advanced interop example (WIP) Example: File Browser - Traverse through directories added from go-ipfs, in the browser Jan 19, 2017
@daviddias
Copy link
Member

Not getting this example to work:
image

@daviddias
Copy link
Member

This example is looking very similar to PaperHub that @dignifiedquire made a while ago, it is interesting, but it the main goal is to have a file manager that can open directories and traverse to them, these directories should be added through go-ipfs.

I know you are still heavily working on this one and that you have the intent of making it the actual File Browser, so I will review it again when it is fulfilling that goal.

@daviddias
Copy link
Member

Ah I added a file on firefox and it showed up in chrome:
image

And then, I added an extra one to Chrome, and the 3 files appeared in Firefox too:

image

@daviddias
Copy link
Member

daviddias commented Jan 20, 2017

I believe that this 'injection' of orbit into the example is creating a distraction to the main goal, which is why developing it incrementally, as suggested, would have been a big win.

Now, the better is just consider the time-left/effort to achieve that main goal and see if we get closer by taking out orbit out of the equation or not.

This was referenced Jan 20, 2017
@daviddias daviddias changed the title (WIP) Example: File Browser - Traverse through directories added from go-ipfs, in the browser (WIP) Tutorial: File File - Track Files being added with go-ipfs using orbit-db Jan 20, 2017
@daviddias
Copy link
Member

@haadcode updated the name of this PR to reflect the decision made through IRC chat. One task that needs to also happen is:

12:01 <haad> daviddias: eating lunch, will get back to you in a few. re. go-ipfs aprt of the tutorial for file feed: I was planning on writing a small .js file that spawns a go-ipfs daemon and adds the file to ipfs+orbit-db.
12:02 <haad> daviddias: ok so re that ^, should object.get/object.put and pubsub interop work with go-ipfs<-->js-ipfs?
12:02 <haad> because if they won't, then we can't do that and we're better off doing the file browser
12:05 <@daviddias> haad: I would say pubsub interop: yes it works, but won't officially say it unless there is a test in interop for that - https://github.com/ipfs/js-ipfs/tree/master/test/interop, it only thing I can say is: It used to work, now something might have changed, we can't tell.
12:05 <@daviddias> That interop test should be part of the list of tasks for that interop example (File Feed)

@daviddias daviddias changed the title (WIP) Tutorial: File File - Track Files being added with go-ipfs using orbit-db (WIP) Tutorial: Files Feed - Track Files being added with go-ipfs using orbit-db Jan 20, 2017
@haadcode
Copy link
Member Author

The browserify-zlib-next dependecy problems have been solved. What is still needed is to merge this: ipfs-shipyard/browserify-zlib-next#23. cc @diasdavid @dignifiedquire

@haadcode
Copy link
Member Author

I'm fixing and updating everything right now to make sure this can be finished by someone.

@dignifiedquire
Copy link
Member

[email protected] was just released with the fix

@haadcode
Copy link
Member Author

Thank you @dignifiedquire 🎉

@haadcode
Copy link
Member Author

Can verify that everything works now with browserify-zlib-next 1.0.1. Hooray \o/

@daviddias
Copy link
Member

TODOs left by @haadcode

TODO

  • Need to merge fix: Use Buffer.isBuffer to check buffer type ipfs-shipyard/browserify-zlib-next#23 and use the updated module. Otherwise the UI will error on zlib._transform.
  • Make sure go-ipfs and the UI connect to each other (last time I checked they didn't)
  • Use new signal server address everywhere (src/App.js, ipfe-daemon.js, ipfe-add.js)
  • 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.

@daviddias
Copy link
Member

daviddias commented Jan 27, 2017

  • The cli tool to add files is pointing at local signalling server
  • still uses ipfs-daemon

@daviddias
Copy link
Member

Found that it works in the browser with no signalling server at all because the browser is mounting always on top of the same repo.

image

@daviddias
Copy link
Member

image

Got the Desktop example to work with DNS

}
this.ipfs = node
this.emit('ready')
})
Copy link
Member

Choose a reason for hiding this comment

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

Async operations in a constructor are an anti-pattern, a good source of errors

Copy link
Member

@daviddias daviddias Jan 28, 2017

Choose a reason for hiding this comment

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

Getting issues from this

image

Copy link
Member

@daviddias daviddias Jan 28, 2017

Choose a reason for hiding this comment

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

ah got it, this always happens if we open without being on a feed which is controlled by the top level domain. This is a bug

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, this is not good. Will change it.

@daviddias
Copy link
Member

daviddias commented Jan 27, 2017

@haadcode how did you manage to use WebPack@2? I'm missing to find any note and ipfs doesn't really work if bundled with WebPack@1 and as @dignifiedquire just mentioned, WebPack@2 will only come in the next version of create-react-app.

If there was alternative, shall we eject and update the react deps?

@daviddias
Copy link
Member

Clicking the "number of peers" throws

image

@daviddias
Copy link
Member

If a peer joins after files where added, it stays on 'Loading database' forever

image

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.

Currently, the App isn't in a state where it is easy to use it, as it shows several bugs during its usage. It might be necessary, since it is a complex app, to have tests for it, it will help the debugging while the remaining of the development is finished.

I've structured it in the same way the other tutorial is, added a bit more information to the Readme and talked with @RichardLitt about making the full tutorial. I'll still add a diagram of the app.

@haadcode I would appreciate your help on getting this ready for Monday, I'll be around Sunday when you come back for us to catch up :)

npm-debug.log

# orbit-db
orbit-db
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to ignore a folder named orbit-db?

Copy link
Member Author

Choose a reason for hiding this comment

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

OrbitDB writes its cache file to that directory when run with go-ipfs or js-ipfs from the CLI. This is per user and we shouldn't add it to the repo.

## Step-by-step instructions

`TODO`

Copy link
Member

Choose a reason for hiding this comment

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

@RichardLitt is on track to do this once the example is completely done. @RichardLitt I'll notify you when that happens ❤️

net: 'empty',
tls: 'empty'
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we validate that we actually need all of this configuration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we need all this configuration. See my long comment below as to why.

Short: the webpack config file here is the create-react-app/react-script config file with the only difference that we add the zlib shim to it.

@@ -0,0 +1,25 @@
{
"name": "file-feed",
Copy link
Member

Choose a reason for hiding this comment

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

I've renamed it to file-feed as I'm afraid of stamping something with a "InterPlanetary X" name that is not a project (i.e example/tutorial) that we support and make it have the same level of activity of a product.

Pointing people to the 'file-feed tutorial' has a completely different tone than 'InterPlanetary FileExchange'

@haadcode hope you understand, we can chat about it and reach an agreement.

Copy link
Member Author

Choose a reason for hiding this comment

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

@diasdavid I'm totally fine changing the name! However, let's catch up on IRC today to discuss the name as I think we can find something more descriptive and less "loaded" word than "feed" (people will make assumption about what a fedd is that I think we can't provide in this example).

Copy link
Member

Choose a reason for hiding this comment

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

I'll be around for the rest of the day

{
"name": "file-feed",
"version": "0.0.0",
"bin": "src/ff-cli/bin.js",
Copy link
Member

Choose a reason for hiding this comment

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

I've also put the CLI under the bin path, for ease of use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good! I was thinking we could yargsify the CLI tool so that we can run
ff-cli daemon hello-world and ff-cli add hello-world file.txt instead of having two separate programs. This would make the code sharing between the two also a lot easier. Unless you're against yargsifying it, I'll go ahead and do that today.

Copy link
Member

Choose a reason for hiding this comment

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

👍 not against at all :)

}

getFile (hash) {
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

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

Back in the January meetings, we talked about using Promises in examples and we agreed at the table that we would use only callbacks for our examples. Is the use of Promises strictly necessary here?

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 don't remember us talking about Promises, but sure, we can make these callbacks too.

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

stream.on('end', () => {
this.emit('load', hash, bytes)
resolve(buffer)
})
Copy link
Member

Choose a reason for hiding this comment

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

Use bl or concat for this

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 would prefer not adding a library to abstract the underlaying functionality of the stream. After all, this is an example and people will have different approaches to how they use streams, some will use bl or concat, some won't., so keeping it clear what ipfs returns is clearer in this case imo.


addFiles (file) {
const addToIpfs = (name, content) => {
return this.ipfs.files.add([{
Copy link
Member

Choose a reason for hiding this comment

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

IPFS might not exist in this context due to the async operation in the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Will fix the constructor problem.

}

const addToOrbitDB = (file, type) => {
return this.feed.add({
Copy link
Member

Choose a reason for hiding this comment

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

this.feed doens't exist if we aren't in a path.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, feed is locally scoped. Will address this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was fixed in a7b6049. Constructor is not async anymore.


setInterval(checkForPeers, 1000)
setInterval(checkForFiles, 1000)
})
Copy link
Member

Choose a reason for hiding this comment

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

The daemon and the cli tool share a ton of code, do we really need too files for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

See my previous comment re. yargisyfying and combining the two program into one. Yes, we should share the code :)

@daviddias
Copy link
Member

feature request: A very cool features would be to 'watch' a folder, and for every file to gets added to the folder, it syncs to the browser and for every file that is added to the browser, it syncs back to the folder.

@daviddias
Copy link
Member

Btw. once we're done and ready to merge, we should squash all these commits to one with a nice commit message as per our guidelines.

Could you squash now? If we get into the habit of pushing clean commit messages, it will be easier to keep it consistent

@daviddias daviddias changed the title (WIP) Example: File Exchange - Transfer files between desktop and browser using go-ipfs, js-ipfs and orbit-db tutorial: File Exchange - Transfer files between desktop and browser using go-ipfs, js-ipfs and orbit-db Jan 31, 2017
@daviddias daviddias added status/ready Ready to be worked and removed status/in-progress In progress labels Mar 13, 2017
@daviddias
Copy link
Member

daviddias commented May 25, 2017

Hey @pgte it seems that this example froze in time, however, it is pretty valuable.

Could you take a look and make it work just with IPFS primitives? You would end up creating a 'small crdt-log' to make it work on top of pubsub, but if that is a single file vs a full external dependency, I feel that would create way more value and direction for the users.

@pgte
Copy link
Contributor

pgte commented May 25, 2017

@diasdavid sure, I'll look at this once I'm done with ipfs-level.

@daviddias daviddias added status/deferred Conscious decision to pause or backlog and removed status/ready Ready to be worked labels Jun 20, 2017
@daviddias daviddias added status/ready Ready to be worked exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue P1 High: Likely tackled by core team if no one steps up and removed status/deferred Conscious decision to pause or backlog labels Oct 17, 2017
@daviddias
Copy link
Member

Closing this PR as the example was never developed further and since then there were a ton of advancements in js-ipfs and orbit

@daviddias daviddias closed this Dec 14, 2017
@ghost ghost removed the status/ready Ready to be worked label Dec 14, 2017
@daviddias daviddias deleted the dcos/interop-example-2 branch December 14, 2017 09:52
@dryajov dryajov restored the dcos/interop-example-2 branch March 3, 2018 18:04
@daviddias daviddias deleted the dcos/interop-example-2 branch June 4, 2018 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue P1 High: Likely tackled by core team if no one steps up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants