BLIP: Come ‘n’ get it!

by Jens Alfke ⟿ May 25, 2008

I’ve released the source code to my “BLIP” protocol implementation, as part of a project I call “MYNetwork”, for “Mooseyard Networking Libraries”. API documentation is available online, and you can check out or browse the source code from its Mercurial repository. For the really curious, there’s even a sketchy overview of the protocol’s wire format.

It’s working quite well for me in Cloudy; it’s been a while since I’ve found any outright bugs, although I know there’s more work to do on performance and features. It’s not production-ready code yet, but I think it’s ready for people to start using!

For now you can leave feedback in comments to this post, or by email to jens at this domain. If there’s enough interest, I could set up a mailing list.

Here’s the description of BLIP from the API docs…

What’s BLIP?

BLIP is a message-oriented network protocol that lets the two peers on either end of a TCP socket send request and response messages to each other. It’s a generic protocol, in that the requests and responses can contain any kind of data you like.

BLIP was inspired by BEEP (in fact BLIP stands for “BEEP-LIke Protocol”) but is deliberately simpler and somewhat more limited. That results in a smaller and cleaner implementation, especially since it takes advantage of Cocoa’s and CFNetwork’s existing support for network streams, SSL and Bonjour. (BLIP is currently a bit under 2,000 lines of code, and the rest of the MYNetwork classes it builds on add up to another 1,500. That’s at least an order of magnitude smaller than existing native-code BEEP libraries.)

BLIP Features:

  • Each message is very much like a MIME body, as in email or HTTP: it consists of a blob of data of arbitrary length, plus a set of key/value pairs called properties. The properties are mostly ignored by BLIP itself, but clients can use them for metadata about the body, and for routing (i.e. something like BEEP’s “profiles”.)
  • Either peer can send a request at any time; there’s no notion of “client” and “server” roles.
    Multiple messages can be transmitted simultaneously in the same direction over the same connection, so a very long message does not block any other messages from being delivered. This means that message ordering is a bit looser than in BEEP or HTTP 1.1: the receiver will see the beginnings of messages in the same order in which the sender posted them, but they might not end in that same order. (For example, a long message will take longer to be delivered, so it may finish after messages that were begun after it.)
  • The BLIPDispatcher class lets you (optionally) use NSPredicate-based rules to route incoming requests to handler methods. The predicates can examine all of the message metadata, so they can act much like the routing functionality of web frameworks like Rails and TurboGears.
  • The sender can indicate whether or not a message needs to be replied to; the response is tagged with the identity of the original message, to make it easy for the sender to recognize. This makes it straighforward to implement RPC-style (or REST-style) interactions. (Responses cannot be replied to again, however.)
  • A message can be flagged as urgent. Urgent messages are pushed ahead in the outgoing queue and get a higher fraction of the available bandwidth.
  • A message can be flagged as compressed. This runs its body through the gzip algorithm, ideally making it faster to transmit. (Common markup-based data formats like XML and JSON compress extremely well, at ratios up to 10::1.) The message is decompressed on the receiving end, invisibly to client code.
  • The implementation supports SSL connections (with optional client-side certificates), and Bonjour service advertising.