anon.mixminion.fec
Class FECCode

java.lang.Object
  extended by anon.mixminion.fec.FECCode
Direct Known Subclasses:
PureCode

public abstract class FECCode
extends java.lang.Object

This class provides the main API/SPI for the FEC library. You cannot construct an FECCode directly, rather you must use an FECCodeFactory. For example: int k = 32; int n = 256; FECCode code = FECCodeFactory.getDefault().createFECCode(k,n); All FEC implementations will sublcass FECCode and implement the encode/decode methods. All codes implemented by this interface are assumed to be systematic codes which means that the first k repair packets will be the same as the original source packets. (c) Copyright 2001 Onion Networks (c) Copyright 2000 OpenCola

Author:
Justin F. Chapweske (justin@chapweske.com), JAP-Team -- made some changes

Field Summary
protected  int k
           
protected  int n
           
 
Constructor Summary
protected FECCode(int k, int n)
          Construct a new FECCode given k and n
 
Method Summary
abstract  void decode(byte[][] pkts, int[] pktsOff, int[] index, int packetLength, boolean shuffled)
          This method takes an array of encoded packets and decodes them.
abstract  void encode(byte[][] src, int[] srcOff, byte[][] repair, int[] repairOff, int[] index, int packetLength)
          This method takes an array of source packets and generates a number of repair packets from them.
protected static void shuffle(byte[][] pkts, int[] pktsOff, int[] index, int k)
          shuffle move src packets in their position
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

k

protected int k

n

protected int n
Constructor Detail

FECCode

protected FECCode(int k,
                  int n)
Construct a new FECCode given k and n

Parameters:
k - The number of source packets to be encoded/decoded.
n - The number of packets that the source packets will be encoded to.
Method Detail

encode

public abstract void encode(byte[][] src,
                            int[] srcOff,
                            byte[][] repair,
                            int[] repairOff,
                            int[] index,
                            int packetLength)
This method takes an array of source packets and generates a number of repair packets from them. This method could have taken in only one repair packet to be generated, but in many cases it is more efficient (and convenient) to encode multiple packets at once. This is especially true of the NativeCode implementation where data must be copied and the Java->Native->Java transition is expensive.

Parameters:
src - An array of k byte[]'s that contain the source packets to be encoded. Often these byte[]'s are actually references to a single byte[] that contains the entire source block, then you must simply vary the srcOff's to pass it in in this fashion. src[0] will point to the 1st packet, src[1] to the second, etc.
srcOff - An array of integers which specifies the offset of each each packet within its associated byte[].
repair - Much like src, variable points to a number of buffers to which the encoded repair packets will be written. This array should be the same length as repairOff and index.
repairOff - This is the repair analog to srcOff.
index - This int[] specifies the indexes of the packets to be encoded and written to repair. These indexes must be between 0..n (should probably be k..n, because encoding < k is a NOP)
packetLength - the packetLength in bytes. All of the buffers in src and repair are assumed to be this long.

decode

public abstract void decode(byte[][] pkts,
                            int[] pktsOff,
                            int[] index,
                            int packetLength,
                            boolean shuffled)
This method takes an array of encoded packets and decodes them. Before the packets are decoded, they are shuffled so that packets that are original source packets (index < k) are positioned so that their index within the byte[][] is the same as their packet index. If the shuffled flag is set to true then it is assumed that the packets are already in the proper order. If not then they will have the references of the byte[]'s shuffled within the byte[][]. No data will be copied, only references swapped. This means that if the byte[][] is wrapping an underlying byte[] then the shuffling proceedure may bring the byte[][] out of sync with the underlying data structure. From an SPI perspective this means that the implementation is expected to follow the exact same behavior as the shuffle() method in this class which means that you should simply call shuffle() if the flag is false.

Parameters:
pkts - An array of k byte[]'s that contain the repair packets to be decoded. The decoding proceedure will copy the decoded data into the byte[]'s that are provided and will place them in order within the byte[][]. If the byte[][] is already properly shuffled then the byte[]'s will not be moved around in the byte[][].
pktsOff - An array of integers which specifies the offset of each each packet within its associated byte[].
index - This int[] specifies the indexes of the packets to be decoded. These indexes must be between 0..n
packetLength - the packetLength in bytes. All of the buffers in pkts are assumed to be this long.

shuffle

protected static final void shuffle(byte[][] pkts,
                                    int[] pktsOff,
                                    int[] index,
                                    int k)
shuffle move src packets in their position