libp2p-stardust
is one of the multiple transports available for libp2p.libp2p-stardust
incorporates both a transport and a discovery service that is facilitated by the stardust server, also available in this repo.
You can read the protocol specification on PROTOCOL.md.
> npm install libp2p-stardust
const Stardust = require('libp2p-stardust')
const multiaddr = require('multiaddr')
const pipe = require('it-pipe')
const { collect } = require('streaming-iterables')
const addr = multiaddr('/ip4/188.166.203.82/tcp/5892/ws/p2p-stardust')
const stardust = new Stardust({ upgrader, libp2p })
const listener = stardust.createListener((socket) => {
console.log('new connection opened')
pipe(
['hello'],
socket
)
})
await listener.listen(addr)
console.log('listening')
const socket = await stardust.dial(addr)
const values = await pipe(
socket,
collect
)
console.log(`Value: ${values[0].toString()}`)
// > hello
// Close connection after reading
await listener.close()
Setting up your own stardust server is really easy
First install stardust globally.
> npm install --global libp2p-stardust
Now you can use the cli command stardust-server
to spawn a stardust server.
It only accepts one argument: The address to listen on.
There isn't much to configure via the CLI currently.
By default it listens on /ip6/::/tcp/5892/ws
For further customization (e.g. swapping the muxer, using other transports) it is recommended to create a server via the API.
We host a stardust server at /dns4/stardust.mkg20001.io
that can be used for practical demos and experimentation, it should not be used for apps in production.
A libp2p-stardust address, using the server we provide, looks like:
/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust/ipfs/<your-peer-id>
Note: The address above indicates WebSockets Secure, which can be accessed from both http and https.
LICENSE MPL-2.0