diff options
| author | Christian Grothoff <christian@grothoff.org> | 2020-11-15 12:27:26 +0100 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2020-11-15 12:27:26 +0100 | 
| commit | bf7a660ec0278e56eea0bce413c61a2ba0daeca2 (patch) | |
| tree | 1a40986846e4d056654843d257fde9d8b20d493f /src | |
| parent | b8e35aaed0dc92e1dc1569f0c09ca4e4c36775b9 (diff) | |
implement notfiy_client_dk_add
Diffstat (limited to 'src')
| -rw-r--r-- | src/util/Makefile.am | 1 | ||||
| -rw-r--r-- | src/util/taler-helper-crypto-rsa.c | 58 | ||||
| -rw-r--r-- | src/util/taler-helper-crypto-rsa.h | 2 | 
3 files changed, 53 insertions, 8 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 991f0a95..e8ad9c4d 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -38,6 +38,7 @@ taler_helper_crypto_rsa_SOURCES = \  taler_helper_crypto_rsa_LDADD = \    libtalerutil.la \    -lgnunetutil \ +  -lpthread \    $(LIBGCRYPT_LIBS) \    $(XLIB) diff --git a/src/util/taler-helper-crypto-rsa.c b/src/util/taler-helper-crypto-rsa.c index a4e08221..a26ac3f4 100644 --- a/src/util/taler-helper-crypto-rsa.c +++ b/src/util/taler-helper-crypto-rsa.c @@ -290,25 +290,69 @@ read_job (void *cls)  /**   * Notify @a client about @a dk becoming available.   * - * @param client the client to notify + * @param[in,out] client the client to notify; possible freed if transmission fails   * @param dk the key to notify @a client about   * @return #GNUNET_OK on success   */  static int -notify_client_dk_add (const struct Client *client, +notify_client_dk_add (struct Client *client,                        const struct DenominationKey *dk)  {    struct TALER_CRYPTO_RsaKeyAvailableNotification *an; - -  // FIXME: send msg! -  return GNUNET_SYSERR; +  struct Denomination *denom = dk->denom; +  size_t nlen = strlen (denom->section) + 1; +  size_t buf_len; +  void *buf; +  void *p; +  ssize_t ret; +  size_t tlen; + +  buf_len = GNUNET_CRYPTO_rsa_public_key_encode (dk->denom_pub.rsa_public_key, +                                                 &buf); +  GNUNET_assert (buf_len < UINT16_MAX); +  GNUNET_assert (nlen < UINT16_MAX); +  tlen = buf_len + nlen + sizeof (*an); +  GNUNET_assert (tlen < UINT16_MAX); +  an = GNUNET_malloc (tlen); +  an->header.size = htons ((uint16_t) tlen); +  an->header.type = htons (TALER_HELPER_RSA_MT_AVAIL); +  an->pub_size = htons ((uint16_t) buf_len); +  an->section_name_len = htons ((uint16_t) nlen); +  an->anchor_time = GNUNET_TIME_absolute_hton (dk->anchor); +  an->duration_withdraw = GNUNET_TIME_relative_hton (denom->duration_withdraw); +  p = (void *) &an[1]; +  memcpy (p, +          buf, +          buf_len); +  GNUNET_free (buf); +  memcpy (p + buf_len, +          denom->section, +          nlen); +  ret = send (GNUNET_NETWORK_get_fd (client->sock), +              an, +              tlen, +              0); +  if (tlen != ret) +  { +    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, +                         "send"); +    GNUNET_free (an); +    GNUNET_NETWORK_socket_close (client->sock); +    GNUNET_CONTAINER_DLL_remove (clients_head, +                                 clients_tail, +                                 client); +    GNUNET_free (client); +    return GNUNET_SYSERR; +  } +  GNUNET_free (an); +  return GNUNET_OK;  }  /**   * Notify @a client about @a dk being purged.   * - * @param client the client to notify + * @param[in,out] client the client to notify; possible freed if transmission fails   * @param dk the key to notify @a client about   * @return #GNUNET_OK on success   */ @@ -1246,7 +1290,7 @@ main (int argc,    };    int ret; -  umask (S_IWGRP | S_IROTH | S_IWOTH | S_IXOTH); +  (void) umask (S_IWGRP | S_IROTH | S_IWOTH | S_IXOTH);    /* force linker to link against libtalerutil; if we do     not do this, the linker may "optimize" libtalerutil     away and skip #TALER_OS_init(), which we do need */ diff --git a/src/util/taler-helper-crypto-rsa.h b/src/util/taler-helper-crypto-rsa.h index 6dbf26af..3715c17c 100644 --- a/src/util/taler-helper-crypto-rsa.h +++ b/src/util/taler-helper-crypto-rsa.h @@ -44,7 +44,7 @@ struct TALER_CRYPTO_RsaKeyAvailableNotification    /**     * Number of bytes of the section name.     */ -  uint16_t section_name; +  uint16_t section_name_len;    /**     * When does the key become available?  | 
