After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 723780 - upnp: filter out devices on the local machine
upnp: filter out devices on the local machine
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
unspecified
Other All
: Normal normal
: ---
Assigned To: grilo-maint
grilo-maint
Depends on: 724019
Blocks:
 
 
Reported: 2014-02-06 16:16 UTC by Giovanni Campagna
Modified: 2014-03-27 19:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
upnp: filter out devices on the local machine (4.87 KB, patch)
2014-02-06 16:16 UTC, Giovanni Campagna
needs-work Details | Review
upnp: tag sources on the local machine (6.49 KB, patch)
2014-03-05 20:20 UTC, Giovanni Campagna
needs-work Details | Review
upnp: tag sources that belong to the same user (10.42 KB, patch)
2014-03-05 20:20 UTC, Giovanni Campagna
needs-work Details | Review
upnp: tag sources on the local machine (9.32 KB, patch)
2014-03-05 21:39 UTC, Giovanni Campagna
committed Details | Review
upnp: tag sources that belong to the same user (11.74 KB, patch)
2014-03-05 21:39 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2014-02-06 16:16:45 UTC
We already have sources for local media, and going through the
TCP/IP subsystem for local files is not the best use of resources.
Also, this avoids a usability issue: the user who enabled
local media sharing, but does not know how rygel, grilo and upnp
in general work might see "John Doe's Media" in Totem,
see his files there and think it's the proper way to open
them.

The actual filtering is a bit hackish, because all we see
is the URI provided by SSDP. There is a fallback to comparing
hostnames, but because usually DNS is not configured in a home
network, we should almost always see an IP address there.
From that, we need to check if any interface is configured to
use it. We could ask NetworkManager or connman, but that would
grow an heavy and unwanted dependency; we could ask netlink,
but that would fail outside of Linux; the simplest, although
quite hackish, solution is to try and bind() to the remote
address - if that succeeds, the address is local after all.
The biggest downside to this solution, besides being Unix only
due to EADDRNOTAVAIL, is that socket() can fail because of
EMFILE/ENFILE, in which case we can't perform the check.
Not a big deal maybe.
Comment 1 Giovanni Campagna 2014-02-06 16:16:49 UTC
Created attachment 268305 [details] [review]
upnp: filter out devices on the local machine
Comment 2 Bastien Nocera 2014-02-06 16:43:54 UTC
Really not interested in that. The media exported through rygel is not the same that's indexed in Tracker.
Comment 3 Giovanni Campagna 2014-02-06 16:49:36 UTC
(In reply to comment #2)
> Really not interested in that. The media exported through rygel is not the same
> that's indexed in Tracker.

It is most of time. Even if you don't configure rygel to export through Tracker (and I don't understand why you would do that...), stuff is most likely to be in Videos, and that's exported and indexed.

And anyway, how do you plan to explain people what's the difference?
They will go to Channels, see their stuff, and say "oh cool, here it is".

Even if they know the difference, having the source right there, big clickable and good-looking is so better than going through the file picker or file manager that they will be tempted to use it anyway. I was, at least.
Comment 4 Bastien Nocera 2014-02-06 18:14:40 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Really not interested in that. The media exported through rygel is not the same
> > that's indexed in Tracker.
> 
> It is most of time.

And sometimes it isn't.

> Even if you don't configure rygel to export through Tracker

Not using Tracker is the default for rygel's setup in the sharing panel. Because your local videos aren't necessarily the ones you want to share out.

> (and I don't understand why you would do that...), stuff is most likely to be
> in Videos, and that's exported and indexed.

Again, assumptions that aren't true.

> And anyway, how do you plan to explain people what's the difference?
> They will go to Channels, see their stuff, and say "oh cool, here it is".

Then we need to do better in the UI, like showing shared videos in a special way.

> Even if they know the difference, having the source right there, big clickable
> and good-looking is so better than going through the file picker or file
> manager that they will be tempted to use it anyway. I was, at least.

Just removing the local UPnP server isn't a good way to fix this. And it also breaks UPnP servers running as a different user, or as a system service.

"Tagging" the UPnP source would still be useful to the front-ends, simply hiding it isn't.
Comment 5 Giovanni Campagna 2014-02-06 20:57:20 UTC
I still believe local sources should be completely hidden from the UI, but if we wanted to that at a upper layer, how do I tag the source?
Comment 6 Juan A. Suarez Romero 2014-02-07 08:05:08 UTC
I think the best approach would be adding a configuration option to hide local servers. Something like "hide-local-servers". If application sets it to TRUE, then the plugin could hide those local servers.
Comment 7 Bastien Nocera 2014-02-07 08:29:40 UTC
(In reply to comment #6)
> I think the best approach would be adding a configuration option to hide local
> servers. Something like "hide-local-servers". If application sets it to TRUE,
> then the plugin could hide those local servers.

That wouldn't help front-ends special case it.

(In reply to comment #5)
> I still believe local sources should be completely hidden from the UI, but if
> we wanted to that at a upper layer, how do I tag the source?

There's no way to do that yet, but I can see a need for tagging sources with arbitrary strings, such as "radio", "tv", marking sources as interesting for certain locales/countries ("countrycode:it" for raitv), etc.
Comment 8 Juan A. Suarez Romero 2014-02-07 09:13:20 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > I think the best approach would be adding a configuration option to hide local
> > servers. Something like "hide-local-servers". If application sets it to TRUE,
> > then the plugin could hide those local servers.
> 
> That wouldn't help front-ends special case it.
> 

Why not?
Comment 9 Bastien Nocera 2014-02-07 09:25:50 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > I think the best approach would be adding a configuration option to hide local
> > > servers. Something like "hide-local-servers". If application sets it to TRUE,
> > > then the plugin could hide those local servers.
> > 
> > That wouldn't help front-ends special case it.
> > 
> 
> Why not?

Because it simply hides the source, instead of making sure that the front-end can do something special with it (like getting a full list of all the items to be merged in the "local" view).
Comment 10 Juan A. Suarez Romero 2014-02-07 10:43:32 UTC
(In reply to comment #9)
> Because it simply hides the source, instead of making sure that the front-end
> can do something special with it (like getting a full list of all the items to
> be merged in the "local" view).

Yes, which is what this issue is about. Hence the option.

But if we want to generalize this issue, I like the proposal of tagging the sources. It was something I had considered some time ago. 

If Giovanni agrees with considering the generic issue, let's hold on the patch and go with the generic proposal.
Comment 11 Bastien Nocera 2014-02-08 18:07:16 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > Because it simply hides the source, instead of making sure that the front-end
> > can do something special with it (like getting a full list of all the items to
> > be merged in the "local" view).
> 
> Yes, which is what this issue is about. Hence the option.

You can't show something in a different place if you can't get to it...

> But if we want to generalize this issue, I like the proposal of tagging the
> sources. It was something I had considered some time ago. 
> 
> If Giovanni agrees with considering the generic issue, let's hold on the patch
> and go with the generic proposal.
Comment 12 Juan A. Suarez Romero 2014-02-09 01:56:30 UTC
(In reply to comment #11)
> You can't show something in a different place if you can't get to it...

Yes, I understand. But the original description is not about showing local servers in a different place, but just do not show them at all, as other sources (like Tracker) could be providing that information.

In any case, as I said, I also prefer having a more generic approach. So just identifying the local sources so the application decides if must be shown in a different place or just hide them completely is my preference too.
Comment 13 Bastien Nocera 2014-02-10 10:50:29 UTC
Comment on attachment 268305 [details] [review]
upnp: filter out devices on the local machine

Let's mark this as needs-work to get it off the review list.
Comment 14 Bastien Nocera 2014-02-10 11:45:56 UTC
There's a simple "tags" property in bug 724019 which this patch could use. This patch also needs to make sure not to tag UPnP servers from other users but from the same machine.
Comment 15 Bastien Nocera 2014-02-21 11:48:04 UTC
(In reply to comment #14)
> There's a simple "tags" property in bug 724019 which this patch could use. This
> patch also needs to make sure not to tag UPnP servers from other users but from
> the same machine.

Giovanni, does "localhost" and "localuser" tags as documented in the patch from bug 724019 comment 9 suit you for this use case?
Comment 16 Giovanni Campagna 2014-03-05 20:20:44 UTC
Created attachment 271027 [details] [review]
upnp: tag sources on the local machine

Recognize sources that correspond to rygel or similar
software on the local machine, and add a "localhost"
tag to the source. This will allow Totem or other
applications to filter the source out.

The actual recognition is a bit hackish, because all we see
is the URI provided by SSDP. There is a fallback to comparing
hostnames, but because usually DNS is not configured in a home
network, we should almost always see an IP address there.
From that, we need to check if any interface is configured to
use it. We could ask NetworkManager or connman, but that would
grow an heavy and unwanted dependency; we could ask netlink,
but that would fail outside of Linux; the simplest, although
quite hackish, solution is to try and bind() to the remote
address - if that succeeds, the address is local after all.
The biggest downside to this solution, besides being Unix only
due to EADDRNOTAVAIL, is that socket() can fail because of
EMFILE/ENFILE, in which case we can't perform the check.
Not a big deal maybe.
Comment 17 Giovanni Campagna 2014-03-05 20:20:55 UTC
Created attachment 271028 [details] [review]
upnp: tag sources that belong to the same user

If the source is found to be on the local machine, scan /proc/net/tcp
to find the UID of the process that is listening on the socket,
and tag the source if it's the same user as the one running the
client.
Comment 18 Bastien Nocera 2014-03-05 20:56:59 UTC
Review of attachment 271027 [details] [review]:

Can you split out is_localhost_url() into a separate file?
We'll probably need to re-use it in the dleyna UPnP source at some point.

::: src/upnp/grl-upnp.c
@@ +530,3 @@
+     It's actually 64 on linux.
+  */
+  char hostname_buffer[256];

Use constant for that, so you can reuse it in the gethostname call lower down.
Comment 19 Bastien Nocera 2014-03-05 21:01:07 UTC
Review of attachment 271028 [details] [review]:

Ditto about splitting in another file.

::: src/upnp/grl-upnp.c
@@ +545,3 @@
+  uid_t uid;
+
+  if (!g_file_get_contents ("/proc/net/tcp", &proc_net_tcp, NULL, NULL))

How big is that file going to get? I have 100k of data on my system without doing much at all.

Reading line-by-line seems like a better idea to me.
Comment 20 Giovanni Campagna 2014-03-05 21:39:09 UTC
Created attachment 271041 [details] [review]
upnp: tag sources on the local machine

Recognize sources that correspond to rygel or similar
software on the local machine, and add a "localhost"
tag to the source. This will allow Totem or other
applications to filter the source out.

The actual recognition is a bit hackish, because all we see
is the URI provided by SSDP. There is a fallback to comparing
hostnames, but because usually DNS is not configured in a home
network, we should almost always see an IP address there.
From that, we need to check if any interface is configured to
use it. We could ask NetworkManager or connman, but that would
grow an heavy and unwanted dependency; we could ask netlink,
but that would fail outside of Linux; the simplest, although
quite hackish, solution is to try and bind() to the remote
address - if that succeeds, the address is local after all.
The biggest downside to this solution, besides being Unix only
due to EADDRNOTAVAIL, is that socket() can fail because of
EMFILE/ENFILE, in which case we can't perform the check.
Not a big deal maybe.
Comment 21 Giovanni Campagna 2014-03-05 21:39:14 UTC
Created attachment 271042 [details] [review]
upnp: tag sources that belong to the same user

If the source is found to be on the local machine, scan /proc/net/tcp
to find the UID of the process that is listening on the socket,
and tag the source if it's the same user as the one running the
client.
Comment 22 Bastien Nocera 2014-03-19 11:42:45 UTC
Review of attachment 271041 [details] [review]:

Looks good to me.
Comment 23 Bastien Nocera 2014-03-19 11:43:35 UTC
Review of attachment 271042 [details] [review]:

Looks good as well.
Comment 24 Giovanni Campagna 2014-03-24 09:11:04 UTC
Ops, I forgot about this before hard code freeze kicked in. Would this be ok for .1, or should I wait until branched?
Comment 25 Bastien Nocera 2014-03-24 13:27:24 UTC
Sounds good for .1
Comment 26 Bastien Nocera 2014-03-27 19:22:23 UTC
Attachment 271041 [details] pushed as 2b4ab2b - upnp: tag sources on the local machine
Attachment 271042 [details] pushed as 91c4ee1 - upnp: tag sources that belong to the same user