Skip to content

Commit

Permalink
fix: fix all the bugs (crypto.encrypt still missing in browser)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Jun 15, 2018
1 parent 144ef94 commit ff6f751
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ module.exports = (myId, requestHandler) => {
source.push(out)
}

log('got request %s', data.ns)

Id.createFromProtobuf(data.remote, (err, remoteId) => {
if (err) {
log(err)
Expand Down Expand Up @@ -204,8 +206,10 @@ module.exports = (myId, requestHandler) => {
source.push({
type: Type.REQUEST,
id: rid,
ns,
data,
signature
signature,
remote: Buffer.from(remoteId.toB58String())
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Server {
conn
)

this.rpc[pi.id.toB58String()] = rpc
this.rpc[pi.id.toB58String()] = rpc.methods
})
})
}
Expand Down
16 changes: 11 additions & 5 deletions src/server/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,25 @@ module.exports = (pi, server) => {
source.push(out)
}

let remote = this.rpc[String(data.remote)]
let remote = server.rpc[String(data.remote)]
let srcId = server.ids[pi.id.toB58String()]

if (!remote) {
return cb(ErrorType.E_NOT_FOUND)
}

remote.forwardRequest(this.ids[pi.id.toB58String()], data.data, data.signature, (err, res) => {
if (!srcId) {
return cb(ErrorType.E_OTHER)
}

remote.forwardRequest(srcId, data.ns, data.data, data.signature, (err, res) => {
if (err) {
return cb(err instanceof Error ? ErrorType.E_OTHER : err)
}

return cb(null, {
data: data.data,
signature: data.signature
data: res.data,
signature: res.signature
})
})

Expand Down Expand Up @@ -135,7 +140,7 @@ module.exports = (pi, server) => {
sink,
methods: {
online: () => online,
requestForward: (remote, data, signature, cb) => {
forwardRequest: (remote, ns, data, signature, cb) => {
if (!online) {
return cb(new Error('Not online!'))
}
Expand All @@ -147,6 +152,7 @@ module.exports = (pi, server) => {
source.push({
type: Type.REQUEST,
id: rid,
ns,
data,
signature,
remote
Expand Down

0 comments on commit ff6f751

Please sign in to comment.