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) => {
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}))