The issue I've struggled with, with most of the cryptocoin binaries (including the canonical bitcoind application, and the bitcoinjs-server NodeJS implementation I've worked with the most) is how monolithic they are; they include mining, wallet, listening server and sending server, JSON-RPC API, etc. Even if you only need a portion of those features, you must deal with the overhead of having all the other components there. And if you're trying to find bugs/memory leaks or trying to tweak it to work with another cryptocoin, there's a lot more code to wade through.
While the source code for those applications usually splits the source out into different files that do their own roles, my goal is to create a set of libraries in more the UNIX mentality of "a small application that does one thing and does it well", and then bundling little applications together into a piecemeal whole that's exactly what you need. I've started to build this in NodeJS (chosen since it has the potential then to be deployable to desktop, server, or run in-browser), and have these three libraries as proof-of-concept so far:
crypto-p2p-node: Manages a single connection to a single peer. Its primary purpose is to replace the 'data' events a bare Node socket emits, and instead collect the chunked data from the peer and break it up by magic byte sequence, and instead emit 'message' events when a whole message is received. Emits 'message' events so you can subscribe to all messages, and custom events per command in the form of "commandMessage" (e.g. "versionMessage", "verackMessage", "getaddrMessage", etc.) to subscribe to messages only of that type. Works with any network communication protocol that has the same envelope structure as Bitcoin (4 byte magic byte identifier, 12 byte command string, 4 byte payload length, 4 byte checksum, then payload).
crypto-p2p-manager: Manages several crypto-p2p-node connections. It maintains lists of active peers, a pool of known peers to potentially connect to, and weeds out bad peers who are unresponsive on a basic level. Provides functions for sending messages to specific sub-sets of active peers.
btc-p2p: Knows how to parse the message payloads of Bitcoin protocol messages, emitted by a crypto-p2p-manager. It ensures Bitcoin protocol rules like sending a VERSION message right after connecting, and sending a VERACK after receiving a VERSION message are followed. It uses the GETADDR/ADDR messages to feed new potential peers to the crypto-p2p-manager pool. This will emit events for new blocks and transactions being transmitted for some parent library to assemble (a blockchain-maintaining library) and store (database).
What do you all think of that structure/methodology? I put several examples in the three libraries (especially crypto-p2p-node) on how they could easily be flexed to conform to other cryptocurrency schemes. That way, there doesn't need to be a monolithic configuration file at the top level of the application that tries to reach deep into the application to change the logic to another cryptocurrency (the way that namecoin has a "namecoin.cpp" source file that overrides the defaults set by the "main.cpp" Bitcoin file which is still in its source). There could be a "ltc-p2p" module that applies the Litecoin logic, and then Litecoin apps get build on that library, rather than building on the btc-p2p library and overriding methods.
Even without the block and transaction relaying, I realized one simple application could already be built on the btc-p2p library as-is: a seed/bootstrap peer distribution app, like a DNS lookup server, for peers wanting to get in the network. Once I add the block and transaction relaying ability to the btc-p2p library, I plan to work towards a website service like blockexplorer/
blockchain.info. Anyone else have interests in this direction or interest in helping create modified versions of these libraries for other cryptocurrencies? Also, the names aren't anything I'm stuck on; anyone got any better naming convention for these little components?
Brooks