psyc: in-order message delivery
[oweals/gnunet.git] / src / core / gnunet-service-core_kx.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file core/gnunet-service-core_kx.h
23  * @brief code for managing the key exchange (SET_KEY, PING, PONG) with other peers
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_CORE_KX_H
27 #define GNUNET_SERVICE_CORE_KX_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_transport_service.h"
31
32
33 /**
34  * Information about the status of a key exchange with another peer.
35  */
36 struct GSC_KeyExchangeInfo;
37
38
39 /**
40  * We received a EPHEMERAL_KEY message.  Validate and update
41  * our key material and status.
42  *
43  * @param kx key exchange status for the corresponding peer
44  * @param msg the set key message we received
45  */
46 void
47 GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
48                              const struct GNUNET_MessageHeader *msg);
49
50
51 /**
52  * We received a PING message.  Validate and transmit
53  * a PONG message.
54  *
55  * @param kx key exchange status for the corresponding peer
56  * @param msg the encrypted PING message itself
57  */
58 void
59 GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
60                     const struct GNUNET_MessageHeader *msg);
61
62
63 /**
64  * We received a PONG message.  Validate and update our status.
65  *
66  * @param kx key exchange status for the corresponding peer
67  * @param msg the encrypted PONG message itself
68  */
69 void
70 GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
71                     const struct GNUNET_MessageHeader *msg);
72
73
74 /**
75  * Encrypt and transmit a message with the given payload.
76  *
77  * @param kx key exchange context
78  * @param payload payload of the message
79  * @param payload_size number of bytes in 'payload'
80  */
81 void
82 GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
83                              const void *payload, size_t payload_size);
84
85
86 /**
87  * We received an encrypted message.  Decrypt, validate and
88  * pass on to the appropriate clients.
89  *
90  * @param kx key exchange information context
91  * @param msg encrypted message
92  */
93 void
94 GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
95                                  const struct GNUNET_MessageHeader *msg);
96
97
98 /**
99  * Start the key exchange with the given peer.
100  *
101  * @param pid identity of the peer to do a key exchange with
102  * @return key exchange information context
103  */
104 struct GSC_KeyExchangeInfo *
105 GSC_KX_start (const struct GNUNET_PeerIdentity *pid);
106
107
108 /**
109  * Stop key exchange with the given peer.  Clean up key material.
110  *
111  * @param kx key exchange to stop
112  */
113 void
114 GSC_KX_stop (struct GSC_KeyExchangeInfo *kx);
115
116
117 /**
118  * Initialize KX subsystem.
119  *
120  * @param pk private key to use for the peer
121  * @param server the server of the CORE service
122  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
123  */
124 int
125 GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk,
126              struct GNUNET_SERVER_Handle *server);
127
128
129 /**
130  * Shutdown KX subsystem.
131  */
132 void
133 GSC_KX_done (void);
134
135
136 /**
137  * Handle #GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request.  For this
138  * request type, the client does not have to have transmitted an INIT
139  * request.  All current peers are returned, regardless of which
140  * message types they accept.
141  *
142  * @param cls unused
143  * @param client client sending the iteration request
144  * @param message iteration request message
145  */
146 void
147 GSC_KX_handle_client_monitor_peers (void *cls,
148                                     struct GNUNET_SERVER_Client *client,
149                                     const struct GNUNET_MessageHeader *message);
150
151
152 #endif
153 /* end of gnunet-service-core_kx.h */