diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 9 | ||||
-rw-r--r-- | toxcore/tox.c | 71 | ||||
-rw-r--r-- | toxcore/tox.h | 47 |
3 files changed, 127 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fffaf4cb..0c23821e 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1773,6 +1773,15 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const | |||
1773 | if (friend_not_valid(m, friendnumber)) | 1773 | if (friend_not_valid(m, friendnumber)) |
1774 | return -1; | 1774 | return -1; |
1775 | 1775 | ||
1776 | if (length == 0) | ||
1777 | return -1; | ||
1778 | |||
1779 | if (data[0] < PACKET_ID_LOSSLESS_RANGE_START) | ||
1780 | return -1; | ||
1781 | |||
1782 | if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) | ||
1783 | return -1; | ||
1784 | |||
1776 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) | 1785 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) |
1777 | return -1; | 1786 | return -1; |
1778 | 1787 | ||
diff --git a/toxcore/tox.c b/toxcore/tox.c index d9d88105..b2aadd39 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -469,6 +469,77 @@ void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key) | |||
469 | memcpy(secret_key, m->net_crypto->self_secret_key, crypto_box_SECRETKEYBYTES); | 469 | memcpy(secret_key, m->net_crypto->self_secret_key, crypto_box_SECRETKEYBYTES); |
470 | } | 470 | } |
471 | 471 | ||
472 | /* Set handlers for custom lossy packets. | ||
473 | * Set the function to be called when friend sends us a lossy packet starting with byte. | ||
474 | * byte must be in the 200-254 range. | ||
475 | * | ||
476 | * NOTE: lossy packets behave like UDP packets meaning they might never reach the other side | ||
477 | * or might arrive more than once (if someone is messing with the connection) or might arrive | ||
478 | * in the wrong order. | ||
479 | * | ||
480 | * Unless latency is an issue, it is recommended that you use lossless packets instead. | ||
481 | * | ||
482 | * return -1 on failure. | ||
483 | * return 0 on success. | ||
484 | */ | ||
485 | int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, | ||
486 | int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) | ||
487 | { | ||
488 | Messenger *m = tox; | ||
489 | |||
490 | if (byte < (PACKET_ID_LOSSY_RANGE_START + 8)) /* First 8 reserved for A/V*/ | ||
491 | return -1; | ||
492 | |||
493 | return custom_lossy_packet_registerhandler(m, friendnumber, byte, packet_handler_callback, object); | ||
494 | } | ||
495 | |||
496 | /* Function to send custom lossy packets. | ||
497 | * First byte of data must be in the range: 200-254. | ||
498 | * | ||
499 | * return -1 on failure. | ||
500 | * return 0 on success. | ||
501 | */ | ||
502 | int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) | ||
503 | { | ||
504 | const Messenger *m = tox; | ||
505 | |||
506 | if (length == 0) | ||
507 | return -1; | ||
508 | |||
509 | if (data[0] < (PACKET_ID_LOSSY_RANGE_START + 8)) /* First 8 reserved for A/V*/ | ||
510 | return -1; | ||
511 | |||
512 | return send_custom_lossy_packet(m, friendnumber, data, length); | ||
513 | } | ||
514 | |||
515 | /* Set handlers for custom lossless packets. | ||
516 | * Set the function to be called when friend sends us a lossless packet starting with byte. | ||
517 | * byte must be in the 160-191 range. | ||
518 | * | ||
519 | * return -1 on failure. | ||
520 | * return 0 on success. | ||
521 | */ | ||
522 | int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, | ||
523 | int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object) | ||
524 | { | ||
525 | Messenger *m = tox; | ||
526 | |||
527 | return custom_lossless_packet_registerhandler(m, friendnumber, byte, packet_handler_callback, object); | ||
528 | } | ||
529 | |||
530 | /* Function to send custom lossless packets. | ||
531 | * First byte of data must be in the range: 160-191. | ||
532 | * | ||
533 | * return -1 on failure. | ||
534 | * return 0 on success. | ||
535 | */ | ||
536 | int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) | ||
537 | { | ||
538 | const Messenger *m = tox; | ||
539 | |||
540 | return send_custom_lossless_packet(m, friendnumber, data, length); | ||
541 | } | ||
542 | |||
472 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ | 543 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ |
473 | 544 | ||
474 | /* Set the callback for group invites. | 545 | /* Set the callback for group invites. |
diff --git a/toxcore/tox.h b/toxcore/tox.h index c17125a7..1f251085 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -354,6 +354,53 @@ void tox_set_nospam(Tox *tox, uint32_t nospam); | |||
354 | if the pointer is NULL, no data will be copied to it.*/ | 354 | if the pointer is NULL, no data will be copied to it.*/ |
355 | void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key); | 355 | void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key); |
356 | 356 | ||
357 | /* Maximum size of custom packets. */ | ||
358 | #define TOX_MAX_CUSTOM_PACKET_SIZE 1373 | ||
359 | |||
360 | /* Set handlers for custom lossy packets. | ||
361 | * Set the function to be called when friend sends us a lossy packet starting with byte. | ||
362 | * byte must be in the 200-254 range. | ||
363 | * | ||
364 | * NOTE: lossy packets behave like UDP packets meaning they might never reach the other side | ||
365 | * or might arrive more than once (if someone is messing with the connection) or might arrive | ||
366 | * in the wrong order. | ||
367 | * | ||
368 | * Unless latency is an issue, it is recommended that you use lossless packets instead. | ||
369 | * | ||
370 | * return -1 on failure. | ||
371 | * return 0 on success. | ||
372 | */ | ||
373 | int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, | ||
374 | int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); | ||
375 | |||
376 | /* Function to send custom lossy packets. | ||
377 | * First byte of data must be in the range: 200-254. | ||
378 | * | ||
379 | * return -1 on failure. | ||
380 | * return 0 on success. | ||
381 | */ | ||
382 | int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length); | ||
383 | |||
384 | /* Set handlers for custom lossless packets. | ||
385 | * Set the function to be called when friend sends us a lossless packet starting with byte. | ||
386 | * byte must be in the 160-191 range. | ||
387 | * | ||
388 | * Lossless packets behave kind of like TCP (reliability, arrive in order.) but with packets instead of a stream. | ||
389 | * | ||
390 | * return -1 on failure. | ||
391 | * return 0 on success. | ||
392 | */ | ||
393 | int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, | ||
394 | int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object); | ||
395 | |||
396 | /* Function to send custom lossless packets. | ||
397 | * First byte of data must be in the range: 160-191. | ||
398 | * | ||
399 | * return -1 on failure. | ||
400 | * return 0 on success. | ||
401 | */ | ||
402 | int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length); | ||
403 | |||
357 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ | 404 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ |
358 | 405 | ||
359 | /* Set the callback for group invites. | 406 | /* Set the callback for group invites. |