Skip to content

Commit 3dd5ff4

Browse files
authored
refactor: circuit relay to async (#477)
* refactor: add dialing over relay support * chore: fix lint * fix: dont clear listeners on close * fix: if dial errors already have codes, just rethrow them * fix: clear the registrar when libp2p stops * fix: improve connection maintenance with circuit * chore: correct feedback * test: use chai as promised * test(fix): reset multiaddrs on dial test
1 parent 4ca569c commit 3dd5ff4

30 files changed

+934
-1166
lines changed

.aegir.js

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ const before = async () => {
2323
transport: [WebSockets],
2424
streamMuxer: [Muxer],
2525
connEncryption: [Crypto]
26+
},
27+
config: {
28+
relay: {
29+
enabled: true,
30+
hop: {
31+
enabled: true,
32+
active: false
33+
}
34+
}
2635
}
2736
})
2837
// Add the echo protocol

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
"mafmt": "^7.0.0",
6060
"merge-options": "^1.0.1",
6161
"moving-average": "^1.0.0",
62-
"multiaddr": "^7.1.0",
62+
"multiaddr": "^7.2.1",
6363
"multistream-select": "^0.15.0",
6464
"once": "^1.4.0",
6565
"p-map": "^3.0.0",
6666
"p-queue": "^6.1.1",
6767
"p-settle": "^3.1.0",
68-
"peer-id": "^0.13.3",
68+
"peer-id": "^0.13.4",
6969
"peer-info": "^0.17.0",
7070
"promisify-es6": "^1.0.3",
7171
"protons": "^1.0.1",
@@ -80,6 +80,7 @@
8080
"abortable-iterator": "^2.1.0",
8181
"aegir": "^20.0.0",
8282
"chai": "^4.2.0",
83+
"chai-as-promised": "^7.1.1",
8384
"chai-checkmark": "^1.0.1",
8485
"cids": "^0.7.1",
8586
"delay": "^4.3.0",

src/circuit/README.md

+2-28
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Prior to `libp2p-circuit` there was a rift in the IPFS network, were IPFS nodes
3232
- [Example](#example)
3333
- [Create dialer/listener](#create-dialerlistener)
3434
- [Create `relay`](#create-relay)
35-
- [This module uses `pull-streams`](#this-module-uses-pull-streams)
36-
- [Converting `pull-streams` to Node.js Streams](#converting-pull-streams-to-nodejs-streams)
3735
- [API](#api)
3836
- [Implementation rational](#implementation-rational)
3937

@@ -48,7 +46,7 @@ const Circuit = require('libp2p-circuit')
4846
const multiaddr = require('multiaddr')
4947
const pull = require('pull-stream')
5048

51-
const mh1 = multiaddr('/p2p-circuit/ipfs/QmHash') // dial /ipfs/QmHash over any circuit
49+
const mh1 = multiaddr('/p2p-circuit/p2p/QmHash') // dial /p2p/QmHash over any circuit
5250

5351
const circuit = new Circuit(swarmInstance, options) // pass swarm instance and options
5452

@@ -91,37 +89,13 @@ const relay = new Relay(options)
9189
relay.mount(swarmInstance) // start relaying traffic
9290
```
9391

94-
### This module uses `pull-streams`
95-
96-
We expose a streaming interface based on `pull-streams`, rather then on the Node.js core streams implementation (aka Node.js streams). `pull-streams` offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this [issue](https://github.com/ipfs/js-ipfs/issues/362).
97-
98-
You can learn more about pull-streams at:
99-
100-
- [The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ)
101-
- [The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams)
102-
- [pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple)
103-
- [pull-streams documentation](https://pull-stream.github.io/)
104-
105-
#### Converting `pull-streams` to Node.js Streams
106-
107-
If you are a Node.js streams user, you can convert a pull-stream to a Node.js stream using the module [`pull-stream-to-stream`](https://github.com/dominictarr/pull-stream-to-stream), giving you an instance of a Node.js stream that is linked to the pull-stream. For example:
108-
109-
```js
110-
const pullToStream = require('pull-stream-to-stream')
111-
112-
const nodeStreamInstance = pullToStream(pullStreamInstance)
113-
// nodeStreamInstance is an instance of a Node.js Stream
114-
```
115-
116-
To learn more about this utility, visit https://pull-stream.github.io/#pull-stream-to-stream.
117-
11892
## API
11993

12094
[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
12195

12296
`libp2p-circuit` accepts Circuit addresses for both IPFS and non IPFS encapsulated addresses, i.e:
12397

124-
`/p2p-circuit/ip4/127.0.0.1/tcp/4001/ipfs/QmHash`
98+
`/p2p-circuit/ip4/127.0.0.1/tcp/4001/p2p/QmHash`
12599

126100
Both for dialing and listening.
127101

src/circuit/circuit.js

-126
This file was deleted.

0 commit comments

Comments
 (0)