From 1dc41efb1e93a825ce260f66cd9b4110deed7451 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Tue, 6 Sep 2016 14:18:19 -0500 Subject: [PATCH] feat: Adds an optional prefix to the local ufrag. --- src/main/java/org/ice4j/ice/Agent.java | 36 +++++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 84f2f8d..613dd63 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -309,7 +309,17 @@ public class Agent */ public Agent() { - this(Level.INFO); + this(Level.INFO, null); + } + + /** + * Creates an empty Agent with no streams, and no address. + * @param ufragPrefix an optional prefix to the generated local ICE username + * fragment. + */ + public Agent(String ufragPrefix) + { + this(Level.INFO, ufragPrefix); } /** @@ -318,6 +328,18 @@ public class Agent * its components. */ public Agent(Level loggingLevel) + { + this(loggingLevel, null); + } + + /** + * Creates an empty Agent with no streams, and no address. + * @param loggingLevel the logging level to be used by the agent and all of + * its components. + * @param ufragPrefix an optional prefix to the generated local ICE username + * fragment. + */ + public Agent(Level loggingLevel, String ufragPrefix) { logger = new Logger(classLogger, loggingLevel); SecureRandom random = new SecureRandom(); @@ -332,12 +354,12 @@ public class Agent if (StackProperties.getString(StackProperties.SOFTWARE) == null) System.setProperty(StackProperties.SOFTWARE, "ice4j.org"); - ufrag - = ensureIceAttributeLength( - new BigInteger(24, random).toString(32) - + BigInteger.valueOf( - System.currentTimeMillis()).toString(32), - /* min */ 4, /* max */ 256); + String ufrag = ufragPrefix == null ? "" : ufragPrefix; + ufrag += new BigInteger(24, random).toString(32); + ufrag += BigInteger.valueOf(System.currentTimeMillis()).toString(32); + ufrag = ensureIceAttributeLength(ufrag, /* min */ 4, /* max */ 256); + this.ufrag = ufrag; + password = ensureIceAttributeLength( new BigInteger(128, random).toString(32),