diff options
Diffstat (limited to 'src/exchange-lib')
| -rw-r--r-- | src/exchange-lib/Makefile.am | 1 | ||||
| -rw-r--r-- | src/exchange-lib/exchange_api_deposit.c | 53 | ||||
| -rw-r--r-- | src/exchange-lib/exchange_api_handle.c | 129 | ||||
| -rw-r--r-- | src/exchange-lib/exchange_api_handle.h | 32 | 
4 files changed, 212 insertions, 3 deletions
| diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am index 4b1105d5..6b64ea65 100644 --- a/src/exchange-lib/Makefile.am +++ b/src/exchange-lib/Makefile.am @@ -27,6 +27,7 @@ libtalerexchange_la_SOURCES = \    exchange_api_track_transfer.c \    exchange_api_wire.c  libtalerexchange_la_LIBADD = \ +  $(top_builddir)/src/auditor-lib/libtalerauditor.la \    $(top_builddir)/src/json/libtalerjson.la \    $(top_builddir)/src/util/libtalerutil.la \    -lgnunetcurl \ diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c index 4b92dea2..23066c7d 100644 --- a/src/exchange-lib/exchange_api_deposit.c +++ b/src/exchange-lib/exchange_api_deposit.c @@ -27,6 +27,7 @@  #include <gnunet/gnunet_json_lib.h>  #include <gnunet/gnunet_curl_lib.h>  #include "taler_json_lib.h" +#include "taler_auditor_service.h"  #include "taler_exchange_service.h"  #include "exchange_api_handle.h"  #include "taler_signatures.h" @@ -83,11 +84,30 @@ struct TALER_EXCHANGE_DepositHandle     * Total value of the coin being transacted with.     */    struct TALER_Amount coin_value; - +    };  /** + * Signature of functions called with the result from our call to the + * auditor's /deposit-confirmation handler. + * + * @param cls closure + * @param http_status HTTP status code, 200 on success + * @param ec taler protocol error status code, 0 on success + * @param json raw json response + */ +static void +acc_confirmation_cb (void *cls, +		     unsigned int http_status, +		     enum TALER_ErrorCode ec, +		     const json_t *json) +{ +  /* FIXME: clean up state, some logging on errors! */ +} + + +/**   * Verify that the signature on the "200 OK" response   * from the exchange is valid.   * @@ -135,6 +155,37 @@ verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,      GNUNET_break_op (0);      return GNUNET_SYSERR;    } +  if (0 /* #5447: replace with "for all auditors, if auditor selected for DC notification... */) +  { +    struct TALER_AUDITOR_DepositConfirmationHandle *dch; +    const struct TALER_EXCHANGE_SigningPublicKey *spk; +    struct TALER_Amount amount_without_fee; +     +    spk = TALER_EXCHANGE_get_signing_key_details (key_state, +						  exchange_pub); +    GNUNET_assert (NULL != spk); +    TALER_amount_ntoh (&amount_without_fee, +		       &dh->depconf.amount_without_fee); +    dch = TALER_AUDITOR_deposit_confirmation (NULL /* FIXME: auditor */, +					      &dh->depconf.h_wire, +					      &dh->depconf.h_contract_terms, +					      GNUNET_TIME_absolute_ntoh (dh->depconf.timestamp), +					      GNUNET_TIME_absolute_ntoh (dh->depconf.refund_deadline), +					      &amount_without_fee, +					      &dh->depconf.coin_pub, +					      &dh->depconf.merchant, +					      exchange_pub, +					      exchange_sig, +					      &key_state->master_pub, +					      spk->valid_from, +					      spk->valid_until, +					      spk->valid_legal, +					      &spk->master_sig, +					      &acc_confirmation_cb, +					      NULL /* FIXME: context! */); +  } + +      return GNUNET_OK;  } diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index f6a5807e..afaabd85 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -28,6 +28,7 @@  #include <gnunet/gnunet_curl_lib.h>  #include "taler_json_lib.h"  #include "taler_exchange_service.h" +#include "taler_auditor_service.h"  #include "taler_signatures.h"  #include "exchange_api_handle.h"  #include "curl_defaults.h" @@ -91,6 +92,77 @@ struct KeysRequest;  /** + * Entry in list of ongoing interactions with an auditor. + */ +struct AuditorInteractionEntry +{ +  /** +   * DLL entry. +   */ +  struct AuditorInteractionEntry *next; +   +  /** +   * DLL entry. +   */ +  struct AuditorInteractionEntry *prev; + +  /** +   * Interaction state. +   */ +  struct TALER_AUDITOR_DepositConfirmationHandle *dch; +}; + + +/** + * Entry in DLL of auditors used by an exchange. + */ +struct AuditorListEntry +{ +  /** +   * Next pointer of DLL. +   */ +  struct AuditorListEntry *next; + +  /** +   * Prev pointer of DLL. +   */ +  struct AuditorListEntry *prev; + +  /** +   * Base URL of the auditor. +   */ +  const char *auditor_url; + +  /** +   * Handle to the auditor. +   */ +  struct TALER_AUDITOR_Handle *ah; + +  /** +   * Head of DLL of interactions with this auditor. +   */ +  struct AuditorInteractionEntry *ai_head; +   +  /** +   * Tail of DLL of interactions with this auditor. +   */ +  struct AuditorInteractionEntry *ai_tail; + +  /** +   * Public key of the auditor. +   */ +  struct TALER_AuditorPublicKeyP auditor_pub; + +  /** +   * Flag indicating that the auditor is available and that protocol +   * version compatibility is given. +   */ +  int is_up; +   +}; + + +/**   * Handle to the exchange   */  struct TALER_EXCHANGE_Handle @@ -134,6 +206,16 @@ struct TALER_EXCHANGE_Handle    json_t *key_data_raw;    /** +   * Head of DLL of auditors of this exchange. +   */ +  struct AuditorListEntry *auditors_head; + +  /** +   * Tail of DLL of auditors of this exchange. +   */ +  struct AuditorListEntry *auditors_tail; +   +  /**     * Key data of the exchange, only valid if     * @e handshake_complete is past stage #MHS_CERT.     */ @@ -152,8 +234,8 @@ struct TALER_EXCHANGE_Handle    /**     * Stage of the exchange's initialization routines.     */ -  enum ExchangeHandleState state; - +  enum ExchangeHandleState state;   +    }; @@ -189,6 +271,24 @@ struct KeysRequest  /** + * Iterate over all available auditors for @a h, calling + * @param ah and giving it a chance to start a deposit + * confirmation interaction. + * + * @param h exchange to go over auditors for + * @param ac function to call per auditor + * @param ac_cls closure for @a ac + */ +void +TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h, +			  TEAH_AuditorCallback ac, +			  void *ac_cls) +{ +  // FIXME! +} + + +/**   * Release memory occupied by a keys request.   * Note that this does not cancel the request   * itself. @@ -1542,6 +1642,30 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange)  /** + * Lookup the given @a pub in @a keys. + * + * @param keys the exchange's key set + * @param pub claimed current online signing key for the exchange + * @return NULL if @a pub was not found + */ +const struct TALER_EXCHANGE_SigningPublicKey * +TALER_EXCHANGE_get_signing_key_details (const struct TALER_EXCHANGE_Keys *keys, +					const struct TALER_ExchangePublicKeyP *pub) +{ +  for (unsigned int i=0;i<keys->num_sign_keys;i++) +  { +    struct TALER_EXCHANGE_SigningPublicKey *spk = &keys->sign_keys[i]; +     +    if (0 == memcmp (pub, +		     &spk->key, +		     sizeof (struct TALER_ExchangePublicKeyP))) +      return spk; +  } +  return NULL; +} + + +/**   * Test if the given @a pub is a the current signing key from the exchange   * according to @a keys.   * @@ -1567,6 +1691,7 @@ TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,    return GNUNET_SYSERR;  } +  /**   * Get exchange's base URL.   * diff --git a/src/exchange-lib/exchange_api_handle.h b/src/exchange-lib/exchange_api_handle.h index 8c439273..f06fa4ee 100644 --- a/src/exchange-lib/exchange_api_handle.h +++ b/src/exchange-lib/exchange_api_handle.h @@ -21,7 +21,39 @@   */  #include "platform.h"  #include <gnunet/gnunet_curl_lib.h> +#include "taler_auditor_service.h"  #include "taler_exchange_service.h" +#include "taler_crypto_lib.h" + + +/** + * Function called for each auditor to give us a chance to possibly + * launch a deposit confirmation interaction.   + *  + * @param cls closure + * @param ah handle to the auditor + * @param auditor_pub public key of the auditor + * @return NULL if no deposit confirmation interaction was launched + */ +typedef struct TALER_AUDITOR_DepositConfirmationHandle * +(*TEAH_AuditorCallback)(void *cls, +			struct TALER_AUDITOR_Handle *ah, +			const struct TALER_AuditorPublicKeyP *auditor_pub); + + +/** + * Iterate over all available auditors for @a h, calling + * @param ah and giving it a chance to start a deposit + * confirmation interaction. + * + * @param h exchange to go over auditors for + * @param ac function to call per auditor + * @param ac_cls closure for @a ac + */ +void +TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h, +			  TEAH_AuditorCallback ac, +			  void *ac_cls);  /** | 
