⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 advertising.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 3 页
字号:
static intforwardhelloHelper (const GNUNET_PeerIdentity * peer,                    unsigned short protocol, int confirmed, void *data){  int *probability = data;  GNUNET_MessageHello *hello;  GNUNET_Int32Time now;  int count;  FCC fcc;  if (GNUNET_network_monitor_get_load      (coreAPI->load_monitor, GNUNET_ND_UPLOAD) > 100)    return GNUNET_SYSERR;       /* network load too high... */  if (confirmed == GNUNET_NO)    return GNUNET_OK;  if (protocol == GNUNET_TRANSPORT_PROTOCOL_NUMBER_NAT)    return GNUNET_OK;           /* don't forward NAT addresses */  hello = identity->identity2Hello (peer, protocol, GNUNET_NO);  if (NULL == hello)    return GNUNET_OK;           /* this should not happen */  /* do not forward expired hellos */  GNUNET_get_time_int32 (&now);  if ((GNUNET_Int32Time) ntohl (hello->expiration_time) < now)    {#if DEBUG_ADVERTISING      GNUNET_EncName enc;      /* remove hellos that expired */      IF_GELOG (ectx,                GNUNET_GE_INFO | GNUNET_GE_REQUEST | GNUNET_GE_USER,                GNUNET_hash_to_enc (&peer->hashPubKey, &enc));      GNUNET_GE_LOG (ectx,                     GNUNET_GE_INFO | GNUNET_GE_REQUEST | GNUNET_GE_USER,                     "Removing HELLO from peer `%s' (expired %ds ago).\n",                     &enc, now - ntohl (hello->expiration_time));#endif      identity->delHostFromKnown (peer, protocol);      GNUNET_free (hello);      (*probability)--;      return GNUNET_OK;    }  if (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, (*probability) + 1) != 0)    {      GNUNET_free (hello);      return GNUNET_OK;         /* only forward with a certain chance,                                   (on average: 1 peer per run!) */    }  count = coreAPI->p2p_connections_iterate (NULL, NULL);  if (count > 0)    {      fcc.msg = hello;      fcc.prob = count;      coreAPI->p2p_connections_iterate (&forwardCallback, &fcc);    }  GNUNET_free (hello);  return GNUNET_OK;}/** * Forward hellos from all known hosts to all connected hosts. * We do on average 1 forwarding (by random selection of * source and target). */static voidforwardhello (void *unused){  int count;  if (GNUNET_cpu_get_load (coreAPI->ectx, coreAPI->cfg) > 100)    return;                     /* CPU load too high... */  if (GNUNET_network_monitor_get_load      (coreAPI->load_monitor, GNUNET_ND_UPLOAD) > 100)    return;                     /* network load too high... */  count = identity->forEachHost (0, NULL, NULL);  if (count > 0)    identity->forEachHost (0,   /* ignore blacklisting */                           &forwardhelloHelper, &count);}/** * Type for a hello send via an encrypted channel. */static intehelloHandler (const GNUNET_PeerIdentity * sender,               const GNUNET_MessageHeader * message){  if (GNUNET_OK == receivedhello (sender, message))    {      /* if the hello was ok, update traffic preference         for the peer (depending on how much we like         to learn about other peers) */      coreAPI->p2p_connection_preference_increase (sender,                                                   getConnectPriority ());    }  return GNUNET_OK;             /* even if we had errors processing the hello, keep going */}/** * Type for a hello send in plaintext. */static intphelloHandler (const GNUNET_PeerIdentity * sender,               const GNUNET_MessageHeader * message,               GNUNET_TSession * session){  receivedhello (sender, message);  return GNUNET_OK;}/** * The configuration has changed, update set of running cron jobs. * Does not have to suspend cron since this guaranteed to be a cron * job! */static intconfigurationUpdateCallback (void *ctx,                             struct GNUNET_GC_Configuration *cfg,                             struct GNUNET_GE_Context *ectx,                             const char *section, const char *option){  if (0 != strcmp (section, "NETWORK"))    return 0;  if (ACJ_ANNOUNCE == (activeCronJobs & ACJ_ANNOUNCE))    {      if (GNUNET_YES == GNUNET_GC_get_configuration_value_yesno (cfg,                                                                 "NETWORK",                                                                 "DISABLE-ADVERTISEMENTS",                                                                 GNUNET_NO))        GNUNET_cron_del_job (coreAPI->cron,                             &broadcasthello, HELLO_BROADCAST_FREQUENCY,                             NULL);      activeCronJobs -= ACJ_ANNOUNCE;    }  else    {      if (GNUNET_YES != GNUNET_GC_get_configuration_value_yesno (cfg,                                                                 "NETWORK",                                                                 "DISABLE-ADVERTISEMENTS",                                                                 GNUNET_NO))        GNUNET_cron_add_job (coreAPI->cron,                             &broadcasthello,                             15 * GNUNET_CRON_SECONDS,                             HELLO_BROADCAST_FREQUENCY, NULL);      activeCronJobs += ACJ_ANNOUNCE;    }  if (ACJ_FORWARD == (activeCronJobs & ACJ_FORWARD))    {      if (GNUNET_YES != GNUNET_GC_get_configuration_value_yesno (cfg,                                                                 "NETWORK",                                                                 "HELLOEXCHANGE",                                                                 GNUNET_YES))        {          GNUNET_cron_del_job (coreAPI->cron, &forwardhello, HELLO_FORWARD_FREQUENCY, NULL);    /* seven minutes: exchange */        }      activeCronJobs -= ACJ_FORWARD;    }  else    {      if (GNUNET_YES == GNUNET_GC_get_configuration_value_yesno (cfg,                                                                 "NETWORK",                                                                 "HELLOEXCHANGE",                                                                 GNUNET_YES))        {          GNUNET_cron_add_job (coreAPI->cron,                               &forwardhello,                               15 * GNUNET_CRON_SECONDS,                               HELLO_FORWARD_FREQUENCY, NULL);        }      activeCronJobs += ACJ_FORWARD;    }  return 0;}/** * Start advertising. */intinitialize_module_advertising (GNUNET_CoreAPIForPlugins * capi){  coreAPI = capi;  ectx = capi->ectx;  identity = capi->service_request ("identity");  if (identity == NULL)    {      GNUNET_GE_BREAK (ectx, 0);      return GNUNET_SYSERR;    }  transport = capi->service_request ("transport");  if (transport == NULL)    {      GNUNET_GE_BREAK (ectx, 0);      capi->service_release (identity);      identity = NULL;      return GNUNET_SYSERR;    }  pingpong = capi->service_request ("pingpong");  if (pingpong == NULL)    {      GNUNET_GE_BREAK (ectx, 0);      capi->service_release (identity);      identity = NULL;      capi->service_release (transport);      transport = NULL;      return GNUNET_SYSERR;    }  topology = capi->service_request ("topology");  if (topology == NULL)    {      GNUNET_GE_BREAK (ectx, 0);      capi->service_release (identity);      identity = NULL;      capi->service_release (transport);      transport = NULL;      capi->service_release (pingpong);      pingpong = NULL;      return GNUNET_SYSERR;    }  stats = capi->service_request ("stats");  if (stats != NULL)    {      stat_hello_in =        stats->create (gettext_noop ("# Peer advertisements received"));      stat_hello_nat_in =        stats->create (gettext_noop                       ("# Peer advertisements of type NAT received"));      stat_hello_verified =        stats->create (gettext_noop                       ("# Peer advertisements confirmed via PONG"));      stat_hello_update =        stats->create (gettext_noop                       ("# Peer advertisements updating earlier HELLOs"));      stat_hello_discard =        stats->create (gettext_noop                       ("# Peer advertisements discarded due to load"));      stat_hello_no_transport =        stats->create (gettext_noop                       ("# Peer advertisements for unsupported transport"));      stat_hello_ping_busy =        stats->create (gettext_noop                       ("# Peer advertisements not confirmed due to ping busy"));      stat_hello_noselfad =        stats->create (gettext_noop                       ("# Peer advertisements not confirmed due to lack of self ad"));      stat_hello_send_error =        stats->create (gettext_noop                       ("# Peer advertisements not confirmed due to send error"));      stat_hello_out =        stats->create (gettext_noop ("# Self advertisments transmitted"));      stat_hello_fwd =        stats->create (gettext_noop ("# Foreign advertisements forwarded"));      stat_plaintextPingSent =        stats->create (gettext_noop ("# plaintext PING messages sent"));    }  GNUNET_GE_LOG (ectx,                 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,                 _                 ("`%s' registering handler %d (plaintext and ciphertext)\n"),                 "advertising", GNUNET_P2P_PROTO_HELLO);  capi->p2p_ciphertext_handler_register (GNUNET_P2P_PROTO_HELLO,                                         &ehelloHandler);  capi->p2p_plaintext_handler_register (GNUNET_P2P_PROTO_HELLO,                                        &phelloHandler);  if (0 !=      GNUNET_GC_attach_change_listener (capi->cfg,                                        &configurationUpdateCallback, NULL))    GNUNET_GE_BREAK (capi->ectx, 0);  startBootstrap (capi);  GNUNET_GE_ASSERT (capi->ectx,                    0 == GNUNET_GC_set_configuration_value_string (capi->cfg,                                                                   capi->ectx,                                                                   "ABOUT",                                                                   "advertising",                                                                   _                                                                   ("ensures that this peer is known by other"                                                                    " peers and discovers other peers")));  return GNUNET_OK;}/** * Stop advertising. */voiddone_module_advertising (){  stopBootstrap ();  GNUNET_GC_detach_change_listener (coreAPI->cfg,                                    &configurationUpdateCallback, NULL);  if (ACJ_ANNOUNCE == (activeCronJobs & ACJ_ANNOUNCE))    {      GNUNET_cron_del_job (coreAPI->cron,                           &broadcasthello, HELLO_BROADCAST_FREQUENCY, NULL);      activeCronJobs -= ACJ_ANNOUNCE;    }  if (ACJ_FORWARD == (activeCronJobs & ACJ_FORWARD))    {      GNUNET_cron_del_job (coreAPI->cron, &forwardhello, HELLO_FORWARD_FREQUENCY, NULL);        /* seven minutes: exchange */      activeCronJobs -= ACJ_FORWARD;    }  coreAPI->p2p_ciphertext_handler_unregister (GNUNET_P2P_PROTO_HELLO,                                              &ehelloHandler);  coreAPI->p2p_plaintext_handler_unregister (GNUNET_P2P_PROTO_HELLO,                                             &phelloHandler);  coreAPI->service_release (transport);  transport = NULL;  coreAPI->service_release (identity);  identity = NULL;  coreAPI->service_release (pingpong);  pingpong = NULL;  coreAPI->service_release (topology);  topology = NULL;  if (stats != NULL)    {      coreAPI->service_release (stats);      stats = NULL;    }  coreAPI = NULL;}/* end of advertising.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -