[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Make FEC build, link -- doesnt work right yet.
Update of /home/minion/cvsroot/src/minion/src
In directory moria.mit.edu:/tmp/cvs-serv6866/src
Modified Files:
_minionlib.h fec.c main.c
Log Message:
Make FEC build, link -- doesnt work right yet.
Index: _minionlib.h
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/_minionlib.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- _minionlib.h 12 Feb 2003 01:23:24 -0000 1.14
+++ _minionlib.h 7 Jul 2003 23:46:51 -0000 1.15
@@ -38,6 +38,7 @@
extern PyTypeObject mm_TLSContext_Type;
extern PyTypeObject mm_TLSSock_Type;
+extern PyTypeObject mm_FEC_Type;
/**
* Macros to declare function prototypes with the proper signatures for Python.
@@ -53,7 +54,6 @@
METH_VARARGS|METH_KEYWORDS, \
(char*)obj##_##name##__doc__ }
-
/* Functions from crypt.c */
FUNC_DOC(mm_sha1);
FUNC_DOC(mm_sha1);
@@ -74,6 +74,11 @@
extern PyObject *mm_CryptoError;
extern char mm_CryptoError__doc__[];
+/* From fec.c */
+FUNC_DOC(mm_FEC_generate);
+extern PyTypeObject mm_FEC_Type;
+extern PyObject *mm_FECError;
+extern char mm_FECError__doc__[];
/* From tls.c */
extern PyTypeObject mm_TLSSock_Type;
Index: fec.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/fec.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fec.c 7 Jul 2003 22:20:15 -0000 1.2
+++ fec.c 7 Jul 2003 23:46:51 -0000 1.3
@@ -3,6 +3,7 @@
/* $Id$ */
#include <Python.h>
+#include "_minionlib.h"
/* ======= ORIGINAL CODE BY LUIGI RIZZO, TUNED AND TWEAKED ======= */
@@ -791,12 +792,14 @@
/* **************** */
+const char mm_FEC_generate__doc__[] = "DOCDOC";
+
PyObject *
mm_FEC_generate(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "k", "n", NULL };
int k, n;
- PyObject *output;
+ mm_FEC *output;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"ii:FEC_generate", kwlist,
@@ -808,7 +811,7 @@
return NULL;
}
- if (!(output=PyObject_NEW(mm_FEC, &mm_FEC_Type)))
+ if (!(output = PyObject_NEW(mm_FEC, &mm_FEC_Type)))
return NULL;
output->fec = NULL;
@@ -821,17 +824,19 @@
return NULL;
}
- return output;
+ return (PyObject*)output;
}
static void
mm_FEC_dealloc(mm_FEC *self)
{
if (self->fec)
- fec_free(p);
+ fec_free(self->fec);
PyObject_DEL(self);
}
+static const char mm_FEC_getParameters__doc__[] = "DOCDOC";
+
static PyObject*
mm_FEC_getParameters(PyObject *self, PyObject *args, PyObject *kwargs)
{
@@ -840,12 +845,12 @@
PyErr_SetString(PyExc_TypeError, "No arguments expected");
return NULL;
}
- fec = ((mm_FEC)self)->fec;
+ fec = ((mm_FEC*)self)->fec;
return Py_BuildValue("ii", fec->k, fec->n);
}
-
+static const char mm_FEC_encode__doc__[] = "DOCDOC";
static PyObject *
mm_FEC_encode(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -870,10 +875,10 @@
fec = ((mm_FEC*)self)->fec;
- /* Check whether the second arg is a sequence of N equally sized
+ /* Check whether the second arg is a sequence of K equally sized
* strings. */
if (!PySequence_Check(blocks)) {
- PyErr_SetString(mm_FECError, "encode expects a list");
+ PyErr_SetString(mm_FECError, "encode expects a sequence");
return NULL;
}
if (PySequence_Size(blocks) != fec->k) {
@@ -892,11 +897,11 @@
if (!(tup = PySequence_Tuple(blocks))) {
return NULL;
}
- if (!stringPtrs = malloc((sizeof gf*)*fec->n)) {
+ if (!(stringPtrs = malloc((sizeof(gf*))*fec->k))) {
PyErr_NoMemory();
- return NULL;
+ goto err;
}
- for (i = 0; i < fec->n; ++i) {
+ for (i = 0; i < fec->k; ++i) {
o = PyTuple_GET_ITEM(tup, i);
if (!PyString_Check(o)) {
PyErr_SetString(mm_FECError,
@@ -904,8 +909,8 @@
goto err;
}
if (sz<0)
- sz = PyString_Length(o);
- else if (sz != PyString_Length(o)) {
+ sz = PyString_Size(o);
+ else if (sz != PyString_Size(o)) {
PyErr_SetString(mm_FECError,
"encode expects a list of equally long strings");
goto err;
@@ -915,7 +920,7 @@
/* We could pull this up, but it's good to do all the checking. */
if (idx < fec->k) {
- result = PyTuple_GET_ITEM(tup, index);
+ result = PyTuple_GET_ITEM(tup, idx);
Py_INCREF(result);
Py_DECREF(tup);
free(stringPtrs);
@@ -944,19 +949,109 @@
return NULL;
}
+static const char mm_FEC_decode__doc__[] = "DOCDOC";
+
static PyObject *
mm_FEC_decode(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "blocks", NULL };
+ struct fec_parms *fec;
+ PyObject *blocks;
+ int tmp;
+ int sz = -1;
+ int i;
+ PyObject *o;
+ PyObject *tup = NULL;
+ char **stringPtrs = NULL;
+ int *indices = NULL;
+ PyObject *result = NULL;
-
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:decode", kwlist,
+ &blocks))
+ return NULL;
+
+ fec = ((mm_FEC*)self)->fec;
+
+ /* Check whether the second arg is a sequence of K equally sized
+ * strings. */
+ if (!PySequence_Check(blocks)) {
+ PyErr_SetString(mm_FECError, "decode expects a sequence");
+ return NULL;
+ }
+ if (PySequence_Size(blocks) != fec->k) {
+ PyErr_SetString(mm_FECError,
+ "encode expects a sequence of length K");
+ return NULL;
+ }
+
+ /* We hold onto the sequence as a tuple to prevent it changing
+ * out from under us, and to temporarily incref all the strings.
+ */
+ if (!(tup = PySequence_Tuple(blocks))) {
+ return NULL;
+ }
+ if (!(stringPtrs = malloc((sizeof(gf*))*fec->k))) {
+ PyErr_NoMemory();
+ goto err;
+ }
+ if (!(indices = malloc((sizeof(int))*fec->k))) {
+ PyErr_NoMemory();
+ goto err;
+ }
+ for (i = 0; i < fec->k; ++i) {
+ o = PyTuple_GET_ITEM(tup, i);
+ if (!PyArg_ParseTuple(o, "is#", &indices[i], &stringPtrs[i],
+ &tmp)) {
+ PyErr_SetString(mm_FECError,
+ "decode expects a list of index-string tuples");
+ goto err;
+ }
+ if (sz<0)
+ sz = tmp;
+ else if (sz != tmp) {
+ PyErr_SetString(mm_FECError,
+ "decode expects equally long strings");
+ goto err;
+ }
+ }
+
+ if (!(result = PyString_FromStringAndSize(NULL, sz*fec->k))) {
+ PyErr_NoMemory(); goto err;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ tmp = fec_decode(fec, (gf**) stringPtrs, (int*) indices, sz);
+ Py_END_ALLOW_THREADS
+
+ if (tmp)
+ goto err;
+
+ for (i = 0; i < fec->k; ++i) {
+ memcpy(PyString_AsString(result)+sz*i, stringPtrs[i], sz);
+ free(stringPtrs[i]);
+ }
+
+ free(stringPtrs);
+ free(indices);
+ Py_DECREF(tup);
+
+ return result;
+ err:
+ if (tup)
+ Py_DECREF(tup);
+ if (indices)
+ free(indices);
+ if (stringPtrs)
+ free(stringPtrs);
return NULL;
}
static PyMethodDef mm_FEC_methods[] = {
+ METHOD(mm_FEC, getParameters),
METHOD(mm_FEC, encode),
METHOD(mm_FEC, decode),
{ NULL, NULL }
@@ -967,6 +1062,8 @@
{
return Py_FindMethod(mm_FEC_methods, self, name);
}
+
+static const char mm_FEC_Type__doc__[] = "DOCDOC";
PyTypeObject mm_FEC_Type = {
PyObject_HEAD_INIT(/*&PyType_Type*/ 0)
Index: main.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/main.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- main.c 17 May 2003 00:08:45 -0000 1.14
+++ main.c 7 Jul 2003 23:46:51 -0000 1.15
@@ -41,6 +41,8 @@
ENTRY(generate_cert),
ENTRY(TLSContext_new),
+
+ ENTRY(FEC_generate),
{ NULL, NULL }
};
@@ -116,10 +118,13 @@
if (exc(d, &mm_TLSClosed, "mixminion._minionlib.TLSClosed",
"TLSClosed", mm_TLSClosed__doc__))
return;
+ if (exc(d, &mm_FECError, "mixminion._minionlib.FECError",
+ "FECError", mm_FECError__doc__))
+ return;
- /* We set ob_type here so that Cygwin is happy. */
+ /* We set ob_type here so that Cygwin and Win32 are happy. */
mm_RSA_Type.ob_type = mm_TLSContext_Type.ob_type =
- mm_TLSSock_Type.ob_type = &PyType_Type;
+ mm_TLSSock_Type.ob_type = mm_FEC_Type.ob_type = &PyType_Type;
Py_INCREF(&mm_RSA_Type);
if (PyDict_SetItemString(d, "RSA", (PyObject*)&mm_RSA_Type) < 0)
@@ -133,6 +138,11 @@
Py_INCREF(&mm_TLSSock_Type);
if (PyDict_SetItemString(d, "TLSSock",
(PyObject*)&mm_TLSSock_Type) < 0)
+ return;
+
+ Py_INCREF(&mm_FEC_Type);
+ if (PyDict_SetItemString(d, "FEC",
+ (PyObject*)&mm_FEC_Type) < 0)
return;
}