Skip to content

Commit

Permalink
fix(p2p): break backward p2p compability < 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 19, 2019
1 parent 77e3af3 commit e0a1c87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/background/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const directoryFilesRecursive = require('./directoryFilesRecursive')
const {promisify} = require('util');
const mkdirp = promisify(require('mkdirp'))
const deleteFolderRecursive = require('./deleteFolderRecursive')
const compareVersions = require('compare-versions');

class p2p {
constructor(send = () => {})
{
this.minClientVersion = '1.1.0'
this.minServerVersion = '1.1.0'

this.events = new EventEmitter
this.peers = []
this.clients = []
Expand Down Expand Up @@ -92,6 +96,11 @@ class p2p {
if(!data || data.protocol != 'rats')
return

if(compareVersions(data.version, this.minServerVersion) < 0) {
logTE('p2p', `ignore peer because of version ${data.version} < ${this.minServerVersion}`);
return;
}

// protocol ok
clearTimeout(socketObject.protocolTimeout)
const { _socket: socket } = socketObject
Expand Down Expand Up @@ -369,6 +378,12 @@ class p2p {
if(this.ignoreAddresses.includes(address.address))
return;

if(compareVersions(data.version, this.minClientVersion) < 0) {
logTE('p2p', `ignore client peer because of version ${data.version} < ${this.minClientVersion}`)
rawSocket.destroy()
return;
}

// success
clearTimeout(protocolTimeout)

Expand Down

0 comments on commit e0a1c87

Please sign in to comment.