dankamongmen / libnetstack

Small library around rtnetlink to track networking stack elements
https://nick-black.com/dankwiki/index.php/Libnetstack
Apache License 2.0
10 stars 0 forks source link

Need on-demand enumeration capability #25

Closed dankamongmen closed 4 years ago

dankamongmen commented 4 years ago

The user ought at any point be able to get a list of all devices (not necessarily handles to all ifaces), routes, etc. There are two forms this could take:

1) a series of callbacks encompassing the space 2) a function that returns all the data into a buffer (requiring streaming for very large return sets)

I think 2 is the better one here, especially because other events could be interleaved with the series of callbacks, leading to confusion (they're also less performant). So if we're returning data, there are three things we could return:

1) A set of shared pointers to actual objects, or 2) A set of copied objects, or 3) A set of summaries

In all cases, it's probably necessary that we have a streaming solution allowing for multiple calls. I don't think such a solution needs to (or should) guarantee atomicity.

In the end, I'm reminded very much of the readdir(3) system call, which is trying to solve the same problem. A space of entries, which might be modified at any time, is to be enumerated over multiple calls. The complete inodes describing these files are fairly large, and we're usually interested in only a small amount of the information.

This points to a pretty solid solution IMHO:

That seems reasonable. There are two potential problems, both related to streaming:

this latter seems to have no obvious exit, but.....it is unlikely that there will ever be a great many objects pending deletion nor more than a few active enumerations. maybe when we remove an object from the hash, check the active enumerations list (which might be active and/or deleted objects), see if it is hnext for any of them, and fix up hnext (o(1)) in such cases. so that would be o(n) on every delete, but N ought almost always be very small...

dankamongmen commented 4 years ago

This is a bit raw, but it's there.