ralphm.net

ralphm's blog

Wednesday, 2 June 2004

Idavoll rewrite

Twistifying matters...

Idavoll needs some loving. Apart from minor updates, it hasn't really moved forward. My luck is that pubsub has not really gotten any (visible) traction apart from being advanced to Draft status last October.

Recently, however, I got kicked by temas and pgmillard, to fix some small bugs in Idavoll, which they are hooking up to the jabber.org server. They are playing with it a bit now, with some serious plans for the near future.

In the mean while, I have been wanting to redo the implementation of Idavoll in Twisted, an event-driven networking framework written in Python. I've been talking to offline offlinedizzyd, who wrote most of the Jabber protocol code in Twisted, for some guidance to go about this. Looking at Proxy65 and the nice step-by-step tutorial for implementing a full-featured, scalable and extensible finger service, Twisted from Scratch, or the Evolution of Finger, I have finally started on the rewrite of Idavoll using Twisted.

The idea is to make the service allow for different, pluggable backends and also, in the philosophy of Twisted, make it possible to hook up other protocols for interfacing with this backend. This, hopefully, means, that it should become rather easy to hook up a web-based interface to help administer the component. Let's see how that evolves.

One of the bugs I needed to fix in Idavoll was to have the Jabber component return error stanzas to signal that unknown queries are not implemented. I did a quick fix on the current implementation, and then started to wonder how to do that using the Twisted framework. This proved to be impossible to do nicely. In Twisted, you can hook up handlers to XPATH like queries that match incoming XML elements. However, there is no ordering in these handlers, so although you can make a catch-all handler, and let other handlers signal whether they did or did not handle a certain stanze, the catch-all can easily be called before the more specific handler.

For now, I hacked xish, which does the XPATH matching and calling of the observers, to have XPathQuery objects contain a priority attribute, and implemented the __cmd__() and __hash__() methods to be able to sort the objects. After modifying the methods for adding observers, you can now give a priority to each XPATH query, much like template matching in XSLT. This works nicely. I just give the catch-all observer a priority of -1, with 0 being the default. This way, existing code is unaffected.

Now, on to the rest of the implementation. If only to prove boyd wrong.