Statistics
| Branch: | Revision:

grapes / include / trade_msg_ha.h @ master

History | View | Annotate | Download (2.23 KB)

1 7818ee58 luca
/** @file trade_msg_ha.h
2
 *
3 b9e0d721 MarcoBiazzini
 * @brief Chunk Delivery API - Higher Abstraction
4 7818ee58 luca
 *
5
 * The Chunk Delivery HA provides the primitives for effective chunks exchange with other peers. <br>
6
 * This is a part of the Data Exchange Protocol which provides high level abstraction for sending chunks to a target peers.
7 e3cf5329 Luca Abeni
 * See @link chunk_sending_test.c chunk_sending_test.c @endlink for an usage example
8
 *
9
 */
10 a40a8d81 MarcoBiazzini
11 e3cf5329 Luca Abeni
/** @example chunk_sending_test.c
12
 * 
13 654c1ec5 Luca Abeni
 * A test program showing how to use the chunk delivery API.
14 e3cf5329 Luca Abeni
 *
15 7818ee58 luca
 */
16 e3cf5329 Luca Abeni
17 7818ee58 luca
#include "chunk.h"
18 b223cba2 Csaba Kiraly
19
/**
20
 * @brief Parse an incoming chunk message, providing the chunk structure and transaction ID.
21
 * @return 1 on success, <0 on error.
22
 *
23 3297f183 Luca Abeni
 * @param[in] buff containing the incoming message.
24 b223cba2 Csaba Kiraly
 * @param[in] buff_len length of the buffer.
25
 * @param[out] c the chunk filled with data (an already allocated chunk structure must be passed!).
26
 * @param[out] transid the transaction ID.
27
 * @return 1 on success, <0 on error.
28
 */
29
int parseChunkMsg(const uint8_t *buff, int buff_len, struct chunk *c, uint16_t *transid);
30
31 7818ee58 luca
/**
32 85c4b598 MarcoBiazzini
  * @brief Send a Chunk to a target Peer
33 7818ee58 luca
  *
34
  * Send a single Chunk to a given Peer
35
  *
36
  * @param[in] to destination peer
37
  * @param[in] c Chunk to send
38 b223cba2 Csaba Kiraly
  * @param[in] transid the ID of transaction this send belongs to (if any)
39 7818ee58 luca
  * @return 0 on success, <0 on error
40
  */
41 f217ce38 Luca Baldesi
int sendChunk(const struct nodeID * localID, const struct nodeID *to, const struct chunk *c, uint16_t transid);
42 7818ee58 luca
43
/**
44 85c4b598 MarcoBiazzini
  * @brief Init the Chunk trading internals.
45 7818ee58 luca
  *
46 85c4b598 MarcoBiazzini
  * Initialization facility.
47 7818ee58 luca
  * @param myID address of this peer
48
  * @return >= 0 on success, <0 on error
49
  */
50 50f04076 Luca Abeni
int chunkDeliveryInit(struct nodeID *myID);
51 7818ee58 luca
52
53 a1432cca Luca
#if 0
54 7818ee58 luca
/** 
55 85c4b598 MarcoBiazzini
  * @brief Notification function for a Chunk arrival
56 7818ee58 luca
  */
57
typedef int (*ChunkNotification)(struct peer *from, struct chunk  *c);
58

59
/**
60 85c4b598 MarcoBiazzini
  * @brief Register a notification for Chunk arrival
61 7818ee58 luca
  * 
62
  * Register a notification function that should be called at every Chunk arrival
63
  *
64
  * @param[in] som Handle to the enclosing SOM instance
65
  * @param[in] p notify a send of chunk from Peer p, or from any peer if NULL
66
  * @param[in] fn pointer to the notification function.
67
  * @return a handle to the notification or NULL on error @see unregisterSendChunk
68
  */
69
void registerSendChunkNotifier(struct peer *p, ChunkNotification *fn);
70 a1432cca Luca
#endif