@libp2p/tcp 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
|
|
13
13
|
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)
|
|
14
14
|
|
|
15
|
-
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.
|
|
15
|
+
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/transport) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.
|
|
16
16
|
|
|
17
17
|
## Table of Contents <!-- omit in toc -->
|
|
18
18
|
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
|
|
40
40
|
```js
|
|
41
41
|
import { TCP } from '@libp2p/tcp'
|
|
42
|
-
import {
|
|
43
|
-
import pipe from 'it-pipe'
|
|
42
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
43
|
+
import {pipe} from 'it-pipe'
|
|
44
44
|
import all from 'it-all'
|
|
45
45
|
|
|
46
46
|
// A simple upgrader that just returns the MultiaddrConnection
|
|
@@ -51,12 +51,14 @@ const upgrader = {
|
|
|
51
51
|
|
|
52
52
|
const tcp = new TCP({ upgrader })
|
|
53
53
|
|
|
54
|
-
const listener = tcp.createListener({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
const listener = tcp.createListener({
|
|
55
|
+
handler: (socket) => {
|
|
56
|
+
console.log('new connection opened')
|
|
57
|
+
pipe(
|
|
58
|
+
['hello', ' ', 'World!'],
|
|
59
|
+
socket
|
|
60
|
+
)
|
|
61
|
+
}
|
|
60
62
|
})
|
|
61
63
|
|
|
62
64
|
const addr = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
|
@@ -79,14 +81,14 @@ Outputs:
|
|
|
79
81
|
```sh
|
|
80
82
|
listening
|
|
81
83
|
new connection opened
|
|
82
|
-
Value: hello
|
|
84
|
+
Value: hello World!
|
|
83
85
|
```
|
|
84
86
|
|
|
85
87
|
## API
|
|
86
88
|
|
|
87
89
|
### Transport
|
|
88
90
|
|
|
89
|
-
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
|
|
91
|
+
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/transport)
|
|
90
92
|
|
|
91
93
|
`libp2p-tcp` accepts TCP addresses as both IPFS and non IPFS encapsulated addresses, i.e:
|
|
92
94
|
|
|
@@ -97,7 +99,7 @@ Value: hello
|
|
|
97
99
|
|
|
98
100
|
### Connection
|
|
99
101
|
|
|
100
|
-
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)
|
|
102
|
+
[](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/connection)
|
|
101
103
|
|
|
102
104
|
## Contribute
|
|
103
105
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-tcp#readme",
|