Moved all configuration property names to StackProperties

This commit is contained in:
emcho 2010-04-25 14:43:56 +00:00
parent 4f61eabce2
commit c43f1f84d1
9 changed files with 124 additions and 48 deletions

View File

@ -12,6 +12,7 @@ import java.util.logging.*;
/** /**
* The class contains a number of property names and their default values that * The class contains a number of property names and their default values that
* we use to configure the behavior of the ice4j stack. * we use to configure the behavior of the ice4j stack.
*
* @author Emil Ivov * @author Emil Ivov
*/ */
public class StackProperties public class StackProperties
@ -27,8 +28,7 @@ public class StackProperties
* should execute in case a port is already bound to (each retry would be on * should execute in case a port is already bound to (each retry would be on
* a new random port). * a new random port).
*/ */
public static final String BIND_RETRIES_PROPERTY_NAME public static final String BIND_RETRIES = "org.ice4j.BIND_RETRIES";
= "org.ice4j.BIND_RETRIES";
/** /**
* The default number of binds that we would try * The default number of binds that we would try
@ -37,6 +37,60 @@ public class StackProperties
*/ */
public static final int BIND_RETRIES_DEFAULT_VALUE = 50; public static final int BIND_RETRIES_DEFAULT_VALUE = 50;
/**
* The number of milliseconds a client transaction should wait before
* retransmitting, after it has sent a request for the first time.
*/
public static final String FIRST_CTRAN_RETRANS_AFTER
= "org.ice4j.FIRST_CTRAN_RETRANS_AFTER";
/**
* The maximum number of milliseconds that an exponential client
* retransmission timer can reach.
*/
public static final String MAX_CTRAN_RETRANS_TIMER
= "org.ice4j.MAX_CTRAN_RETRANS_TIMER";
/**
* Indicates whether a client transaction should be kept after a response
* is received rather than destroying it which is the default.
*/
public static final String KEEP_CRANS_AFTER_A_RESPONSE
= "org.ice4j.KEEP_CRANS_AFTER_A_RESPONSE";
/**
* The maximum number of retransmissions a client transaction should send.
*/
public static final String MAX_CTRAN_RETRANSMISSIONS
= "org.ice4j.MAX_RETRANSMISSIONS";
/**
* The name of the System property that allows us to set a custom maximum
* for check list sizes.
*/
public static final String MAX_CHECK_LIST_SIZE
= "org.ice4j.MAX_CHECK_LIST_SIZE";
/**
* The value of the SOFTWARE attribute that ice4j should include in all
* outgoing messages.
*/
public static final String SOFTWARE = "org.ice4j.SOFTWARE";
/**
* The name of the property that tells the stack whether or not it should
* let the application see retransmissions of incoming requests.
*/
public static final String PROPAGATE_RECEIVED_RETRANSMISSIONS
= "org.ice4j.PROPAGATE_RECEIVED_RETRANSMISSIONS";
/**
* A property that allows us to specify whether we would expect link local
* IPv6 addresses to be able to reach globally routable ones.
*/
public static final String ALLOW_LINK_TO_GLOBAL_REACHABILITY
= "org.ice4j.ALLOW_LINK_TO_GLOBAL_REACHABILITY";
/** /**
* Returns the String value of the specified property (minus all * Returns the String value of the specified property (minus all
* encompassing whitespaces)and null in case no property value was mapped * encompassing whitespaces)and null in case no property value was mapped

View File

@ -24,13 +24,6 @@ public class TransportAddress
*/ */
private static final long serialVersionUID = 5076001401234631237L; private static final long serialVersionUID = 5076001401234631237L;
/**
* A property that allows us to specify whether we would expect link local
* IPv6 addresses to be able to reach globally routable ones.
*/
public static final String PNAME_ALLOW_LINK_TO_GLOBAL_REACHABILITY
= "org.ice4j.ALLOW_LINK_TO_GLOBAL_REACHABILITY";
/** /**
* The variable that we are using to store the transport that this address * The variable that we are using to store the transport that this address
* is pertaining to. * is pertaining to.
@ -260,12 +253,17 @@ public class TransportAddress
//trying to reach a distant global address through one of our //trying to reach a distant global address through one of our
//own. Therefore we would return false here by default. //own. Therefore we would return false here by default.
if(Boolean.getBoolean(PNAME_ALLOW_LINK_TO_GLOBAL_REACHABILITY)) if(Boolean.getBoolean(
StackProperties.ALLOW_LINK_TO_GLOBAL_REACHABILITY))
{
return true; return true;
}
else else
{
return false; return false;
} }
} }
}
//may add more unreachability condition here in the future; //may add more unreachability condition here in the future;

View File

@ -37,13 +37,6 @@ public class Agent
private static final Logger logger private static final Logger logger
= Logger.getLogger(Agent.class.getName()); = Logger.getLogger(Agent.class.getName());
/**
* The name of the System property that allows us to set a custom maximum
* for check list sizes.
*/
public static final String PNAME_MAX_CHECK_LIST_SIZE
= "org.ice4j.MAX_CHECK_LIST_SIZE";
/** /**
* The default maximum size for check lists. * The default maximum size for check lists.
*/ */
@ -267,7 +260,8 @@ public class Agent
//init the maximum number of check list entries per stream. //init the maximum number of check list entries per stream.
int maxCheckListSize = Integer.getInteger( int maxCheckListSize = Integer.getInteger(
PNAME_MAX_CHECK_LIST_SIZE, DEFAULT_MAX_CHECK_LIST_SIZE); StackProperties.MAX_CHECK_LIST_SIZE,
DEFAULT_MAX_CHECK_LIST_SIZE);
int maxPerStreamSize = maxCheckListSize / streams.size(); int maxPerStreamSize = maxCheckListSize / streams.size();

View File

@ -192,7 +192,7 @@ public class HostCandidateHarvester
} }
int bindRetries = StackProperties.getInt( int bindRetries = StackProperties.getInt(
StackProperties.BIND_RETRIES_PROPERTY_NAME, StackProperties.BIND_RETRIES,
StackProperties.BIND_RETRIES_DEFAULT_VALUE); StackProperties.BIND_RETRIES_DEFAULT_VALUE);
int port = preferredPort; int port = preferredPort;

View File

@ -78,8 +78,8 @@ public class StunCandidateHarvester
this.stunServer = stunServer; this.stunServer = stunServer;
//these should be configurable. //these should be configurable.
System.setProperty("org.ice4j.MAX_WAIT_INTERVAL", "400"); System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "400");
System.setProperty("org.ice4j.MAX_RETRANSMISSIONS", "2"); System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "2");
} }
/** /**

View File

@ -89,10 +89,10 @@ public abstract class Message
public static final byte TRANSACTION_ID_LENGTH = 12; public static final byte TRANSACTION_ID_LENGTH = 12;
/** /**
* The list of attributes contained by the message. We are using a hastable * The list of attributes contained by the message. We are using a Map
* rather than a uni-dimensional list, in order to facilitate attribute * rather than a uni-dimensional list, in order to facilitate attribute
* search (even though it introduces some redundancies). Order is important * search (even though it introduces some redundancies). Order is important
* so we'll be using a LinkedHashMap * so we'll be using a <tt>LinkedHashMap</tt>
*/ */
//not sure this is the best solution but I'm trying to keep entry order //not sure this is the best solution but I'm trying to keep entry order
protected LinkedHashMap<Character, Attribute> attributes protected LinkedHashMap<Character, Attribute> attributes
@ -303,28 +303,21 @@ public abstract class Message
return attributes.get(new Character(attributeType)); return attributes.get(new Character(attributeType));
} }
/*
* Returns an enumeration containing all message attributes.
* @return an enumeration containing all message attributes..
*/
/*
public Iterator getAttributes()
{
return attributes.entrySet().iterator();
}
*/
/** /**
* Removes the specified attribute. * Removes the specified attribute.
*
* @param attributeType the attribute to remove. * @param attributeType the attribute to remove.
*
* @return the <tt>Attribute</tt> we've just removed.
*/ */
public void removeAttribute(char attributeType) public Attribute removeAttribute(char attributeType)
{ {
attributes.remove(new Character(attributeType)); return attributes.remove(new Character(attributeType));
} }
/** /**
* Returns the number of attributes, currently contained by the message. * Returns the number of attributes, currently contained by the message.
*
* @return the number of attributes, currently contained by the message. * @return the number of attributes, currently contained by the message.
*/ */
public int getAttributeCount() public int getAttributeCount()
@ -339,6 +332,7 @@ public abstract class Message
* as it should not permit changing the type of message once it has been * as it should not permit changing the type of message once it has been
* initialized (could provoke attribute discrepancies). Called by * initialized (could provoke attribute discrepancies). Called by
* messageFactory. * messageFactory.
*
* @param messageType the message type. * @param messageType the message type.
*/ */
protected void setMessageType(char messageType) protected void setMessageType(char messageType)
@ -348,6 +342,7 @@ public abstract class Message
/** /**
* The message type of this message. * The message type of this message.
*
* @return the message type of the message. * @return the message type of the message.
*/ */
public char getMessageType() public char getMessageType()
@ -357,7 +352,9 @@ public abstract class Message
/** /**
* Copies the specified tranID and sets it as this message's transactionID. * Copies the specified tranID and sets it as this message's transactionID.
*
* @param tranID the transaction id to set in this message. * @param tranID the transaction id to set in this message.
*
* @throws StunException ILLEGAL_ARGUMENT if the transaction id is not valid. * @throws StunException ILLEGAL_ARGUMENT if the transaction id is not valid.
*/ */
public void setTransactionID(byte[] tranID) public void setTransactionID(byte[] tranID)
@ -375,6 +372,7 @@ public abstract class Message
/** /**
* Returns a reference to this message's transaction id. * Returns a reference to this message's transaction id.
*
* @return a reference to this message's transaction id. * @return a reference to this message's transaction id.
*/ */
public byte[] getTransactionID() public byte[] getTransactionID()
@ -384,7 +382,9 @@ public abstract class Message
/** /**
* Returns whether an attribute could be present in this message. * Returns whether an attribute could be present in this message.
*
* @param attributeType the id of the attribute to check . * @param attributeType the id of the attribute to check .
*
* @return Message.N_A - for not applicable <br/> * @return Message.N_A - for not applicable <br/>
* Message.C - for case depending <br/> * Message.C - for case depending <br/>
* Message.N_A - for not applicable <br/> * Message.N_A - for not applicable <br/>
@ -451,6 +451,7 @@ public abstract class Message
* Returns the human readable name of this message. Message names do * Returns the human readable name of this message. Message names do
* not really matter from the protocol point of view. They are only used * not really matter from the protocol point of view. They are only used
* for debugging and readability. * for debugging and readability.
*
* @return this message's name. * @return this message's name.
*/ */
public String getName() public String getName()
@ -473,6 +474,7 @@ public abstract class Message
* type, length, and all their attributes are equal. * type, length, and all their attributes are equal.
* *
* @param obj the object to compare this message with. * @param obj the object to compare this message with.
*
* @return true if the messages are equal and false otherwise. * @return true if the messages are equal and false otherwise.
*/ */
public boolean equals(Object obj) public boolean equals(Object obj)
@ -504,12 +506,16 @@ public abstract class Message
* Returns a binary representation of this message. * Returns a binary representation of this message.
* *
* @return a binary representation of this message. * @return a binary representation of this message.
*
* @throws IllegalStateException if the message does not have all * @throws IllegalStateException if the message does not have all
* required attributes. * required attributes.
*/ */
public byte[] encode() public byte[] encode()
throws IllegalStateException throws IllegalStateException
{ {
prepareForEncoding();
//make sure that
//make sure we have everything necessary to encode a proper message //make sure we have everything necessary to encode a proper message
validateAttributePresentity(); validateAttributePresentity();
char dataLength = getDataLength(); char dataLength = getDataLength();
@ -554,6 +560,32 @@ public abstract class Message
return binMsg; return binMsg;
} }
/**
* Adds attributes that have been requested vis configuration properties.
* Asserts attribute order where necessary.
*/
private void prepareForEncoding()
{
//remove MESSAGE-INTEGRITY and FINGERPRINT attributes so that we can
//make sure they are added at the end.
Attribute msgIntegrity = removeAttribute(Attribute.MESSAGE_INTEGRITY);
Attribute fingerprint = removeAttribute(Attribute.FINGERPRINT);
//add a SOFTWARE attribute if the user said so, and unless they did it
//themselves.
String software = System.getProperty(StackProperties.SOFTWARE);
if (getAttribute(Attribute.SOFTWARE) == null
&& software != null)
{
addAttribute(AttributeFactory
.createSoftwareAttribute(software.getBytes()));
}
//if ( getAttribute(Attribute.SOFTWARE) != null )
}
/** /**
* Constructs a message from its binary representation. * Constructs a message from its binary representation.
* @param binMessage the binary array that contains the encoded message * @param binMessage the binary array that contains the encoded message

View File

@ -221,7 +221,7 @@ class Connector
@Override @Override
public String toString() public String toString()
{ {
return "org.ice4j.stack.AccessPoint@" return "ice4j.Connector@"
+ listenAddress + listenAddress
+" status: " +" status: "
+ (isRunning? "not":"") + (isRunning? "not":"")

View File

@ -312,7 +312,7 @@ class StunClientTransaction
void handleResponse(StunMessageEvent evt) void handleResponse(StunMessageEvent evt)
{ {
String keepTran = System.getProperty( String keepTran = System.getProperty(
"org.ice4j.KEEP_CLIENT_TRANS_AFTER_A_RESPONSE"); StackProperties.KEEP_CRANS_AFTER_A_RESPONSE);
if( keepTran == null || !keepTran.trim().equalsIgnoreCase("true")) if( keepTran == null || !keepTran.trim().equalsIgnoreCase("true"))
this.cancel(); this.cancel();
@ -337,8 +337,8 @@ class StunClientTransaction
private void initTransactionConfiguration() private void initTransactionConfiguration()
{ {
//Max Retransmissions //Max Retransmissions
String maxRetransmissionsStr = String maxRetransmissionsStr
System.getProperty("org.ice4j.MAX_RETRANSMISSIONS"); = System.getProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS);
if(maxRetransmissionsStr != null if(maxRetransmissionsStr != null
&& maxRetransmissionsStr.trim().length() > 0){ && maxRetransmissionsStr.trim().length() > 0){
@ -356,8 +356,8 @@ class StunClientTransaction
} }
//Original Wait Interval //Original Wait Interval
String originalWaitIntervalStr = String originalWaitIntervalStr
System.getProperty("org.ice4j.ORIGINAL_WAIT_INTERVAL"); = System.getProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER);
if(originalWaitIntervalStr != null if(originalWaitIntervalStr != null
&& originalWaitIntervalStr.trim().length() > 0){ && originalWaitIntervalStr.trim().length() > 0){
@ -376,8 +376,8 @@ class StunClientTransaction
} }
//Max Wait Interval //Max Wait Interval
String maxWaitIntervalStr = String maxWaitIntervalStr
System.getProperty("org.ice4j.MAX_WAIT_INTERVAL"); = System.getProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER);
if(maxWaitIntervalStr != null if(maxWaitIntervalStr != null
&& maxWaitIntervalStr.trim().length() > 0){ && maxWaitIntervalStr.trim().length() > 0){

View File

@ -400,10 +400,8 @@ public class StunStack
"Failed to retransmit a stun response", ex); "Failed to retransmit a stun response", ex);
} }
String propagate = System.getProperty( if(Boolean.getBoolean(
"org.ice4j.PROPAGATE_RECEIVED_RETRANSMISSIONS"); StackProperties.PROPAGATE_RECEIVED_RETRANSMISSIONS))
if(propagate == null
|| !propagate.trim().equalsIgnoreCase("true"))
{ {
return; return;
} }