ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Algorithm-FEC/README
Revision: 1.6
Committed: Thu Mar 3 16:58:00 2005 UTC (21 years, 6 months ago) by root
Branch: MAIN
Changes since 1.5: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 NAME
2 root 1.2 Algorithm::FEC - Forward Error Correction using Vandermonde Matrices
3 root 1.1
4     SYNOPSIS
5 root 1.2 use Algorithm::FEC;
6 root 1.1
7     DESCRIPTION
8     This module is an interface to the fec library by Luigi Rizzo et al.,
9     see the file README.fec in the distribution for more details.
10    
11 root 1.4 This library implements a simple ("encoded_blocks","data_blocks")
12 root 1.1 erasure code based on Vandermonde matrices. The encoder takes
13 root 1.4 "data_blocks" blocks of size "block_size" each, and is able to produce
14     up to "encoded_blocks" different encoded blocks, numbered from 0 to
15     "encoded_blocks-1", such that any subset of "data_blocks" members
16 root 1.1 permits reconstruction of the original data.
17    
18 root 1.4 Allowed values for "data_blocks" and "encoded_blocks" must obey the
19 root 1.1 following equation:
20    
21 root 1.4 data_blocks <= encoded_blocks <= MAXBLOCKS
22 root 1.1
23     Where "MAXBLOCKS=256" for the fast implementation and "MAXBLOCKS=65536"
24     for the slow implementation (the implementation is chosen
25     automatically).
26    
27 root 1.4 $fec = new data_blocks, encoded_blocks, blocksize
28     $fec->set_encode_blocks ([array_of_blocks])
29 root 1.1 Sets the data blocks used for the encoding. Each member of the array
30     can either be:
31    
32     * a string of size "blocksize" "exactly".
33     This is useful for small files (encoding entirely in memory).
34    
35     * a filehandle of a file of size "blocksize" "exactly".
36     This is useful when the amount of data is large and resides in
37     single files.
38    
39     * a reference to an array containing a filehandle and, optionally,
40     an offset into that file.
41     This is useful if the amount of data is large and resides in a
42     single file. Needless to say, all parts must not overlap and
43     must fit into the file.
44    
45     If your data is not of the required size (i.e. a multiple of
46     "blocksize" bytes), then you must pad it (e.g. with zero bytes) on
47 root 1.5 encoding (and you should truncate it after decoding). Otherwise,
48     this library croaks.
49    
50     Future versions might instead load the short segment into memory or
51     extend your scalar (this might enable nice tricks, like "$fec-"copy
52     (..., my $x)> :). Mail me if you want this to happen.
53 root 1.1
54     If called without arguments, the internal storage associated with
55     the blocks is freed again.
56    
57     $block = $fec->encode (block_index)
58 root 1.4 Creates a single encoded block of index "block_index", which must be
59     between 0 and "encoded_blocks-1" (inclusive). The blocks from 0 to
60     "data_blocks-1" are simply copies of the original data blocks.
61 root 1.1
62     The encoded block is returned as a perl scalar (so the blocks should
63     fit into memory. If this is a problem for you mail me and I'll make
64     it a file.
65    
66 root 1.4 $fec->set_decode_blocks ([array_of_blocks], [array_of_indices])
67     Prepares to decode "data_blocks" of blocks (see "set_encode_blocks"
68     for the "array_of_blocks" parameter).
69 root 1.1
70     Since these are not necessarily the original data blocks, an array
71 root 1.4 of indices (ranging from 0 to "encoded_blocks-1") must be supplied
72 root 1.1 as the second arrayref.
73    
74 root 1.4 Both arrays must have exactly "data_blocks" entries.
75 root 1.1
76 root 1.4 This method also reorders the blocks and index array in place (if
77     necessary) to reflect the order the blocks will have in the decoded
78     result.
79    
80     Both arrays must have exactly "data_blocks" entries.
81    
82     The index array represents the decoded ordering, in that the n-th
83     entry in the indices array corresponds to the n-th data block of the
84     decoded result. The value stored in the n-th place in the array will
85     contain the index of the encoded data block.
86    
87     Input blocks with indices less than "data_blocks" will be moved to
88     their final position (block k to position k), while the gaps between
89     them will be filled with check blocks. The decoding process will not
90     modify the already decoded data blocks, but will modify the check
91     blocks.
92 root 1.1
93     That is, if you call this function with "indices = [4,3,1]", with
94 root 1.4 "data_blocks = 3", then this array will be returned: "[0,2,1]". This
95     means that input block 0 corresponds to file block 0, input block 1
96     to file block 2 and input block 2 to data block 1.
97 root 1.1
98     You can just iterate over this array and write out the corresponding
99 root 1.3 data block (although this is inefficient):
100    
101 root 1.4 for my $i (0 .. $#idx)
102     if ($idx[$i] != $i) # need we move this block?
103     copy encoded block $idx[$i] to position $i
104     }
105 root 1.3 }
106 root 1.1
107 root 1.4 The "copy" method can be helpful here.
108 root 1.1
109 root 1.4 This method destroys the block array as set up by
110     "set_encode_blocks".
111    
112     $fec->shuffle ([array_of_blocks], [array_of_indices])
113     The same same as "set_decode_blocks", with the exception that the
114     blocks are not actually set for decoding.
115    
116     This method is not normally used, but if you want to move blocks
117     around after reodering and before decoding, then calling Cshuffle>
118     followed by "set_decode_blocks" incurs lower overhead than calling
119     "set_decode_blocks" twice, as files are not mmapped etc.
120    
121     $fec->decode
122     Decode the blocks set by a prior call to "set_decode_blocks".
123    
124     This method destroys the block array as set up by
125     "set_decode_blocks".
126 root 1.1
127 root 1.2 $fec->copy ($srcblock, $dstblock)
128 root 1.1 Utility function that simply copies one block (specified like in
129 root 1.4 "set_encode_blocks") into another. This, btw., destroys the blocks
130     set by "set_*_blocks".
131 root 1.1
132 root 1.5 COMPATIBILITY
133     The way this module works is compatible with the way freenet
134     (<http://freenet.sf.net>) encodes files. Comaptibility to other file
135     formats or networks is not know, please tell me if you find more
136     examples.
137 root 1.1
138     SEE ALSO
139 root 1.5 Net::FCP. And the author, who might be happy to receive mail from any
140     user, just to see that this rather rarely-used module is actually being
141     used (except for freenet ;)
142 root 1.1
143     BUGS
144 root 1.5 * too complicated.
145     * largely untested, please change this.
146     * file descriptors are not supported, but should be.
147     * utility functions for files should be provided.
148     * 16 bit version not tested
149 root 1.1
150     AUTHOR
151 root 1.6 Marc Lehmann <schmorp@schmorp.de>
152 root 1.5 http://home.schmorp.de
153 root 1.1