Skip to content

Commit

Permalink
feat(secure): responce only to rats messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Mar 3, 2018
1 parent dfd8378 commit 16aa63e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/background/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@ class p2p {
socket.on('message', (message) => {
if(message.type && this.messageHandlers[message.type])
{
// responce only to rats messages
if(message.type != 'protocol' && !socket.rats)
return

this.messageHandlers[message.type](message.data, (data) => {
socket.sendMessage({
id: message.id,
data
});
}, socket._socket)
}, socket)
}
});
})
// check protocol
this.on('protocol', (data, callback, socket) => {
this.on('protocol', (data, callback, socketObject) => {
if(!data || data.protocol != 'rats')
return

const { _socket: socket } = socketObject
socketObject.rats = true

callback({
protocol: 'rats',
peers: this.peersList().slice(0, 4).map(peer => ({address: peer.address, port: peer.port}))
Expand Down

0 comments on commit 16aa63e

Please sign in to comment.