示例#1
0
文件: debug.c 项目: AlertMe/libnice
void nice_debug_init (void)
{
  static gboolean debug_initialized = FALSE;
  const gchar *flags_string;
  const gchar *gflags_string;
  guint flags = 0;

  if (!debug_initialized) {
    debug_initialized = TRUE;

    flags_string = g_getenv ("NICE_DEBUG");
    gflags_string = g_getenv ("G_MESSAGES_DEBUG");

    if (flags_string)
      flags = g_parse_debug_string (flags_string, keys,  4);
    if (gflags_string && strstr (gflags_string, "libnice-pseudotcp-verbose"))
      flags |= NICE_DEBUG_PSEUDOTCP_VERBOSE;

    stun_set_debug_handler (stun_handler);
    nice_debug_enable (TRUE);

    /* Set verbose before normal so that if we use 'all', then only
       normal debug is enabled, we'd need to set pseudotcp-verbose without the
       pseudotcp flag in order to actually enable verbose pseudotcp */
    if (flags & NICE_DEBUG_PSEUDOTCP_VERBOSE)
      pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_VERBOSE);
    else
      pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_NORMAL);
  }
}
示例#2
0
文件: debug.c 项目: daviad/MeadTest
void nice_debug_init ()
{
//  const gchar *flags_string;
//  guint flags;

  //flags_string = g_getenv ("NICE_DEBUG");

  nice_debug_disable (TRUE);
  nice_debug_enable(TRUE);

//  if (flags_string != NULL) {
//    //flags = g_parse_debug_string (flags_string, keys,  4);
//
//    if (flags & NICE_DEBUG_NICE)
//      nice_debug_enable (FALSE);
//    if (flags & NICE_DEBUG_STUN)
//      stun_debug_enable ();
//
//    /* Set verbose before normal so that if we use 'all', then only
//       normal debug is enabled, we'd need to set pseudotcp-verbose without the
//       pseudotcp flag in order to actually enable verbose pseudotcp */
//    //if (flags & NICE_DEBUG_PSEUDOTCP_VERBOSE)
////      pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_VERBOSE);
////    if (flags & NICE_DEBUG_PSEUDOTCP)
////      pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_NORMAL);
//
//  }
}
示例#3
0
  NiceConnection::NiceConnection(MediaType med, const std::string &transport_name,NiceConnectionListener* listener, 
      unsigned int iceComponents, const IceConfig& iceConfig, std::string username, std::string password)
     : mediaType(med), agent_(NULL), listener_(listener), candsDelivered_(0), context_(NULL), iceState_(NICE_INITIAL), iceComponents_(iceComponents) {

    localCandidates.reset(new std::vector<CandidateInfo>());
    transportName.reset(new std::string(transport_name));
    for (unsigned int i = 1; i<=iceComponents_; i++) {
      comp_state_list_[i] = NICE_INITIAL;
    }
    
    g_type_init();
    context_ = g_main_context_new();
    g_main_context_set_poll_func(context_,timed_poll);
    ELOG_DEBUG("Creating Agent");
    nice_debug_enable( FALSE );
    // Create a nice agent
    agent_ = nice_agent_new(context_, NICE_COMPATIBILITY_RFC5245);
    GValue controllingMode = { 0 };
    g_value_init(&controllingMode, G_TYPE_BOOLEAN);
    g_value_set_boolean(&controllingMode, false);
    g_object_set_property(G_OBJECT( agent_ ), "controlling-mode", &controllingMode);

    GValue checks = { 0 };
    g_value_init(&checks, G_TYPE_UINT);
    g_value_set_uint(&checks, 100);
    g_object_set_property(G_OBJECT( agent_ ), "max-connectivity-checks", &checks);


    if (iceConfig.stunServer.compare("") != 0 && iceConfig.stunPort!=0){
      GValue val = { 0 }, val2 = { 0 };
      g_value_init(&val, G_TYPE_STRING);
      g_value_set_string(&val, iceConfig.stunServer.c_str());
      g_object_set_property(G_OBJECT( agent_ ), "stun-server", &val);

      g_value_init(&val2, G_TYPE_UINT);
      g_value_set_uint(&val2, iceConfig.stunPort);
      g_object_set_property(G_OBJECT( agent_ ), "stun-server-port", &val2);

      ELOG_DEBUG("Setting STUN server %s:%d", iceConfig.stunServer.c_str(), iceConfig.stunPort);
    }

    // Connect the signals
    g_signal_connect( G_OBJECT( agent_ ), "candidate-gathering-done",
        G_CALLBACK( cb_candidate_gathering_done ), this);
    g_signal_connect( G_OBJECT( agent_ ), "component-state-changed",
        G_CALLBACK( cb_component_state_changed ), this);
    g_signal_connect( G_OBJECT( agent_ ), "new-selected-pair",
        G_CALLBACK( cb_new_selected_pair ), this);
    g_signal_connect( G_OBJECT( agent_ ), "new-candidate",
        G_CALLBACK( cb_new_candidate ), this);

    // Create a new stream and start gathering candidates
    ELOG_DEBUG("Adding Stream... Number of components %d", iceComponents_);
    nice_agent_add_stream(agent_, iceComponents_);
    gchar *ufrag = NULL, *upass = NULL;
    nice_agent_get_local_credentials(agent_, 1, &ufrag, &upass);
    ufrag_ = std::string(ufrag); g_free(ufrag);
    upass_ = std::string(upass); g_free(upass);

    // Set our remote credentials.  This must be done *after* we add a stream.
    if (username.compare("")!=0 && password.compare("")!=0){
      ELOG_DEBUG("Setting remote credentials in constructor");
      this->setRemoteCredentials(username, password);
    }
    // Set Port Range ----> If this doesn't work when linking the file libnice.sym has to be modified to include this call
    if (iceConfig.minPort!=0 && iceConfig.maxPort!=0){
      ELOG_DEBUG("Setting port range: %d to %d\n", iceConfig.minPort, iceConfig.maxPort);
      nice_agent_set_port_range(agent_, (guint)1, (guint)1, (guint)iceConfig.minPort, (guint)iceConfig.maxPort);
    }

    if (iceConfig.turnServer.compare("") != 0 && iceConfig.turnPort!=0){
        ELOG_DEBUG("Setting TURN server %s:%d", iceConfig.turnServer.c_str(), iceConfig.turnPort);
        ELOG_DEBUG("Setting TURN credentials %s:%s", iceConfig.turnUsername.c_str(), iceConfig.turnPass.c_str());

        for (unsigned int i = 1; i <= iceComponents_ ; i++){
          nice_agent_set_relay_info     (agent_,
              1,
              i,
              iceConfig.turnServer.c_str(),      // TURN Server IP
              iceConfig.turnPort,    // TURN Server PORT
              iceConfig.turnUsername.c_str(),      // Username
              iceConfig.turnPass.c_str(),      // Pass
              NICE_RELAY_TYPE_TURN_UDP);
        }
    }
    
    if(agent_){
      for (unsigned int i = 1; i<=iceComponents_; i++){
        nice_agent_attach_recv(agent_, 1, i, context_, cb_nice_recv, this);
      }
      running_ = true;
    }
    else{
      running_=false;
    }
  m_Thread_ = boost::thread(&NiceConnection::init, this);
}