summaryrefslogtreecommitdiff
path: root/core/net_crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/net_crypto.h')
-rw-r--r--core/net_crypto.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/core/net_crypto.h b/core/net_crypto.h
index 745f1f14..887b432b 100644
--- a/core/net_crypto.h
+++ b/core/net_crypto.h
@@ -25,7 +25,6 @@
25#define NET_CRYPTO_H 25#define NET_CRYPTO_H
26 26
27#include "Lossless_UDP.h" 27#include "Lossless_UDP.h"
28#include "DHT.h"
29 28
30#ifdef __cplusplus 29#ifdef __cplusplus
31extern "C" { 30extern "C" {
@@ -33,9 +32,6 @@ extern "C" {
33 32
34#define MAX_INCOMING 64 33#define MAX_INCOMING 64
35 34
36extern uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];//TODO: Remove this
37extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
38
39typedef struct { 35typedef struct {
40 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* the real public key of the peer. */ 36 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* the real public key of the peer. */
41 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* nonce of received packets */ 37 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* nonce of received packets */
@@ -51,25 +47,32 @@ typedef struct {
51 47
52} Crypto_Connection; 48} Crypto_Connection;
53 49
54typedef int (*cryptopacket_handler_callback)(IP_Port ip_port, uint8_t *source_pubkey, uint8_t *data, uint32_t len); 50typedef int (*cryptopacket_handler_callback)(void * object, IP_Port ip_port, uint8_t *source_pubkey, uint8_t *data, uint32_t len);
51
52typedef struct {
53 cryptopacket_handler_callback function;
54 void * object;
55}Cryptopacket_Handles;
55 56
56typedef struct { 57typedef struct {
57Lossless_UDP * lossless_udp; 58 Lossless_UDP * lossless_udp;
58 59
59Crypto_Connection *crypto_connections; 60 Crypto_Connection *crypto_connections;
60 61
61uint32_t crypto_connections_length; /* Length of connections array */ 62 uint32_t crypto_connections_length; /* Length of connections array */
62 63
63/* Our public and secret keys. */ 64 /* Our public and secret keys. */
64uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; 65 uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
65uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; 66 uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
66 67
67/* keeps track of the connection numbers for friends request so we can check later if they were sent */ 68 /* keeps track of the connection numbers for friends request so we can check later if they were sent */
68int incoming_connections[MAX_INCOMING]; 69 int incoming_connections[MAX_INCOMING];
69 70
70cryptopacket_handler_callback cryptopackethandlers[256]; 71 Cryptopacket_Handles cryptopackethandlers[256];
71} Net_Crypto; 72} Net_Crypto;
72 73
74#include "DHT.h"
75
73Net_Crypto * temp_net_crypto; //TODO: remove this 76Net_Crypto * temp_net_crypto; //TODO: remove this
74 77
75#define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) 78#define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
@@ -130,7 +133,7 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *
130 133
131 134
132/* Function to call when request beginning with byte is received */ 135/* Function to call when request beginning with byte is received */
133void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb); 136void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void * object);
134 137
135/* Start a secure connection with other peer who has public_key and ip_port 138/* Start a secure connection with other peer who has public_key and ip_port
136 returns -1 if failure 139 returns -1 if failure
@@ -183,6 +186,9 @@ void do_net_crypto(Net_Crypto *c);
183 186
184void kill_net_crypto(Net_Crypto *c); 187void kill_net_crypto(Net_Crypto *c);
185 188
189/* Init the cryptopacket handling */
190void init_cryptopackets(void *dht);
191
186#ifdef __cplusplus 192#ifdef __cplusplus
187} 193}
188#endif 194#endif