Compare commits

...

7 Commits

Author SHA1 Message Date
e52586bf12 chore: release version v0.1.5 2018-03-14 06:22:21 -07:00
f5ce4cf7dd chore: update contributors 2018-03-14 06:22:21 -07:00
1544df1d62 chore: update deps 2018-03-14 06:20:41 -07:00
6a66986129 docs: update README (#22) 2018-03-14 13:18:10 +00:00
d061cdac5a fix: creating a proper peerId instead of using a simple buffer or string 2018-03-14 13:17:17 +00:00
364e1552bf Merge pull request #20 from libp2p/automatic-ci-script-update
Updating CI files
2017-12-14 17:32:14 +01:00
eecad599cc Updating CI files
This commit updates all CI scripts to the latest version
2017-12-13 21:49:32 +01:00
10 changed files with 99 additions and 54 deletions

View File

@ -1,3 +1,4 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
sudo: false sudo: false
language: node_js language: node_js

View File

@ -1,3 +1,13 @@
<a name="0.1.5"></a>
## [0.1.5](https://github.com/libp2p/js-libp2p-circuit/compare/v0.1.4...v0.1.5) (2018-03-14)
### Bug Fixes
* creating a proper peerId instead of using a simple buffer or string ([d061cda](https://github.com/libp2p/js-libp2p-circuit/commit/d061cda))
<a name="0.1.4"></a> <a name="0.1.4"></a>
## [0.1.4](https://github.com/libp2p/js-libp2p-circuit/compare/v0.1.3...v0.1.4) (2017-11-03) ## [0.1.4](https://github.com/libp2p/js-libp2p-circuit/compare/v0.1.3...v0.1.4) (2017-11-03)

View File

@ -22,9 +22,8 @@
`circuit-relaying` uses additional nodes in order to transfer traffic between two otherwise unreachable nodes. This allows nodes that don't speak the same protocols or are running in limited environments, e.g. browsers and IoT devices, to communicate, which would otherwise be impossible given the fact that for example browsers don't have any socket support and as such cannot be directly dialed. `circuit-relaying` uses additional nodes in order to transfer traffic between two otherwise unreachable nodes. This allows nodes that don't speak the same protocols or are running in limited environments, e.g. browsers and IoT devices, to communicate, which would otherwise be impossible given the fact that for example browsers don't have any socket support and as such cannot be directly dialed.
The applicability of circuit-relaying is not limited to routing traffic between browser nodes, other uses include: The use of circuit-relaying is not limited to routing traffic between browser nodes, other uses include:
- routing traffic between private nets - routing traffic between private nets and circumventing NAT layers
- circumventing NAT layers
- route mangling for better privacy (matreshka/shallot dialing). - route mangling for better privacy (matreshka/shallot dialing).
It's also possible to use it for clients that implement exotic transports such as devices that only have bluetooth radios to be reachable over bluetooth enabled relays and become full p2p nodes. It's also possible to use it for clients that implement exotic transports such as devices that only have bluetooth radios to be reachable over bluetooth enabled relays and become full p2p nodes.
@ -146,39 +145,33 @@ Both for dialing and listening.
This module is not a transport, however it implements `interface-transport` interface in order to allow circuit to be plugged with `libp2p-swarm`. The rational behind it is that, `libp2p-circuit` has a dial and listen flow, which fits nicely with other transports, moreover, it requires the _raw_ connection to be encrypted and muxed just as a regular transport's connection does. All in all, `interface-transport` ended up being the correct level of abstraction for circuit, as well as allowed us to reuse existing integration points in `libp2p-swarm` and `libp2p` without adding any ad-hoc logic. All parts of `interface-transport` are used, including `.getAddr` which returns a list of `/p2p-circuit` addresses that circuit is currently listening. This module is not a transport, however it implements `interface-transport` interface in order to allow circuit to be plugged with `libp2p-swarm`. The rational behind it is that, `libp2p-circuit` has a dial and listen flow, which fits nicely with other transports, moreover, it requires the _raw_ connection to be encrypted and muxed just as a regular transport's connection does. All in all, `interface-transport` ended up being the correct level of abstraction for circuit, as well as allowed us to reuse existing integration points in `libp2p-swarm` and `libp2p` without adding any ad-hoc logic. All parts of `interface-transport` are used, including `.getAddr` which returns a list of `/p2p-circuit` addresses that circuit is currently listening.
``` ```
libp2p libp2p-circuit (transport)
libp2p libp2p-circuit +-------------------------------------------------+ +--------------------------+
+-------------------------------------------------+ +---------------------------------------------------------+ | +---------------------------------+ | | |
| | | | | | | | | +------------------+ |
| +---------------------------------+ | | | | | | | circuit-relay listens for the HOP | | | |
| | | | | +------------------------+ | | | libp2p-swarm <------------------------------------------------| circuit-relay | |
| | | | circuit-relay registers the /hop | | | | | | | | message to handle incomming relay | | | |
| | libp2p-swarm |<----------------------------------------------------->| circuit-relay | | | | | | requests from other nodes | +------------------+ |
| | | | multistream handler with the swarm | | | | | +---------------------------------+ | | |
| | | | to handle incomming dial requests | +------------------------+ | | ^ ^ ^ ^ ^ ^ | | +------------------+ |
| +---------------------------------+ | from other nodes | transport | | | | | | | | | | | +-------------+ | |
| ^ ^ ^ ^ ^ ^ | | +-------------------------------------------+ | | | | | | | | | dialer uses libp2p-swarm to dial | | | | | |
| | | | | | | | | | +----------------------------------+ | | | | | | +----------------------------------------------------------------------> dialer | | |
| | | | | | | | dialer uses the swarm to dial to a | | | | | | | | | transports | | to a circuit-relay node using the | | | | | |
| | | | +------------------------------------------------------------------------------>| dialer | | | | | | | | | | HOP message | | +-------------+ | |
| | |transports | | relay node listening on the /hop | | | | | | | | | | | | | | | | |
| | | | | | | multistream endpoint | | +----------------------------------+ | | | v v | v v | | | | |
| | | | | | | | | | | |+------------------|----------------------------+| | | +-------------+ | |
| v v | v v | | | | | || | | | | || | | | | | |
|+------------------|----------------------------+| | | +----------------------------------+ | | ||libp2p-tcp |libp2p-ws | .... |libp2p-circuit || listener handles STOP messages from| | | listener | | |
|| | | | | || | | | | | | || | +--------------------------------------------------------------------------> | | |
||libp2p-tcp |libp2p-ws | .... |libp2p-circuit ||listener registers a /stop multistream | | listener | | | || | | |pluggs in just || circuit-relay nodes | | +-------------+ | |
|| | +-------------------------------------------------------------------------------->| | | | || | | |as any other || | | | |
|| | | |pluggs in just ||handler with the swarm to handle | | +----------------------------------+ | | || | | |transport || | +------------------+ |
|| | | |as any other ||incomming relay connections | | | | |+-----------------------------------------------+| | |
|| | | |transport || | +-------------------------------------------+ | +-------------------------------------------------+ +--------------------------+
|+-----------------------------------------------+| | |
| | | |
| | | |
+-------------------------------------------------+ +---------------------------------------------------------+
``` ```
## Contribute ## Contribute

29
appveyor.yml Normal file
View File

@ -0,0 +1,29 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
version: "{build}"
environment:
matrix:
- nodejs_version: "6"
- nodejs_version: "8"
matrix:
fast_finish: true
install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version
# Upgrade npm
- npm install -g npm
# Output our current versions for debugging
- node --version
- npm --version
# Install our package dependencies
- npm install
test_script:
- npm run test:node
build: off

2
ci/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,2 @@
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
javascript()

View File

@ -1,11 +1,8 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
machine: machine:
node: node:
version: stable version: stable
test:
post:
- npm run coverage -- --upload
dependencies: dependencies:
pre: pre:
- google-chrome --version - google-chrome --version

View File

@ -1,6 +1,6 @@
{ {
"name": "libp2p-circuit", "name": "libp2p-circuit",
"version": "0.1.4", "version": "0.1.5",
"description": "JavaScript implementation of circuit/switch relaying", "description": "JavaScript implementation of circuit/switch relaying",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
@ -33,32 +33,34 @@
}, },
"homepage": "https://github.com/libp2p/js-libp2p-circuit#readme", "homepage": "https://github.com/libp2p/js-libp2p-circuit#readme",
"devDependencies": { "devDependencies": {
"aegir": "^12.1.3", "aegir": "^13.0.6",
"chai": "^4.1.2", "chai": "^4.1.2",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2", "pre-commit": "^1.2.2",
"sinon": "^4.1.1" "sinon": "^4.4.5"
}, },
"contributors": [ "contributors": [
"David Dias <daviddias.p@gmail.com>", "David Dias <daviddias.p@gmail.com>",
"Dmitriy Ryajov <dryajov@gmail.com>", "Dmitriy Ryajov <dryajov@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>" "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Pedro Teixeira <i@pgte.me>",
"Victor Bjelkholm <victorbjelkholm@gmail.com>"
], ],
"dependencies": { "dependencies": {
"assert": "^1.4.1", "assert": "^1.4.1",
"async": "^2.5.0", "async": "^2.6.0",
"debug": "^3.1.0", "debug": "^3.1.0",
"interface-connection": "^0.3.2", "interface-connection": "^0.3.2",
"lodash": "^4.17.4", "lodash": "^4.17.5",
"mafmt": "^3.0.2", "mafmt": "^4.0.0",
"multiaddr": "^3.0.1", "multiaddr": "^3.0.2",
"multistream-select": "^0.14.0", "multistream-select": "^0.14.1",
"peer-id": "^0.10.2", "peer-id": "^0.10.6",
"peer-info": "^0.11.0", "peer-info": "^0.11.6",
"protons": "^1.0.0", "protons": "^1.0.1",
"pull-abortable": "^4.1.1", "pull-abortable": "^4.1.1",
"pull-handshake": "^1.1.4", "pull-handshake": "^1.1.4",
"pull-stream": "^3.6.1", "pull-stream": "^3.6.2",
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"setimmediate": "^1.0.5" "setimmediate": "^1.0.5"
} }

View File

@ -6,6 +6,7 @@ const EE = require('events').EventEmitter
const Connection = require('interface-connection').Connection const Connection = require('interface-connection').Connection
const utilsFactory = require('./utils') const utilsFactory = require('./utils')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const proto = require('../protocol') const proto = require('../protocol')
const series = require('async/series') const series = require('async/series')
@ -33,7 +34,7 @@ class Stop extends EE {
return log(err) return log(err)
} }
const peerInfo = new PeerInfo(message.srcPeer.id) const peerInfo = new PeerInfo(peerIdFromId(message.srcPeer.id))
message.srcPeer.addrs.forEach((addr) => peerInfo.multiaddrs.add(addr)) message.srcPeer.addrs.forEach((addr) => peerInfo.multiaddrs.add(addr))
const newConn = new Connection(streamHandler.rest()) const newConn = new Connection(streamHandler.rest())
newConn.setPeerInfo(peerInfo) newConn.setPeerInfo(peerInfo)
@ -44,3 +45,11 @@ class Stop extends EE {
} }
module.exports = Stop module.exports = Stop
function peerIdFromId (id) {
if (typeof id === 'string') {
return PeerId.createFromB58String(id)
}
return PeerId.createFromBytes(id)
}

View File

@ -94,7 +94,9 @@ module.exports = (swarm, options, connHandler) => {
* address to `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer` where * address to `/ip4/0.0.0.0/tcp/0/ipfs/QmRelay/p2p-circuit/ipfs/QmPeer` where
* `QmPeer` is this peers id * `QmPeer` is this peers id
* b) If it's not a /p2p-circuit address, it will encapsulate the address as a /p2p-circuit * b) If it's not a /p2p-circuit address, it will encapsulate the address as a /p2p-circuit
* addr such that dials a relay uses that address to dial this peer * addr, such when dialing over a relay with this address, it will create the circuit using
* the encapsulated transport address. This is useful when for example, a peer should only
* be dialed over TCP rather than any other transport
* *
* @param {Function} callback * @param {Function} callback
* @return {void} * @return {void}