summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-08-12 16:20:46 -0400
committerirungentoo <irungentoo@gmail.com>2014-08-12 16:20:46 -0400
commitdb655c77f8089a152097fbd299e91ab18594ecdb (patch)
tree7d81b08c6b8cec4f7c3ba6f70f71ece324cb9630
parent2c7654bd9a9d55b84093fb4586389e984faa38a6 (diff)
Onion packets can now be received via TCP.
-rw-r--r--toxcore/onion_client.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 1d6cdb6b..2551a162 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -611,6 +611,24 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co
611 611
612 return 0; 612 return 0;
613} 613}
614
615static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length)
616{
617 if (length == 0)
618 return 1;
619
620 IP_Port ip_port = {0};
621 ip_port.ip.family = TCP_FAMILY;
622
623 if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) {
624 return handle_announce_response(object, ip_port, data, length);
625 } else if (data[0] == NET_PACKET_ONION_DATA_RESPONSE) {
626 return handle_data_response(object, ip_port, data, length);
627 }
628
629 return 1;
630}
631
614/* Send data of length length to friendnum. 632/* Send data of length length to friendnum.
615 * This data will be received by the friend using the Onion_Data_Handlers callbacks. 633 * This data will be received by the friend using the Onion_Data_Handlers callbacks.
616 * 634 *
@@ -1191,6 +1209,7 @@ Onion_Client *new_onion_client(Net_Crypto *c)
1191 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); 1209 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c);
1192 oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c); 1210 oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c);
1193 cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); 1211 cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c);
1212 tcp_onion_response_handler(onion_c->c, &handle_tcp_onion, onion_c);
1194 1213
1195 return onion_c; 1214 return onion_c;
1196} 1215}
@@ -1206,6 +1225,7 @@ void kill_onion_client(Onion_Client *onion_c)
1206 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); 1225 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL);
1207 oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL); 1226 oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL);
1208 cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, NULL, NULL); 1227 cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, NULL, NULL);
1228 tcp_onion_response_handler(onion_c->c, NULL, NULL);
1209 memset(onion_c, 0, sizeof(Onion_Client)); 1229 memset(onion_c, 0, sizeof(Onion_Client));
1210 free(onion_c); 1230 free(onion_c);
1211} 1231}