diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-06 21:32:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-06 21:32:05 +0000 |
commit | ca1cd117f6a59c0d19f841f72ac37340284ada57 (patch) | |
tree | 698e924a91c96d6ff79b738262a463f0d5004be6 /src/core/gnunet-service-core_kx.h | |
parent | 68f027903ee06b86c56c9f16dba9a83333936dbe (diff) | |
download | gnunet-ca1cd117f6a59c0d19f841f72ac37340284ada57.tar.gz gnunet-ca1cd117f6a59c0d19f841f72ac37340284ada57.zip |
towards KX
Diffstat (limited to 'src/core/gnunet-service-core_kx.h')
-rw-r--r-- | src/core/gnunet-service-core_kx.h | 112 |
1 files changed, 81 insertions, 31 deletions
diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h index 104aed5e4..071665a19 100644 --- a/src/core/gnunet-service-core_kx.h +++ b/src/core/gnunet-service-core_kx.h | |||
@@ -30,16 +30,76 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * State machine for our P2P encryption handshake. Everyone starts in | ||
34 | * "DOWN", if we receive the other peer's key (other peer initiated) | ||
35 | * we start in state RECEIVED (since we will immediately send our | ||
36 | * own); otherwise we start in SENT. If we get back a PONG from | ||
37 | * within either state, we move up to CONFIRMED (the PONG will always | ||
38 | * be sent back encrypted with the key we sent to the other peer). | ||
39 | */ | ||
40 | enum KxStateMachine | ||
41 | { | ||
42 | /** | ||
43 | * No handshake yet. | ||
44 | */ | ||
45 | KX_STATE_DOWN, | ||
46 | |||
47 | /** | ||
48 | * We've sent our session key. | ||
49 | */ | ||
50 | KX_STATE_KEY_SENT, | ||
51 | |||
52 | /** | ||
53 | * We've received the other peers session key. | ||
54 | */ | ||
55 | KX_STATE_KEY_RECEIVED, | ||
56 | |||
57 | /** | ||
58 | * The other peer has confirmed our session key with a message | ||
59 | * encrypted with his session key (which we got). Key exchange | ||
60 | * is done. | ||
61 | */ | ||
62 | KX_STATE_UP | ||
63 | }; | ||
64 | |||
65 | |||
66 | /** | ||
33 | * Information about the status of a key exchange with another peer. | 67 | * Information about the status of a key exchange with another peer. |
34 | */ | 68 | */ |
35 | struct GSC_KeyExchangeInfo | 69 | struct GSC_KeyExchangeInfo |
36 | { | 70 | { |
71 | /** | ||
72 | * Identity of the peer. | ||
73 | */ | ||
74 | struct GNUNET_PeerIdentity peer; | ||
37 | 75 | ||
38 | /** | 76 | /** |
39 | * SetKeyMessage to transmit, NULL if we are not currently trying | 77 | * SetKeyMessage to transmit (initialized the first |
40 | * to send one. | 78 | * time our status goes past 'KX_STATE_KEY_SENT'). |
41 | */ | 79 | */ |
42 | struct SetKeyMessage *skm; | 80 | struct SetKeyMessage skm; |
81 | |||
82 | /** | ||
83 | * PING message we transmit to the other peer. | ||
84 | */ | ||
85 | struct PingMessage ping; | ||
86 | |||
87 | /** | ||
88 | * SetKeyMessage we received and did not process yet. | ||
89 | */ | ||
90 | struct SetKeyMessage *skm_received; | ||
91 | |||
92 | /** | ||
93 | * PING message we received from the other peer and | ||
94 | * did not process yet (or NULL). | ||
95 | */ | ||
96 | struct PingMessage *ping_received; | ||
97 | |||
98 | /** | ||
99 | * PONG message we received from the other peer and | ||
100 | * did not process yet (or NULL). | ||
101 | */ | ||
102 | struct PongMessage *pong_received; | ||
43 | 103 | ||
44 | /** | 104 | /** |
45 | * Non-NULL if we are currently looking up HELLOs for this peer. | 105 | * Non-NULL if we are currently looking up HELLOs for this peer. |
@@ -53,13 +113,6 @@ struct GSC_KeyExchangeInfo | |||
53 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; | 113 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; |
54 | 114 | ||
55 | /** | 115 | /** |
56 | * We received a PING message before we got the "public_key" | ||
57 | * (or the SET_KEY). We keep it here until we have a key | ||
58 | * to decrypt it. NULL if no PING is pending. | ||
59 | */ | ||
60 | struct PingMessage *pending_ping; | ||
61 | |||
62 | /** | ||
63 | * We received a PONG message before we got the "public_key" | 116 | * We received a PONG message before we got the "public_key" |
64 | * (or the SET_KEY). We keep it here until we have a key | 117 | * (or the SET_KEY). We keep it here until we have a key |
65 | * to decrypt it. NULL if no PONG is pending. | 118 | * to decrypt it. NULL if no PONG is pending. |
@@ -89,6 +142,11 @@ struct GSC_KeyExchangeInfo | |||
89 | struct GNUNET_TIME_Absolute decrypt_key_created; | 142 | struct GNUNET_TIME_Absolute decrypt_key_created; |
90 | 143 | ||
91 | /** | 144 | /** |
145 | * When should the session time out (if there are no PONGs)? | ||
146 | */ | ||
147 | struct GNUNET_TIME_Absolute timeout; | ||
148 | |||
149 | /** | ||
92 | * At what frequency are we currently re-trying SET_KEY messages? | 150 | * At what frequency are we currently re-trying SET_KEY messages? |
93 | */ | 151 | */ |
94 | struct GNUNET_TIME_Relative set_key_retry_frequency; | 152 | struct GNUNET_TIME_Relative set_key_retry_frequency; |
@@ -111,7 +169,7 @@ struct GSC_KeyExchangeInfo | |||
111 | /** | 169 | /** |
112 | * What is our connection status? | 170 | * What is our connection status? |
113 | */ | 171 | */ |
114 | enum PeerStateMachine status; | 172 | enum KxStateMachine status; |
115 | 173 | ||
116 | }; | 174 | }; |
117 | 175 | ||
@@ -122,14 +180,10 @@ struct GSC_KeyExchangeInfo | |||
122 | * | 180 | * |
123 | * @param kx key exchange status for the corresponding peer | 181 | * @param kx key exchange status for the corresponding peer |
124 | * @param msg the set key message we received | 182 | * @param msg the set key message we received |
125 | * @param ats performance data | ||
126 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
127 | */ | 183 | */ |
128 | void | 184 | void |
129 | GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *n, | 185 | GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, |
130 | const struct GNUNET_MessageHandler *msg, | 186 | const struct GNUNET_MessageHandler *msg); |
131 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
132 | uint32_t ats_count); | ||
133 | 187 | ||
134 | 188 | ||
135 | /** | 189 | /** |
@@ -138,14 +192,10 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *n, | |||
138 | * | 192 | * |
139 | * @param kx key exchange status for the corresponding peer | 193 | * @param kx key exchange status for the corresponding peer |
140 | * @param msg the encrypted PING message itself | 194 | * @param msg the encrypted PING message itself |
141 | * @param ats performance data | ||
142 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
143 | */ | 195 | */ |
144 | void | 196 | void |
145 | GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | 197 | GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, |
146 | const struct GNUNET_MessageHeader *msg, | 198 | const struct GNUNET_MessageHeader *msg); |
147 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
148 | uint32_t ats_count); | ||
149 | 199 | ||
150 | 200 | ||
151 | /** | 201 | /** |
@@ -153,25 +203,25 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | |||
153 | * | 203 | * |
154 | * @param kx key exchange status for the corresponding peer | 204 | * @param kx key exchange status for the corresponding peer |
155 | * @param msg the encrypted PONG message itself | 205 | * @param msg the encrypted PONG message itself |
156 | * @param ats performance data | ||
157 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
158 | */ | 206 | */ |
159 | void | 207 | void |
160 | GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, | 208 | GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, |
161 | const struct GNUNET_MessageHeader *msg, | 209 | const struct GNUNET_MessageHeader *msg); |
162 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
163 | uint32_t ats_count); | ||
164 | 210 | ||
165 | 211 | ||
166 | /** | 212 | /** |
167 | * Encrypt and transmit a message with the given payload. | 213 | * Encrypt and transmit a message with the given payload. |
168 | * | 214 | * |
169 | * @param kx key exchange context | 215 | * @param kx key exchange context |
216 | * @param bw_in bandwidth limit to transmit to the other peer; | ||
217 | * the other peer shall not send us more than the | ||
218 | * given rate | ||
170 | * @param payload payload of the message | 219 | * @param payload payload of the message |
171 | * @param payload_size number of bytes in 'payload' | 220 | * @param payload_size number of bytes in 'payload' |
172 | */ | 221 | */ |
173 | void | 222 | void |
174 | GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | 223 | GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, |
224 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, | ||
175 | const void *payload, | 225 | const void *payload, |
176 | size_t payload_size); | 226 | size_t payload_size); |
177 | 227 | ||
@@ -182,14 +232,14 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
182 | * | 232 | * |
183 | * @param kx key exchange information context | 233 | * @param kx key exchange information context |
184 | * @param msg encrypted message | 234 | * @param msg encrypted message |
185 | * @param ats performance data | 235 | * @param atsi performance data |
186 | * @param ats_count number of entries in ats (excluding 0-termination) | 236 | * @param atsi_count number of entries in ats (excluding 0-termination) |
187 | */ | 237 | */ |
188 | void | 238 | void |
189 | GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | 239 | GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, |
190 | const struct GNUNET_MessageHeader *msg, | 240 | const struct GNUNET_MessageHeader *msg, |
191 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 241 | const struct GNUNET_TRANSPORT_ATS_Information *atsi, |
192 | uint32_t ats_count); | 242 | uint32_t atsi_count); |
193 | 243 | ||
194 | 244 | ||
195 | /** | 245 | /** |