Given a single public IP address (peer A) and a list of many other public IP addresses (a mix of IPv4 and IPv6 addresses), what is the easiest way to match up peer A the IP addresses of the n
nearest peers without having the peers manually ping each other for latency benchmarking?
I think that this is possible using BGP with a bunch of complicated queries (and maybe something involving OSPF), but I was hoping that there might be a solution or library that would make it as easy as the theoretical functional call below.
// `peer` is a single IP address. `peer_list` is a list of IP addresses
// get the 5 nearest peers (ordered) to `peer` from `peer_list`
nearest_peers = get_nearest_ips(peer, peer_list, 5);
Should I just use a local instance of MaxMind's GeoIP database + Haversine/Vincenty, or is it practical to use BGP through a library (with proper caching where needed) to accomplish this?
It seems like this kind of code might exist in an open source anycast routing implementation, although I haven't been able to find anything that fits this use case.
The solution or suggested library doesn't have to work on node.js—any language is fine.
Install https://github.com/runk/node-maxmind
Download 'GeoLite2-City.mmdb' from: http://dev.maxmind.com/geoip/geoip2/geolite2/
As I read it, your question is way more general than your Javascript / WebRTC use case.
Who about something like: "Given a P2P network, and a central server that knows all connected peers, which is the best metric than can be used to pair them up?".
=> As good metric to pair two arbitrary nodes would be the hop-distance between them. The problem being that this value is not possible to compute (you can only guess which path the ISP routers will chose between the nodes).
How to approximate it then?
1. Use geographical distance as an approximation to hop distance
In that case, you are pretty much done. Use any "ip to latlng" service and you are done.
2. Try to guess the real hop distance by mapping the internet
I found a paper on that subject, that might be useful to you. You might as well dig a bit on their references to retrieve previous papers on the same subject:
The easiest way to find the nearest peers, would be to send each of the peers an echo request and measure the time it takes to get a response, like ping does.