Geolocation API for distributed computing research
Last quarter, I quit my web development job at the UW Clinical Trial Center in order to pursue research within UW’s CSE department. As a startup project for a distributed computing research project called Seattle, I put together a simple geolocation library that uses a Python library called pygeoip to look up location data for hostnames and IP addresses.
The first step was to set up an XML-RPC server to serve remote calls to the pygeoip API. This was fairly easy to do using Python’s SimpleXMLRPCServer class:
from SimpleXMLRPCServer import SimpleXMLRPCServer import pygeoip ... # Create server server = SimpleXMLRPCServer((ip, port), allow_none=True)
The location-lookup methods within the pygeoip library must be registered for use via the XML-RPC server. We first initialize a GeoIP object, passing it the filename of a valid binary GeoIP database. Then the GeoIP object is passed to the XML-RPC server’s register_instance method to expose its methods for remote execution:
# Initialize and register GeoIP object gi = pygeoip.GeoIP(geoipdb_filename) server.register_instance(gi) # Run the server's main loop server.serve_forever()
The lookup methods of pygeoip can now be called remotely. To demonstrate my project, I wrote a script that fetches the IPs of all nodes in the distributed computing network that you’ve allocated, looks up their lat/lang coordinates, and plots them on a Google map. For funsies I used the geolocation API built into Firefox 3.5+to include a pointer to the user’s current location.
Hopefully my little library will get some use. Moving into the new year, I’m hoping to increase my involvement in the Seattle project and become more familiar with networking and API design.
