feat(secure): responce only to rats messages

This commit is contained in:
Alexey Kasyanchuk 2018-03-03 05:55:14 +03:00
parent c2b030dddc
commit 65354947ba

View File

@ -19,20 +19,27 @@ class p2p {
socket.on('message', (message) => { socket.on('message', (message) => {
if(message.type && this.messageHandlers[message.type]) 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) => { this.messageHandlers[message.type](message.data, (data) => {
socket.sendMessage({ socket.sendMessage({
id: message.id, id: message.id,
data data
}); });
}, socket._socket) }, socket)
} }
}); });
}) })
// check protocol // check protocol
this.on('protocol', (data, callback, socket) => { this.on('protocol', (data, callback, socketObject) => {
if(!data || data.protocol != 'rats') if(!data || data.protocol != 'rats')
return return
const { _socket: socket } = socketObject
socketObject.rats = true
callback({ callback({
protocol: 'rats', protocol: 'rats',
peers: this.peersList().slice(0, 4).map(peer => ({address: peer.address, port: peer.port})) peers: this.peersList().slice(0, 4).map(peer => ({address: peer.address, port: peer.port}))