Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat: update to latest interfaces (#184)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses new single-issue libp2p interface modules
  • Loading branch information
achingbrain authored Jun 15, 2022
1 parent 499a137 commit 2924414
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# js-libp2p-tcp <!-- omit in toc -->
# @libp2p/tcp <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-tcp)
[![Build Status](https://github.com/libp2p/js-libp2p-tcp/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-tcp/actions/workflows/js-test-and-release.yml)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-tcp)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-tcp)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-tcp/actions/workflows/js-test-and-release.yml)

[![](https://github.com/raw/libp2p/js-libp2p-interfaces/master/src/transport/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
[![](https://github.com/raw/libp2p/js-libp2p-interfaces/master/src/connection/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)
> Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces
> 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.
## Table of Contents <!-- omit in toc -->
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [npm](#npm)
- [Usage](#usage)
- [API](#api)
- [Transport](#transport)
- [Connection](#connection)
- [Contribute](#contribute)
- [Contribute](#contribute-1)
- [License](#license)
- [Contribution](#contribution)
- [Contribution](#contribution)

## Install

### npm
```console
$ npm i @libp2p/tcp
```

[![](https://github.com/raw/libp2p/js-libp2p-interfaces/master/src/transport/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
[![](https://github.com/raw/libp2p/js-libp2p-interfaces/master/src/connection/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)

```sh
> npm install @libp2p/tcp
Expand Down Expand Up @@ -117,16 +115,16 @@ Small note: If editing the README, please conform to the [standard-readme](https

The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:

- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.

## License

Licensed under either of

* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

### Contribution
## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
],
"exports": {
".": {
"types": "./src/index.d.ts",
"import": "./dist/src/index.js"
}
},
Expand Down Expand Up @@ -135,7 +136,9 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/interfaces": "^2.0.1",
"@libp2p/interface-connection": "^1.0.1",
"@libp2p/interface-transport": "^1.0.0",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/logger": "^1.1.2",
"@libp2p/utils": "^1.0.9",
"@multiformats/mafmt": "^11.0.2",
Expand All @@ -145,7 +148,8 @@
"stream-to-it": "^0.2.2"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^2.0.1",
"@libp2p/interface-mocks": "^1.0.1",
"@libp2p/interface-transport-compliance-tests": "^1.0.0",
"aegir": "^37.0.4",
"it-all": "^1.0.6",
"it-pipe": "^2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createListener } from './listener.js'
import { multiaddrToNetConfig } from './utils.js'
import { AbortError } from '@libp2p/interfaces/errors'
import { CODE_CIRCUIT, CODE_P2P } from './constants.js'
import { CreateListenerOptions, DialOptions, symbol, Transport } from '@libp2p/interfaces/transport'
import { CreateListenerOptions, DialOptions, symbol, Transport } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { Socket } from 'net'
import type { AbortOptions } from '@libp2p/interfaces'
Expand Down
4 changes: 2 additions & 2 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
multiaddrToNetConfig
} from './utils.js'
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
import type { Connection } from '@libp2p/interfaces/connection'
import type { MultiaddrConnection, Upgrader, Listener } from '@libp2p/interfaces/transport'
import type { MultiaddrConnection, Connection } from '@libp2p/interface-connection'
import type { Upgrader, Listener } from '@libp2p/interface-transport'
import type { Server } from 'net'
import type { Multiaddr } from '@multiformats/multiaddr'

Expand Down
2 changes: 1 addition & 1 deletion src/socket-to-conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ipPortToMultiaddr as toMultiaddr } from '@libp2p/utils/ip-port-to-multi
import { CLOSE_TIMEOUT } from './constants.js'
import type { Socket } from 'net'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
import type { MultiaddrConnection } from '@libp2p/interface-connection'

const log = logger('libp2p:tcp:socket')

Expand Down
2 changes: 1 addition & 1 deletion test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sinon from 'sinon'
import tests from '@libp2p/interface-compliance-tests/transport'
import tests from '@libp2p/interface-transport-compliance-tests'
import { Multiaddr } from '@multiformats/multiaddr'
import net from 'net'
import { TCP } from '../src/index.js'
Expand Down
6 changes: 3 additions & 3 deletions test/connection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'aegir/chai'
import { TCP } from '../src/index.js'
import { Multiaddr } from '@multiformats/multiaddr'
import { mockUpgrader } from '@libp2p/interface-compliance-tests/mocks'
import type { Connection } from '@libp2p/interfaces/connection'
import type { Upgrader } from '@libp2p/interfaces/transport'
import { mockUpgrader } from '@libp2p/interface-mocks'
import type { Connection } from '@libp2p/interface-connection'
import type { Upgrader } from '@libp2p/interface-transport'

describe('valid localAddr and remoteAddr', () => {
let tcp: TCP
Expand Down
4 changes: 2 additions & 2 deletions test/listen-dial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import path from 'path'
import { Multiaddr } from '@multiformats/multiaddr'
import { pipe } from 'it-pipe'
import all from 'it-all'
import { mockRegistrar, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks'
import { mockRegistrar, mockUpgrader } from '@libp2p/interface-mocks'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import type { Upgrader } from '@libp2p/interfaces/transport'
import type { Upgrader } from '@libp2p/interface-transport'

const isCI = process.env.CI

Expand Down

0 comments on commit 2924414

Please sign in to comment.