Commit 3b0780ed authored by Dafydd Harries's avatar Dafydd Harries

add functions for calculating candidate priority

darcs-hash:20070129133026-c9803-856ad09c7a437c7ca65c3baa8fb5832e14df3030.gz
parent 2eb59b51
......@@ -24,7 +24,8 @@ check_PROGRAMS = \
test-util \
test-add-stream \
test-recv \
test-stun
test-stun \
test-priority
TESTS = $(check_PROGRAMS)
......@@ -44,5 +45,7 @@ test_recv_LDADD = $(COMMON_LDADD)
test_stun_LDADD = $(COMMON_LDADD)
test_priority_LDADD = $(COMMON_LDADD)
pkginclude_HEADERS = agent.h
......@@ -39,6 +39,57 @@ candidate_free (Candidate *candidate)
}
gfloat
candidate_jingle_priority (Candidate *candidate)
{
switch (candidate->type)
{
case CANDIDATE_TYPE_HOST: return 1.0;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_PEER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_RELAYED: return 0.5;
}
/* appease GCC */
return 0;
}
/* ICE-13 §4.1.2; returns number between 1 and 0x7effffff */
G_GNUC_CONST
guint32
_candidate_ice_priority (
// must be ∈ (0, 126) (max 2^7 - 2)
guint type_preference,
// must be ∈ (0, 65535) (max 2^16 - 1)
guint local_preference,
// must be ∈ (1, 255) (max 2 ^ 8 - 1)
guint component_id)
{
return (
0x1000000 * type_preference +
0x100 * local_preference +
(0x100 - component_id));
}
guint32
candidate_ice_priority (Candidate *candidate)
{
guint8 type_preference = 0;
switch (candidate->type)
{
case CANDIDATE_TYPE_HOST: type_preference = 120; break;
case CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break;
case CANDIDATE_TYPE_RELAYED: type_preference = 60; break;
}
return _candidate_ice_priority (type_preference, 1, candidate->component_id);
}
/*** component ***/
......@@ -153,20 +204,6 @@ enum check_list_state
};
/* ICE12 §5.2 */
guint64
candidate_priority (
guint type_preference,
guint local_preference,
guint component_id)
{
return (
0x1000000 * type_preference +
0x100 * local_preference +
(256 - component_id));
}
/* ICE12 §6.7 */
guint64
candidate_pair_priority (
......
......@@ -50,6 +50,10 @@ Candidate *
candidate_new (CandidateType type);
void
candidate_free (Candidate *candidate);
gfloat
candidate_jingle_priority (Candidate *candidate);
guint32
candidate_ice_priority (Candidate *candidate);
/*** event ***/
......
#include <arpa/inet.h>
#include <glib.h>
#include "udp.h"
#include "agent.h"
int
main (void)
{
Candidate *candidate;
candidate = candidate_new (CANDIDATE_TYPE_HOST);
g_assert (candidate_ice_priority (candidate) == 0x78000200);
g_assert (candidate_jingle_priority (candidate) == 1.0);
candidate_free (candidate);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment