Class Serverinfo

java.lang.Object
  extended by Serverinfo

public final class Serverinfo
extends java.lang.Object

This class stores an IP address and port number. This class is used as a data member of class Fc3tuple to define the contact information for a feralcore node. Serverinfo has its own custom serialization member function. It sometimes has to add padding when serializing. This is done deterministically. This achieves the following. It is possible to compare two serialized Serverinfo objects for equality using Arrays.equals().


Field Summary
static Serverinfo EMPTYADDR
           
 
Constructor Summary
Serverinfo(Addrenum addre, java.lang.String instr, Reg16 port)
          Constructs a new Serverinfo object.
 
Method Summary
static Serverinfdres deserialize(ByteArray data)
          Factory method that deserializes the input data and returns the resulting object to the caller.
 boolean equals(java.lang.Object o)
          Returns true if and only if this matches the Serverinfo object that is passed in within the input parameter o.
static Serverinfo genrandomserverinfo(YYrandom yyrandomobj)
          Factory method that returns a Serverinfo object containing randomly generated data members with the exception of the domain name.
 Addrenum getaddrtype()
          Returns the address enumeration type Addrenum of the address in this.
 java.net.InetAddress getinetaddress()
          Returns an InetAddress object corresponding to the stored Internet address.
 Reg16 getport()
          Returns the port number as a reference to an immutable Reg16 object.
 int hashCode()
          Returns a hashcode computed on a serialized object of this.
 ByteArray serialize()
          Returns the data members of this serialized into a byte array.
static int serializedlength()
          Returns the length in bytes of this when it is serialized.
 java.lang.String toString()
          Returns a printable string that displays the data members in this.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTYADDR

public static final Serverinfo EMPTYADDR
Constructor Detail

Serverinfo

public Serverinfo(Addrenum addre,
                  java.lang.String instr,
                  Reg16 port)
           throws FeralcoreException,
                  java.io.UnsupportedEncodingException,
                  java.net.UnknownHostException
Constructs a new Serverinfo object.

Parameters:
addre - Defines whether the object is of type: domain name, IPv4 address, or IPv6 address. These are denoted using Addrenum names DOMAINNAME, IPV4, IPV6, respectively. This field tells the constructor what to expect as input in instr.
instr - Must be either a domain name, IPv4 address, or IPv6 address. The domain name is converted using InetAddress.getByName(java.lang.String), the latter two are converted to addresses using InetAddress.getByAddress(java.lang.String, byte[]).
port - The port number. This port must lie between Feralcoreconstants.MIN_PORTNUM and Feralcoreconstants.MAX_PORTNUM, inclusive. Otherwise, an exception is thrown.
Throws:
FeralcoreException
java.io.UnsupportedEncodingException
java.net.UnknownHostException
Method Detail

getport

public Reg16 getport()
              throws FeralcoreException
Returns the port number as a reference to an immutable Reg16 object.

Throws:
FeralcoreException

getinetaddress

public java.net.InetAddress getinetaddress()
                                    throws FeralcoreException,
                                           java.net.UnknownHostException,
                                           java.io.UnsupportedEncodingException
Returns an InetAddress object corresponding to the stored Internet address. If no address is stored internally then an exception is thrown.

Throws:
FeralcoreException
java.net.UnknownHostException
java.io.UnsupportedEncodingException

equals

public boolean equals(java.lang.Object o)
Returns true if and only if this matches the Serverinfo object that is passed in within the input parameter o.

Overrides:
equals in class java.lang.Object
Parameters:
o - The Serverinfo object that gets compared.

hashCode

public int hashCode()
Returns a hashcode computed on a serialized object of this.

Overrides:
hashCode in class java.lang.Object

serialize

public ByteArray serialize()
Returns the data members of this serialized into a byte array. The format of serialized data is: TYPE || ADDR || PORT. TYPE is a single byte defining how the address in addr is represented. If type = 0 then addr is a domain name, if type = 1 then addr is an IPv4 address, if type = 2 then addr is an IPv6 address. ADDR is a 64 byte field. If ADDR is a domain name then the 1st byte is the length of the domain name represented in ASCII. The domain name immediately follows. 0x00 octets of padding come after to make it a 64 byte field. If ADDR is an IPv4 address then the first 4 bytes of ADDR is the address and the rest are 0x00 bytes. If ADDR is an IPv6 address then the first 16 bytes of ADDR is the address and the rest are 0x00 byets. PORT is a 2 byte field representing the port number.


getaddrtype

public Addrenum getaddrtype()
Returns the address enumeration type Addrenum of the address in this.


serializedlength

public static int serializedlength()
Returns the length in bytes of this when it is serialized. Since Serverinfo always serializes to a fixed length byte array, a fixed value is always returned.


deserialize

public static Serverinfdres deserialize(ByteArray data)
                                 throws FeralcoreException,
                                        java.lang.CloneNotSupportedException
Factory method that deserializes the input data and returns the resulting object to the caller. If deserialization fails then null is returned.

Parameters:
data - The byte array that encodes an object of type Serverinfo.
Throws:
FeralcoreException
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Returns a printable string that displays the data members in this.

Overrides:
toString in class java.lang.Object

genrandomserverinfo

public static Serverinfo genrandomserverinfo(YYrandom yyrandomobj)
                                      throws FeralcoreException,
                                             java.io.FileNotFoundException,
                                             java.io.IOException
Factory method that returns a Serverinfo object containing randomly generated data members with the exception of the domain name. It will never return an object with the domain name defined internally.

Parameters:
yyrandomobj - An instance of YYrandom used to generate the random data members.
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException