libbrandt/brandt.h

202 lines
8.1 KiB
C
Raw 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-07-06 14:56:14 +02:00
/** defined in internals.h */
2016-05-17 23:52:56 +02:00
struct BRANDT_Auction;
2016-05-17 22:03:26 +02:00
/**
* Functions of this type are called by libbrandt to broadcast messages to the
2016-07-06 14:56:14 +02:00
* blackboard of a specific auction. They have to be sent using authenticated
* encryption.
2016-05-17 22:03:26 +02:00
*
* @param[in] auction_closure Closure pointer representing the respective
* auction. This is the Pointer given to BRANDT_join().
2016-05-17 22:03:26 +02:00
* @param[in] msg The message to be broadcast to all participants of
* @a auction_closure.
* @param[in] msg_len The length of the message @a msg in bytes.
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-07-06 14:56:14 +02:00
(*BRANDT_CbBroadcast)(void *auction_closure,
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 unicast messages to the
2016-07-06 14:56:14 +02:00
* seller of a specific auction. They have to be sent using authenticated
* encryption.
2016-05-17 22:03:26 +02:00
*
* @param[in] auction_closure Closure pointer representing the respective
* auction. This is the Pointer given to BRANDT_join().
2016-05-17 22:03:26 +02:00
* @param[in] msg The message to be sent to the seller of @a auction_closure.
* @param[in] msg_len The length of the message @a msg in bytes.
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-07-06 14:56:14 +02:00
(*BRANDT_CbUnicast)(void *auction_closure,
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-06-19 23:21:01 +02:00
* \todo: export proof of erroneous behaviour.
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().
* @param[in] bidder_id The numeric Id of the bidder this report refers to.
* @param[in] status 1 if the user @a bidder_id has won the auction, 0 if he has
* lost, -1 if erroneous behaviour was detected.
2016-05-17 22:03:26 +02:00
* @param[in] price The price, the winner has to pay or 0 if the auction result
* is private and the user did not win.
*/
2016-05-17 23:52:56 +02:00
typedef void
2016-07-06 14:56:14 +02:00
(*BRANDT_CbResult)(void *auction_closure,
unsigned int bidder_id,
int status,
uint16_t price);
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
2016-07-13 14:01:24 +02:00
BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
2016-06-12 20:52:22 +02:00
2016-05-17 22:03:26 +02:00
/**
* Join an auction described by the @a auction_data parameter.
2016-05-17 23:52:56 +02:00
*
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
2016-07-06 14:56:14 +02:00
* @param[in] result Pointer to the result 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 itself. It is only passed to the callbacks.
* @param[in] auction_data The auction information data published by the seller.
* This is an opaque data structure. It will be parsed and checked by
* BRANDT_join().
2016-05-17 22:03:26 +02:00
* @param[in] auction_data_len The length in bytes of the @a auction_data
* structure.
* @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 *
2016-07-06 14:56:14 +02:00
BRANDT_join (BRANDT_CbBroadcast broadcast,
BRANDT_CbUnicast unicast,
BRANDT_CbResult result,
void *auction_closure,
2016-07-06 14:56:14 +02:00
const void *auction_data,
size_t auction_data_len);
2016-06-19 23:21:01 +02:00
/* \todo: where do I specify my bid? */
2016-06-12 01:13:03 +02:00
2016-06-19 23:21:01 +02:00
/* \todo: Distinguish handles for seller/buyers */
/* \todo: have cancellation (BRANDT_join_cancel()) */
/* \todo: provide means to extract a hash from auction data to */
2016-06-12 01:13:03 +02:00
/* tie cryptographic operations to application-readable proposal */
2016-06-19 23:21:01 +02:00
/* \todo: have separate function to export 'out' variables */
/* \todo: might want to specify timeout? How do we deal with time? */
/* \todo: separate creating an auction from starting it; initial */
2016-06-12 01:13:03 +02:00
/* setup needs more auction proposal details (hash, timeout, */
/* bid structure), later we need to know # participants */
2016-05-17 22:03:26 +02:00
/**
* Create a new auction described by the @a auction_data parameter.
2016-05-17 23:52:56 +02:00
*
2016-05-17 22:03:26 +02:00
* @param[in] broadcast Pointer to the broadcast callback function
2016-07-06 14:56:14 +02:00
* @param[in] result Pointer to the result 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_data The auction information data a an opaque data
* structure. It will be generated by BRANDT_new() and should be distributed to
2016-05-17 22:03:26 +02:00
* all possibly interested bidders.
* @param[out] auction_data_len The length in bytes of the @a auction_data
* structure. Will be filled by BRANDT_new().
2016-05-17 22:03:26 +02:00
* @param[in] num_prices The amount of possible valuations for the sold item(s).
2016-06-19 23:21:01 +02:00
* If 0, a default of 256 will be used. \todo: what about 1, does it work with
2016-05-17 22:03:26 +02:00
* second price auctions?
* @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-06-19 23:21:01 +02:00
* the price of the highest loosing bid. \todo: what if bidders < m?
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.
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 *
2016-08-12 14:38:10 +02:00
BRANDT_new (BRANDT_CbBroadcast broadcast,
BRANDT_CbResult result,
void *auction_closure,
void **auction_data,
size_t *auction_data_len,
struct GNUNET_TIME_Absolute time_start,
struct GNUNET_TIME_Relative time_round,
2016-08-12 14:38:10 +02:00
void *description,
uint32_t description_len,
uint16_t num_prices,
uint16_t m,
int outcome_public);
2016-05-17 23:52:56 +02:00
2016-05-17 22:03:26 +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().
* \todo: implement (de)serialization */
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.
* @param[in] msg_len The length in bytes of @a msg.
*/
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,
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-05-17 22:03:26 +02:00
2016-06-12 01:13:03 +02:00
#endif /* ifndef _BRANDT_BRANDT_H */