Class Fcsend

java.lang.Object
  extended by Fcsend

public final class Fcsend
extends java.lang.Object

Fcsend.java implements three types of messages, distinguished by a 16 character string near the start of the serialized message: a program transmit message, a ping, and a ping response. The ping is used to see if a remote feralcore node is currently reachable or not and results in the Fc3tuplecontainer object being updated accordingly. These strings are the toString() values of the enumeration type "fcsendeunum". Pay close attention to this class. The deserialize() function accepts potentially tainted data from the network.

See the description of the serialize() member function for the design decisions regarding serialization of this class.


Field Summary
static int FCSENDIDLENGTH
           
 
Constructor Summary
Fcsend(ByteArray ID, Fc3tuple sender, Fc3tuple rnd1, Fc3tuple rnd2, Reg32 startaddr, ByteArray datain)
          Constructs an object of type Fcsend that is used to transmit a program.
 
Method Summary
static Fcsenddres deserialize(ByteArray inarray)
          Factory method that deserializes the byte array inarray and returns an Fcsenddres object.
 boolean equals(java.lang.Object o)
           
static Fcsend fcsendping(ByteArray ID, Fc3tuple sender, Fc3tuple rnd1, Fc3tuple rnd2)
          Factory method that returns an object of type Fcsend that is a feralcore ping packet.
static Fcsend fcsendpingresponse(ByteArray ID, Fc3tuple sender, Fc3tuple rnd1, Fc3tuple rnd2)
          Factory method that returns an object of type Fcsend that is a feralcore ping response packet.
 ByteArray getdata()
          Returns a reference to the program contained in the Fcsend object when the Fcsend object is of type Fcsendenum.FCPROGSNDREQUEST.
 Fcsendenum getfcsendenumobj()
          Returns the value of the Fcsendenum object.
 ByteArray getfcsendID()
          Returns a copy of the fcsendID object.
 Fc3tuple getrnd1fc3tuple()
          Returns a copy of the rnd1fc3tuple object.
 Fc3tuple getrnd2fc3tuple()
          Returns a copy of the rnd2fc3tuple object.
 Fc3tuple getsenderfc3tuple()
          Returns a copy of the senderfc3tuple object.
 Reg32 getstartaddress()
          Returns a copy of the internal startaddress object when the Fcsend object is of type Fcsendenum.FCPROGSNDREQUEST.
 int hashCode()
           
static void main()
          Performs a series of tests on the serialization and deserialization functions.
static int minimumserializedlength()
          Returns the smallest length in bytes that an Fcsend object will serialize to.
 ByteArray serialize()
          Serializes the internal objects of this Fcsend object and returns them in a byte array.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FCSENDIDLENGTH

public static final int FCSENDIDLENGTH
See Also:
Constant Field Values
Constructor Detail

Fcsend

public Fcsend(ByteArray ID,
              Fc3tuple sender,
              Fc3tuple rnd1,
              Fc3tuple rnd2,
              Reg32 startaddr,
              ByteArray datain)
       throws java.io.UnsupportedEncodingException,
              java.lang.CloneNotSupportedException,
              FeralcoreException
Constructs an object of type Fcsend that is used to transmit a program. It is therefore an Fcsend object with type FCPROGSNDREQUEST as defined in Fcsendenum.

Throws:
java.io.UnsupportedEncodingException
java.lang.CloneNotSupportedException
FeralcoreException
Method Detail

fcsendping

public static Fcsend fcsendping(ByteArray ID,
                                Fc3tuple sender,
                                Fc3tuple rnd1,
                                Fc3tuple rnd2)
                         throws java.io.UnsupportedEncodingException,
                                java.lang.CloneNotSupportedException
Factory method that returns an object of type Fcsend that is a feralcore ping packet.

Throws:
java.io.UnsupportedEncodingException
java.lang.CloneNotSupportedException

fcsendpingresponse

public static Fcsend fcsendpingresponse(ByteArray ID,
                                        Fc3tuple sender,
                                        Fc3tuple rnd1,
                                        Fc3tuple rnd2)
                                 throws java.io.UnsupportedEncodingException,
                                        java.lang.CloneNotSupportedException
Factory method that returns an object of type Fcsend that is a feralcore ping response packet.

Throws:
java.io.UnsupportedEncodingException
java.lang.CloneNotSupportedException

minimumserializedlength

public static int minimumserializedlength()
Returns the smallest length in bytes that an Fcsend object will serialize to.


serialize

public ByteArray serialize()
Serializes the internal objects of this Fcsend object and returns them in a byte array.

In [1] Item 74 indicates that an issue with implementing Serializable is that it increases the chances of bugs and security holes. So, we don't implement Serializable. We use custom serialization.

In [1], Item 75 indicates that no matter what form of serialization is used, be sure to employ an explicit version identifier for the serializable classes that are created. This helps avoid incompatability issues as the software evolves over time. This class adheres to this by employing a serialization version number which is checked upon deserialization.

[1] Joshua Block, "Effective Java", 2nd Edition, Addison Wesley, 2008.


deserialize

public static Fcsenddres deserialize(ByteArray inarray)
                              throws FeralcoreException,
                                     java.io.UnsupportedEncodingException,
                                     java.lang.CloneNotSupportedException
Factory method that deserializes the byte array inarray and returns an Fcsenddres object. The Fcsenddres object indicates whether or not the call succeeded. When the calls succeeds the deserialized Fcsend object can be obtained using an accessor method of the returned object.

Parameters:
inarray - untrusted input byte array that supposedly encodes an Fcsend object
Throws:
FeralcoreException
java.io.UnsupportedEncodingException
java.lang.CloneNotSupportedException

getfcsendenumobj

public Fcsendenum getfcsendenumobj()
Returns the value of the Fcsendenum object. This indicates whether the Fcsend object is a program send request, feralcore ping, or feralcore ping response.


getfcsendID

public ByteArray getfcsendID()
Returns a copy of the fcsendID object.


getsenderfc3tuple

public Fc3tuple getsenderfc3tuple()
                           throws java.lang.CloneNotSupportedException
Returns a copy of the senderfc3tuple object.

Throws:
java.lang.CloneNotSupportedException

getrnd1fc3tuple

public Fc3tuple getrnd1fc3tuple()
                         throws java.lang.CloneNotSupportedException
Returns a copy of the rnd1fc3tuple object.

Throws:
java.lang.CloneNotSupportedException

getrnd2fc3tuple

public Fc3tuple getrnd2fc3tuple()
                         throws java.lang.CloneNotSupportedException
Returns a copy of the rnd2fc3tuple object.

Throws:
java.lang.CloneNotSupportedException

getstartaddress

public Reg32 getstartaddress()
Returns a copy of the internal startaddress object when the Fcsend object is of type Fcsendenum.FCPROGSNDREQUEST. If the object is not of type Fcsendenum.FCPROGSNDREQUEST then an exception is thrown. This disallows improper use of this class.


getdata

public ByteArray getdata()
Returns a reference to the program contained in the Fcsend object when the Fcsend object is of type Fcsendenum.FCPROGSNDREQUEST. If the object is not of type Fcsendenum.FCPROGSNDREQUEST then an exception is thrown. This disallows improper use of this class.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

main

public static void main()
                 throws FeralcoreException,
                        java.security.NoSuchAlgorithmException,
                        java.io.FileNotFoundException,
                        java.io.IOException,
                        java.lang.InterruptedException,
                        java.lang.CloneNotSupportedException
Performs a series of tests on the serialization and deserialization functions. This is done by performing them on randomly generated Fcsend objects.

Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException