napa-baselibs / tests / peer / peer.h @ 507372bb
History | View | Annotate | Download (3.53 KB)
1 |
#ifndef _PEER_H
|
---|---|
2 |
#define _PEER_H
|
3 |
|
4 |
/** @file peer.h
|
5 |
*
|
6 |
* Local header file defining nuts 'n bolts for the peer implementation.
|
7 |
*
|
8 |
*/
|
9 |
|
10 |
#define _GNU_SOURCE
|
11 |
|
12 |
#include <stdio.h> |
13 |
#include <stdlib.h> |
14 |
#include <string.h> |
15 |
#include <math.h> |
16 |
|
17 |
#include <event2/event.h> |
18 |
#include <event2/buffer.h> |
19 |
#include <event2/http.h> |
20 |
#include <event2/http_struct.h> |
21 |
#include <confuse.h> |
22 |
|
23 |
#include <napa.h> |
24 |
#include <napa_log.h> |
25 |
#include <ml.h> |
26 |
#include <mon.h> |
27 |
#include <repoclient.h> |
28 |
#include <neighborlist.h> |
29 |
#include <chunkbuffer.h> |
30 |
#include <chunk.h> |
31 |
|
32 |
/** Struct maintainging data for this Peer instance */
|
33 |
typedef struct _peer { |
34 |
/** Local PeerID, obtained from ML */
|
35 |
char LocalID[64]; |
36 |
/** Repository handle */
|
37 |
HANDLE repository; |
38 |
/** Neighborlist handle */
|
39 |
HANDLE neighborlist; |
40 |
/** Neighborhood size */
|
41 |
int neighborlist_size;
|
42 |
/** Neighborlist array */
|
43 |
NeighborListEntry *neighbors; |
44 |
/** No. of neighbors in the list */
|
45 |
int num_neighbors;
|
46 |
/* ChunkBuffer */
|
47 |
struct chunk_buffer *cb;
|
48 |
} Peer; |
49 |
|
50 |
/** Global peer structure */
|
51 |
extern Peer *peer;
|
52 |
|
53 |
/** Read config file and initialize the local peer instance accordingly
|
54 |
|
55 |
@param[in] configfile name of configuration file
|
56 |
@return pointer to an initialized Peer structure
|
57 |
**/
|
58 |
Peer *peer_init(const char *configfile); |
59 |
|
60 |
/** Tell whether client mode is active
|
61 |
*
|
62 |
* @return boolean value indicating client mode
|
63 |
*/
|
64 |
bool client_mode();
|
65 |
|
66 |
/** Tell whether source mode is active
|
67 |
*
|
68 |
* @return boolean value indicating source mode
|
69 |
*/
|
70 |
bool source_mode();
|
71 |
|
72 |
/** Notifier callback for new Peers in the NeighborList
|
73 |
|
74 |
@param h Handle to the NeighborList instance generating the notification.
|
75 |
@param cbarg arbitrary user-provided parameter for the callback
|
76 |
*/
|
77 |
void newPeers_cb(HANDLE rep, void *cbarg); |
78 |
|
79 |
/**
|
80 |
* The peer receives data per callback from the messaging layer.
|
81 |
* @param *buffer A pointer to the buffer
|
82 |
* @param buflen The length of the buffer
|
83 |
* @param msgtype The message type
|
84 |
* @param *arg An argument that receives metadata about the received data
|
85 |
*/
|
86 |
void recv_data_from_peer_cb(char *buffer,int buflen,unsigned char msgtype,void *arg); |
87 |
|
88 |
/**
|
89 |
* The peer receives a chunk per callback from the messaging layer.
|
90 |
* @param *buffer A pointer to the buffer
|
91 |
* @param buflen The length of the buffer
|
92 |
* @param msgtype The message type
|
93 |
* @param *arg An argument that receives metadata about the received data
|
94 |
*/
|
95 |
void recv_chunk_from_peer_cb(char *buffer,int buflen,unsigned char msgtype,void *arg); |
96 |
|
97 |
/**
|
98 |
* A callback function that tells a connection has been established.
|
99 |
* @param connectionID The connection ID
|
100 |
* @param *arg An argument for data about the connection
|
101 |
*/
|
102 |
void receive_conn_cb (int connectionID, void *arg); |
103 |
|
104 |
/**
|
105 |
* A funtion that prints a connection establishment has failed
|
106 |
* @param connectionID The connection ID
|
107 |
* @param *arg An argument for data about the connection
|
108 |
*/
|
109 |
void conn_fail_cb(int connectionID,void *arg); |
110 |
|
111 |
struct chunk;
|
112 |
void chunk_transmit_callback(struct chunk *chunk, void *arg); |
113 |
|
114 |
/**
|
115 |
* A callback function that tells a connection has been established.
|
116 |
* @param connectionID The connection ID
|
117 |
* @param *arg An argument for data about the connection
|
118 |
*/
|
119 |
void receive_outconn_cb (int connectionID, void *arg); |
120 |
|
121 |
/**
|
122 |
* Initialize the mini-UserLayer
|
123 |
* @param source name of the source stream (currently: udp://ipaddr:port is supported)
|
124 |
* @param chunk_duration length of a chunk in secords
|
125 |
* @return 0 on success
|
126 |
*/
|
127 |
int init_source_ul(const char *source, double chunk_duration); |
128 |
|
129 |
void new_chunk(struct chunk_buffer *cb, void *cbarg, const struct chunk *c) ; |
130 |
|
131 |
|
132 |
#endif
|