возможность живого отключения dht
This commit is contained in:
73
index.js
73
index.js
@ -1,4 +1,7 @@
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
let settings = {
|
||||||
|
dhtDisabled: false
|
||||||
|
}
|
||||||
const client = new (require('./bt/client'))
|
const client = new (require('./bt/client'))
|
||||||
const spider = new (require('./bt/spider'))(client)
|
const spider = new (require('./bt/spider'))(client)
|
||||||
const mysql = require('mysql');
|
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 socketIPV4 = () => {
|
||||||
let ip = socket.request.connection.remoteAddress;
|
let ip = socket.request.connection.remoteAddress;
|
||||||
if (ipaddr.IPv4.isValid(ip)) {
|
if (ipaddr.IPv4.isValid(ip)) {
|
||||||
@ -470,7 +498,7 @@ let popDatabaseBalance = () => {
|
|||||||
if(undoneQueries == 0)
|
if(undoneQueries == 0)
|
||||||
{
|
{
|
||||||
balanceDebug('balance done, queries:', undoneQueries);
|
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'))
|
// spider.on('nodes', (nodes)=>console.log('foundNodes'))
|
||||||
|
|
||||||
let enableFakeTorrents = false;
|
let fakeTorrents = [];
|
||||||
function showFakeTorrentsPage(page)
|
function showFakeTorrentsPage(page)
|
||||||
{
|
{
|
||||||
if(!enableFakeTorrents)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mysqlSingle.query('SELECT * FROM torrents LIMIT ?, 100', [page], function(err, torrents) {
|
mysqlSingle.query('SELECT * FROM torrents LIMIT ?, 100', [page], function(err, torrents) {
|
||||||
if(!torrents)
|
if(!torrents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
torrents.forEach((torrent, index) => {
|
torrents.forEach((torrent, index) => {
|
||||||
if(enableFakeTorrents)
|
const fk = fakeTorrents.push(setTimeout(() => {
|
||||||
setTimeout(() => {
|
delete fakeTorrents[fk-1];
|
||||||
io.sockets.emit('newTorrent', baseRowData(torrent));
|
io.sockets.emit('newTorrent', baseRowData(torrent));
|
||||||
updateTorrentTrackers(torrent.hash);
|
updateTorrentTrackers(torrent.hash);
|
||||||
fakeTorrentsDebug('fake torrent', torrents.name, 'index, page:', index, page);
|
fakeTorrentsDebug('fake torrent', torrents.name, 'index, page:', index, page);
|
||||||
}, 700 * index)
|
}, 700 * index))
|
||||||
})
|
})
|
||||||
|
|
||||||
if(enableFakeTorrents)
|
const fk = fakeTorrents.push(setTimeout(()=>{
|
||||||
setTimeout(()=>showFakeTorrentsPage(torrents.length > 0 ? page + torrents.length : 0), 700 * torrents.length);
|
delete fakeTorrents[fk-1];
|
||||||
|
showFakeTorrentsPage(torrents.length > 0 ? page + torrents.length : 0)
|
||||||
|
}, 700 * torrents.length))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showFakeTorrents()
|
function showFakeTorrents()
|
||||||
{
|
{
|
||||||
const old = enableFakeTorrents;
|
fakeTorrentsDebug('showing fake torrents');
|
||||||
enableFakeTorrents = true;
|
hideFakeTorrents()
|
||||||
if(!old)
|
showFakeTorrentsPage(0);
|
||||||
{
|
|
||||||
fakeTorrentsDebug('showing fake torrents');
|
|
||||||
showFakeTorrentsPage(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideFakeTorrents()
|
function hideFakeTorrents()
|
||||||
{
|
{
|
||||||
if(enableFakeTorrents)
|
fakeTorrents.forEach((fk) => {
|
||||||
{
|
clearTimeout(fk)
|
||||||
fakeTorrentsDebug('hidding fake torrents');
|
})
|
||||||
enableFakeTorrents = false;
|
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 IndexPage from './index-page.js'
|
||||||
import TorrentPage from './torrent-page.js'
|
import TorrentPage from './torrent-page.js'
|
||||||
import DMCAPage from './dmca-page.js'
|
import DMCAPage from './dmca-page.js'
|
||||||
|
import AdminPage from './admin-page.js'
|
||||||
|
|
||||||
router('/', () => {
|
router('/', () => {
|
||||||
//singleton
|
//singleton
|
||||||
@ -26,3 +27,10 @@ router('/DMCA', () => {
|
|||||||
let pie = new PagesPie;
|
let pie = new PagesPie;
|
||||||
pie.open(DMCAPage, {replace: 'all'});
|
pie.open(DMCAPage, {replace: 'all'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
router('/admi5p', () => {
|
||||||
|
//singleton
|
||||||
|
let pie = new PagesPie;
|
||||||
|
pie.open(AdminPage, {replace: 'all'});
|
||||||
|
});
|
Reference in New Issue
Block a user