* the encoding matrix.
*/
fec_t *
-fec_new (int k, int n) {
- int row, col;
+fec_new (unsigned char k, unsigned char n) {
+ unsigned char row, col;
gf *p, *tmp_m;
fec_t *retval;
if (fec_initialized == 0)
init_fec ();
- if (k < 1 || k > 256 || n > 256 || k > n) {
- ERR("Invalid parameters k %d n %d GF_SIZE %d", k, n, 255);
- return NULL;
- }
retval = (fec_t *) my_malloc (sizeof (fec_t), "new_code");
retval->k = k;
retval->n = n;
* @param matrix a space allocated for a k by k matrix
*/
void
-build_decode_matrix_into_space(const fec_t*restrict const code, const int*const restrict index, const int k, gf*restrict const matrix) {
+build_decode_matrix_into_space(const fec_t*restrict const code, const unsigned char*const restrict index, const unsigned char k, gf*restrict const matrix) {
unsigned i;
gf* p;
for (i=0, p=matrix; i < k; i++, p += k) {
}
void
-fec_decode_all(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, unsigned sz) {
+fec_decode_all(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned char*restrict const index, size_t sz) {
gf m_dec[code->k * code->k];
build_decode_matrix_into_space(code, index, code->k, m_dec);
} fec_t;
void fec_free (fec_t *p);
-fec_t *fec_new (int k, int n);
+fec_t *fec_new (unsigned char k, unsigned char n);
/**
* @param inpkts the "primary shares" i.e. the chunks of the input data
* @param index an array of the shareids of the packets in inpkts
* @param sz size of a packet in bytes
*/
-void fec_decode_all(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, unsigned sz);
+void fec_decode_all(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned char*restrict const index, size_t sz);
/* end of file */
return NULL;
const gf*restrict cshares[self->kk];
- unsigned csharenums[self->kk];
+ unsigned char csharenums[self->kk];
gf*restrict recoveredcstrs[self->kk]; /* self->kk is actually an upper bound -- we probably won't need all of this space. */
PyObject*restrict recoveredpystrs[self->kk]; /* self->kk is actually an upper bound -- we probably won't need all of this space. */
unsigned i;
for (i=0; i<self->kk; i++) {
if (!PyInt_Check(fastsharenumsitems[i]))
goto err;
- csharenums[i] = PyInt_AsLong(fastsharenumsitems[i]);
+ long tmpl = PyInt_AsLong(fastsharenumsitems[i]);
+ if (tmpl < 0 || tmpl >= UCHAR_MAX) {
+ py_raise_fec_error("Precondition violation: Share ids can't be less than zero or greater than 255. %ld\n", tmpl);
+ goto err;
+ }
+ csharenums[i] = (unsigned char)tmpl;
if (csharenums[i] >= self->kk)
needtorecover+=1;
nums = [ x[0] for x in nums_and_shares ]
# sys.stdout.write("about to construct Decoder.\n") ; sys.stdout.flush()
decer = fec.Decoder(k, m)
- # sys.stdout.write("about to decode.\n") ; sys.stdout.flush()
+ # sys.stdout.write("about to decode from %s.\n"%nums) ; sys.stdout.flush()
decoded = decer.decode(shares, nums)
# sys.stdout.write("decoded.\n") ; sys.stdout.flush()
_assert(len(decoded) == len(ss), len(decoded), len(ss))
return 0
def _test_random():
- # m = random.randrange(1, 255)
- m = 99
- # k = random.randrange(1, m+1)
- k = 33
- # l = random.randrange(0, 2**16)
- l = 2**12
+ m = random.randrange(1, 255)
+ k = random.randrange(1, m+1)
+ l = random.randrange(0, 2**16)
ss = [ randstr(l/k) + '\x00' * pad_size(l/k, k) for x in range(k) ]
_h(k, m, ss)
def test_random():
- for i in range(2**9):
+ for i in range(2**10):
sys.stdout.write(",")
_test_random()
sys.stdout.write(".")