]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/blob - zfec/zfec/fec.h
249fe666f495f647892b73d234d769f5e77e4c77
[tahoe-lafs/zfec.git] / zfec / zfec / fec.h
1 /**
2  * zfec -- fast forward error correction library with Python interface
3  *
4  * See README.rst for documentation.
5  */
6
7 #include <stddef.h>
8
9 typedef unsigned char gf;
10
11 typedef struct {
12   unsigned long magic;
13   unsigned short k, n;                     /* parameters of the code */
14   gf* enc_matrix;
15 } fec_t;
16
17 #if defined(_MSC_VER)
18 // actually, some of the flavors (i.e. Enterprise) do support restrict
19 //#define restrict __restrict
20 #define restrict
21 #endif
22
23 /**
24  * param k the number of blocks required to reconstruct
25  * param m the total number of blocks created
26  */
27 fec_t* fec_new(unsigned short k, unsigned short m);
28 void fec_free(fec_t* p);
29
30 /**
31  * @param inpkts the "primary blocks" i.e. the chunks of the input data
32  * @param fecs buffers into which the secondary blocks will be written
33  * @param block_nums the numbers of the desired check blocks (the id >= k) which fec_encode() will produce and store into the buffers of the fecs parameter
34  * @param num_block_nums the length of the block_nums array
35  * @param sz size of a packet in bytes
36  */
37 void fec_encode(const fec_t* code, const gf*restrict const*restrict const src, gf*restrict const*restrict const fecs, const unsigned*restrict const block_nums, size_t num_block_nums, size_t sz);
38
39 /**
40  * @param inpkts an array of packets (size k); If a primary block, i, is present then it must be at index i. Secondary blocks can appear anywhere.
41  * @param outpkts an array of buffers into which the reconstructed output packets will be written (only packets which are not present in the inpkts input will be reconstructed and written to outpkts)
42  * @param index an array of the blocknums of the packets in inpkts
43  * @param sz size of a packet in bytes
44  */
45 void fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, size_t sz);
46
47 #if defined(_MSC_VER)
48 #define alloca _alloca
49 #else
50 #ifdef __GNUC__
51 #ifndef alloca
52 #define alloca(x) __builtin_alloca(x)
53 #endif
54 #else
55 #include <alloca.h>
56 #endif
57 #endif
58
59 /**
60  * zfec -- fast forward error correction library with Python interface
61  * 
62  * Copyright (C) 2007-2008 Allmydata, Inc.
63  * Author: Zooko Wilcox-O'Hearn
64  * 
65  * This file is part of zfec.
66  * 
67  * See README.rst for licensing information.
68  */
69
70 /*
71  * Much of this work is derived from the "fec" software by Luigi Rizzo, et 
72  * al., the copyright notice and licence terms of which are included below 
73  * for reference.
74  * 
75  * fec.h -- forward error correction based on Vandermonde matrices
76  * 980614
77  * (C) 1997-98 Luigi Rizzo (luigi@iet.unipi.it)
78  *
79  * Portions derived from code by Phil Karn (karn@ka9q.ampr.org),
80  * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari
81  * Thirumoorthy (harit@spectra.eng.hawaii.edu), Aug 1995
82  *
83  * Modifications by Dan Rubenstein (see Modifications.txt for 
84  * their description.
85  * Modifications (C) 1998 Dan Rubenstein (drubenst@cs.umass.edu)
86  *
87  * Redistribution and use in source and binary forms, with or without
88  * modification, are permitted provided that the following conditions
89  * are met:
90
91  * 1. Redistributions of source code must retain the above copyright
92  *    notice, this list of conditions and the following disclaimer.
93  * 2. Redistributions in binary form must reproduce the above
94  *    copyright notice, this list of conditions and the following
95  *    disclaimer in the documentation and/or other materials
96  *    provided with the distribution.
97  *
98  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
99  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
100  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
101  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
102  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
103  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
104  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
105  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
107  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
108  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
109  * OF SUCH DAMAGE.
110  */
111