mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
docs: update examples
This commit is contained in:
parent
f7f85dce0a
commit
0062a4b5eb
@ -47,7 +47,7 @@ async.parallel([
|
||||
console.log(ma.toString() + '/ipfs/' + idListener.toB58String())
|
||||
})
|
||||
|
||||
nodeDialer.dial(peerListener, '/chat/1.0.0', (err, conn) => {
|
||||
nodeDialer.dialProtocol(peerListener, '/chat/1.0.0', (err, conn) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ async.parallel([
|
||||
'/ipfs/' + dialerId.toB58String()))
|
||||
|
||||
console.log('Dialing to peer:', listenerMultiaddr.toString())
|
||||
dialerNode.dial(listenerPeerInfo, '/echo/1.0.0', (err, conn) => {
|
||||
dialerNode.dialProtocol(listenerPeerInfo, '/echo/1.0.0', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
console.log('nodeA dialed to nodeB on protocol: /echo/1.0.0')
|
||||
|
@ -52,7 +52,7 @@ parallel([
|
||||
)
|
||||
})
|
||||
|
||||
node1.dial(node2.peerInfo, '/a-protocol', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/a-protocol', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['This information is sent out encrypted to the other peer']), conn)
|
||||
})
|
||||
|
@ -75,20 +75,20 @@ parallel([
|
||||
})
|
||||
*/
|
||||
|
||||
node1.dial(node2.peerInfo, '/your-protocol', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/your-protocol', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['my own protocol, wow!']), conn)
|
||||
})
|
||||
|
||||
/*
|
||||
node1.dial(node2.peerInfo, '/another-protocol/1.0.0', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/another-protocol/1.0.0', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['semver me please']), conn)
|
||||
})
|
||||
*/
|
||||
|
||||
/*
|
||||
node1.dial(node2.peerInfo, '/custom-match-func/some-query', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/custom-match-func/some-query', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['do I fall into your criteria?']), conn)
|
||||
})
|
||||
|
@ -60,17 +60,17 @@ parallel([
|
||||
})
|
||||
|
||||
series([
|
||||
(cb) => node1.dial(node2.peerInfo, '/a', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/a', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['protocol (a)']), conn)
|
||||
cb()
|
||||
}),
|
||||
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['protocol (b)']), conn)
|
||||
cb()
|
||||
}),
|
||||
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['another conn on protocol (b)']), conn)
|
||||
cb()
|
||||
|
@ -30,7 +30,7 @@ node2.handle('/your-protocol', (protocol, conn) => {
|
||||
After the protocol is _handled_, now we can dial to it.
|
||||
|
||||
```JavaScript
|
||||
node1.dial(node2.peerInfo, '/your-protocol', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/your-protocol', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['my own protocol, wow!']), conn)
|
||||
})
|
||||
@ -47,7 +47,7 @@ node2.handle('/another-protocol/1.0.1', (protocol, conn) => {
|
||||
)
|
||||
})
|
||||
// ...
|
||||
node1.dial(node2.peerInfo, '/another-protocol/1.0.0', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/another-protocol/1.0.0', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['semver me please']), conn)
|
||||
})
|
||||
@ -74,7 +74,7 @@ node2.handle('/custom-match-func', (protocol, conn) => {
|
||||
}
|
||||
})
|
||||
// ...
|
||||
node1.dial(node2.peerInfo, '/custom-match-func/some-query', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/custom-match-func/some-query', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['do I fall into your criteria?']), conn)
|
||||
})
|
||||
@ -129,17 +129,17 @@ node2.handle('/b', (protocol, conn) => {
|
||||
})
|
||||
|
||||
series([
|
||||
(cb) => node1.dial(node2.peerInfo, '/a', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/a', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['protocol (a)']), conn)
|
||||
cb()
|
||||
}),
|
||||
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['protocol (b)']), conn)
|
||||
cb()
|
||||
}),
|
||||
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => {
|
||||
(cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
pull(pull.values(['another conn on protocol (b)']), conn)
|
||||
cb()
|
||||
|
@ -54,7 +54,7 @@ parallel([
|
||||
)
|
||||
})
|
||||
|
||||
node1.dial(node2.peerInfo, '/print', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn)
|
||||
|
@ -66,19 +66,19 @@ parallel([
|
||||
node2.handle('/print', print)
|
||||
node3.handle('/print', print)
|
||||
|
||||
node1.dial(node2.peerInfo, '/print', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['node 1 dialed to node 2 successfully']), conn)
|
||||
})
|
||||
|
||||
node2.dial(node3.peerInfo, '/print', (err, conn) => {
|
||||
node2.dialProtocol(node3.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['node 2 dialed to node 3 successfully']), conn)
|
||||
})
|
||||
|
||||
node3.dial(node1.peerInfo, '/print', (err, conn) => {
|
||||
node3.dialProtocol(node1.peerInfo, '/print', (err, conn) => {
|
||||
if (err) {
|
||||
console.log('node 3 failed to dial to node 1 with:', err.message)
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ parallel([
|
||||
)
|
||||
})
|
||||
|
||||
node1.dial(node2.peerInfo, '/print', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn)
|
||||
@ -240,21 +240,21 @@ parallel([
|
||||
node3.handle('/print', print)
|
||||
|
||||
// node 1 (TCP) dials to node 2 (TCP+WebSockets)
|
||||
node1.dial(node2.peerInfo, '/print', (err, conn) => {
|
||||
node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['node 1 dialed to node 2 successfully']), conn)
|
||||
})
|
||||
|
||||
// node 2 (TCP+WebSockets) dials to node 2 (WebSockets)
|
||||
node2.dial(node3.peerInfo, '/print', (err, conn) => {
|
||||
node2.dialProtocol(node3.peerInfo, '/print', (err, conn) => {
|
||||
if (err) { throw err }
|
||||
|
||||
pull(pull.values(['node 2 dialed to node 3 successfully']), conn)
|
||||
})
|
||||
|
||||
// node 3 (WebSockets) attempts to dial to node 1 (TCP)
|
||||
node3.dial(node1.peerInfo, '/print', (err, conn) => {
|
||||
node3.dialProtocol(node1.peerInfo, '/print', (err, conn) => {
|
||||
if (err) {
|
||||
console.log('node 3 failed to dial to node 1 with:', err.message)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user