├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── img
├── badge.png
├── badge.sketch
└── badge.svg
├── package.json
├── src
├── connection.js
├── index.js
└── tests.js
└── test
├── compliance.spec.js
├── connection.js
└── utils
└── peers.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 |
29 | dist
30 | package-lock.json
31 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 |
29 | test
30 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | cache: npm
3 | stages:
4 | - check
5 | - test
6 | - cov
7 |
8 | node_js:
9 | - '10'
10 | - '12'
11 |
12 | os:
13 | - linux
14 | - osx
15 | - windows
16 |
17 | script: npx nyc -s npm run test:node -- --bail
18 | after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
19 |
20 | jobs:
21 | include:
22 | - stage: check
23 | script:
24 | - npx aegir dep-check
25 | - npm run lint
26 |
27 | - stage: test
28 | name: chrome
29 | addons:
30 | chrome: stable
31 | script: npx aegir test -t browser -t webworker
32 |
33 | - stage: test
34 | name: firefox
35 | addons:
36 | firefox: latest
37 | script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
38 |
39 | notifications:
40 | email: false
41 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | ## [0.4.1](https://github.com/libp2p/interface-connection/compare/v0.4.0...v0.4.1) (2019-10-17)
3 |
4 |
5 | ### Features
6 |
7 | * add support for timeline proxying ([#31](https://github.com/libp2p/interface-connection/issues/31)) ([541bf83](https://github.com/libp2p/interface-connection/commit/541bf83))
8 |
9 |
10 |
11 |
12 | # [0.4.0](https://github.com/libp2p/interface-connection/compare/v0.3.3...v0.4.0) (2019-09-27)
13 |
14 |
15 | ### Code Refactoring
16 |
17 | * API changes and switch to async iterators ([#29](https://github.com/libp2p/interface-connection/issues/29)) ([bf5c646](https://github.com/libp2p/interface-connection/commit/bf5c646))
18 |
19 |
20 | ### BREAKING CHANGES
21 |
22 | * all the callbacks in the provided API were removed and each function uses async/await. Additionally, pull-streams are no longer being used. See the README for new usage.
23 |
24 |
25 |
26 |
27 | ## [0.3.3](https://github.com/libp2p/interface-connection/compare/v0.3.1...v0.3.3) (2018-11-29)
28 |
29 |
30 |
31 |
32 | ## [0.3.1](https://github.com/libp2p/interface-connection/compare/v0.3.0...v0.3.1) (2017-02-09)
33 |
34 |
35 |
36 |
37 | # [0.3.0](https://github.com/libp2p/interface-connection/compare/v0.2.1...v0.3.0) (2016-11-03)
38 |
39 |
40 | ### Features
41 |
42 | * async crypto + sauce labs + aegir 9 ([b40114c](https://github.com/libp2p/interface-connection/commit/b40114c))
43 |
44 |
45 |
46 |
47 | ## [0.2.1](https://github.com/libp2p/interface-connection/compare/v0.2.0...v0.2.1) (2016-09-05)
48 |
49 |
50 | ### Bug Fixes
51 |
52 | * **package.json:** point to right main ([84cd2ca](https://github.com/libp2p/interface-connection/commit/84cd2ca))
53 |
54 |
55 |
56 |
57 | # [0.2.0](https://github.com/libp2p/interface-connection/compare/v0.1.8...v0.2.0) (2016-09-05)
58 |
59 |
60 | ### Bug Fixes
61 |
62 | * **deps:** fix package.json ([e0f7db3](https://github.com/libp2p/interface-connection/commit/e0f7db3))
63 |
64 |
65 | ### Features
66 |
67 | * **connection:** migrate to pull-streams ([ed5727a](https://github.com/libp2p/interface-connection/commit/ed5727a))
68 |
69 |
70 |
71 |
72 | ## [0.1.8](https://github.com/libp2p/interface-connection/compare/v0.1.7...v0.1.8) (2016-08-03)
73 |
74 |
75 |
76 |
77 | ## [0.1.7](https://github.com/libp2p/interface-connection/compare/v0.1.6...v0.1.7) (2016-06-27)
78 |
79 |
80 |
81 |
82 | ## [0.1.6](https://github.com/libp2p/interface-connection/compare/v0.1.5...v0.1.6) (2016-06-23)
83 |
84 |
85 |
86 |
87 | ## [0.1.5](https://github.com/libp2p/interface-connection/compare/v0.1.4...v0.1.5) (2016-06-23)
88 |
89 |
90 |
91 |
92 | ## [0.1.4](https://github.com/libp2p/interface-connection/compare/v0.1.3...v0.1.4) (2016-06-23)
93 |
94 |
95 |
96 |
97 | ## [0.1.3](https://github.com/libp2p/interface-connection/compare/v0.1.0...v0.1.3) (2016-06-16)
98 |
99 |
100 |
101 |
102 | # [0.1.0](https://github.com/libp2p/interface-connection/compare/v0.0.3...v0.1.0) (2016-06-16)
103 |
104 |
105 |
106 |
107 | ## [0.0.3](https://github.com/libp2p/interface-connection/compare/v0.0.1...v0.0.3) (2015-12-12)
108 |
109 |
110 |
111 |
112 | ## 0.0.1 (2015-09-17)
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 David Dias
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ⛔️ DEPRECATED: interface-connection is now included in [libp2p-interfaces](https://github.com/libp2p/js-interfaces)
2 | ======
3 |
4 | # interface-connection
5 |
6 | [](http://protocol.ai)
7 | [](http://libp2p.io/)
8 | [](http://webchat.freenode.net/?channels=%23libp2p)
9 | [](https://discuss.libp2p.io)
10 | [](https://codecov.io/gh/libp2p/interface-connection)
11 | [](https://travis-ci.com/libp2p/interface-connection)
12 | [](https://david-dm.org/libp2p/interface-connection)
13 | [](https://github.com/feross/standard)
14 |
15 | This is a test suite and interface you can use to implement a connection. The connection interface contains all the metadata associated with it, as well as an array of the streams opened through this connection. In the same way as the connection, a stream contains properties with its metadata, plus an iterable duplex object that offers a mechanism for writing and reading data, with back pressure. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer.
16 |
17 | The primary goal of this module is to enable developers to pick, swap or upgrade their connection without losing the same API expectations and mechanisms such as back pressure and the ability to half close a connection.
18 |
19 | Publishing a test suite as a module lets multiple modules ensure compatibility since they use the same test suite.
20 |
21 | ## Lead Maintainer
22 |
23 | [Jacob Heun](https://github.com/jacobheun/)
24 |
25 | ## Usage
26 |
27 | ### Connection
28 |
29 | Before creating a connection from a transport compatible with `libp2p` it is important to understand some concepts:
30 |
31 | - **socket**: the underlying raw duplex connection between two nodes. It is created by the transports during a dial/listen.
32 | - **[multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection)**: an abstraction over the socket to allow it to work with multiaddr addresses. It is a duplex connection that transports create to wrap the socket before passing to an upgrader that turns it into a standard connection (see below).
33 | - **connection**: a connection between two _peers_ that has built in multiplexing and info about the connected peer. It is created from a [multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection) by an upgrader. The upgrader uses multistream-select to add secio and multiplexing and returns this object.
34 | - **stream**: a muxed duplex channel of the `connection`. Each connection may have many streams.
35 |
36 | A connection stands for the libp2p communication duplex layer between two nodes. It is **not** the underlying raw transport duplex layer (socket), such as a TCP socket, but an abstracted layer that sits on top of the raw socket.
37 |
38 | This helps ensuring that the transport is responsible for socket management, while also allowing the application layer to handle the connection management.
39 |
40 | ### Test suite
41 |
42 | #### JS
43 |
44 | ```js
45 | describe('your connection', () => {
46 | require('interface-connection/src/tests')({
47 | async setup () {
48 | return YourConnection
49 | },
50 | async teardown () {
51 | // cleanup resources created by setup()
52 | }
53 | })
54 | })
55 | ```
56 |
57 | #### Go
58 |
59 | > WIP
60 |
61 | ## API
62 |
63 | ### Connection
64 |
65 | A valid connection (one that follows this abstraction), must implement the following API:
66 |
67 | - type: `Connection`
68 | ```js
69 | new Connection({
70 | localAddr,
71 | remoteAddr,
72 | localPeer,
73 | remotePeer,
74 | newStream,
75 | close,
76 | getStreams,
77 | stat: {
78 | direction,
79 | timeline: {
80 | open,
81 | upgraded
82 | },
83 | multiplexer,
84 | encryption
85 | }
86 | })
87 | ```
88 | - ` conn.localAddr`
89 | - ` conn.remoteAddr`
90 | - ` conn.localPeer`
91 | - ` conn.remotePeer`
92 | - `