возможность живого отключения dht
This commit is contained in:
73
index.js
73
index.js
@ -1,4 +1,7 @@
|
||||
const config = require('./config');
|
||||
let settings = {
|
||||
dhtDisabled: false
|
||||
}
|
||||
const client = new (require('./bt/client'))
|
||||
const spider = new (require('./bt/spider'))(client)
|
||||
const mysql = require('mysql');
|
||||
@ -393,6 +396,31 @@ io.on('connection', function(socket)
|
||||
});
|
||||
*/
|
||||
|
||||
socket.on('admin', function(callback)
|
||||
{
|
||||
if(typeof callback != 'function')
|
||||
return;
|
||||
|
||||
callback(settings)
|
||||
});
|
||||
|
||||
socket.on('setAdmin', function(options, callback)
|
||||
{
|
||||
if(typeof options !== 'object')
|
||||
return;
|
||||
|
||||
settings.dhtDisabled = !!options.dhtDisabled;
|
||||
spider.ignore = settings.dhtDisabled;
|
||||
|
||||
if(settings.dhtDisabled)
|
||||
showFakeTorrents()
|
||||
else
|
||||
hideFakeTorrents()
|
||||
|
||||
if(typeof callback === 'function')
|
||||
callback(true)
|
||||
});
|
||||
|
||||
let socketIPV4 = () => {
|
||||
let ip = socket.request.connection.remoteAddress;
|
||||
if (ipaddr.IPv4.isValid(ip)) {
|
||||
@ -470,7 +498,7 @@ let popDatabaseBalance = () => {
|
||||
if(undoneQueries == 0)
|
||||
{
|
||||
balanceDebug('balance done, queries:', undoneQueries);
|
||||
spider.ignore = false;
|
||||
spider.ignore = settings.dhtDisabled;
|
||||
}
|
||||
};
|
||||
|
||||
@ -701,48 +729,43 @@ client.on('complete', function (metadata, infohash, rinfo) {
|
||||
|
||||
// spider.on('nodes', (nodes)=>console.log('foundNodes'))
|
||||
|
||||
let enableFakeTorrents = false;
|
||||
let fakeTorrents = [];
|
||||
function showFakeTorrentsPage(page)
|
||||
{
|
||||
if(!enableFakeTorrents)
|
||||
return;
|
||||
|
||||
mysqlSingle.query('SELECT * FROM torrents LIMIT ?, 100', [page], function(err, torrents) {
|
||||
if(!torrents)
|
||||
return;
|
||||
|
||||
torrents.forEach((torrent, index) => {
|
||||
if(enableFakeTorrents)
|
||||
setTimeout(() => {
|
||||
io.sockets.emit('newTorrent', baseRowData(torrent));
|
||||
updateTorrentTrackers(torrent.hash);
|
||||
fakeTorrentsDebug('fake torrent', torrents.name, 'index, page:', index, page);
|
||||
}, 700 * index)
|
||||
const fk = fakeTorrents.push(setTimeout(() => {
|
||||
delete fakeTorrents[fk-1];
|
||||
io.sockets.emit('newTorrent', baseRowData(torrent));
|
||||
updateTorrentTrackers(torrent.hash);
|
||||
fakeTorrentsDebug('fake torrent', torrents.name, 'index, page:', index, page);
|
||||
}, 700 * index))
|
||||
})
|
||||
|
||||
if(enableFakeTorrents)
|
||||
setTimeout(()=>showFakeTorrentsPage(torrents.length > 0 ? page + torrents.length : 0), 700 * torrents.length);
|
||||
const fk = fakeTorrents.push(setTimeout(()=>{
|
||||
delete fakeTorrents[fk-1];
|
||||
showFakeTorrentsPage(torrents.length > 0 ? page + torrents.length : 0)
|
||||
}, 700 * torrents.length))
|
||||
});
|
||||
}
|
||||
|
||||
function showFakeTorrents()
|
||||
{
|
||||
const old = enableFakeTorrents;
|
||||
enableFakeTorrents = true;
|
||||
if(!old)
|
||||
{
|
||||
fakeTorrentsDebug('showing fake torrents');
|
||||
showFakeTorrentsPage(0);
|
||||
}
|
||||
fakeTorrentsDebug('showing fake torrents');
|
||||
hideFakeTorrents()
|
||||
showFakeTorrentsPage(0);
|
||||
}
|
||||
|
||||
function hideFakeTorrents()
|
||||
{
|
||||
if(enableFakeTorrents)
|
||||
{
|
||||
fakeTorrentsDebug('hidding fake torrents');
|
||||
enableFakeTorrents = false;
|
||||
}
|
||||
fakeTorrents.forEach((fk) => {
|
||||
clearTimeout(fk)
|
||||
})
|
||||
fakeTorrents = []
|
||||
fakeTorrentsDebug('hidding fake torrents');
|
||||
}
|
||||
|
||||
|
||||
|
49
src/admin-page.js
Normal file
49
src/admin-page.js
Normal file
@ -0,0 +1,49 @@
|
||||
import React from 'react';
|
||||
import Page from './page';
|
||||
import Footer from './footer';
|
||||
import {Header} from './index-page'
|
||||
|
||||
import Toggle from 'material-ui/Toggle';
|
||||
|
||||
export default class AdminPage extends Page {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.setTitle('-=-= Some page =-=-');
|
||||
this.options = {}
|
||||
}
|
||||
componentDidMount() {
|
||||
this.loadSettings()
|
||||
}
|
||||
loadSettings() {
|
||||
window.torrentSocket.emit('admin', window.customLoader((options) => {
|
||||
this.options = options;
|
||||
console.log(this.options)
|
||||
this.forceUpdate();
|
||||
}));
|
||||
}
|
||||
saveSettings() {
|
||||
window.torrentSocket.emit('setAdmin', this.options)
|
||||
this.forceUpdate()
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Header />
|
||||
<div className='column center w100p pad0-75'>
|
||||
<Toggle
|
||||
style={{marginTop: '10px'}}
|
||||
label="Disable DHT scanning"
|
||||
toggled={this.options.dhtDisabled}
|
||||
thumbSwitchedStyle={{backgroundColor: 'red'}}
|
||||
trackSwitchedStyle={{backgroundColor: '#ff9d9d'}}
|
||||
onToggle={(e, checked) => {
|
||||
this.options.dhtDisabled = checked
|
||||
this.saveSettings()
|
||||
}}
|
||||
/>
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import PagesPie from './pages-pie.js';
|
||||
import IndexPage from './index-page.js'
|
||||
import TorrentPage from './torrent-page.js'
|
||||
import DMCAPage from './dmca-page.js'
|
||||
import AdminPage from './admin-page.js'
|
||||
|
||||
router('/', () => {
|
||||
//singleton
|
||||
@ -26,3 +27,10 @@ router('/DMCA', () => {
|
||||
let pie = new PagesPie;
|
||||
pie.open(DMCAPage, {replace: 'all'});
|
||||
});
|
||||
|
||||
|
||||
router('/admi5p', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(AdminPage, {replace: 'all'});
|
||||
});
|
Reference in New Issue
Block a user