mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-08 05:11:33 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
e52586bf12 | |||
f5ce4cf7dd | |||
1544df1d62 | |||
6a66986129 | |||
d061cdac5a | |||
364e1552bf | |||
eecad599cc |
@ -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
|
||||
language: node_js
|
||||
|
||||
|
10
CHANGELOG.md
10
CHANGELOG.md
@ -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>
|
||||
## [0.1.4](https://github.com/libp2p/js-libp2p-circuit/compare/v0.1.3...v0.1.4) (2017-11-03)
|
||||
|
||||
|
63
README.md
63
README.md
@ -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.
|
||||
|
||||
The applicability of circuit-relaying is not limited to routing traffic between browser nodes, other uses include:
|
||||
- routing traffic between private nets
|
||||
- circumventing NAT layers
|
||||
The use of circuit-relaying is not limited to routing traffic between browser nodes, other uses include:
|
||||
- routing traffic between private nets and circumventing NAT layers
|
||||
- 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.
|
||||
@ -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.
|
||||
|
||||
```
|
||||
|
||||
libp2p libp2p-circuit
|
||||
+-------------------------------------------------+ +---------------------------------------------------------+
|
||||
| | | |
|
||||
| +---------------------------------+ | | |
|
||||
| | | | | +------------------------+ |
|
||||
| | | | circuit-relay registers the /hop | | | |
|
||||
| | libp2p-swarm |<----------------------------------------------------->| circuit-relay | |
|
||||
| | | | multistream handler with the swarm | | | |
|
||||
| | | | to handle incomming dial requests | +------------------------+ |
|
||||
| +---------------------------------+ | from other nodes | transport |
|
||||
| ^ ^ ^ ^ ^ ^ | | +-------------------------------------------+ |
|
||||
| | | | | | | | | | +----------------------------------+ | |
|
||||
| | | | | | | | dialer uses the swarm to dial to a | | | | | |
|
||||
| | | | +------------------------------------------------------------------------------>| dialer | | |
|
||||
| | |transports | | relay node listening on the /hop | | | | | |
|
||||
| | | | | | | multistream endpoint | | +----------------------------------+ | |
|
||||
| | | | | | | | | | |
|
||||
| v v | v v | | | | |
|
||||
|+------------------|----------------------------+| | | +----------------------------------+ | |
|
||||
|| | | | | || | | | | | |
|
||||
||libp2p-tcp |libp2p-ws | .... |libp2p-circuit ||listener registers a /stop multistream | | listener | | |
|
||||
|| | +-------------------------------------------------------------------------------->| | | |
|
||||
|| | | |pluggs in just ||handler with the swarm to handle | | +----------------------------------+ | |
|
||||
|| | | |as any other ||incomming relay connections | | | |
|
||||
|| | | |transport || | +-------------------------------------------+ |
|
||||
|+-----------------------------------------------+| | |
|
||||
| | | |
|
||||
| | | |
|
||||
+-------------------------------------------------+ +---------------------------------------------------------+
|
||||
libp2p libp2p-circuit (transport)
|
||||
+-------------------------------------------------+ +--------------------------+
|
||||
| +---------------------------------+ | | |
|
||||
| | | | | +------------------+ |
|
||||
| | | | circuit-relay listens for the HOP | | | |
|
||||
| | libp2p-swarm <------------------------------------------------| circuit-relay | |
|
||||
| | | | message to handle incomming relay | | | |
|
||||
| | | | requests from other nodes | +------------------+ |
|
||||
| +---------------------------------+ | | |
|
||||
| ^ ^ ^ ^ ^ ^ | | +------------------+ |
|
||||
| | | | | | | | | | +-------------+ | |
|
||||
| | | | | | | | dialer uses libp2p-swarm to dial | | | | | |
|
||||
| | | | +----------------------------------------------------------------------> dialer | | |
|
||||
| | | transports | | to a circuit-relay node using the | | | | | |
|
||||
| | | | | | | HOP message | | +-------------+ | |
|
||||
| | | | | | | | | | |
|
||||
| v v | v v | | | | |
|
||||
|+------------------|----------------------------+| | | +-------------+ | |
|
||||
|| | | | | || | | | | | |
|
||||
||libp2p-tcp |libp2p-ws | .... |libp2p-circuit || listener handles STOP messages from| | | listener | | |
|
||||
|| | +--------------------------------------------------------------------------> | | |
|
||||
|| | | |pluggs in just || circuit-relay nodes | | +-------------+ | |
|
||||
|| | | |as any other || | | | |
|
||||
|| | | |transport || | +------------------+ |
|
||||
|+-----------------------------------------------+| | |
|
||||
+-------------------------------------------------+ +--------------------------+
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Contribute
|
||||
|
||||
|
29
appveyor.yml
Normal file
29
appveyor.yml
Normal 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
2
ci/Jenkinsfile
vendored
Normal 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()
|
@ -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:
|
||||
node:
|
||||
version: stable
|
||||
|
||||
test:
|
||||
post:
|
||||
- npm run coverage -- --upload
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
- google-chrome --version
|
||||
|
28
package.json
28
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-circuit",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"description": "JavaScript implementation of circuit/switch relaying",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
@ -33,32 +33,34 @@
|
||||
},
|
||||
"homepage": "https://github.com/libp2p/js-libp2p-circuit#readme",
|
||||
"devDependencies": {
|
||||
"aegir": "^12.1.3",
|
||||
"aegir": "^13.0.6",
|
||||
"chai": "^4.1.2",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"pre-commit": "^1.2.2",
|
||||
"sinon": "^4.1.1"
|
||||
"sinon": "^4.4.5"
|
||||
},
|
||||
"contributors": [
|
||||
"David Dias <daviddias.p@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": {
|
||||
"assert": "^1.4.1",
|
||||
"async": "^2.5.0",
|
||||
"async": "^2.6.0",
|
||||
"debug": "^3.1.0",
|
||||
"interface-connection": "^0.3.2",
|
||||
"lodash": "^4.17.4",
|
||||
"mafmt": "^3.0.2",
|
||||
"multiaddr": "^3.0.1",
|
||||
"multistream-select": "^0.14.0",
|
||||
"peer-id": "^0.10.2",
|
||||
"peer-info": "^0.11.0",
|
||||
"protons": "^1.0.0",
|
||||
"lodash": "^4.17.5",
|
||||
"mafmt": "^4.0.0",
|
||||
"multiaddr": "^3.0.2",
|
||||
"multistream-select": "^0.14.1",
|
||||
"peer-id": "^0.10.6",
|
||||
"peer-info": "^0.11.6",
|
||||
"protons": "^1.0.1",
|
||||
"pull-abortable": "^4.1.1",
|
||||
"pull-handshake": "^1.1.4",
|
||||
"pull-stream": "^3.6.1",
|
||||
"pull-stream": "^3.6.2",
|
||||
"safe-buffer": "^5.1.1",
|
||||
"setimmediate": "^1.0.5"
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ const EE = require('events').EventEmitter
|
||||
const Connection = require('interface-connection').Connection
|
||||
const utilsFactory = require('./utils')
|
||||
const PeerInfo = require('peer-info')
|
||||
const PeerId = require('peer-id')
|
||||
const proto = require('../protocol')
|
||||
const series = require('async/series')
|
||||
|
||||
@ -33,7 +34,7 @@ class Stop extends EE {
|
||||
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))
|
||||
const newConn = new Connection(streamHandler.rest())
|
||||
newConn.setPeerInfo(peerInfo)
|
||||
@ -44,3 +45,11 @@ class Stop extends EE {
|
||||
}
|
||||
|
||||
module.exports = Stop
|
||||
|
||||
function peerIdFromId (id) {
|
||||
if (typeof id === 'string') {
|
||||
return PeerId.createFromB58String(id)
|
||||
}
|
||||
|
||||
return PeerId.createFromBytes(id)
|
||||
}
|
||||
|
@ -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
|
||||
* `QmPeer` is this peers id
|
||||
* 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
|
||||
* @return {void}
|
||||
|
Reference in New Issue
Block a user