feat(config): p2p replication client and server separate for performance optimization

This commit is contained in:
Alexey Kasyanchuk 2018-07-02 04:48:28 +03:00
parent 352213ae0e
commit f8c6a401bc
8 changed files with 73 additions and 42 deletions

View File

@ -219,6 +219,20 @@ export default class ConfigPage extends Page {
/>
</div>
</div>
<div className='column w100p'>
<Toggle
style={{marginTop: '10px'}}
label={__('P2P torrents replication server')}
toggled={this.options.p2pReplicationServer}
onToggle={(e, checked) => {
this.options.p2pReplicationServer = checked
if(!checked)
this.options.p2pReplication = false
this.forceUpdate()
}}
/>
<div className='fs0-75' style={{color: 'grey'}}>* {__('Enable torrents replication server for other rats clients (required for replication)')}.</div>
</div>
<div className='column w100p'>
<Toggle
style={{marginTop: '10px'}}
@ -226,6 +240,8 @@ export default class ConfigPage extends Page {
toggled={this.options.p2pReplication}
onToggle={(e, checked) => {
this.options.p2pReplication = checked
if(checked)
this.options.p2pReplicationServer = true
this.forceUpdate()
}}
/>

View File

@ -198,9 +198,9 @@ module.exports = async ({
onTorrent(hash, options, (data) => callback(data))
})
if(config.p2pReplication)
if(config.p2pReplicationServer)
{
console.log('p2p replication enabled')
console.log('p2p replication server enabled')
p2p.on('randomTorrents', (nil, callback) => {
if(typeof callback != 'function')
@ -236,6 +236,8 @@ module.exports = async ({
})
});
if(config.p2pReplication)
{
const getReplicationTorrents = (nextTimeout = 5000) => {
let gotTorrents = 0
p2p.emit('randomTorrents', null, (torrents, nil, address) => {
@ -259,8 +261,10 @@ module.exports = async ({
setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout)
}
// start
console.log('replication client is enabled')
getReplicationTorrents()
}
}
const searchTorrentCall = function(text, navigation, callback)
{

View File

@ -16,6 +16,7 @@ let config = {
p2pConnections: 10,
p2pBootstrap: true,
p2pReplication: true,
p2pReplicationServer: true,
upnp: true,
@ -76,6 +77,10 @@ const configProxy = new Proxy(config, {
value = 10
if(prop == 'p2pConnections' && value > 300)
value = 300
if(prop == 'p2pReplication' && value)
target['p2pReplicationServer'] = true
if(prop == 'p2pReplicationServer' && !value)
target['p2pReplication'] = false
target[prop] = value

View File

@ -175,6 +175,8 @@
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
"Delete download (files saved)": "Delete download (files saved)",
"Serching metadata in progress... Click will delete this torrent.": "Serching metadata in progress... Click will delete this torrent.",
"Pause torrent downloading": "Pause torrent downloading"
"Pause torrent downloading": "Pause torrent downloading",
"P2P torrents replication server": "P2P torrents replication server",
"Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)"
}
}

View File

@ -175,6 +175,8 @@
"Dont start to seed torrent after download finish": "Не начинать сидировать торрент после окончания загрузки",
"Delete download (files saved)": "Удалить закачку (сохранив файлы)",
"Serching metadata in progress... Click will delete this torrent.": "Поиск методанных в процессе... Клик удалит этот торрент.",
"Pause torrent downloading": "Пауза скачки торрента"
"Pause torrent downloading": "Пауза скачки торрента",
"P2P torrents replication server": "Сервер репликация торрентов через p2p",
"Enable torrents replication server for other rats clients (required for replication)": "Включить сервер репликацияя для остальных клиентов крыс (необходим для репликации)"
}
}

View File

@ -175,6 +175,8 @@
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
"Delete download (files saved)": "Delete download (files saved)",
"Serching metadata in progress... Click will delete this torrent.": "Serching metadata in progress... Click will delete this torrent.",
"Pause torrent downloading": "Pause torrent downloading"
"Pause torrent downloading": "Pause torrent downloading",
"P2P torrents replication server": "P2P torrents replication server",
"Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)"
}
}