Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

[WIP] Actually implement this #1

Merged
merged 1 commit into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
sudo: false
language: node_js

matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env:
- SAUCE=true
- CXX=g++-4.8
- node_js: stable
env: CXX=g++-4.8

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test
- npm run coverage
- make test

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
52 changes: 46 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
# js-libp2p-dht
# js-libp2p-kad-dht

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![Build Status](https://travis-ci.org/libp2p/js-libp2p-dht.svg?style=flat-square)](https://travis-ci.org/libp2p/js-libp2p-dht) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/libp2p/js-libp2p-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-dht) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Build Status](https://travis-ci.org/ipfs/js-libp2p-kad-dht.svg?style=flat-square)](https://travis-ci.org/ipfs/js-libp2p-kad-dht)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-libp2p-kad-dht/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-libp2p-kad-dht?branch=master)
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-kad-dht)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)

> JavaScript implementation of the DHT for libp2p
> JavaScript implementation of the Kademlia DHT for libp2p, based on [go-libp2p-kad-dht](https://github.com/libp2p/go-libp2p-kad-dht).

## Description
## Table of Contents

## Usage
- [Install](#install)
- [npm](#npm)
- [Use in Node.js](#use-in-nodejs)
- [API](#api)
- [Contribute](#contribute)
- [License](#license)

## Install

### npm

```sh
> npm i libp2p-dht
Copy link
Member

Choose a reason for hiding this comment

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

s/libp2p-dht/libp2p-kad-dht/g

```

### Use in Node.js

```js
const KadDHT = require('libp2p-kad-dht')
```

## API

See https://libp2p.github.io/js-libp2p-kad-dht

## Contribute

Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-libp2p-ipfs/issues)!

This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)

## License

MIT
MIT - Protocol Labs 2017
17 changes: 17 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version

test:
override:
- npm run test
- npm run test:interop
79 changes: 79 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "libp2p-kad-dht",
"version": "0.0.1",
"description": "JavaScript implementation of the Kad-DHT for libp2p",
"main": "src/index.js",
"scripts": {
"lint": "aegir-lint",
"test": "aegir-test --env node",
"test:node": "aegir-test node",
"test:browser": "aegir-test browser",
"build": "aegir-build",
"docs": "aegir-docs",
"release": "aegir-release --docs --env node",
"release-minor": "aegir-release --type minor --docs --env node",
"release-major": "aegir-release --type major --docs --env node",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
},
"browser": {
"libp2p-ipfs-nodejs": "libp2p-ipfs-browser"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "https://github.com/libp2p/js-libp2p-kad-dht.git"
},
"keywords": [
"IPFS"
],
"author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-kad-dht/issues"
},
"engines": {
"node": ">=4.0.0",
"npm": ">=3.0.0"
},
"homepage": "https://github.com/libp2p/js-libp2p-kad-dht",
"dependencies": {
"async": "^2.3.0",
"base32.js": "^0.1.0",
"cids": "~0.5.0",
"debug": "^2.6.3",
"hashlru": "^2.1.0",
"heap": "^0.2.6",
"interface-datastore": "^0.2.0",
"k-bucket": "^3.2.1",
"libp2p-crypto": "~0.8.7",
"libp2p-record": "~0.3.1",
"multihashing-async": "~0.4.5",
"peer-id": "~0.8.7",
"peer-info": "~0.9.2",
"priorityqueue": "^0.2.0",
"protocol-buffers": "^3.2.1",
"pull-length-prefixed": "^1.2.0",
"pull-stream": "^3.5.0",
"varint": "^5.0.0",
"xor-distance": "^1.0.0"
},
"devDependencies": {
"aegir": "^11.0.1",
"chai": "^3.5.0",
"datastore-level": "^0.3.0",
"dirty-chai": "^1.2.2",
"interface-connection": "^0.3.2",
"left-pad": "^1.1.3",
"libp2p-ipfs-browser": "~0.23.0",
"libp2p-ipfs-nodejs": "~0.23.0",
"lodash": "^4.17.4",
"lodash.random": "^3.2.0",
"lodash.range": "^3.2.0",
"peer-book": "~0.4.0",
"pre-commit": "^1.2.2"
}
}
34 changes: 34 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

// MaxRecordAge specifies the maximum time that any node will hold onto a record
// from the time its received. This does not apply to any other forms of validity that
// the record may contain.
// For example, a record may contain an ipns entry with an EOL saying its valid
// until the year 2020 (a great time in the future). For that record to stick around
// it must be rebroadcasted more frequently than once every 'MaxRecordAge'

const second = exports.second = 1000
const minute = exports.minute = 60 * second
const hour = exports.hour = 60 * minute

exports.MAX_RECORD_AGE = 36 * hour

exports.PROTOCOL_DHT = '/ipfs/kad/1.0.0'

exports.PROVIDERS_KEY_PREFIX = '/providers/'

exports.PROVIDERS_LRU_CACHE_SIZE = 256

exports.PROVIDERS_VALIDITY = 24 * hour

exports.PROVIDERS_CLEANUP_INTERVAL = hour

exports.READ_MESSAGE_TIMEOUT = minute

// K is the maximum number of requests to perform before returning failue
exports.K = 20

// Alpha is the concurrency for asynchronous requests
exports.ALPHA = 3

exports.maxMessageSize = 2 << 22 // 4MB
13 changes: 13 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

class InvalidRecordError extends Error {}

class NotFoundError extends Error {}

class LookupFailureError extends Error {}

module.exports = {
InvalidRecordError,
NotFoundError,
LookupFailureError
}
Loading