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

📄 search.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
  event.data.SearchStarted.sc.pos = pos;  event.data.SearchStarted.sc.cctx = NULL;  event.data.SearchStarted.searchURI = pos->uri;  event.data.SearchStarted.anonymityLevel = pos->anonymityLevel;  pos->cctx = pos->ctx->ecb (pos->ctx->ecbClosure, &event);  if (GNUNET_ECRS_uri_test_ksk (uri))    {      /* (possibly boolean) keyword search */      GNUNET_ECRS_uri_get_keywords_from_ksk (uri, &count_mandatory_keywords,                                             pos);      GNUNET_ECRS_uri_get_keywords_from_ksk (uri, &create_ecrs_search, pos);      if (pos->start_time == 0)        {          /* failed to start ECRS searches */          while (pos->searches != NULL)            {              srl = pos->searches;              pos->searches = srl->next;              GNUNET_ECRS_search_stop (srl->search);              GNUNET_ECRS_uri_destroy (srl->uri);              GNUNET_free (srl);            }        }    }  else    {      /* Namespace search, only one ECRS search */      srl = GNUNET_malloc (sizeof (struct SearchRecordList));      memset (srl, 0, sizeof (struct SearchRecordList));      srl->uri = GNUNET_ECRS_uri_duplicate (uri);      srl->search = GNUNET_ECRS_search_start (pos->ctx->ectx,                                              pos->ctx->cfg,                                              pos->probe_context,                                              pos->uri,                                              pos->anonymityLevel,                                              &GNUNET_FSUI_search_progress_callback,                                              pos);      if (srl->search == NULL)        {          GNUNET_ECRS_uri_destroy (srl->uri);          GNUNET_free (srl);        }      else        {          pos->searches = srl;        }    }  if (pos->searches == NULL)    {      /* failed to initiate searches */      event.type = GNUNET_FSUI_search_stopped;      event.data.SearchStopped.sc.pos = pos;      event.data.SearchStopped.sc.cctx = NULL;      pos->cctx = pos->ctx->ecb (pos->ctx->ecbClosure, &event);      GNUNET_ECRS_uri_destroy (pos->uri);      GNUNET_free (pos);      return NULL;    }  /* success, add to FSUI state */  GNUNET_mutex_lock (ctx->lock);  pos->next = ctx->activeSearches;  ctx->activeSearches = pos;  GNUNET_mutex_unlock (ctx->lock);  return pos;}/** * Abort a search. */intGNUNET_FSUI_search_abort (struct GNUNET_FSUI_SearchList *sl){  GNUNET_FSUI_Event event;  struct SearchRecordList *rec;  struct SearchResultList *srl;  struct GNUNET_FSUI_Context *ctx;  ctx = sl->ctx;  GNUNET_mutex_lock (ctx->lock);  if (sl->state == GNUNET_FSUI_PENDING)    {      sl->state = GNUNET_FSUI_ABORTED_JOINED;      GNUNET_mutex_unlock (ctx->lock);      return GNUNET_OK;    }  if (sl->state != GNUNET_FSUI_ACTIVE)    {      GNUNET_mutex_unlock (ctx->lock);      return GNUNET_SYSERR;    }  sl->state = GNUNET_FSUI_ABORTED_JOINED;  GNUNET_mutex_unlock (ctx->lock);  /* must not hold lock while stopping ECRS searches! */  while (sl->searches != NULL)    {      rec = sl->searches;      GNUNET_ECRS_search_stop (rec->search);      sl->searches = rec->next;      GNUNET_ECRS_uri_destroy (rec->uri);      GNUNET_free (rec);    }  /* clean up a bit more: we don't need matchingSearches     anymore, and the pointers are now invalid! */  GNUNET_mutex_lock (ctx->lock);  srl = sl->resultsReceived;  while (srl != NULL)    {      GNUNET_array_grow (srl->matchingSearches, srl->matchingSearchCount, 0);      if (srl->test_download != NULL)        {          GNUNET_ECRS_file_download_partial_stop (srl->test_download);          srl->test_download = NULL;          ctx->active_probes--;        }      srl = srl->next;    }  event.type = GNUNET_FSUI_search_aborted;  event.data.SearchAborted.sc.pos = sl;  event.data.SearchAborted.sc.cctx = sl->cctx;  sl->ctx->ecb (sl->ctx->ecbClosure, &event);  GNUNET_mutex_unlock (ctx->lock);  return GNUNET_OK;}/** * Pause a search. */intGNUNET_FSUI_search_pause (struct GNUNET_FSUI_SearchList *sl){  GNUNET_FSUI_Event event;  struct SearchRecordList *rec;  struct SearchResultList *srl;  struct GNUNET_FSUI_Context *ctx;  ctx = sl->ctx;  GNUNET_mutex_lock (ctx->lock);  if (sl->state != GNUNET_FSUI_ACTIVE)    {      GNUNET_mutex_unlock (ctx->lock);      return GNUNET_SYSERR;    }  sl->state = GNUNET_FSUI_PAUSED;  GNUNET_mutex_unlock (ctx->lock);  /* must not hold lock while stopping ECRS searches */  rec = sl->searches;  while (rec != NULL)    {      if (rec->search != NULL)        GNUNET_ECRS_search_stop (rec->search);      rec->search = NULL;      rec = rec->next;    }  GNUNET_mutex_lock (ctx->lock);  srl = sl->resultsReceived;  while (srl != NULL)    {      if (srl->test_download != NULL)        {          GNUNET_ECRS_file_download_partial_stop (srl->test_download);          srl->test_download = NULL;          ctx->active_probes--;        }      srl = srl->next;    }  event.type = GNUNET_FSUI_search_paused;  event.data.SearchPaused.sc.pos = sl;  event.data.SearchPaused.sc.cctx = sl->cctx;  sl->ctx->ecb (sl->ctx->ecbClosure, &event);  GNUNET_mutex_unlock (ctx->lock);  return GNUNET_OK;}/** * Restart a paused search. */intGNUNET_FSUI_search_restart (struct GNUNET_FSUI_SearchList *pos){  GNUNET_FSUI_Event event;  struct SearchRecordList *rec;  struct GNUNET_FSUI_Context *ctx;  ctx = pos->ctx;  GNUNET_mutex_lock (ctx->lock);  pos->state = GNUNET_FSUI_ACTIVE;  event.type = GNUNET_FSUI_search_restarted;  event.data.SearchStarted.sc.pos = pos;  event.data.SearchStarted.sc.cctx = pos->cctx;  pos->ctx->ecb (pos->ctx->ecbClosure, &event);  rec = pos->searches;  while (rec != NULL)    {      rec->search = GNUNET_ECRS_search_start (pos->ctx->ectx,                                              pos->ctx->cfg,                                              pos->probe_context,                                              rec->uri,                                              pos->anonymityLevel,                                              &GNUNET_FSUI_search_progress_callback,                                              pos);      if (rec->search == NULL)        break;      rec = rec->next;    }  if (rec != NULL)    {      /* failed to restart, auto-pause again */      GNUNET_FSUI_search_pause (pos);      GNUNET_mutex_unlock (ctx->lock);      return GNUNET_SYSERR;    }  GNUNET_mutex_unlock (ctx->lock);  return GNUNET_OK;}/** * Stop a search. */intGNUNET_FSUI_search_stop (struct GNUNET_FSUI_SearchList *sl){  GNUNET_FSUI_Event event;  GNUNET_FSUI_SearchList *pos;  GNUNET_FSUI_SearchList *prev;  int i;  struct SearchRecordList *rec;  struct SearchResultList *srl;  struct GNUNET_FSUI_Context *ctx;  ctx = sl->ctx;  GNUNET_mutex_lock (ctx->lock);  if (sl->state == GNUNET_FSUI_ACTIVE)    GNUNET_FSUI_search_abort (sl);  prev = NULL;  pos = ctx->activeSearches;  while ((pos != sl) && (pos != NULL))    {      prev = pos;      pos = pos->next;    }  if (pos == NULL)    {      GNUNET_mutex_unlock (ctx->lock);      return GNUNET_SYSERR;    }  if (prev == NULL)    ctx->activeSearches = pos->next;  else    prev->next = pos->next;  for (i = 0; i < sl->my_downloads_size; i++)    sl->my_downloads[i]->search = NULL;  GNUNET_array_grow (sl->my_downloads, sl->my_downloads_size, 0);  GNUNET_mutex_unlock (ctx->lock);  pos->next = NULL;  while (sl->searches != NULL)    {      rec = sl->searches;      sl->searches = rec->next;      if (rec->search != NULL)        {          GNUNET_GE_BREAK (ctx->ectx, 0);          GNUNET_ECRS_search_stop (rec->search);          rec->search = NULL;        }      GNUNET_ECRS_uri_destroy (rec->uri);      GNUNET_free (rec);    }  event.type = GNUNET_FSUI_search_stopped;  event.data.SearchStopped.sc.pos = pos;  event.data.SearchStopped.sc.cctx = pos->cctx;  pos->ctx->ecb (pos->ctx->ecbClosure, &event);  GNUNET_ECRS_uri_destroy (pos->uri);  while (sl->resultsReceived != NULL)    {      srl = sl->resultsReceived;      sl->resultsReceived = srl->next;      GNUNET_array_grow (srl->matchingSearches, srl->matchingSearchCount, 0);      GNUNET_ECRS_uri_destroy (srl->fi.uri);      GNUNET_meta_data_destroy (srl->fi.meta);      if (srl->test_download != NULL)        {          GNUNET_ECRS_file_download_partial_stop (srl->test_download);          ctx->active_probes--;        }      GNUNET_free (srl);    }  if (pos->probe_context != NULL)    GNUNET_FS_destroy_search_context (pos->probe_context);  GNUNET_free (pos);  return GNUNET_OK;}/* end of search.c */

⌨️ 快捷键说明

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