diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-15 00:29:51 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-16 15:46:13 +0000 |
commit | 22db2b9fe581a35300b66126604d12e83c2eafb1 (patch) | |
tree | f0a4b46fd2453f917e89bf8034eafd5a5946d0f0 /toxcore/net_crypto.c | |
parent | bc58c6ea2f68123abb12ccd09bb9f50bcb230e10 (diff) |
Make Net_Crypto a module-private type.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 3150392e..521dad2f 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -33,6 +33,146 @@ | |||
33 | 33 | ||
34 | #include <math.h> | 34 | #include <math.h> |
35 | 35 | ||
36 | typedef struct { | ||
37 | uint64_t sent_time; | ||
38 | uint16_t length; | ||
39 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; | ||
40 | } Packet_Data; | ||
41 | |||
42 | typedef struct { | ||
43 | Packet_Data *buffer[CRYPTO_PACKET_BUFFER_SIZE]; | ||
44 | uint32_t buffer_start; | ||
45 | uint32_t buffer_end; /* packet numbers in array: {buffer_start, buffer_end) */ | ||
46 | } Packets_Array; | ||
47 | |||
48 | typedef struct { | ||
49 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The real public key of the peer. */ | ||
50 | uint8_t recv_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of received packets. */ | ||
51 | uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of sent packets. */ | ||
52 | uint8_t sessionpublic_key[CRYPTO_PUBLIC_KEY_SIZE]; /* Our public key for this session. */ | ||
53 | uint8_t sessionsecret_key[CRYPTO_SECRET_KEY_SIZE]; /* Our private key for this session. */ | ||
54 | uint8_t peersessionpublic_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The public key of the peer. */ | ||
55 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; /* The precomputed shared key from encrypt_precompute. */ | ||
56 | uint8_t status; /* 0 if no connection, 1 we are sending cookie request packets, | ||
57 | * 2 if we are sending handshake packets | ||
58 | * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet), | ||
59 | * 4 if the connection is established. | ||
60 | */ | ||
61 | uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */ | ||
62 | uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer */ | ||
63 | |||
64 | uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */ | ||
65 | uint16_t temp_packet_length; | ||
66 | uint64_t temp_packet_sent_time; /* The time at which the last temp_packet was sent in ms. */ | ||
67 | uint32_t temp_packet_num_sent; | ||
68 | |||
69 | IP_Port ip_portv4; /* The ip and port to contact this guy directly.*/ | ||
70 | IP_Port ip_portv6; | ||
71 | uint64_t direct_lastrecv_timev4; /* The Time at which we last received a direct packet in ms. */ | ||
72 | uint64_t direct_lastrecv_timev6; | ||
73 | |||
74 | uint64_t last_tcp_sent; /* Time the last TCP packet was sent. */ | ||
75 | |||
76 | Packets_Array send_array; | ||
77 | Packets_Array recv_array; | ||
78 | |||
79 | int (*connection_status_callback)(void *object, int id, uint8_t status, void *userdata); | ||
80 | void *connection_status_callback_object; | ||
81 | int connection_status_callback_id; | ||
82 | |||
83 | int (*connection_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata); | ||
84 | void *connection_data_callback_object; | ||
85 | int connection_data_callback_id; | ||
86 | |||
87 | int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata); | ||
88 | void *connection_lossy_data_callback_object; | ||
89 | int connection_lossy_data_callback_id; | ||
90 | |||
91 | uint64_t last_request_packet_sent; | ||
92 | uint64_t direct_send_attempt_time; | ||
93 | |||
94 | uint32_t packet_counter; | ||
95 | double packet_recv_rate; | ||
96 | uint64_t packet_counter_set; | ||
97 | |||
98 | double packet_send_rate; | ||
99 | uint32_t packets_left; | ||
100 | uint64_t last_packets_left_set; | ||
101 | double last_packets_left_rem; | ||
102 | |||
103 | double packet_send_rate_requested; | ||
104 | uint32_t packets_left_requested; | ||
105 | uint64_t last_packets_left_requested_set; | ||
106 | double last_packets_left_requested_rem; | ||
107 | |||
108 | uint32_t last_sendqueue_size[CONGESTION_QUEUE_ARRAY_SIZE], last_sendqueue_counter; | ||
109 | long signed int last_num_packets_sent[CONGESTION_LAST_SENT_ARRAY_SIZE], | ||
110 | last_num_packets_resent[CONGESTION_LAST_SENT_ARRAY_SIZE]; | ||
111 | uint32_t packets_sent, packets_resent; | ||
112 | uint64_t last_congestion_event; | ||
113 | uint64_t rtt_time; | ||
114 | |||
115 | /* TCP_connection connection_number */ | ||
116 | unsigned int connection_number_tcp; | ||
117 | |||
118 | uint8_t maximum_speed_reached; | ||
119 | |||
120 | pthread_mutex_t mutex; | ||
121 | |||
122 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata); | ||
123 | void *dht_pk_callback_object; | ||
124 | uint32_t dht_pk_callback_number; | ||
125 | } Crypto_Connection; | ||
126 | |||
127 | struct Net_Crypto { | ||
128 | Logger *log; | ||
129 | |||
130 | DHT *dht; | ||
131 | TCP_Connections *tcp_c; | ||
132 | |||
133 | Crypto_Connection *crypto_connections; | ||
134 | pthread_mutex_t tcp_mutex; | ||
135 | |||
136 | pthread_mutex_t connections_mutex; | ||
137 | unsigned int connection_use_counter; | ||
138 | |||
139 | uint32_t crypto_connections_length; /* Length of connections array. */ | ||
140 | |||
141 | /* Our public and secret keys. */ | ||
142 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
143 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | ||
144 | |||
145 | /* The secret key used for cookies */ | ||
146 | uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE]; | ||
147 | |||
148 | int (*new_connection_callback)(void *object, New_Connection *n_c); | ||
149 | void *new_connection_callback_object; | ||
150 | |||
151 | /* The current optimal sleep time */ | ||
152 | uint32_t current_sleep_time; | ||
153 | |||
154 | BS_LIST ip_port_list; | ||
155 | }; | ||
156 | |||
157 | const uint8_t *nc_get_self_public_key(const Net_Crypto *c) | ||
158 | { | ||
159 | return c->self_public_key; | ||
160 | } | ||
161 | |||
162 | const uint8_t *nc_get_self_secret_key(const Net_Crypto *c) | ||
163 | { | ||
164 | return c->self_secret_key; | ||
165 | } | ||
166 | |||
167 | TCP_Connections *nc_get_tcp_c(const Net_Crypto *c) | ||
168 | { | ||
169 | return c->tcp_c; | ||
170 | } | ||
171 | |||
172 | DHT *nc_get_dht(const Net_Crypto *c) | ||
173 | { | ||
174 | return c->dht; | ||
175 | } | ||
36 | 176 | ||
37 | static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id) | 177 | static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id) |
38 | { | 178 | { |