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

Changes required for #968 feat/Gateway #989

Merged
merged 9 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/http/gateway/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
const mh = require('multihashes')
const promisify = require('promisify-es6')
const eachOfSeries = require('async/eachOfSeries')
const CID = require('cids')
const Unixfs = require('ipfs-unixfs')
const debug = require('debug')
const log = debug('jsipfs:http-gateway:resolver')
log.error = debug('jsipfs:http-gateway:resolver:error')

const html = require('./utils/html')
const PathUtil = require('./utils/path')

Expand Down Expand Up @@ -41,32 +42,31 @@ const resolveMultihash = promisify((ipfs, path, callback) => {
const partsLength = parts.length

let currentMultihash = parts[0]

let currentCid
eachOfSeries(parts, (multihash, currentIndex, next) => {
// throws error when invalid multihash is passed
mh.validate(mh.fromB58String(currentMultihash))
// throws error when invalid CID is passed
try {
currentCid = new CID(mh.fromB58String(currentMultihash))
} catch (e) {
if (e) throw e
}

log('currentMultihash: ', currentMultihash)
log('currentIndex: ', currentIndex, '/', partsLength)

ipfs.object.get(currentMultihash, { enc: 'base58' }, (err, dagNode) => {
ipfs.dag.get(currentCid, (err, result) => {
if (err) { return next(err) }
let dagNode = result.value

if (currentIndex === partsLength - 1) {
// leaf node
log('leaf node: ', currentMultihash)

// TODO: Check if it is a directory by using Unixfs Type, right now
// it won't detect empty dirs
if (dagNode.links &&
dagNode.links.length > 0 &&
dagNode.links[0].name.length > 0) {
// this is a directory.

let dagDataObj = Unixfs.unmarshal(dagNode.data)
if (dagDataObj.type === 'directory') {
let isDirErr = new Error('This dag node is a directory')
// add currentMultihash as a fileName so it can be used by resolveDirectory
isDirErr.fileName = currentMultihash
return next(isDirErr)
}

return next()
}

Expand Down
6 changes: 3 additions & 3 deletions src/http/gateway/resources/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const PathUtils = require('../utils/path')
const Stream = require('stream')

module.exports = {
checkHash: (request, reply) => {
if (!request.params.hash) {
checkCID: (request, reply) => {
if (!request.params.cid) {
return reply({
Message: 'Path Resolve error: path must contain at least one component',
Code: 0
}).code(400).takeover()
}

return reply({
ref: `/ipfs/${request.params.hash}`
ref: `/ipfs/${request.params.cid}`
})
},
handler: (request, reply) => {
Expand Down
4 changes: 2 additions & 2 deletions src/http/gateway/routes/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module.exports = (server) => {

gateway.route({
method: '*',
path: '/ipfs/{hash*}',
path: '/ipfs/{cid*}',
config: {
pre: [
{ method: resources.gateway.checkHash, assign: 'args' }
{ method: resources.gateway.checkCID, assign: 'args' }
],
handler: resources.gateway.handler
}
Expand Down
6 changes: 3 additions & 3 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const ncp = require('ncp').ncp
const path = require('path')
const clean = require('../utils/clean')

describe('HTTP GATEWAY', () => {
const repoExample = path.join(__dirname, '../go-ipfs-repo')
describe('HTTP Gateway', () => {
const repoExample = path.join(__dirname, '../js-ipfs-repo')
Copy link
Member

Choose a reason for hiding this comment

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

Hi @ya7ya. It seems I didn't explain myself well. What I mean is that there should be no "repo copying" either from a previously generated go-ipfs or js-ipfs node. When you spawn a daemon after doing init, it will have its own repo created, that is what should be used for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@diasdavid oh, Ma bad, I'll fix that. Sorry.

Copy link
Member

@daviddias daviddias Sep 5, 2017

Choose a reason for hiding this comment

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

No, my bad for not being clear, I'm sorry. Thank you for pushing this :)

const repoTests = path.join(__dirname, '../repo-tests-run')

let http = {}
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('HTTP GATEWAY', () => {
url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
}, (res) => {
expect(res.statusCode).to.equal(200)
expect(res.rawPayload).to.deep.equal(new Buffer('hello world' + '\n'))
expect(res.rawPayload).to.deep.equal(Buffer.from('hello world' + '\n'))
expect(res.payload).to.equal('hello world' + '\n')
done()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

ys# js-ipfs-repo
Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript
s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

�� IPFS Alpha Security Notes

We try hard to ensure our system is safe and robust, but all software
has bugs, especially new software. This distribution is meant to be an
alpha preview, don't use it for anything mission critical.

Please note the following:

- This is alpha software and has not been audited. It is our goal
to conduct a proper security audit once we close in on a 1.0 release.

- ipfs is a networked program, and may have serious undiscovered
vulnerabilities. It is written in Go, and we do not execute any
user provided data. But please point any problems out to us in a
github issue, or email [email protected] privately.

- ipfs uses encryption for all communication, but it's NOT PROVEN SECURE
YET! It may be totally broken. For now, the code is included to make
sure we benchmark our operations with encryption in mind. In the future,
there will be an "unsafe" mode for high performance intranet apps.
If this is a blocking feature for you, please contact us.
�
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

��
IPFS -- Inter-Planetary File system

IPFS is a global, versioned, peer-to-peer filesystem. It combines good ideas
from Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bit-
torrent swarm, exchanging git objects. IPFS provides an interface as simple
as the HTTP web, but with permanence built in. You can also mount the world
at /ipfs.

IPFS is a protocol:
- defines a content-addressed file system
- coordinates content delivery
- combines Kademlia + BitTorrent + Git

IPFS is a filesystem:
- has directories and files
- mountable filesystem (via FUSE)

IPFS is a web:
- can be used to view documents like the web
- files accessible via HTTP at `http://ipfs.io/<path>`
- browsers or extensions can learn to use `ipfs://` directly
- hash-addressed content guarantees authenticity

IPFS is modular:
- connection layer over any network protocol
- routing layer
- uses a routing layer DHT (kademlia/coral)
- uses a path-based naming service
- uses bittorrent-inspired block exchange

IPFS uses crypto:
- cryptographic-hash content addressing
- block-level deduplication
- file integrity + versioning
- filesystem-level encryption + signing support

IPFS is p2p:
- worldwide peer-to-peer file transfers
- completely decentralized architecture
- **no** central point of failure

IPFS is a cdn:
- add a file to the filesystem locally, and it's now available to the world
- caching-friendly (content-hash naming)
- bittorrent-based bandwidth distribution

IPFS has a name service:
- IPNS, an SFS inspired name system
- global namespace based on PKI
- serves to build trust chains
- compatible with other NSes
- can map DNS, .onion, .bit, etc to IPNS
�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/
" g�q���6\u�8~:��6~�g���Z.��direct�T2
" 6(���%݄���.��Ӿ5(���������ab recursive�T
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
5
" ���׾F�_�uؔ�l��z�S?��|ڲ��Pc@ js-ipfs-repo�


Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

��The MIT License (MIT)

Copyright (c) 2015 IPFS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

�
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
" ��,��Qv3��k>\�IzxEEl�M/f�LICENSE�1
" JZ�XoR�X�!Fwd87U��;��SöWw� README.md{

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

��Come hang out in our IRC chat room if you have any questions.

Contact the ipfs dev team:
- Bugs: https://github.com/ipfs/go-ipfs/issues
- Help: irc.freenode.org/#ipfs
- Email: [email protected]
�
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/
" ��!6���1�ص��F��2$`7#u@1�direct�T2
" ����Hz�8�#3u2�ED� ��ƥ��*Q�KMQ� recursive�T
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

��Some helpful resources for finding your way around ipfs:

- quick-start: a quick show of various ipfs features.
- ipfs commands: a list of all commands
- ipfs --help: every command describes itself
- https://github.com/ipfs/go-ipfs -- the src repository
- #ipfs on irc.freenode.org -- the community irc channel
�
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

��# 0.1 - Quick Start

This is a set of short examples with minimal explanation. It is meant as
a "quick start". Soon, we'll write a longer tour :-)


Add a file to ipfs:

echo "hello world" >hello
ipfs add hello


View it:

ipfs cat <the-hash-you-got-here>


Try a directory:

mkdir foo
mkdir foo/bar
echo "baz" > foo/baz
echo "baz" > foo/bar/baz
ipfs add -r foo


View things:

ipfs ls <the-hash-here>
ipfs ls <the-hash-here>/bar
ipfs cat <the-hash-here>/baz
ipfs cat <the-hash-here>/bar/baz
ipfs cat <the-hash-here>/bar
ipfs ls <the-hash-here>/baz


References:

ipfs refs <the-hash-here>
ipfs refs -r <the-hash-here>
ipfs refs --help


Get:

ipfs get <the-hash-here> -o foo2
diff foo foo2


Objects:

ipfs object get <the-hash-here>
ipfs object get <the-hash-here>/foo2
ipfs object --help


Pin + GC:

ipfs pin add <the-hash-here>
ipfs repo gc
ipfs ls <the-hash-here>
ipfs pin rm <the-hash-here>
ipfs repo gc


Daemon:

ipfs daemon (in another terminal)
ipfs id


Network:

(must be online)
ipfs swarm peers
ipfs id
ipfs cat <hash-of-remote-object>


Mount:

(warning: fuse is finicky!)
ipfs mount
cd /ipfs/<the-hash-here>
ls


Tool:

ipfs version
ipfs update
ipfs commands
ipfs config --help
open http://localhost:5001/webui


Browse:

webui:

http://localhost:5001/webui

video:

http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse

images:

http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs

markdown renderer app:

http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown
�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/
" �@������ԆD���g����A���7direct�T2
" �;A��P���Y0��k��}�E�=��p���� recursive�T
Expand Down
Loading