Author: poeml Date: Thu Mar 18 02:31:57 2010 New Revision: 8009 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8009&view=rev Log: mb: - Added a Python extension for fast checksumming with zsync's "rsum" checksum. It would be far too slow, if not done in C. Added: trunk/mirrordoctor/zsyncmodule.c Modified: trunk/mirrordoctor/setup.py Modified: trunk/mirrordoctor/setup.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/setup.py?rev=8009&r1=8008&r2=8009&view=diff ============================================================================== --- trunk/mirrordoctor/setup.py (original) +++ trunk/mirrordoctor/setup.py Thu Mar 18 02:31:57 2010 @@ -1,9 +1,9 @@ #!/usr/bin/env python -from distutils.core import setup +from distutils.core import setup, Extension setup(name='mirrordoctor', - version='2.12.0', + version='2.13.0', description='MirrorDoctor, a tool to maintain the MirrorBrain database', author='MirrorBrain project', author_email='info_at_mirrorbrain.org', @@ -12,4 +12,6 @@ packages=['mb'], scripts=['mirrordoctor.py'], + + ext_modules=[Extension('zsync', sources=['zsyncmodule.c'])], ) Added: trunk/mirrordoctor/zsyncmodule.c URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/zsyncmodule.c?rev=8009&view=auto ============================================================================== --- trunk/mirrordoctor/zsyncmodule.c (added) +++ trunk/mirrordoctor/zsyncmodule.c Thu Mar 18 02:31:57 2010 @@ -1,0 +1,56 @@ +/* "rsum" checksumming function from zsync's librcksum/rsum.c, version 0.6.1, + * wrapped into a Python extension + * + * Copyright 2010 Peter Poeml <poeml_at_mirrorbrain.org> + * + * The checksumming function itself is available under the Artistic License; + * the boilerplate was a nice exercise. + * + * This is something that will be a whole lot slower when programmed in a + * scripting language, thus I wanted this Python extension. */ + +#include <stdlib.h> +#include <arpa/inet.h> +#include "Python.h" + +static PyObject *zsync_rsum06(PyObject *self, PyObject *args) { + char *data; + int len; + unsigned short a, b; + unsigned char digest[4]; + memset(digest, 0, sizeof(digest)); + + if (!PyArg_ParseTuple(args, "s#", &data, &len)) + return NULL; + + { + register unsigned short aa = 0; + register unsigned short bb = 0; + while (len) { + register unsigned char c = *data++; + aa += c; + bb += len * c; + len--; + } + a = aa; + b = bb; + } + + a = htons(a); + b = htons(b); + memcpy((void *)&digest, &a, 2); + memcpy((void *)&digest + 2, &b, 2); + + return PyString_FromStringAndSize((const char *)digest, sizeof(digest)); +} + +static PyMethodDef zsyncMethods[] = { + {"rsum06", zsync_rsum06, METH_VARARGS, "Calculate a zsync rsum value."}, + {NULL, NULL, 0, NULL} +}; + +void initzsync() { + Py_InitModule("zsync", zsyncMethods); +} + +/* vim: set ts=4 sw=4 expandtab smarttab: */ _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu Mar 18 2010 - 01:31:58 GMT
This archive was generated by hypermail 2.2.0 : Thu Mar 18 2010 - 01:32:12 GMT