docs: update examples

This commit is contained in:
David Dias 2018-02-07 08:28:36 +00:00
parent f7f85dce0a
commit 0062a4b5eb
9 changed files with 23 additions and 23 deletions

View File

@ -47,7 +47,7 @@ async.parallel([
console.log(ma.toString() + '/ipfs/' + idListener.toB58String()) 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) { if (err) {
throw err throw err
} }

View File

@ -38,7 +38,7 @@ async.parallel([
'/ipfs/' + dialerId.toB58String())) '/ipfs/' + dialerId.toB58String()))
console.log('Dialing to peer:', listenerMultiaddr.toString()) 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 } if (err) { throw err }
console.log('nodeA dialed to nodeB on protocol: /echo/1.0.0') console.log('nodeA dialed to nodeB on protocol: /echo/1.0.0')

View File

@ -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 } if (err) { throw err }
pull(pull.values(['This information is sent out encrypted to the other peer']), conn) pull(pull.values(['This information is sent out encrypted to the other peer']), conn)
}) })

View File

@ -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 } if (err) { throw err }
pull(pull.values(['my own protocol, wow!']), conn) 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 } if (err) { throw err }
pull(pull.values(['semver me please']), conn) 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 } if (err) { throw err }
pull(pull.values(['do I fall into your criteria?']), conn) pull(pull.values(['do I fall into your criteria?']), conn)
}) })

View File

@ -60,17 +60,17 @@ parallel([
}) })
series([ series([
(cb) => node1.dial(node2.peerInfo, '/a', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/a', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['protocol (a)']), conn) pull(pull.values(['protocol (a)']), conn)
cb() cb()
}), }),
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['protocol (b)']), conn) pull(pull.values(['protocol (b)']), conn)
cb() cb()
}), }),
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['another conn on protocol (b)']), conn) pull(pull.values(['another conn on protocol (b)']), conn)
cb() cb()

View File

@ -30,7 +30,7 @@ node2.handle('/your-protocol', (protocol, conn) => {
After the protocol is _handled_, now we can dial to it. After the protocol is _handled_, now we can dial to it.
```JavaScript ```JavaScript
node1.dial(node2.peerInfo, '/your-protocol', (err, conn) => { node1.dialProtocol(node2.peerInfo, '/your-protocol', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['my own protocol, wow!']), conn) 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 } if (err) { throw err }
pull(pull.values(['semver me please']), conn) 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 } if (err) { throw err }
pull(pull.values(['do I fall into your criteria?']), conn) pull(pull.values(['do I fall into your criteria?']), conn)
}) })
@ -129,17 +129,17 @@ node2.handle('/b', (protocol, conn) => {
}) })
series([ series([
(cb) => node1.dial(node2.peerInfo, '/a', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/a', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['protocol (a)']), conn) pull(pull.values(['protocol (a)']), conn)
cb() cb()
}), }),
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['protocol (b)']), conn) pull(pull.values(['protocol (b)']), conn)
cb() cb()
}), }),
(cb) => node1.dial(node2.peerInfo, '/b', (err, conn) => { (cb) => node1.dialProtocol(node2.peerInfo, '/b', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['another conn on protocol (b)']), conn) pull(pull.values(['another conn on protocol (b)']), conn)
cb() cb()

View File

@ -54,7 +54,7 @@ parallel([
) )
}) })
node1.dial(node2.peerInfo, '/print', (err, conn) => { node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn) pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn)

View File

@ -66,19 +66,19 @@ parallel([
node2.handle('/print', print) node2.handle('/print', print)
node3.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 } if (err) { throw err }
pull(pull.values(['node 1 dialed to node 2 successfully']), conn) 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 } if (err) { throw err }
pull(pull.values(['node 2 dialed to node 3 successfully']), conn) 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) { if (err) {
console.log('node 3 failed to dial to node 1 with:', err.message) console.log('node 3 failed to dial to node 1 with:', err.message)
} }

View File

@ -143,7 +143,7 @@ parallel([
) )
}) })
node1.dial(node2.peerInfo, '/print', (err, conn) => { node1.dialProtocol(node2.peerInfo, '/print', (err, conn) => {
if (err) { throw err } if (err) { throw err }
pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn) pull(pull.values(['Hello', ' ', 'p2p', ' ', 'world', '!']), conn)
@ -240,21 +240,21 @@ parallel([
node3.handle('/print', print) node3.handle('/print', print)
// node 1 (TCP) dials to node 2 (TCP+WebSockets) // 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 } if (err) { throw err }
pull(pull.values(['node 1 dialed to node 2 successfully']), conn) pull(pull.values(['node 1 dialed to node 2 successfully']), conn)
}) })
// node 2 (TCP+WebSockets) dials to node 2 (WebSockets) // 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 } if (err) { throw err }
pull(pull.values(['node 2 dialed to node 3 successfully']), conn) pull(pull.values(['node 2 dialed to node 3 successfully']), conn)
}) })
// node 3 (WebSockets) attempts to dial to node 1 (TCP) // 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) { if (err) {
console.log('node 3 failed to dial to node 1 with:', err.message) console.log('node 3 failed to dial to node 1 with:', err.message)
} }