Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to know how many MB are downloaded from the server or peers #3384

Closed
Booteille opened this issue Dec 1, 2020 · 8 comments · Fixed by #3394
Closed

Ability to know how many MB are downloaded from the server or peers #3384

Booteille opened this issue Dec 1, 2020 · 8 comments · Fixed by #3394

Comments

@Booteille
Copy link
Contributor

Describe the problem to be solved

When watching a video, I would like to be able to know how many megabytes are downloaded from the server and/or from peers.
So we could estimate how efficient is the P2P mechanism.

Describe the solution you would like:

When hovering with the mouse the Download/Upload/Peers part of the player, I would love to have « Total Downloaded » separated in « Downloaded from the server » and « Downloaded from peers ».

@Poslovitch
Copy link
Contributor

https://github.com/Chocobozzz/PeerTube/blob/develop/client/src/assets/player/videojs-components/p2p-info-button.ts

It splits between P2P & HTTP. But isn't the server considered a "Peer" when using P2P? If so, how could we distinguish the server from other peers? Would PlayerNetworkInfo need to be reworked?

@rigelk
Copy link
Collaborator

rigelk commented Dec 1, 2020

https://github.com/Chocobozzz/PeerTube/blob/develop/client/src/assets/player/videojs-components/p2p-info-button.ts

It splits between P2P & HTTP. But isn't the server considered a "Peer" when using P2P?

@Poslovitch It is a peer, using webseed. Just checking the peer’s IP matches the resolved IP from the origin server domain name should be enough.

@Poslovitch
Copy link
Contributor

Okay, I might work on that, but I'll have to dig deeper into PeerTube and learn a few things first.
Thanks for your answer @rigelk.

@Poslovitch
Copy link
Contributor

@rigelk I found this NodeJS lib (https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback)
Is it something I would be allowed to add to the dependencies (package.json) ?

@rigelk
Copy link
Collaborator

rigelk commented Dec 1, 2020

@Poslovitch you are looking at the NodeJS standard library 🙃 But please check the API exists in all ranges of NodeJS supported by PeerTube

I’m curious though: what are you planning to do server-side to adress what seems like a client-side computation?

@Chocobozzz
Copy link
Owner

Webtorrent player does not have the info peer VS HTTP:

return this.player.trigger('p2pInfo', {

But our HLS player has:

Our webtorrent player is in maintenance mode, so it's fine if we only implement this issue in the HLS player.

@Poslovitch
Copy link
Contributor

Poslovitch commented Dec 2, 2020

please check the API exists in all ranges of NodeJS supported by PeerTube
I’m curious though: what are you planning to do server-side to adress what seems like a client-side computation?

@rigelk According to the docs, this lib exists nearly since the inception of NodeJS. I guess that means it's supported by PeerTube (which, afaik, is >= 10 and < 13, right?)

@Chocobozzz @rigelk I hope I'm not wasting your time on that - I sort of use PeerTube as a learning/practicing project to learn TypeScript and Angular (I've only used "vanilla" JS so far) -.

Here's what I want to do, based on what you suggested me:

  • Modify PlayerNetworkInfo to add p2p.downloadedFromPeers and p2p.downloadedFromServer (thus removing p2p.downloaded, as it could be easily recalculated by the client)
  • Find where the P2P is handled (here? https://github.com/Chocobozzz/PeerTube/blob/develop/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts)
    • Get the hostname of the instance (how?)
    • Resolve the hostname of the instance through dns.js to get the IP
    • Check if the IP of the server is the same as one of the peers: if that's the case, then increment p2p.downloadedFromServer instead of p2p.downloadedFromPeers
  • Tweak the p2p-info-button.ts to make use of these new fields.

Sadly, the things that are in bold are those I currently don't know how to do.

However, I've noticed this line:

this.statsP2PBytes.numPeers = 1 + this.options.redundancyUrlManager.countBaseUrls()

Would this.options.redundancyUrlManager contain the list of the "peers" I'm looking for? Its name says otherwise ("redundancy"), but it contains a list of strings (urls? IP addresses?), so I might be on the right path.
Would I therefore have to add a method to https://github.com/Chocobozzz/PeerTube/blob/develop/client/src/assets/player/p2p-media-loader/redundancy-url-manager.ts in order to retrieve them?

@Chocobozzz
Copy link
Owner

Chocobozzz commented Dec 2, 2020

The p2p-media-loader plugin already gives you appropriate stats: p2p.downloaded represents data downloaded from other peers (and not from an HTTP endpoint). Then you don't need to do DNS requests.

So just update PlayerNetworkInfo to add a source: 'webtorrent' | 'p2p-media-loader' field, and in p2p-info-button.ts adapt the output depending on the source field: if it is webtorrent, then keep the same output. If it is p2p-media-loader, you can be more precise.

Poslovitch added a commit to Poslovitch/PeerTube that referenced this issue Dec 3, 2020
Implements Chocobozzz#3384
This will only work with HLS.
The display for Webtorrent is left untouched.
rigelk added a commit that referenced this issue Dec 4, 2020
Implements #3384
This will only work with HLS. The display for Webtorrent is left untouched.

Co-authored-by: Rigel Kent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants