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
* we use to configure the behavior of the ice4j stack.
*
* @author Emil Ivov
*/
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
* a new random port).
*/
public static final String BIND_RETRIES_PROPERTY_NAME
= "org.ice4j.BIND_RETRIES";
public static final String BIND_RETRIES = "org.ice4j.BIND_RETRIES";
/**
* 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;
/**
* 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
* 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;
/**
* 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
* is pertaining to.
@ -260,10 +253,15 @@ public class TransportAddress
//trying to reach a distant global address through one of our
//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;
}
else
{
return false;
}
}
}

View File

@ -37,13 +37,6 @@ public class Agent
private static final Logger logger
= 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.
*/
@ -267,7 +260,8 @@ public class Agent
//init the maximum number of check list entries per stream.
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();

View File

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

View File

@ -78,8 +78,8 @@ public class StunCandidateHarvester
this.stunServer = stunServer;
//these should be configurable.
System.setProperty("org.ice4j.MAX_WAIT_INTERVAL", "400");
System.setProperty("org.ice4j.MAX_RETRANSMISSIONS", "2");
System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "400");
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;
/**
* 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
* 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
protected LinkedHashMap<Character, Attribute> attributes
@ -303,28 +303,21 @@ public abstract class Message
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.
*
* @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.
*
* @return the number of attributes, currently contained by the message.
*/
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
* initialized (could provoke attribute discrepancies). Called by
* messageFactory.
*
* @param messageType the message type.
*/
protected void setMessageType(char messageType)
@ -348,6 +342,7 @@ public abstract class Message
/**
* The message type of this message.
*
* @return the message type of the message.
*/
public char getMessageType()
@ -357,7 +352,9 @@ public abstract class Message
/**
* Copies the specified tranID and sets it as this message's transactionID.
*
* @param tranID the transaction id to set in this message.
*
* @throws StunException ILLEGAL_ARGUMENT if the transaction id is not valid.
*/
public void setTransactionID(byte[] tranID)
@ -375,6 +372,7 @@ public abstract class Message
/**
* Returns a reference to this message's transaction id.
*
* @return a reference to this message's transaction id.
*/
public byte[] getTransactionID()
@ -384,7 +382,9 @@ public abstract class Message
/**
* Returns whether an attribute could be present in this message.
*
* @param attributeType the id of the attribute to check .
*
* @return Message.N_A - for not applicable <br/>
* Message.C - for case depending <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
* not really matter from the protocol point of view. They are only used
* for debugging and readability.
*
* @return this message's name.
*/
public String getName()
@ -473,6 +474,7 @@ public abstract class Message
* type, length, and all their attributes are equal.
*
* @param obj the object to compare this message with.
*
* @return true if the messages are equal and false otherwise.
*/
public boolean equals(Object obj)
@ -504,12 +506,16 @@ public abstract class Message
* Returns a binary representation of this message.
*
* @return a binary representation of this message.
*
* @throws IllegalStateException if the message does not have all
* required attributes.
*/
public byte[] encode()
throws IllegalStateException
{
prepareForEncoding();
//make sure that
//make sure we have everything necessary to encode a proper message
validateAttributePresentity();
char dataLength = getDataLength();
@ -554,6 +560,32 @@ public abstract class Message
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.
* @param binMessage the binary array that contains the encoded message

View File

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

View File

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

View File

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