feat(config): p2p replication client and server separate for performance optimization
This commit is contained in:
parent
352213ae0e
commit
f8c6a401bc
@ -219,6 +219,20 @@ export default class ConfigPage extends Page {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</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'>
|
<div className='column w100p'>
|
||||||
<Toggle
|
<Toggle
|
||||||
style={{marginTop: '10px'}}
|
style={{marginTop: '10px'}}
|
||||||
@ -226,6 +240,8 @@ export default class ConfigPage extends Page {
|
|||||||
toggled={this.options.p2pReplication}
|
toggled={this.options.p2pReplication}
|
||||||
onToggle={(e, checked) => {
|
onToggle={(e, checked) => {
|
||||||
this.options.p2pReplication = checked
|
this.options.p2pReplication = checked
|
||||||
|
if(checked)
|
||||||
|
this.options.p2pReplicationServer = true
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -163,8 +163,8 @@ export default class Torrent extends Component {
|
|||||||
downloaded: false,
|
downloaded: false,
|
||||||
startingDownloading: false,
|
startingDownloading: false,
|
||||||
downloadProgress: {},
|
downloadProgress: {},
|
||||||
downloadRemoveOnDone: false,
|
downloadRemoveOnDone: false,
|
||||||
downloadPaused: false,
|
downloadPaused: false,
|
||||||
}
|
}
|
||||||
constructor(props)
|
constructor(props)
|
||||||
{
|
{
|
||||||
@ -179,8 +179,8 @@ export default class Torrent extends Component {
|
|||||||
}
|
}
|
||||||
this.state.downloading = progress < 1
|
this.state.downloading = progress < 1
|
||||||
this.state.downloaded = progress === 1
|
this.state.downloaded = progress === 1
|
||||||
this.state.downloadRemoveOnDone = removeOnDone
|
this.state.downloadRemoveOnDone = removeOnDone
|
||||||
this.state.downloadPaused = paused
|
this.state.downloadPaused = paused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,8 +226,8 @@ export default class Torrent extends Component {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
downloadRemoveOnDone: options.removeOnDone,
|
downloadRemoveOnDone: options.removeOnDone,
|
||||||
downloadPaused: options.paused
|
downloadPaused: options.paused
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
window.torrentSocket.on('downloadUpdate', this.downloadUpdate);
|
window.torrentSocket.on('downloadUpdate', this.downloadUpdate);
|
||||||
@ -253,8 +253,8 @@ export default class Torrent extends Component {
|
|||||||
if(torrent.good > 0 || torrent.bad > 0)
|
if(torrent.good > 0 || torrent.bad > 0)
|
||||||
torrentRating = Math.round(rating(torrent.good, torrent.bad) * 100);
|
torrentRating = Math.round(rating(torrent.good, torrent.bad) * 100);
|
||||||
|
|
||||||
const canDeleteDownloadAfterFinish = (this.state.downloading || this.state.startingDownloading) && !this.state.downloaded
|
const canDeleteDownloadAfterFinish = (this.state.downloading || this.state.startingDownloading) && !this.state.downloaded
|
||||||
const canPause = (this.state.downloading || this.state.startingDownloading)
|
const canPause = (this.state.downloading || this.state.startingDownloading)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -359,7 +359,7 @@ export default class Torrent extends Component {
|
|||||||
leftIcon={contentIcon(torrent.contentType, torrent.contentCategory, torrent.contentCategory != 'xxx' ? (torrent.peer ? '#6f5ee0' : 'grey') : (torrent.peer ? '#9083e2' : '#d3d3d3'))}
|
leftIcon={contentIcon(torrent.contentType, torrent.contentCategory, torrent.contentCategory != 'xxx' ? (torrent.peer ? '#6f5ee0' : 'grey') : (torrent.peer ? '#9083e2' : '#d3d3d3'))}
|
||||||
rightIcon={
|
rightIcon={
|
||||||
<div className='row inline' style={{width: 63 + (canDeleteDownloadAfterFinish ? 40 : 0) + (canPause ? 40 : 0)}}>
|
<div className='row inline' style={{width: 63 + (canDeleteDownloadAfterFinish ? 40 : 0) + (canPause ? 40 : 0)}}>
|
||||||
{
|
{
|
||||||
// mark delete after finish
|
// mark delete after finish
|
||||||
canPause
|
canPause
|
||||||
&&
|
&&
|
||||||
@ -374,14 +374,14 @@ export default class Torrent extends Component {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
window.torrentSocket.emit('downloadUpdate', torrent.hash, {pause: 'switch'})
|
window.torrentSocket.emit('downloadUpdate', torrent.hash, {pause: 'switch'})
|
||||||
}} viewBox="0 0 438.536 438.536">
|
}} viewBox="0 0 438.536 438.536">
|
||||||
<g>
|
<g>
|
||||||
<path d="M164.453,0H18.276C13.324,0,9.041,1.807,5.425,5.424C1.808,9.04,0.001,13.322,0.001,18.271v401.991
|
<path d="M164.453,0H18.276C13.324,0,9.041,1.807,5.425,5.424C1.808,9.04,0.001,13.322,0.001,18.271v401.991
|
||||||
c0,4.948,1.807,9.233,5.424,12.847c3.619,3.617,7.902,5.428,12.851,5.428h146.181c4.949,0,9.231-1.811,12.847-5.428
|
c0,4.948,1.807,9.233,5.424,12.847c3.619,3.617,7.902,5.428,12.851,5.428h146.181c4.949,0,9.231-1.811,12.847-5.428
|
||||||
c3.617-3.613,5.424-7.898,5.424-12.847V18.271c0-4.952-1.807-9.231-5.428-12.847C173.685,1.807,169.402,0,164.453,0z"/>
|
c3.617-3.613,5.424-7.898,5.424-12.847V18.271c0-4.952-1.807-9.231-5.428-12.847C173.685,1.807,169.402,0,164.453,0z"/>
|
||||||
<path d="M433.113,5.424C429.496,1.807,425.215,0,420.267,0H274.086c-4.949,0-9.237,1.807-12.847,5.424
|
<path d="M433.113,5.424C429.496,1.807,425.215,0,420.267,0H274.086c-4.949,0-9.237,1.807-12.847,5.424
|
||||||
c-3.621,3.615-5.432,7.898-5.432,12.847v401.991c0,4.948,1.811,9.233,5.432,12.847c3.609,3.617,7.897,5.428,12.847,5.428h146.181
|
c-3.621,3.615-5.432,7.898-5.432,12.847v401.991c0,4.948,1.811,9.233,5.432,12.847c3.609,3.617,7.897,5.428,12.847,5.428h146.181
|
||||||
c4.948,0,9.229-1.811,12.847-5.428c3.614-3.613,5.421-7.898,5.421-12.847V18.271C438.534,13.319,436.73,9.04,433.113,5.424z"/>
|
c4.948,0,9.229-1.811,12.847-5.428c3.614-3.613,5.421-7.898,5.421-12.847V18.271C438.534,13.319,436.73,9.04,433.113,5.424z"/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
|
@ -198,9 +198,9 @@ module.exports = async ({
|
|||||||
onTorrent(hash, options, (data) => callback(data))
|
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) => {
|
p2p.on('randomTorrents', (nil, callback) => {
|
||||||
if(typeof callback != 'function')
|
if(typeof callback != 'function')
|
||||||
@ -236,30 +236,34 @@ module.exports = async ({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const getReplicationTorrents = (nextTimeout = 5000) => {
|
if(config.p2pReplication)
|
||||||
let gotTorrents = 0
|
{
|
||||||
p2p.emit('randomTorrents', null, (torrents, nil, address) => {
|
const getReplicationTorrents = (nextTimeout = 5000) => {
|
||||||
if(!torrents || torrents.length == 0)
|
let gotTorrents = 0
|
||||||
return
|
p2p.emit('randomTorrents', null, (torrents, nil, address) => {
|
||||||
|
if(!torrents || torrents.length == 0)
|
||||||
|
return
|
||||||
|
|
||||||
if(compareVersions(address.version, '0.19.0') < 0)
|
if(compareVersions(address.version, '0.19.0') < 0)
|
||||||
{
|
{
|
||||||
console.log('replication now works only with 0.19.0 version, ignore this torrent')
|
console.log('replication now works only with 0.19.0 version, ignore this torrent')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gotTorrents += torrents.length
|
gotTorrents += torrents.length
|
||||||
|
|
||||||
torrents.forEach((torrent) => {
|
torrents.forEach((torrent) => {
|
||||||
console.log('replicate remote torrent', torrent && torrent.name)
|
console.log('replicate remote torrent', torrent && torrent.name)
|
||||||
insertTorrentToDB(torrent)
|
insertTorrentToDB(torrent)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout)
|
setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout)
|
||||||
|
}
|
||||||
|
// start
|
||||||
|
console.log('replication client is enabled')
|
||||||
|
getReplicationTorrents()
|
||||||
}
|
}
|
||||||
// start
|
|
||||||
getReplicationTorrents()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchTorrentCall = function(text, navigation, callback)
|
const searchTorrentCall = function(text, navigation, callback)
|
||||||
|
@ -16,6 +16,7 @@ let config = {
|
|||||||
p2pConnections: 10,
|
p2pConnections: 10,
|
||||||
p2pBootstrap: true,
|
p2pBootstrap: true,
|
||||||
p2pReplication: true,
|
p2pReplication: true,
|
||||||
|
p2pReplicationServer: true,
|
||||||
|
|
||||||
upnp: true,
|
upnp: true,
|
||||||
|
|
||||||
@ -76,7 +77,11 @@ const configProxy = new Proxy(config, {
|
|||||||
value = 10
|
value = 10
|
||||||
if(prop == 'p2pConnections' && value > 300)
|
if(prop == 'p2pConnections' && value > 300)
|
||||||
value = 300
|
value = 300
|
||||||
|
if(prop == 'p2pReplication' && value)
|
||||||
|
target['p2pReplicationServer'] = true
|
||||||
|
if(prop == 'p2pReplicationServer' && !value)
|
||||||
|
target['p2pReplication'] = false
|
||||||
|
|
||||||
|
|
||||||
target[prop] = value
|
target[prop] = value
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ describe("sphinx", () => {
|
|||||||
for(let i = 0; i < 500; i++)
|
for(let i = 0; i < 500; i++)
|
||||||
promises.push(sphinx.query(`insert into feed(id, data) values(${i}, 'a')`))
|
promises.push(sphinx.query(`insert into feed(id, data) values(${i}, 'a')`))
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
sphinx.query(`delete from feed where id >= 0`, () => done())
|
sphinx.query(`delete from feed where id >= 0`, () => done())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -175,6 +175,8 @@
|
|||||||
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
|
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
|
||||||
"Delete download (files saved)": "Delete download (files saved)",
|
"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.",
|
"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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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": "Пауза скачки торрента",
|
||||||
|
"P2P torrents replication server": "Сервер репликация торрентов через p2p",
|
||||||
|
"Enable torrents replication server for other rats clients (required for replication)": "Включить сервер репликацияя для остальных клиентов крыс (необходим для репликации)"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -175,6 +175,8 @@
|
|||||||
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
|
"Dont start to seed torrent after download finish": "Dont start to seed torrent after download finish",
|
||||||
"Delete download (files saved)": "Delete download (files saved)",
|
"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.",
|
"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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user