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

📄 fsui.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
      event.data.SearchResumed.searchURI = list->uri;      event.data.SearchResumed.state = list->state;      event.data.SearchResumed.availability_rank = av_ranks;      event.data.SearchResumed.availability_certainty = av_certs;      event.data.SearchResumed.applicability_rank = ap_ranks;      list->cctx = cb (closure, &event);      GNUNET_free_non_null (fis);      GNUNET_free_non_null (av_ranks);      GNUNET_free_non_null (av_certs);      GNUNET_free_non_null (ap_ranks);      list = list->next;    }  /* 2b) signal download restarts */  signalDownloadResume (ret->activeDownloads.child, ret);  /* 2c) signal upload restarts */  signalUploadResume (ret->activeUploads.child, ret);  /* 2d) signal unindex restarts */  xlist = ret->unindexOperations;  while (xlist != NULL)    {      if (GNUNET_OK !=          GNUNET_disk_file_size (ectx, xlist->filename, &size, GNUNET_YES))        size = 0;      event.type = GNUNET_FSUI_unindex_resumed;      event.data.UnindexResumed.uc.pos = xlist;      event.data.UnindexResumed.uc.cctx = NULL;      event.data.UnindexResumed.completed =        (xlist->state == GNUNET_FSUI_COMPLETED_JOINED) ? size : 0;      event.data.UnindexResumed.total = size;      event.data.UnindexResumed.eta = GNUNET_get_time ();      event.data.UnindexResumed.filename = xlist->filename;      event.data.UnindexResumed.state = xlist->state;      xlist->cctx = cb (closure, &event);      xlist = xlist->next;    }  /* 3) restart processing */  ret->cron = GNUNET_cron_create (ectx);  /* 3a) resume searching */  list = ret->activeSearches;  while (list != NULL)    {      list->probe_context        = GNUNET_FS_create_search_context (ret->ectx, ret->cfg);      if (list->state == GNUNET_FSUI_PENDING)        {          list->state = GNUNET_FSUI_ACTIVE;          rec = list->searches;          while (rec != NULL)            {              rec->search = GNUNET_ECRS_search_start (list->ctx->ectx,                                                      list->ctx->cfg,                                                      list->probe_context,                                                      rec->uri,                                                      list->anonymityLevel,                                                      &GNUNET_FSUI_search_progress_callback,                                                      list);              if (rec->search == NULL)                {                  GNUNET_GE_LOG (ectx,                                 GNUNET_GE_FATAL | GNUNET_GE_ADMIN |                                 GNUNET_GE_IMMEDIATE,                                 "Failed to resume search\n");                  list->state = GNUNET_FSUI_PENDING;                }              rec = rec->next;            }          if (list->state != GNUNET_FSUI_ACTIVE)            {              /* stop searches, we failed... */              rec = list->searches;              while (rec != NULL)                {                  if (rec->search != NULL)                    {                      GNUNET_ECRS_search_stop (rec->search);                      rec->search = NULL;                    }                  rec = rec->next;                }            }        }      list = list->next;    }  /* 3b) resume unindexing */  xlist = ret->unindexOperations;  while (xlist != NULL)    {      if (xlist->state == GNUNET_FSUI_PENDING)        {          xlist->state = GNUNET_FSUI_ACTIVE;          xlist->handle = GNUNET_thread_create (&GNUNET_FSUI_unindexThread,                                                xlist, 32 * 1024);          if (xlist->handle == NULL)            GNUNET_GE_DIE_STRERROR (ectx,                                    GNUNET_GE_FATAL | GNUNET_GE_ADMIN |                                    GNUNET_GE_IMMEDIATE, "pthread_create");        }      xlist = xlist->next;    }  /* 3c) resume downloads */  GNUNET_cron_add_job (ret->cron,                       &updateDownloadThreads, 0, GNUNET_FSUI_UDT_FREQUENCY,                       ret);  GNUNET_cron_start (ret->cron);  /* 3d) resume uploads */  doResumeUploads (ret->activeUploads.child, ret);  return ret;}/* ******************* STOP code *********************** *//** * (recursively) signal download suspension. */static voidsignalDownloadSuspend (struct GNUNET_GE_Context *ectx,                       GNUNET_FSUI_Context * ctx,                       GNUNET_FSUI_DownloadList * list){  GNUNET_FSUI_Event event;  while (list != NULL)    {      signalDownloadSuspend (ectx, ctx, list->child);      event.type = GNUNET_FSUI_download_suspended;      event.data.DownloadSuspended.dc.pos = list;      event.data.DownloadSuspended.dc.cctx = list->cctx;      event.data.DownloadSuspended.dc.ppos =        list->parent == &ctx->activeDownloads ? NULL : list->parent;      event.data.DownloadSuspended.dc.pcctx = list->parent->cctx;      event.data.DownloadSuspended.dc.spos = list->search;      event.data.DownloadSuspended.dc.sctx =        list->search == NULL ? NULL : list->search->cctx;      ctx->ecb (ctx->ecbClosure, &event);      list = list->next;    }}/** * (recursively) signal upload suspension. */static voidsignalUploadSuspend (struct GNUNET_GE_Context *ectx,                     GNUNET_FSUI_Context * ctx, GNUNET_FSUI_UploadList * upos){  GNUNET_FSUI_Event event;  while (upos != NULL)    {      signalUploadSuspend (ectx, ctx, upos->child);      event.type = GNUNET_FSUI_upload_suspended;      event.data.UploadSuspended.uc.pos = upos;      event.data.UploadSuspended.uc.cctx = upos->cctx;      event.data.UploadSuspended.uc.ppos = upos->parent;      event.data.UploadSuspended.uc.pcctx = upos->parent->cctx;      ctx->ecb (ctx->ecbClosure, &event);      upos = upos->next;    }}/** * (recursively) free download list */static voidfreeDownloadList (GNUNET_FSUI_DownloadList * list){  GNUNET_FSUI_DownloadList *next;  int i;  while (list != NULL)    {      freeDownloadList (list->child);      GNUNET_ECRS_uri_destroy (list->fi.uri);      GNUNET_meta_data_destroy (list->fi.meta);      GNUNET_free (list->filename);      for (i = 0; i < list->completedDownloadsCount; i++)        GNUNET_ECRS_uri_destroy (list->completedDownloads[i]);      GNUNET_array_grow (list->completedDownloads,                         list->completedDownloadsCount, 0);      next = list->next;      GNUNET_free (list);      list = next;    }}/** * (recursively) free upload list */static voidfreeUploadList (struct GNUNET_FSUI_Context *ctx,                GNUNET_FSUI_UploadList * list){  GNUNET_FSUI_UploadList *next;  GNUNET_FSUI_UploadShared *shared;  while (list != NULL)    {      freeUploadList (ctx, list->child);      next = list->next;      GNUNET_free (list->filename);      if (list->meta != NULL)        GNUNET_meta_data_destroy (list->meta);      if (list->keywords != NULL)        GNUNET_ECRS_uri_destroy (list->keywords);      if (list->uri != NULL)        GNUNET_ECRS_uri_destroy (list->uri);      if (list->parent == &ctx->activeUploads)        {          shared = list->shared;          EXTRACTOR_removeAll (shared->extractors);          if (shared->global_keywords != NULL)            GNUNET_ECRS_uri_destroy (shared->global_keywords);          GNUNET_free_non_null (shared->extractor_config);          GNUNET_free (shared);        }      GNUNET_free (list);      list = next;    }}static voidsuspend_active_upload (struct GNUNET_FSUI_UploadList *ul){  while (ul != NULL)    {      if (ul->state == GNUNET_FSUI_ACTIVE)        {          ul->state = GNUNET_FSUI_PENDING;          suspend_active_upload (ul->child);        }      ul = ul->next;    }}/** * Stop all processes under FSUI control (serialize state, continue * later if possible). */voidGNUNET_FSUI_stop (struct GNUNET_FSUI_Context *ctx){  struct GNUNET_GE_Context *ectx;  GNUNET_FSUI_SearchList *spos;  GNUNET_FSUI_DownloadList *dpos;  GNUNET_FSUI_UnindexList *xpos;  GNUNET_FSUI_UploadList *upos;  struct SearchRecordList *rec;  struct SearchResultList *res;  GNUNET_FSUI_Event event;  void *unused;  ectx = ctx->ectx;  if (ctx->ipc != NULL)    GNUNET_GE_LOG (ectx,                   GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,                   "FSUI shutdown.  This may take a while.\n");  /* 1) stop everything */  GNUNET_cron_stop (ctx->cron);  GNUNET_cron_del_job (ctx->cron, &updateDownloadThreads,                       GNUNET_FSUI_UDT_FREQUENCY, ctx);  GNUNET_cron_destroy (ctx->cron);  /* 1a) stop downloading */  ctx->threadPoolSize = 0;  dpos = ctx->activeDownloads.child;  while (dpos != NULL)    {      GNUNET_FSUI_updateDownloadThread (dpos);      dpos = dpos->next;    }  /* 1b) stop searching */  spos = ctx->activeSearches;  while (spos != NULL)    {      if ((spos->state == GNUNET_FSUI_ACTIVE) ||          (spos->state == GNUNET_FSUI_ABORTED) ||          (spos->state == GNUNET_FSUI_ERROR)          || (spos->state == GNUNET_FSUI_COMPLETED))        {          if (spos->state == GNUNET_FSUI_ACTIVE)            spos->state = GNUNET_FSUI_PENDING;          rec = spos->searches;          while (rec != NULL)            {              GNUNET_ECRS_search_stop (rec->search);              rec->search = NULL;              rec = rec->next;            }          res = spos->resultsReceived;          while (res != NULL)            {              if (res->test_download != NULL)                {                  GNUNET_ECRS_file_download_partial_stop (res->test_download);                  res->test_download = NULL;                  ctx->active_probes--;                }              res = res->next;            }          if (spos->state != GNUNET_FSUI_PENDING)            spos->state++;      /* _JOINED */        }      if (spos->probe_context != NULL)        {          GNUNET_FS_destroy_search_context (spos->probe_context);          spos->probe_context = NULL;        }      spos = spos->next;    }  /* 1c) stop unindexing */  xpos = ctx->unindexOperations;  while (xpos != NULL)    {      if ((xpos->state == GNUNET_FSUI_ACTIVE) ||          (xpos->state == GNUNET_FSUI_ABORTED) ||          (xpos->state == GNUNET_FSUI_ERROR)          || (xpos->state == GNUNET_FSUI_COMPLETED))        {          if (xpos->state == GNUNET_FSUI_ACTIVE)            xpos->state = GNUNET_FSUI_PENDING;          GNUNET_thread_stop_sleep (xpos->handle);          GNUNET_thread_join (xpos->handle, &unused);          if (xpos->state != GNUNET_FSUI_PENDING)            xpos->state++;      /* _JOINED */        }      xpos = xpos->next;    }  /* 1d) stop uploading */  upos = ctx->activeUploads.child;  while (upos != NULL)    {      if ((upos->state == GNUNET_FSUI_ACTIVE) ||          (upos->state == GNUNET_FSUI_ABORTED) ||          (upos->state == GNUNET_FSUI_ERROR)          || (upos->state == GNUNET_FSUI_COMPLETED))        {          if (upos->state == GNUNET_FSUI_ACTIVE)            upos->state = GNUNET_FSUI_PENDING;          suspend_active_upload (upos->child);          GNUNET_thread_stop_sleep (upos->shared->handle);          GNUNET_thread_join (upos->shared->handle, &unused);          if (upos->state != GNUNET_FSUI_PENDING)            upos->state++;      /* _JOINED */        }      upos = upos->next;    }  /* 2) signal suspension events */  /* 2a) signal uploads suspension */  signalUploadSuspend (ectx, ctx, ctx->activeUploads.child);  /* 2b) signal downloads suspension */  signalDownloadSuspend (ectx, ctx, ctx->activeDownloads.child);  /* 2c) signal unindex suspension */  xpos = ctx->unindexOperations;  while (xpos != NULL)    {      event.type = GNUNET_FSUI_unindex_suspended;      event.data.UnindexSuspended.uc.pos = xpos;      event.data.UnindexSuspended.uc.cctx = xpos->cctx;      ctx->ecb (ctx->ecbClosure, &event);      xpos = xpos->next;    }  /* 2d) signal search suspension */  spos = ctx->activeSearches;  while (spos != NULL)    {      event.type = GNUNET_FSUI_search_suspended;      event.data.SearchSuspended.sc.pos = spos;      event.data.SearchSuspended.sc.cctx = spos->cctx;      ctx->ecb (ctx->ecbClosure, &event);      spos = spos->next;    }  /* 3) serialize all of the FSUI state */  if (ctx->ipc != NULL)    GNUNET_FSUI_serialize (ctx);  /* 4) finally, free memory */  /* 4a) free search memory */  while (ctx->activeSearches != NULL)    {      spos = ctx->activeSearches;      ctx->activeSearches = spos->next;      GNUNET_ECRS_uri_destroy (spos->uri);      while (spos->searches != NULL)        {          rec = spos->searches;          spos->searches = rec->next;          GNUNET_ECRS_uri_destroy (rec->uri);          GNUNET_free (rec);        }      while (spos->resultsReceived != NULL)        {          res = spos->resultsReceived;          spos->resultsReceived = res->next;          GNUNET_meta_data_destroy (res->fi.meta);          GNUNET_ECRS_uri_destroy (res->fi.uri);          GNUNET_free (res->matchingSearches);          GNUNET_free (res);        }      GNUNET_free (spos);    }  /* 4b) free unindex memory */  while (ctx->unindexOperations != NULL)    {      xpos = ctx->unindexOperations;      ctx->unindexOperations = xpos->next;      GNUNET_free (xpos->filename);      GNUNET_free (xpos);    }  /* 4c) free upload memory */  freeUploadList (ctx, ctx->activeUploads.child);  /* 4d) free download memory */  freeDownloadList (ctx->activeDownloads.child);  /* 5) finish FSUI Context */  if (ctx->ipc != NULL)    {      GNUNET_IPC_semaphore_up (ctx->ipc);      GNUNET_IPC_semaphore_destroy (ctx->ipc);    }  GNUNET_mutex_destroy (ctx->lock);  GNUNET_free (ctx->name);  if (ctx->ipc != NULL)    GNUNET_GE_LOG (ectx,                   GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,                   "FSUI shutdown complete.\n");  GNUNET_free (ctx);}/* end of fsui.c */

⌨️ 快捷键说明

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