diff --git a/src/background/config.js b/src/background/config.js index 65f54ad..793dba7 100644 --- a/src/background/config.js +++ b/src/background/config.js @@ -9,7 +9,10 @@ let config = { spiderPort: 4445, udpTrackersPort: 4446, udpTrackersTimeout: 3 * 60 * 1000, + p2p: true, + p2pConnections: 10, + upnp: true, sitemapMaxSize: 25000, @@ -54,6 +57,13 @@ if(app && app.getPath("userData") && app.getPath("userData").length > 0) const configProxy = new Proxy(config, { set: (target, prop, value, receiver) => { + // some values check (important!) + if(prop == 'p2pConnections' && value < 10) + value = 10 + if(prop == 'p2pConnections' && value > 300) + value = 300 + + target[prop] = value if(!fs.existsSync(configPath)) diff --git a/src/background/p2p.js b/src/background/p2p.js index b5adf26..06d999d 100644 --- a/src/background/p2p.js +++ b/src/background/p2p.js @@ -13,7 +13,11 @@ class p2p { { this.send = send this.tcpServer = net.createServer(); + this.tcpServer.maxConnections = config.p2pConnections * 2; this.tcpServer.on('connection', (socket) => { + this.tcpServer.getConnections((err, count) => { + console.log('connection', count) + }) socket = new JsonSocket(socket); socket.on('error', (err) => {}) socket.on('message', (message) => { @@ -93,7 +97,7 @@ class p2p { add(address) { const { peers } = this - if(this.size > 10) + if(this.size > config.p2pConnections) return; if(address.port <= 1 || address.port > 65535)