-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: update libp2p deps to v2 (#170)
Updates examples to use the new libp2p release
- Loading branch information
1 parent
d006979
commit 83dd9df
Showing
28 changed files
with
101 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,37 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { createFromJSON } from '@libp2p/peer-id-factory' | ||
import { multiaddr } from '@multiformats/multiaddr' | ||
import { createLibp2p } from './libp2p.js' | ||
import peerIdDialerJson from './peer-id-dialer.js' | ||
import peerIdListenerJson from './peer-id-listener.js' | ||
import { stdinToStream, streamToConsole } from './stream.js' | ||
|
||
async function run () { | ||
const [idDialer, idListener] = await Promise.all([ | ||
createFromJSON(peerIdDialerJson), | ||
createFromJSON(peerIdListenerJson) | ||
]) | ||
|
||
// Create a new libp2p node on localhost with a randomly chosen port | ||
const nodeDialer = await createLibp2p({ | ||
peerId: idDialer, | ||
const dialer = await createLibp2p({ | ||
addresses: { | ||
listen: ['/ip4/0.0.0.0/tcp/0'] | ||
} | ||
}) | ||
|
||
// Output this node's address | ||
console.log('Dialer ready, listening on:') | ||
nodeDialer.getMultiaddrs().forEach((ma) => { | ||
dialer.getMultiaddrs().forEach((ma) => { | ||
console.log(ma.toString()) | ||
}) | ||
|
||
// Dial to the remote peer (the "listener") | ||
const listenerMa = multiaddr(`/ip4/127.0.0.1/tcp/10333/p2p/${idListener.toString()}`) | ||
const stream = await nodeDialer.dialProtocol(listenerMa, '/chat/1.0.0') | ||
dialer.addEventListener('peer:discovery', (evt) => { | ||
console.info('peer:discovery', evt.detail) | ||
|
||
console.log('Dialer dialed to listener on protocol: /chat/1.0.0') | ||
console.log('Type a message and see what happens') | ||
// Dial to the remote peer (the "listener") | ||
dialer.dialProtocol(evt.detail.multiaddrs, '/chat/1.0.0') | ||
.then(stream => { | ||
console.log('Dialer dialed to listener on protocol: /chat/1.0.0') | ||
console.log('Type a message and see what happens') | ||
|
||
// Send stdin to the stream | ||
stdinToStream(stream) | ||
// Read the stream and output to console | ||
streamToConsole(stream) | ||
// Send stdin to the stream | ||
stdinToStream(stream) | ||
// Read the stream and output to console | ||
streamToConsole(stream) | ||
}) | ||
}) | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.