Adds generation of agent-level user name and password values

This commit is contained in:
emcho 2010-02-28 09:44:06 +00:00
parent 00bf037003
commit 152eb6282b
2 changed files with 48 additions and 4 deletions

View File

@ -8,7 +8,9 @@
package org.ice4j.ice;
import java.io.*;
import java.math.*;
import java.net.*;
import java.security.*;
import java.util.*;
import java.util.logging.*;
@ -63,11 +65,25 @@ public class Agent
*/
private FoundationsRegistry foundationsRegistry = new FoundationsRegistry();
/**
* The user fragment that we should use for the ice-ufrag attribute.
*/
private final String ufrag;
/**
* The password that we should use for the ice-pwd attribute.
*/
private final String password;
/**
* Creates an empty <tt>Agent</tt> with no streams, and no address
*/
public Agent()
{
SecureRandom random = new SecureRandom();
ufrag = new BigInteger(24, random).toString(32);
password = new BigInteger(128, random).toString(32);
}
/**
@ -216,4 +232,29 @@ public class Agent
harvesters.add(harvester);
}
}
/**
* Returns that user name that should be advertised in session descriptions
* containing ICE data from this agent.
*
* @return that user name that should be advertised in session descriptions
* containing ICE data from this agent.
*/
public String getUserName()
{
return ufrag;
}
/**
* Returns that password that should be advertised in session descriptions
* containing ICE data from this agent.
*
* @return that password that should be advertised in session descriptions
* containing ICE data from this agent.
*/
public String getPassword()
{
return password;
}
}

View File

@ -32,6 +32,9 @@ public class Ice
{
Agent agent = new Agent();
System.out.println("ice-pwd:"+ agent.getPassword());
System.out.println("ice-ufrag:" + agent.getUserName() + "\n");
StunCandidateHarvester stunHarv = new StunCandidateHarvester(
new TransportAddress("sip-communicator.net", 3478, Transport.UDP));
StunCandidateHarvester stun6Harv = new StunCandidateHarvester(
@ -49,8 +52,8 @@ public class Ice
stream, Transport.UDP, 9090, 9090, 10000);
System.out.println("rtpComp:" + rtpComp);
long endTime = System.currentTimeMillis();
System.out.println("Componente created in "
+ (endTime - startTime) +" ms");
System.out.println("Component created in "
+ (endTime - startTime) +" ms\n");
startTime = endTime;
//rtcpComp
Component rtcpComp = agent.createComponent(
@ -58,8 +61,8 @@ public class Ice
System.out.println("rtcpComp:" + rtcpComp);
endTime = System.currentTimeMillis();
System.out.println("Componente created in "
+ (endTime - startTime) +" ms");
System.out.println("Component created in "
+ (endTime - startTime) +" ms\n");
}
/**