Skip to content

Commit

Permalink
Add cb to tunnel connect + update README
Browse files Browse the repository at this point in the history
  • Loading branch information
arj03 committed Apr 7, 2020
1 parent 4db7eaf commit 8604ee0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,14 @@ encrypted ephemeral messages between two peers.
Tell the pub to allow incoming connections, but call confirmHandler
with the remote feedId for manual confirmation.

#### connect(feedId)
#### connect(feedId, cb)

Connect to a remote feedId. When connected a message will be put in
`messages`.
`messages`. Takes an optional cb.

#### disconnect()

Disconnects all currently active tunnel connections.

#### sendMessage(type, data)

Expand Down
6 changes: 4 additions & 2 deletions tunnel-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ exports.init = function (sbot, config) {
rpc.tunnel.announce()
})
},
connect: function(remoteId) {
connect: function(remoteId, cb) {
const remoteKey = remoteId.substring(1, remoteId.indexOf('.'))
const remoteAddr = 'tunnel:@'+SSB.remoteAddress.split(':')[3]+ ':' + remoteId + '~shs:' + remoteKey
messages({ type: "info", user: remoteId, data: "waiting for accept" })
SSB.net.connect(remoteAddr, (err, rpc) => {
if (err) throw(err)
if (err) return cb(err)

remotes.push(rpc)
messages({ type: "info", user: rpc.id, data: "connected" })
Expand All @@ -59,6 +59,8 @@ exports.init = function (sbot, config) {
remotes = remotes.filter(remote => remote.id != rpc.id)
messages({ type: "info", user: rpc.id, data: "disconnected" })
})

if (cb) cb()
})
},
disconnect: function() {
Expand Down

0 comments on commit 8604ee0

Please sign in to comment.