summaryrefslogtreecommitdiff
path: root/core/friend_requests.c
diff options
context:
space:
mode:
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}