feat(p2p): show torrents number of other clients
This commit is contained in:
parent
7952c283ef
commit
2ba49380f6
@ -87,21 +87,27 @@ window.isReady = () => {
|
||||
}
|
||||
|
||||
window.peers = 0;
|
||||
window.peersTorrents = 0;
|
||||
|
||||
class App extends Component {
|
||||
componentDidMount() {
|
||||
window.router()
|
||||
appReady = true;
|
||||
|
||||
window.torrentSocket.on('peer', (numOfPeers) => {
|
||||
window.peers = numOfPeers
|
||||
window.torrentSocket.on('peer', (peer) => {
|
||||
if(peer.size > window.peers)
|
||||
window.peersTorrents = (window.peersTorrents || 0) + peer.torrents
|
||||
else
|
||||
window.peersTorrents = (window.peersTorrents || 0) - peer.torrents
|
||||
window.peers = peer.size
|
||||
this.forceUpdate()
|
||||
})
|
||||
|
||||
window.torrentSocket.emit('peers', (numOfPeers) => {
|
||||
if(numOfPeers > 0)
|
||||
window.torrentSocket.emit('peers', (peers) => {
|
||||
if(peers.size > 0 || window.peers == 1)
|
||||
{
|
||||
window.peers = numOfPeers
|
||||
window.peers = peers.size
|
||||
window.peersTorrents = peers.torrents
|
||||
this.forceUpdate()
|
||||
}
|
||||
})
|
||||
|
@ -151,7 +151,7 @@ const Header = (props) => {
|
||||
!window.currentWindow.isModal()
|
||||
&&
|
||||
<div className='fs0-85 pad0-75 column peers-status' style={{marginLeft: 'auto', marginTop: '-10px', color: window.peers > 0 ? '#42f445' : 'white'}}>
|
||||
<div>rats peers: {window.peers} {window.peers > 0 ? ' (p2p rats search enabled)' : ' (p2p rats search not available at this moment)'}</div>
|
||||
<div>rats peers: {window.peers} [{window.peersTorrents} torrents] {window.peers > 0 ? ' (p2p rats search enabled)' : ' (p2p rats search not available at this moment)'}</div>
|
||||
{
|
||||
window.p2pStatus == 0
|
||||
&&
|
||||
|
@ -461,7 +461,10 @@ module.exports = ({
|
||||
if(typeof callback != 'function')
|
||||
return;
|
||||
|
||||
callback(p2p.size)
|
||||
callback({
|
||||
size: p2p.size,
|
||||
torrents: p2p.peersList().reduce((a, b) => (a.info ? a.info.torrents || 0 : 0) + (b.info ? b.info.torrents || 0 : 0), 0)
|
||||
})
|
||||
});
|
||||
|
||||
recive('p2pStatus', (callback) =>
|
||||
|
@ -14,6 +14,8 @@ class p2p {
|
||||
p2pStatus = 0
|
||||
version = '0'
|
||||
|
||||
info = {}
|
||||
|
||||
constructor(send = () => {})
|
||||
{
|
||||
this.send = send
|
||||
@ -55,6 +57,7 @@ class p2p {
|
||||
callback({
|
||||
protocol: 'rats',
|
||||
version: this.version,
|
||||
info: this.info,
|
||||
peers: this.peersList().slice(0, 4).map(peer => ({address: peer.address, port: peer.port}))
|
||||
})
|
||||
|
||||
@ -227,6 +230,7 @@ class p2p {
|
||||
protocol: 'rats',
|
||||
port: config.spiderPort,
|
||||
version: this.version,
|
||||
info: this.info,
|
||||
peers: this.peersList().slice(0, 4).map(peer => ({address: peer.address, port: peer.port})).concat(this.externalPeers) // also add external peers
|
||||
}, (data) => {
|
||||
if(!data || data.protocol != 'rats')
|
||||
@ -246,8 +250,14 @@ class p2p {
|
||||
address.emit = emit
|
||||
address.disconnect = () => rawSocket.destroy()
|
||||
this.size++;
|
||||
this.send('peer', this.size)
|
||||
console.log('new peer', address)
|
||||
//extra info
|
||||
address.version = data.version
|
||||
address.info = data.info
|
||||
this.send('peer', {
|
||||
size: this.size,
|
||||
torrents: data.info ? data.info.torrents || 0 : 0
|
||||
})
|
||||
console.log('new peer', address)
|
||||
|
||||
// add some other peers
|
||||
if(data.peers && data.peers.length > 0)
|
||||
@ -264,7 +274,10 @@ class p2p {
|
||||
if(this.peers[index].emit) // only autorized peers
|
||||
{
|
||||
this.size--;
|
||||
this.send('peer', this.size)
|
||||
this.send('peer', {
|
||||
size: this.size,
|
||||
torrents: this.peers[index].info ? this.peers[index].info.torrents || 0 : 0
|
||||
})
|
||||
// trying reconnect once
|
||||
setTimeout(() => this.add(this.addr(address)), 5000)
|
||||
}
|
||||
|
@ -49,6 +49,12 @@ let sphinx = mysql.createPool({
|
||||
port : config.sphinx.port
|
||||
});
|
||||
|
||||
// initialize p2p
|
||||
const p2p = new P2PServer(send)
|
||||
p2p.version = version
|
||||
p2p.encryptor = encryptor
|
||||
p2p.listen()
|
||||
|
||||
const udpTrackers = [
|
||||
{
|
||||
host: 'tracker.coppersurfer.tk',
|
||||
@ -87,6 +93,8 @@ function handleListenerDisconnect() {
|
||||
|
||||
if(rows[0] && rows[0].mx >= 1)
|
||||
torrentsId = rows[0].mx + 1;
|
||||
|
||||
p2p.info.torrents = torrentsId
|
||||
})
|
||||
|
||||
mysqlSingle.query("SELECT MAX(`id`) as mx from files", (err, rows) => {
|
||||
@ -95,6 +103,8 @@ function handleListenerDisconnect() {
|
||||
|
||||
if(rows[0] &&rows[0].mx >= 1)
|
||||
filesId = rows[0].mx + 1;
|
||||
|
||||
p2p.info.files = filesId
|
||||
})
|
||||
});
|
||||
|
||||
@ -252,10 +262,6 @@ function baseRowData(row)
|
||||
}
|
||||
}
|
||||
|
||||
const p2p = new P2PServer(send)
|
||||
p2p.version = version
|
||||
p2p.encryptor = encryptor
|
||||
p2p.listen()
|
||||
// load initial peers
|
||||
if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
{
|
||||
@ -267,6 +273,7 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
console.log('loaded', peers.length, 'peers')
|
||||
}
|
||||
}
|
||||
|
||||
if(config.p2pBootstrap)
|
||||
{
|
||||
http.get('https://api.myjson.com/bins/1e5rmh', (resp) => {
|
||||
|
Loading…
Reference in New Issue
Block a user