A memory transport for libp2p
A libp2p transport that operates in-memory only.
This is intended for testing and can only be used to connect two libp2p nodes that are running in the same process.
import { createLibp2p } from 'libp2p'
import { memory } from '@libp2p/memory'
import { multiaddr } from '@multiformats/multiaddr'
const listener = await createLibp2p({
addresses: {
listen: [
'/memory/address-a'
]
},
transports: [
memory()
]
})
const dialer = await createLibp2p({
transports: [
memory()
]
})
const ma = multiaddr('/memory/address-a')
// dial the listener, timing out after 10s
const connection = await dialer.dial(ma, {
signal: AbortSignal.timeout(10_000)
})
// use connection...
$ npm i @libp2p/memory
Loading this module through a script tag will make its exports available as Libp2pMemory
in the global namespace.
<script src="https://unpkg.com/@libp2p/memory/dist/index.min.js"></script>
Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.