summaryrefslogtreecommitdiff
path: root/core/friend_requests.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-14 18:26:00 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-14 18:26:00 -0400
commit4330bfbf871e769cf1599825bfb09ba56293d6a0 (patch)
tree7f4b5a11c6992e7c9cf6a95a4e03a0ba02a720a9 /core/friend_requests.c
parent95664357d42d4d71a093d011124b0b1be7c1e380 (diff)
Metadata collection prevention part 1 of ???.
Crypto requests packets are packets that can be routed by nodes in the DHT. In this pull request I have merged both Natping requests and friend requests into one common packet (Crypto request packets). Both these packets should now only be distinguishable by the size of the data in them to an outside observer for an example on how to send and recieve data with these packets see: friend_requests.c Note that these packets are prefixed with id 32 (friend request packets) which means this change is compatible with the currently running DHT bootstrap servers. Also changed small thing in DHT_test.c
Diffstat (limited to 'core/friend_requests.c')
-rw-r--r--core/friend_requests.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/core/friend_requests.c b/core/friend_requests.c
index 8276db29..ae19ebdd 100644
--- a/core/friend_requests.c
+++ b/core/friend_requests.c
@@ -123,39 +123,23 @@ static int request_received(uint8_t * client_id)
123} 123}
124 124
125 125
126static int friendreq_handlepacket(IP_Port source, uint8_t * packet, uint32_t length) 126static int friendreq_handlepacket(IP_Port source, uint8_t * source_pubkey, uint8_t * packet, uint32_t length)
127{ 127{
128 if (packet[0] == 32) { 128 if (handle_friendrequest_isset == 0)
129 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING || 129 return 1;
130 length > MAX_DATA_SIZE + ENCRYPTION_PADDING) 130 if (length <= sizeof(nospam))
131 return 1; 131 return 1;
132 if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) {// check if request is for us. 132 if (request_received(source_pubkey))
133 if (handle_friendrequest_isset == 0) 133 return 1;
134 return 1; 134 if (memcmp(packet, &nospam, sizeof(nospam)) != 0)
135 135 return 1;
136 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 136
137 uint8_t data[MAX_DATA_SIZE]; 137 addto_receivedlist(source_pubkey);
138 int len = handle_request(public_key, data, packet, length); 138 (*handle_friendrequest)(source_pubkey, packet + 4, length - 4, handle_friendrequest_userdata);
139 if (len == -1) 139 return 0;
140 return 1;
141 if (len <= sizeof(nospam))
142 return 1;
143 if (request_received(public_key))
144 return 1;
145 if (memcmp(data, &nospam, sizeof(nospam)) != 0)
146 return 1;
147
148 addto_receivedlist(public_key);
149 (*handle_friendrequest)(public_key, data + 4, len - 4, handle_friendrequest_userdata);
150 } else { /* if request is not for us, try routing it. */
151 if(route_packet(packet + 1, packet, length) == length)
152 return 0;
153 }
154 }
155 return 1;
156} 140}
157 141
158void friendreq_init(void) 142void friendreq_init(void)
159{ 143{
160 networking_registerhandler(32, &friendreq_handlepacket); 144 cryptopacket_registerhandler(32, &friendreq_handlepacket);
161} 145}