You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 23, 2019. It is now read-only.
libp2p-swarm expects transports that implement [interface-transport](https://github.com/diasdavid/abstract-transport). For example [libp2p-tcp](https://github.com/diasdavid/js-libp2p-tcp).
68
+
libp2p-swarm expects transports that implement [interface-transport](https://github.com/libp2p/abstract-transport). For example [libp2p-tcp](https://github.com/libp2p/js-libp2p-tcp).
69
69
70
70
-`key` - the transport identifier.
71
71
-`transport` -
@@ -100,20 +100,31 @@ Close the listeners of a given transport.
100
100
101
101
##### `swarm.connection.addUpgrade()`
102
102
103
-
A connection upgrade must be able to receive and return something that implements the [interface-connection](https://github.com/diasdavid/interface-connection) specification.
103
+
A connection upgrade must be able to receive and return something that implements the [interface-connection](https://github.com/libp2p/interface-connection) specification.
104
104
105
105
> **WIP**
106
106
107
107
##### `swarm.connection.addStreamMuxer(muxer)`
108
108
109
-
Upgrading a connection to use a stream muxer is still considered an upgrade, but a special case since once this connection is applied, the returned obj will implement the [interface-stream-muxer](https://github.com/diasdavid/interface-stream-muxer) spec.
109
+
Upgrading a connection to use a stream muxer is still considered an upgrade, but a special case since once this connection is applied, the returned obj will implement the [interface-stream-muxer](https://github.com/libp2p/interface-stream-muxer) spec.
110
110
111
111
-`muxer`
112
112
113
113
##### `swarm.connection.reuse()`
114
114
115
115
Enable the identify protocol.
116
116
117
+
##### `swarm.connection.crypto([tag, encrypt])`
118
+
119
+
Enable a specified crypto protocol. By default no encryption is used, aka `plaintext`. If called with no arguments it resets to use `plaintext`.
120
+
121
+
You can use for example [libp2p-secio](https://github.com/libp2p/js-libp2p-secio) like this
122
+
123
+
```js
124
+
constsecio=require('libp2p-secio')
125
+
swarm.connection.crypto(secio.tag, secio.encrypt)
126
+
```
127
+
117
128
### `swarm.dial(pi, protocol, callback)`
118
129
119
130
dial uses the best transport (whatever works first, in the future we can have some criteria), and jump starts the connection until the point where we have to negotiate the protocol. If a muxer is available, then drop the muxer onto that connection. Good to warm up connections or to check for connectivity. If we have already a muxer for that peerInfo, then do nothing.
@@ -152,17 +163,43 @@ Close all the listeners and muxers.
152
163
153
164
-`callback`
154
165
166
+
### This module uses `pull-streams`
167
+
168
+
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).
169
+
170
+
You can learn more about pull-streams at:
171
+
172
+
-[The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ)
173
+
-[The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams)
174
+
-[pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple)
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:
// nodeStreamInstance is an instance of a Node.js Stream
186
+
```
187
+
188
+
To learn more about this utility, visit https://pull-stream.github.io/#pull-stream-to-stream.
189
+
190
+
191
+
155
192
## Design
156
193
157
194
### Multitransport
158
195
159
196
libp2p is designed to support multiple transports at the same time. While peers are identified by their ID (which are generated from their public keys), the addresses of each pair may vary, depending the device where they are being run or the network in which they are accessible through.
160
197
161
-
In order for a transport to be supported, it has to follow the [interface-transport](https://github.com/diasdavid/interface-transport) spec.
198
+
In order for a transport to be supported, it has to follow the [interface-transport](https://github.com/libp2p/interface-transport) spec.
162
199
163
200
### Connection upgrades
164
201
165
-
Each connection in libp2p follows the [interface-connection](https://github.com/diasdavid/interface-connection) spec. This design decision enables libp2p to have upgradable transports.
202
+
Each connection in libp2p follows the [interface-connection](https://github.com/libp2p/interface-connection) spec. This design decision enables libp2p to have upgradable transports.
166
203
167
204
We think of `upgrade` as a very important notion when we are talking about connections, we can see mechanisms like: stream multiplexing, congestion control, encrypted channels, multipath, simulcast, etc, as `upgrades` to a connection. A connection can be a simple and with no guarantees, drop a packet on the network with a destination thing, a transport in the other hand can be a connection and or a set of different upgrades that are mounted on top of each other, giving extra functionality to that connection and therefore `upgrading` it.
0 commit comments