• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GNUNET_malloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GNUNET_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ GNUNET_malloc函数的具体用法?C++ GNUNET_malloc怎么用?C++ GNUNET_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GNUNET_malloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: udp_broadcast_receive

void
udp_broadcast_receive (struct Plugin *plugin, const char * buf, ssize_t size, struct sockaddr *addr, size_t addrlen)
{
  struct GNUNET_ATS_Information ats;

  if ((GNUNET_YES == plugin->broadcast_ipv4) && (addrlen == sizeof (struct sockaddr_in)))
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Received IPv4 HELLO beacon broadcast with %i bytes from address %s\n",
         size, GNUNET_a2s ((const struct sockaddr *) addr, addrlen));
    struct Mstv4Context *mc;

    mc = GNUNET_malloc (sizeof (struct Mstv4Context));
    struct sockaddr_in *av4 = (struct sockaddr_in *) addr;

    mc->addr.ipv4_addr = av4->sin_addr.s_addr;
    mc->addr.u4_port = av4->sin_port;
    ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) addr, addrlen);
    mc->ats_address_network_type = ats.value;

    GNUNET_assert (NULL != plugin->broadcast_ipv4_mst);
    if (GNUNET_OK !=
        GNUNET_SERVER_mst_receive (plugin->broadcast_ipv4_mst, mc, buf, size,
                                   GNUNET_NO, GNUNET_NO))
      GNUNET_free (mc);
  }
  else if ((GNUNET_YES == plugin->broadcast_ipv4) && (addrlen == sizeof (struct sockaddr_in6)))
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Received IPv6 HELLO beacon broadcast with %i bytes from address %s\n",
         size, GNUNET_a2s ((const struct sockaddr *) &addr, addrlen));
    struct Mstv6Context *mc;

    mc = GNUNET_malloc (sizeof (struct Mstv6Context));
    struct sockaddr_in6 *av6 = (struct sockaddr_in6 *) addr;

    mc->addr.ipv6_addr = av6->sin6_addr;
    mc->addr.u6_port = av6->sin6_port;
    ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) addr, addrlen);
    mc->ats_address_network_type = ats.value;
    GNUNET_assert (NULL != plugin->broadcast_ipv4_mst);
    if (GNUNET_OK !=
        GNUNET_SERVER_mst_receive (plugin->broadcast_ipv6_mst, mc, buf, size,
                                   GNUNET_NO, GNUNET_NO))
      GNUNET_free (mc);
  }
}
开发者ID:amatus,项目名称:gnunet-debian,代码行数:47,代码来源:plugin_transport_udp_broadcasting.c


示例2: GNUNET_PSYC_transmit_message

/**
 * Transmit a message.
 *
 * @param tmit
 *        Transmission handle.
 * @param method_name
 *        Which method should be invoked.
 * @param env
 *        Environment for the message.
 *        Should stay available until the first call to notify_data.
 *        Can be NULL if there are no modifiers or @a notify_mod is
 *        provided instead.
 * @param notify_mod
 *        Function to call to obtain modifiers.
 *        Can be NULL if there are no modifiers or @a env is provided instead.
 * @param notify_data
 *        Function to call to obtain fragments of the data.
 * @param notify_cls
 *        Closure for @a notify_mod and @a notify_data.
 * @param flags
 *        Flags for the message being transmitted.
 *
 * @return #GNUNET_OK if the transmission was started.
 *         #GNUNET_SYSERR if another transmission is already going on.
 */
int
GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
                              const char *method_name,
                              const struct GNUNET_ENV_Environment *env,
                              GNUNET_PSYC_TransmitNotifyModifier notify_mod,
                              GNUNET_PSYC_TransmitNotifyData notify_data,
                              void *notify_cls,
                              uint32_t flags)
{
  if (GNUNET_NO != tmit->in_transmit)
    return GNUNET_SYSERR;
  tmit->in_transmit = GNUNET_YES;

  size_t size = strlen (method_name) + 1;
  struct GNUNET_PSYC_MessageMethod *pmeth;
  tmit->msg = GNUNET_malloc (sizeof (*tmit->msg) + sizeof (*pmeth) + size);
  tmit->msg->size = sizeof (*tmit->msg) + sizeof (*pmeth) + size;

  if (NULL != notify_mod)
  {
    tmit->notify_mod = notify_mod;
    tmit->notify_mod_cls = notify_cls;
  }
  else
  {
    tmit->notify_mod = &transmit_notify_env;
    tmit->notify_mod_cls = tmit;
    if (NULL != env)
    {
      struct GNUNET_ENV_Modifier mod = {};
      mod.next = GNUNET_ENV_environment_head (env);
      tmit->mod = &mod;

      struct GNUNET_ENV_Modifier *m = tmit->mod;
      while (NULL != (m = m->next))
      {
        if (m->oper != GNUNET_ENV_OP_SET)
          flags |= GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY;
      }
    }
    else
    {
      tmit->mod = NULL;
    }
  }

  pmeth = (struct GNUNET_PSYC_MessageMethod *) &tmit->msg[1];
  pmeth->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD);
  pmeth->header.size = htons (sizeof (*pmeth) + size);
  pmeth->flags = htonl (flags);
  memcpy (&pmeth[1], method_name, size);

  tmit->state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
  tmit->notify_data = notify_data;
  tmit->notify_data_cls = notify_cls;

  transmit_mod (tmit);
  return GNUNET_OK;
}
开发者ID:muggenhor,项目名称:GNUnet,代码行数:84,代码来源:psyc_util_lib.c


示例3: create_record

static struct GNUNET_GNSRECORD_Data *
create_record (int count)
{
  unsigned int c;
  struct GNUNET_GNSRECORD_Data *rd;

  rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
  for (c = 0; c < count; c++)
  {
    rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
    rd[c].record_type = TEST_RECORD_TYPE;
    rd[c].data_size = TEST_RECORD_DATALEN;
    rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
    memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  }
  return rd;
}
开发者ID:claudiuolteanu,项目名称:gnunet-1,代码行数:17,代码来源:test_gnsrecord_crypto.c


示例4: create_record

static struct GNUNET_NAMESTORE_RecordData *
create_record (unsigned int count)
{
  unsigned int c;
  struct GNUNET_NAMESTORE_RecordData * rd;

  rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
  for (c = 0; c < count; c++)
  {
    rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value;
    rd[c].record_type = 1111;
    rd[c].data_size = 50;
    rd[c].data = GNUNET_malloc(50);
    memset ((char *) rd[c].data, 'a', 50);
  }
  return rd;
}
开发者ID:schanzen,项目名称:gnunet-mirror,代码行数:17,代码来源:test_namestore_api_zone_iteration_stop.c


示例5: state_machine

/**
 * Main state machine that goes over all options and
 * runs the next requested function.
 *
 * @param cls unused
 * @param tc scheduler context
 */
static void
state_machine (void *cls,
	       const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  tt = GNUNET_SCHEDULER_NO_TASK;

  if (NULL != put_uri)
  {
    GPI_plugins_load (cfg);
    if (GNUNET_SYSERR == parse_hello_uri (put_uri))
      fprintf (stderr,
	       _("Invalid URI `%s'\n"),
	       put_uri);    
    GNUNET_free (put_uri);
    put_uri = NULL;
    return;
  }
  if (GNUNET_YES == get_info)
  {
    get_info = GNUNET_NO;
    GPI_plugins_load (cfg);
    pic = GNUNET_PEERINFO_iterate (peerinfo, NULL,
				   TIMEOUT,
				   &print_peer_info, NULL);
    return;
  }
  if (GNUNET_YES == get_self)
  {
    struct GNUNET_CRYPTO_HashAsciiEncoded enc;

    get_self = GNUNET_NO;
    GNUNET_CRYPTO_hash_to_enc (&my_peer_identity.hashPubKey, &enc);
    if (be_quiet)
      printf ("%s\n", (char *) &enc);
    else
      printf (_("I am peer `%s'.\n"), (const char *) &enc);
  }
  if (GNUNET_YES == get_uri)
  {
    struct GetUriContext *guc;
    char *pkey;

    guc = GNUNET_malloc (sizeof (struct GetUriContext));
    pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&my_public_key);
    GNUNET_asprintf (&guc->uri,
		     "%s%s",
		     HELLO_URI_PREFIX,
		     pkey);
    GNUNET_free (pkey);
    GPI_plugins_load (cfg);
    pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity,
				   TIMEOUT,
				   &print_my_uri, guc);
    get_uri = GNUNET_NO;
    return;
  }
  GNUNET_SCHEDULER_shutdown ();
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:65,代码来源:gnunet-peerinfo.c


示例6: GDS_CLIENTS_process_get

/**
 * Check if some client is monitoring GET messages and notify
 * them in that case.
 *
 * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
 * @param type The type of data in the request.
 * @param hop_count Hop count so far.
 * @param path_length number of entries in path (or 0 if not recorded).
 * @param path peers on the GET path (or NULL if not recorded).
 * @param desired_replication_level Desired replication level.
 * @param key Key of the requested data.
 */
void
GDS_CLIENTS_process_get (uint32_t options,
                         enum GNUNET_BLOCK_Type type,
                         uint32_t hop_count,
                         uint32_t desired_replication_level,
                         unsigned int path_length,
                         const struct GNUNET_PeerIdentity *path,
                         const struct GNUNET_HashCode * key)
{
  struct ClientMonitorRecord *m;
  struct ClientList **cl;
  unsigned int cl_size;

  cl = NULL;
  cl_size = 0;
  for (m = monitor_head; NULL != m; m = m->next)
  {
    if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
        (NULL == m->key ||
         memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
    {
      struct PendingMessage *pm;
      struct GNUNET_DHT_MonitorGetMessage *mmsg;
      struct GNUNET_PeerIdentity *msg_path;
      size_t msize;
      unsigned int i;

      /* Don't send duplicates */
      for (i = 0; i < cl_size; i++)
        if (cl[i] == m->client)
          break;
      if (i < cl_size)
        continue;
      GNUNET_array_append (cl, cl_size, m->client);

      msize = path_length * sizeof (struct GNUNET_PeerIdentity);
      msize += sizeof (struct GNUNET_DHT_MonitorGetMessage);
      msize += sizeof (struct PendingMessage);
      pm = GNUNET_malloc (msize);
      mmsg = (struct GNUNET_DHT_MonitorGetMessage *) &pm[1];
      pm->msg = &mmsg->header;
      mmsg->header.size = htons (msize - sizeof (struct PendingMessage));
      mmsg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET);
      mmsg->options = htonl(options);
      mmsg->type = htonl(type);
      mmsg->hop_count = htonl(hop_count);
      mmsg->desired_replication_level = htonl(desired_replication_level);
      mmsg->get_path_length = htonl(path_length);
      memcpy (&mmsg->key, key, sizeof (struct GNUNET_HashCode));
      msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
      if (path_length > 0)
        memcpy (msg_path, path,
                path_length * sizeof (struct GNUNET_PeerIdentity));
      add_pending_message (m->client, pm);
    }
  }
  GNUNET_free_non_null (cl);
}
开发者ID:claudiuolteanu,项目名称:gnunet-1,代码行数:70,代码来源:gnunet-service-xdht_clients.c


示例7: GNUNET_SECRETSHARING_share_read

/**
 * Read a share from its binary representation.
 *
 * @param data Binary representation of the share.
 * @param len Length of @a data.
 * @param[out] readlen Number of bytes read,
 *             ignored if NULL.
 * @return The share, or NULL on error.
 */
struct GNUNET_SECRETSHARING_Share *
GNUNET_SECRETSHARING_share_read (const void *data,
                                 size_t len,
                                 size_t *readlen)
{
  struct GNUNET_SECRETSHARING_Share *share;
  const struct GNUNET_SECRETSHARING_ShareHeaderNBO *sh = data;
  char *p;
  size_t n;
  uint16_t payload_size;

  payload_size = ntohs (sh->num_peers) *
      (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) +
       sizeof (struct GNUNET_PeerIdentity));

  if (NULL != readlen)
    *readlen = payload_size + sizeof *sh;

  share = GNUNET_malloc (sizeof *share);

  share->threshold = ntohs (sh->threshold);
  share->num_peers = ntohs (sh->num_peers);
  share->my_peer = ntohs (sh->my_peer);

  share->my_share = sh->my_share;
  share->public_key = sh->public_key;

  p = (void *) &sh[1];

  n = share->num_peers * sizeof (struct GNUNET_PeerIdentity);
  share->peers = GNUNET_malloc (n);
  memcpy (share->peers, p, n);
  p += n;

  n = share->num_peers * sizeof (struct GNUNET_SECRETSHARING_FieldElement);
  share->sigmas = GNUNET_malloc (n);
  memcpy (share->sigmas, p, n);
  p += n;

  n = share->num_peers * sizeof (uint16_t);
  share->original_indices = GNUNET_malloc (n);
  memcpy (share->original_indices, p, n);

  return share;
}
开发者ID:tg-x,项目名称:gnunet,代码行数:54,代码来源:secretsharing_common.c


示例8: print_peer_info

/**
 * Print information about the peer.
 * Currently prints the GNUNET_PeerIdentity and the transport address.
 *
 * @param cls the 'struct PrintContext'
 * @param peer identity of the peer 
 * @param hello addresses of the peer
 * @param err_msg error message
 */
static void
print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
  struct GNUNET_CRYPTO_HashAsciiEncoded enc;
  struct PrintContext *pc;

  if (NULL == peer)
  {
    pic = NULL; /* end of iteration */
    if (NULL != err_msg)
    {
      FPRINTF (stderr, 
	       _("Error in communication with PEERINFO service: %s\n"),
	       err_msg);
    }
    if (NULL == pc_head)
      tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
    return;
  }
  if ((GNUNET_YES == be_quiet) || (NULL == hello))
  {
    GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
    printf ("%s\n", (const char *) &enc);
    return;
  }
  pc = GNUNET_malloc (sizeof (struct PrintContext));
  GNUNET_CONTAINER_DLL_insert (pc_head,
			       pc_tail, 
			       pc);
  pc->peer = *peer;
  GNUNET_HELLO_iterate_addresses (hello, 
				  GNUNET_NO, 
				  &count_address, 
				  pc);
  if (0 == pc->off)
  {
    dump_pc (pc);
    return;
  }
  pc->address_list_size = pc->off;
  pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off);
  GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, 
				  &print_address, pc);
}
开发者ID:amatus,项目名称:gnunet-debian,代码行数:54,代码来源:gnunet-peerinfo.c


示例9: get_my_cnf_path

/**
 * Obtain the location of ".my.cnf".
 *
 * @param cfg our configuration
 * @param section the section
 * @return NULL on error
 */
static char *
get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
                 const char *section)
{
  char *cnffile;
  char *home_dir;
  struct stat st;

#ifndef WINDOWS
  struct passwd *pw;
#endif
  int configured;

#ifndef WINDOWS
  pw = getpwuid (getuid ());
  if (!pw)
  {
    GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid");
    return NULL;
  }
  if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG"))
  {
    GNUNET_assert (GNUNET_OK ==
                   GNUNET_CONFIGURATION_get_value_filename (cfg, section,
                                                            "CONFIG",
                                                            &cnffile));
    configured = GNUNET_YES;
  }
  else
  {
    home_dir = GNUNET_strdup (pw->pw_dir);
    GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
    GNUNET_free (home_dir);
    configured = GNUNET_NO;
  }
#else
  home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
  plibc_conv_to_win_path ("~/", home_dir);
  GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
  GNUNET_free (home_dir);
  configured = GNUNET_NO;
#endif
  GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
                   _("Trying to use file `%s' for MySQL configuration.\n"),
                   cnffile);
  if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
      (!S_ISREG (st.st_mode)))
  {
    if (configured == GNUNET_YES)
      GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
                       _("Could not access file `%s': %s\n"), cnffile,
                       STRERROR (errno));
    GNUNET_free (cnffile);
    return NULL;
  }
  return cnffile;
}
开发者ID:GNUnet,项目名称:gnunet,代码行数:64,代码来源:mysql.c


示例10: dns_pre_request_handler

/**
 * This function is called *before* the DNS request has been 
 * given to a "local" DNS resolver.  Tunneling for DNS requests
 * was enabled, so we now need to send the request via some MESH
 * tunnel to a DNS EXIT for resolution.
 *
 * @param cls closure
 * @param rh request handle to user for reply
 * @param request_length number of bytes in request
 * @param request udp payload of the DNS request
 */
static void 
dns_pre_request_handler (void *cls,
			 struct GNUNET_DNS_RequestHandle *rh,
			 size_t request_length,
			 const char *request)
{
  struct RequestContext *rc;
  size_t mlen;
  struct GNUNET_MessageHeader hdr;
  struct GNUNET_TUN_DnsHeader dns;

  GNUNET_STATISTICS_update (stats,
			    gettext_noop ("# DNS requests intercepted"),
			    1, GNUNET_NO);
  if (0 == dns_exit_available)
  {
    GNUNET_STATISTICS_update (stats,
			      gettext_noop ("# DNS requests dropped (DNS mesh tunnel down)"),
			      1, GNUNET_NO);
    GNUNET_DNS_request_drop (rh);
    return;
  }
  if (request_length < sizeof (dns))
  {
    GNUNET_STATISTICS_update (stats,
			      gettext_noop ("# DNS requests dropped (malformed)"),
			      1, GNUNET_NO);
    GNUNET_DNS_request_drop (rh);
    return;
  }
  memcpy (&dns, request, sizeof (dns));
  GNUNET_assert (NULL != mesh_tunnel);
  mlen = sizeof (struct GNUNET_MessageHeader) + request_length;
  rc = GNUNET_malloc (sizeof (struct RequestContext) + mlen);
  rc->rh = rh;
  rc->mesh_message = (const struct GNUNET_MessageHeader*) &rc[1];
  rc->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
						   &timeout_request,
						   rc);
  rc->dns_id = dns.id;
  hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET);
  hdr.size = htons (mlen);
  memcpy (&rc[1], &hdr, sizeof (struct GNUNET_MessageHeader));
  memcpy (&(((char*)&rc[1])[sizeof (struct GNUNET_MessageHeader)]),
	  request,
	  request_length);
  GNUNET_CONTAINER_DLL_insert_tail (transmit_queue_head,
				    transmit_queue_tail,
				    rc);
  if (NULL == mesh_th)
    mesh_th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel,
						 GNUNET_NO, 0,
						 TIMEOUT,
						 NULL, mlen,
						 &transmit_dns_request_to_mesh,
						 NULL);
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:68,代码来源:gnunet-daemon-pt.c


示例11: GNUNET_DHT_put

/**
 * Perform a PUT operation storing data in the DHT.  FIXME: we should
 * change the protocol to get a confirmation for the PUT from the DHT
 * and call 'cont' only after getting the confirmation; otherwise, the
 * client has no good way of telling if the 'PUT' message actually got
 * to the DHT service!
 *
 * @param handle handle to DHT service
 * @param key the key to store under
 * @param desired_replication_level estimate of how many
 *                nearest peers this request should reach
 * @param options routing options for this message
 * @param type type of the value
 * @param size number of bytes in data; must be less than 64k
 * @param data the data to store
 * @param exp desired expiration time for the value
 * @param timeout how long to wait for transmission of this request
 * @param cont continuation to call when done (transmitting request to service)
 *        You must not call #GNUNET_DHT_disconnect in this continuation
 * @param cont_cls closure for @a cont
 */
struct GNUNET_DHT_PutHandle *
GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
		const struct GNUNET_HashCode * key,
                uint32_t desired_replication_level,
                enum GNUNET_DHT_RouteOption options,
                enum GNUNET_BLOCK_Type type, size_t size,
		const void *data,
                struct GNUNET_TIME_Absolute exp,
                struct GNUNET_TIME_Relative timeout,
		GNUNET_DHT_PutContinuation cont,
                void *cont_cls)
{
  struct GNUNET_DHT_ClientPutMessage *put_msg;
  size_t msize;
  struct PendingMessage *pending;
  struct GNUNET_DHT_PutHandle *ph;


  msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size;
  if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
      (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
  {
    GNUNET_break (0);
    return NULL;
  }
  ph = GNUNET_new (struct GNUNET_DHT_PutHandle);
  ph->dht_handle = handle;
  ph->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_put_request, ph);
  ph->cont = cont;
  ph->cont_cls = cont_cls;
  ph->unique_id = ++handle->uid_gen;
  pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
  ph->pending = pending;
  put_msg = (struct GNUNET_DHT_ClientPutMessage *) &pending[1];
  pending->msg = &put_msg->header;
  pending->handle = handle;
  pending->cont = &mark_put_message_gone;
  pending->cont_cls = ph;
  pending->free_on_send = GNUNET_YES;
  put_msg->header.size = htons (msize);
  put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT);
  put_msg->type = htonl (type);
  put_msg->options = htonl ((uint32_t) options);
  put_msg->desired_replication_level = htonl (desired_replication_level);
  put_msg->unique_id = ph->unique_id;
  put_msg->expiration = GNUNET_TIME_absolute_hton (exp);
  put_msg->key = *key;
  memcpy (&put_msg[1], data, size);
  GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
                               pending);
  pending->in_pending_queue = GNUNET_YES;
  GNUNET_CONTAINER_DLL_insert_tail (handle->put_head,
				    handle->put_tail,
				    ph);
  process_pending_messages (handle);
  return ph;
}
开发者ID:claudiuolteanu,项目名称:gnunet-1,代码行数:78,代码来源:dht_api.c


示例12: create_session

struct Session *
create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
                const void *addr, size_t addrlen)
{
  struct Session *s = NULL;

  GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
                 (addrlen == sizeof (struct IPv4HttpAddress)));
  s = GNUNET_malloc (sizeof (struct Session));
  memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
  s->plugin = plugin;
  s->addr = GNUNET_malloc (addrlen);
  memcpy (s->addr, addr, addrlen);
  s->addrlen = addrlen;
  s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
  start_session_timeout(s);
  return s;
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:18,代码来源:plugin_transport_http.c


示例13: create_record

static struct GNUNET_NAMESTORE_RecordData *
create_record (int count)
{
  int c;
  struct GNUNET_NAMESTORE_RecordData * rd;
  rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));

  for (c = 0; c < RECORDS; c++)
  {
  rd[c].expiration = GNUNET_TIME_absolute_get();
  rd[c].record_type = TEST_RECORD_TYPE;
  rd[c].data_size = TEST_RECORD_DATALEN;
  rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
  memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  }

  return rd;
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:18,代码来源:test_namestore_api_lookup.c


示例14: change_service

/**
 * Start or stop a service.
 *
 * @param h handle to ARM
 * @param service_name name of the service
 * @param timeout how long to wait before failing for good
 * @param cb callback to invoke when service is ready
 * @param cb_cls closure for callback
 * @param type type of the request
 */
static void
change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
		struct GNUNET_TIME_Relative timeout, GNUNET_ARM_ResultCallback cb,
		void *cb_cls, uint16_t type)
{
  struct ARMControlMessage *cm;
  size_t slen;
  struct GNUNET_ARM_Message *msg;

  slen = strlen (service_name) + 1;
  if (slen + sizeof (struct GNUNET_ARM_Message) >=
      GNUNET_SERVER_MAX_MESSAGE_SIZE)
  {
    GNUNET_break (0);
    if (cb != NULL)
      cb (cb_cls, GNUNET_ARM_REQUEST_TOO_LONG, NULL, 0);
    return;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting %s of service `%s'.\n",
       (GNUNET_MESSAGE_TYPE_ARM_START == type) ? "start" : "termination",
       service_name);
  cm = GNUNET_malloc (sizeof (struct ARMControlMessage) + slen);
  cm->h = h;
  cm->result_cont = cb;
  cm->cont_cls = cb_cls;
  cm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
  memcpy (&cm[1], service_name, slen);
  msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message) + slen);
  msg->header.size = htons (sizeof (struct GNUNET_ARM_Message) + slen);
  msg->header.type = htons (type);
  msg->reserved = htonl (0);
  memcpy (&msg[1], service_name, slen);
  cm->msg = msg;
  LOG (GNUNET_ERROR_TYPE_DEBUG,
      "Inserting a control message into the queue. Timeout is %s\n",
       GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (cm->timeout),
					       GNUNET_NO));
  GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
                                    h->control_pending_tail, cm);
  cm->timeout_task_id =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
                                    (cm->timeout), &control_message_timeout, cm);
  trigger_next_request (h, GNUNET_NO);
}
开发者ID:claudiuolteanu,项目名称:gnunet-1,代码行数:54,代码来源:arm_api.c


示例15: get_regex

/**
 * Transform topics to regex expression.
 *
 * @param topic topic of subscription as provided by the subscriber
 * @param regex_topic client identification of the client
 */
static void
get_regex (char *topic,
	   char **regex_topic)
{
  char *plus;
  char *hash;
  char *prefixed_topic;
  int i;
  int j;
  int k;
  int plus_counter = 0;
  int hash_exists = 0;

  plus = strchr(topic,'+');
  while (plus != NULL)
  {
    plus_counter +=1;
    plus=strchr(plus+1,'+');
  }
  hash = strchr(topic,'#');
  if (hash != NULL)
  {
    hash_exists = 1;
  }

  add_prefix(topic, &prefixed_topic);

  *regex_topic = GNUNET_malloc (strlen(prefixed_topic) - plus_counter - hash_exists + plus_counter*strlen(plus_regex) + hash_exists*strlen(hash_regex)+1);
  j = 0;
  for (i = 0; prefixed_topic[i] != '\0'; i++)
  {
    if (prefixed_topic[i] == '+')
    {
      for (k = 0; k<strlen(plus_regex); k++)
      {
	(*regex_topic)[j] = plus_regex[k];
	j++;
      }
    }
    else if (prefixed_topic[i] == '#')
    {
      j--;
      for (k = 0; k<strlen(hash_regex); k++)
      {
	(*regex_topic)[j] = hash_regex[k];
	j++;
      }
    }
    else
    {
      (*regex_topic)[j] = prefixed_topic[i];
      j++;
    }
  }
  (*regex_topic)[j] = '\0';
}
开发者ID:vsaw,项目名称:gnunet-mqtt,代码行数:62,代码来源:gnunet-service-mqtt.c


示例16: EnumNICs2

int
EnumNICs2 (INTERFACE_INFO **ifs4, int *ifs4_len, SOCKET_ADDRESS_LIST **ifs6)
{
  int result = 0;
  SOCKET s4;
  SOCKET s6;
  int ifs4len = 0;
  int ifs6len = 0;
  INTERFACE_INFO *interfaces4 = NULL;
  SOCKET_ADDRESS_LIST *interfaces6 = NULL;

  SetLastError (0);
  s4 = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
  (void) GetLastError ();
  SetLastError (0);
  s6 = socket (AF_INET6, SOCK_STREAM, IPPROTO_TCP);
  (void) GetLastError ();
  if (s6 != INVALID_SOCKET)
  {
    ifs6len = EnumNICs_IPv6_get_ifs_count (s6);
    if (ifs6len > 0)
    {
      interfaces6 = (SOCKET_ADDRESS_LIST *) GNUNET_malloc (ifs6len);
      result = EnumNICs_IPv6_get_ifs (s6, interfaces6, ifs6len) || result;
    }
    closesocket (s6);
    s6 = INVALID_SOCKET;
  }

  if (s4 != INVALID_SOCKET)
  {
    result = EnumNICs_IPv4_get_ifs (s4, &interfaces4, &ifs4len) || result;
    closesocket (s4);
    s4 = INVALID_SOCKET;
  }
  if (ifs6len + ifs4len == 0)
    goto error;

  if (!result)
  {
    *ifs4 = interfaces4;
    *ifs4_len = ifs4len;
    *ifs6 = interfaces6;
    return GNUNET_OK;
  }
error:
  if (interfaces4 != NULL)
    GNUNET_free (interfaces4);
  if (interfaces6 != NULL)
    GNUNET_free (interfaces6);
  if (s4 != INVALID_SOCKET)
    closesocket (s4);
  if (s6 != INVALID_SOCKET)
    closesocket (s6);
  return GNUNET_SYSERR;
}
开发者ID:tg-x,项目名称:gnunet,代码行数:56,代码来源:win.c


示例17: GNUNET_PEERINFO_connect

/**
 * Connect to the peerinfo service.
 *
 * @param cfg configuration to use
 * @return NULL on error (configuration related, actual connection
 *         establishment may happen asynchronously).
 */
struct GNUNET_PEERINFO_Handle *
GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_PEERINFO_Handle *h;

  h = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle));
  h->client = GNUNET_CLIENT_connect ("peerinfo", cfg);
  h->cfg = cfg;
  return h;
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:17,代码来源:peerinfo_api.c


示例18: GNUNET_DNSSTUB_start

/**
 * Start a DNS stub resolver.
 *
 * @param dns_ip target IP address to use
 * @return NULL on error
 */
struct GNUNET_DNSSTUB_Context *
GNUNET_DNSSTUB_start (const char *dns_ip)
{
  struct GNUNET_DNSSTUB_Context *ctx;
  
  ctx = GNUNET_malloc (sizeof (struct GNUNET_DNSSTUB_Context));
  if (NULL != dns_ip)
    ctx->dns_exit = GNUNET_strdup (dns_ip);
  return ctx;
}
开发者ID:amatus,项目名称:gnunet-debian,代码行数:16,代码来源:dnsstub.c


示例19: GNUNET_GNS_connect

/**
 * Initialize the connection with the GNS service.
 *
 * @param cfg configuration to use
 * @return handle to the GNS service, or NULL on error
 */
struct GNUNET_GNS_Handle *
GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_GNS_Handle *handle;

  handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
  handle->cfg = cfg;
  reconnect (handle);
  return handle;
}
开发者ID:amatus,项目名称:gnunet-debian,代码行数:16,代码来源:gns_api.c


示例20: GNUNET_LOAD_value_init

/**
 * Create a new load value.
 *
 * @param autodecline speed at which this value should automatically
 *        decline in the absence of external events; at the given
 *        frequency, 0-load values will be added to the load
 * @return the new load value
 */
struct GNUNET_LOAD_Value *
GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline)
{
  struct GNUNET_LOAD_Value *ret;

  ret = GNUNET_malloc (sizeof (struct GNUNET_LOAD_Value));
  ret->autodecline = autodecline;
  ret->last_update = GNUNET_TIME_absolute_get ();
  return ret;
}
开发者ID:amatus,项目名称:gnunet-debian,代码行数:18,代码来源:load.c



注:本文中的GNUNET_malloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GNUNET_strdup函数代码示例发布时间:2022-05-30
下一篇:
C++ GNUNET_i2s函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap