0.17.2 • Published 3 years ago

libp2p-tcp v0.17.2

Weekly downloads
7,627
License
MIT
Repository
github
Last release
3 years ago

js-libp2p-tcp

npm.io npm.io npm.io Discourse posts npm.io npm.io Dependency Status js-standard-style

npm.io npm.io

JavaScript implementation of the TCP module for libp2p. It exposes the interface-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.

Lead Maintainer

Jacob Heun

Table of Contents

Install

npm

> npm install libp2p-tcp

Usage

const TCP = require('libp2p-tcp')
const multiaddr = require('multiaddr')
const pipe = require('it-pipe')
const { collect } = require('streaming-iterables')

// A simple upgrader that just returns the MultiaddrConnection
const upgrader = {
  upgradeInbound: maConn => maConn,
  upgradeOutbound: maConn => maConn
}

const tcp = new TCP({ upgrader })

const listener = tcp.createListener((socket) => {
  console.log('new connection opened')
  pipe(
    ['hello'],
    socket
  )
})

const addr = multiaddr('/ip4/127.0.0.1/tcp/9090')
await listener.listen(addr)
console.log('listening')

const socket = await tcp.dial(addr)
const values = await pipe(
  socket,
  collect
)
console.log(`Value: ${values.toString()}`)

// Close connection after reading
await listener.close()

Outputs:

listening
new connection opened
Value: hello

API

Transport

npm.io

libp2p-tcp accepts TCP addresses as both IPFS and non IPFS encapsulated addresses, i.e:

/ip4/127.0.0.1/tcp/4001 /ip4/127.0.0.1/tcp/4001/ipfs/QmHash

(both for dialing and listening)

Connection

npm.io

Contribute

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

Please be aware that all interactions related to libp2p are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2015-2016 David Dias

0.17.2

3 years ago

0.17.1

3 years ago

0.17.0

3 years ago

0.16.0

3 years ago

0.15.4

3 years ago

0.15.3

3 years ago

0.15.2

3 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.14.6

4 years ago

0.14.5

4 years ago

0.14.4

4 years ago

0.14.3

4 years ago

0.14.2

4 years ago

0.13.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.1

5 years ago

0.13.0

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.6

6 years ago

0.11.5

6 years ago

0.11.4

6 years ago

0.11.3

6 years ago

0.11.2

6 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.4

8 years ago

0.7.3

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago