Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
feat: add .stop() to server and .dial() to client
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Jan 6, 2019
1 parent b100396 commit b699bae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,26 @@ class Connection {
}

async dial (addr) {
/*
- TODO: get peer id, open new conn via muxed, do handshake, do dial, forward
*/
const id = addr.getPeerId()
const _id = ID.createFromB58String(id)._id

const conn = await prom(cb => this.muxed.newStream(cb))

const stream = handshake()
pull(
conn,
stream,
conn
)

const shake = stream.handshake
const rpc = LP.wrap(shake, {push: shake.write})

rpc.writeProto(DialRequest, {target: _id})
const {error} = await rpc.readProto(DialResponse)
if (error) { translateAndThrow(error) }

return shake.rest()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/micro-switch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class MicroSwitch {
if (err) {
reject(err)
} else {
resolve(address)
resolve(listener)
}
})
}))
Expand Down
4 changes: 4 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class Server {
async start () {
await this.switch.startListen()
}

async stop () {
await this.switch.stopListen()
}
}

module.exports = Server

0 comments on commit b699bae

Please sign in to comment.