libbrandt/brandt.h

267 lines
10 KiB
C
Raw Permalink Normal View History

2016-05-17 22:03:26 +02:00
/* This file is part of libbrandt.
2016-05-27 13:56:03 +02:00
* Copyright (C) 2016 GNUnet e.V.
2016-05-17 22:03:26 +02:00
*
* libbrandt is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file brandt.h
* @brief This Header defines the external interface of libbrandt.
2016-06-22 23:18:46 +02:00
* @author Markus Teich
2016-05-17 22:03:26 +02:00
*/
#ifndef _BRANDT_BRANDT_H
#define _BRANDT_BRANDT_H
2016-06-12 20:52:22 +02:00
#include <stdint.h>
2016-07-06 14:56:14 +02:00
#include <unistd.h>
2016-06-12 20:52:22 +02:00
2016-07-13 14:01:24 +02:00
#include <gnunet/gnunet_util_lib.h>
2016-12-02 11:45:19 +01:00
/** opaque, defined in internals.h */
struct BRANDT_Auction;
2016-08-31 14:37:22 +02:00
/** Enumeration of all possible status reports for a single bidder */
enum BRANDT_BidderStatus
{
BRANDT_bidder_won,
2016-08-31 14:37:22 +02:00
};
/**
* An array of this struct is given to the application by the BRANDT_CbResult()
* callback. One instance represents the status of a single bidder.
*/
struct BRANDT_Result
{
/** Id of the bidder this instance refers to */
uint16_t bidder;
2016-08-31 14:37:22 +02:00
/** The price the bidder has to pay. This value is only set if the #status
* indicates the bidder has won. */
uint16_t price;
2016-08-31 14:37:22 +02:00
/** Status of the bidder */
enum BRANDT_BidderStatus status;
2016-08-31 14:37:22 +02:00
};
/**
* Functions of this type are called by libbrandt when the auction should be
2016-11-04 16:41:14 +01:00
* started as a seller. The application has to broadcast the ordered list of all
* bidders to the bidders and must return the amount of bidders to libbrandt.
* After this function is called no more new bidders may be accepted by the
* application.
*
* @param[in] auction_closure Closure pointer representing the respective
* auction. This is the Pointer given to BRANDT_new().
* @return The amount of bidders participating in the auction.
*/
typedef uint16_t
(*BRANDT_CbStart)(void *auction_closure);
2016-05-17 22:03:26 +02:00
/**
2016-12-02 11:45:05 +01:00
* Functions of this type are called by libbrandt to deliver messages to other
* participants of an auction. There are two variants how this Callback needs to
* be implemented. The first is delivering messages as unicast directly to the
* seller, the second is delivering messages as broadcast to all participants
* (bidders + seller). All messages need to be authenticated and encrypted
* before sending and the signature needs to be checked immediately after
* receipt.
2016-05-17 22:03:26 +02:00
*
* @param[in] auction_closure Closure pointer representing the respective
2016-12-02 11:45:05 +01:00
* auction. This is the Pointer given to BRANDT_join() / BRANDT_new().
* @param[in] msg The message to be delivered
2016-12-02 12:18:35 +01:00
* @param[in] msg_len The length of the message @a msg in byte.
2016-05-27 13:56:03 +02:00
* @return 0 on success, -1 on failure.
2016-05-17 22:03:26 +02:00
*/
2016-05-17 23:52:56 +02:00
typedef int
2016-12-02 11:45:05 +01:00
(*BRANDT_CbDeliver)(void *auction_closure,
2016-07-06 14:56:14 +02:00
const void *msg,
size_t msg_len);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +02:00
/**
* Functions of this type are called by libbrandt to report the auction outcome
2016-05-27 13:56:03 +02:00
* or malicious/erroneous participants.
2016-05-17 22:03:26 +02:00
*
2016-08-31 14:37:22 +02:00
* \todo: export *proof* of erroneous behaviour / outcome.
2016-05-17 22:03:26 +02:00
*
* @param[in] auction_closure Closure pointer representing the respective
2016-05-27 13:56:03 +02:00
* auction. This is the Pointer given to BRANDT_join() / BRANDT_new().
2016-08-31 14:37:22 +02:00
* @param[in] results An array of results for one or more bidders. Each bidder
* will only be listed once. Misbehaving bidder results and auction completion
* results are not mixed.
* @param[in] results_len Amount of items in @a results.
2016-05-17 22:03:26 +02:00
*/
2016-05-17 23:52:56 +02:00
typedef void
2016-08-31 14:37:22 +02:00
(*BRANDT_CbResult)(void *auction_closure,
struct BRANDT_Result results[],
uint16_t results_len);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +02:00
2016-06-12 20:52:22 +02:00
void
BRANDT_init ();
2016-06-12 20:52:22 +02:00
2016-08-16 13:25:03 +02:00
/**
* Parse an auction description data block. See BRANDT_new()
2016-08-16 13:25:03 +02:00
* for an explanation of the different auction description fields.
*
* @param[in] auction_desc The auction description blob published by the seller.
2016-12-02 12:18:35 +01:00
* @param[in] auction_desc_len Length of @a auction_desc in byte.
2016-08-16 13:25:03 +02:00
* @param[out] time_start Starting time of the auction. May be NULL.
* @param[out] time_round Maximum round time of the auction. May be NULL.
* @param[out] num_prices Amount of possible prices. May be NULL.
* @param[out] m Auction mode. May be NULL.
* @param[out] outcome_public Outcome setting. May be NULL.
2016-12-02 11:45:19 +01:00
* @return 0 on success, -1 on failure.
2016-08-16 13:25:03 +02:00
*/
int
BRANDT_parse_desc (const void *auction_desc,
size_t auction_desc_len,
struct GNUNET_TIME_Absolute *time_start,
struct GNUNET_TIME_Relative *time_round,
uint16_t *num_prices,
uint16_t *m,
uint16_t *outcome_public);
2016-08-16 13:25:03 +02:00
2016-05-17 22:03:26 +02:00
/**
2016-08-16 13:25:03 +02:00
* Join an auction described by the @a auction_desc parameter.
2016-05-17 23:52:56 +02:00
*
2016-12-02 11:45:19 +01:00
* @param[in] result Pointer to the result callback function
2016-05-17 22:03:26 +02:00
* @param[in] broadcast Pointer to the broadcast callback function
* @param[in] unicast Pointer to the unicast callback function
* @param[in] auction_closure Closure pointer representing the auction. This
* will not be touched by libbrandt itself. It is only passed to the callbacks.
2016-08-16 13:25:03 +02:00
* @param[in] auction_desc The auction information data published by the seller.
* This is opaque to the application. Its content will be parsed. The
* application MUST check the signature on this data block before passing it to
* libbrandt!
* @param[in] auction_desc_len The length in byte of the @a auction_desc
2016-05-17 22:03:26 +02:00
* structure.
2016-12-02 11:45:19 +01:00
* @param[in] bid How much to bid on this auction.
* @param[in] dlogctx The discrete log context obtained from
* GNUNET_CRYPTO_ecc_dlog_prepare(). Only needed for M+1st price auctions.
2016-05-17 22:03:26 +02:00
* @return A pointer, which should only be remembered and passed to
* libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT dereference/change it or the data it points to!
2016-05-17 22:03:26 +02:00
*/
2016-05-17 23:52:56 +02:00
struct BRANDT_Auction *
BRANDT_join (BRANDT_CbResult result,
BRANDT_CbDeliver broadcast,
BRANDT_CbDeliver unicast,
void *auction_closure,
const void *auction_desc,
size_t auction_desc_len,
uint16_t bid,
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
2016-06-12 01:13:03 +02:00
2016-06-19 23:21:01 +02:00
/* \todo: have cancellation (BRANDT_join_cancel()) */
2016-05-17 22:03:26 +02:00
/**
2016-11-04 16:42:59 +01:00
* Create a new auction described by the @a auction_desc parameter as seller.
2016-05-17 23:52:56 +02:00
*
2016-07-06 14:56:14 +02:00
* @param[in] result Pointer to the result callback function
2016-12-02 11:45:19 +01:00
* @param[in] broadcast Pointer to the broadcast callback function
* @param[in] start Pointer to the seller start callback function
2016-05-17 22:03:26 +02:00
* @param[in] auction_closure Closure pointer representing the auction. This
* will not be touched by libbrandt. It is only passed to the callbacks.
* @param[out] auction_desc The auction information data as an opaque data
* structure. It is generated by this function and should be distributed to
* all possibly interested bidders. The seller MUST sign this data block before
* publishing it!
2016-12-02 12:18:35 +01:00
* @param[out] auction_desc_len The length in byte of the @a auction_desc
* structure. Will be filled by BRANDT_new().
2016-11-23 23:44:28 +01:00
* @param[in] time_start The time when the auction will start. Bidders have
* until then to register.
* @param[in] time_round The maximum duration of each round in the protocol.
2016-05-17 22:03:26 +02:00
* @param[in] num_prices The amount of possible valuations for the sold item(s).
2016-12-02 11:04:45 +01:00
* Must be > 0.
2016-05-17 22:03:26 +02:00
* @param[in] m The mode of the auction. If 0, it will be a first price auction
* where the winner has to pay the price of his bid. If >0 it will be a second
* price auction selling exactly that amount of items and each winner has to pay
2016-12-02 11:04:45 +01:00
* the price of the highest loosing bid.
2016-05-17 22:03:26 +02:00
* @param[in] outcome_public If 1, the auction winner and price will be public
* to all participants, if 0, this information will only be revealed to the
2016-06-20 00:36:18 +02:00
* winner and the seller.
* @param[in] dlogctx The discrete log context obtained from
* GNUNET_CRYPTO_ecc_dlog_prepare(). Only needed for M+1st price auctions.
* @return If invalid parameters are passed, NULL is returned. Else the return
* value is a pointer, which should only be remembered and passed to
2016-05-17 22:03:26 +02:00
* libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT dereference/change it or the data it points to!
2016-05-17 22:03:26 +02:00
*/
2016-05-17 23:52:56 +02:00
struct BRANDT_Auction *
BRANDT_new (BRANDT_CbResult result,
BRANDT_CbDeliver broadcast,
BRANDT_CbStart start,
void *auction_closure,
void **auction_desc,
size_t *auction_desc_len,
struct GNUNET_TIME_Absolute time_start,
struct GNUNET_TIME_Relative time_round,
uint16_t num_prices,
uint16_t m,
int outcome_public,
struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +02:00
2016-08-12 14:38:10 +02:00
/**
2016-08-17 23:53:49 +02:00
* This function must be called when bidding after receipt of the start
2016-08-19 22:24:49 +02:00
* notification from the seller.
2016-08-17 23:53:49 +02:00
*
* @param[in] auction The pointer returned by BRANDT_join().
2016-08-31 14:37:22 +02:00
* @param[in] i The index of this bidder assigned by the seller (from the start
* announcement message).
2016-08-17 23:53:49 +02:00
* @param[in] n The amount of bidders (from the start announcement message).
2016-08-19 22:24:49 +02:00
*/
void
BRANDT_bidder_start (struct BRANDT_Auction *auction,
uint16_t i,
uint16_t n);
2016-08-17 23:53:49 +02:00
2016-08-19 22:24:49 +02:00
/**
2016-08-12 14:38:10 +02:00
* Clean up this auction on shutdown.
*
* @param[in] auction The pointer returned by BRANDT_join() or BRANDT_new().
2016-12-02 11:04:45 +01:00
*/
2016-05-17 23:52:56 +02:00
void
2016-08-12 14:38:10 +02:00
BRANDT_destroy (struct BRANDT_Auction *auction);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +02:00
/**
2016-07-06 14:56:14 +02:00
* Receive a message related to a specific auction.
2016-05-17 23:52:56 +02:00
*
2016-08-03 14:07:21 +02:00
* If the message is from a future round and cannot be processed yet, it is
* cached in RAM. It will not be stored on disc until it can be used, since the
* messages completing the previous round should all arrive relatively soon.
*
2016-07-06 14:56:14 +02:00
* @param[in] auction The pointer returned by BRANDT_join() or BRANDT_new() from
* which message @a msg was received.
* @param[in] sender The id of the sender.
2016-05-17 22:03:26 +02:00
* @param[in] msg The message that was received.
2016-12-02 12:18:35 +01:00
* @param[in] msg_len The length in byte of @a msg.
2016-05-17 22:03:26 +02:00
*/
2016-05-17 23:52:56 +02:00
void
2016-07-06 14:56:14 +02:00
BRANDT_got_message (struct BRANDT_Auction *auction,
uint16_t sender,
2016-07-06 14:56:14 +02:00
const unsigned char *msg,
size_t msg_len);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +02:00
2016-06-19 23:21:01 +02:00
/**\todo: Error handling functions? */
2016-12-02 11:04:45 +01:00
/* \todo: implement (de)serialization / persistent caching on disk */
2016-05-17 22:03:26 +02:00
2016-06-12 01:13:03 +02:00
#endif /* ifndef _BRANDT_BRANDT_H */