diff options
-rw-r--r-- | docs/Avatars.md | 17 | ||||
-rw-r--r-- | toxcore/tox.h | 12 |
2 files changed, 14 insertions, 15 deletions
diff --git a/docs/Avatars.md b/docs/Avatars.md index fee401c0..75517004 100644 --- a/docs/Avatars.md +++ b/docs/Avatars.md | |||
@@ -128,7 +128,7 @@ complete API documentation is available in `tox.h`. | |||
128 | 128 | ||
129 | ``` | 129 | ``` |
130 | #define TOX_AVATAR_MAX_DATA_LENGTH 16384 | 130 | #define TOX_AVATAR_MAX_DATA_LENGTH 16384 |
131 | #define TOX_AVATAR_HASH_LENGTH 32 | 131 | #define TOX_HASH_LENGTH 32 |
132 | 132 | ||
133 | 133 | ||
134 | /* Data formats for user avatar images */ | 134 | /* Data formats for user avatar images */ |
@@ -146,8 +146,8 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt | |||
146 | /* Get avatar data from the current user. */ | 146 | /* Get avatar data from the current user. */ |
147 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash); | 147 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash); |
148 | 148 | ||
149 | /* Generates a cryptographic hash of the given avatar data. */ | 149 | /* Generates a cryptographic hash of the given data (usually a cached avatar). */ |
150 | int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen); | 150 | int tox_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen); |
151 | 151 | ||
152 | /* Request avatar information from a friend. */ | 152 | /* Request avatar information from a friend. */ |
153 | int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber); | 153 | int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber); |
@@ -332,7 +332,7 @@ As in this example: | |||
332 | printf("Receiving avatar information from friend %d. Format = %d\n", | 332 | printf("Receiving avatar information from friend %d. Format = %d\n", |
333 | friendnumber, format); | 333 | friendnumber, format); |
334 | printf("Data hash: "); | 334 | printf("Data hash: "); |
335 | hex_printf(hash, TOX_AVATAR_HASH_LENGTH); /* Hypothetical function */ | 335 | hex_printf(hash, TOX_HASH_LENGTH); /* Hypothetical function */ |
336 | printf("\n"); | 336 | printf("\n"); |
337 | } | 337 | } |
338 | 338 | ||
@@ -592,11 +592,10 @@ The present proposal mitigates this situation by: | |||
592 | avatar information when nothing has changed (`PACKET_ID_AVATAR_INFO`); | 592 | avatar information when nothing has changed (`PACKET_ID_AVATAR_INFO`); |
593 | 593 | ||
594 | - Having per-friend data transfer limit. As the current protocol still | 594 | - Having per-friend data transfer limit. As the current protocol still |
595 | allows an user to request an infinite data stream by asking the the | 595 | allows an user to request avatar data again and again, the implementation |
596 | same offset of the avatar again and again, the implementation limits | 596 | limits the amount of data a particular user can request for some time. The |
597 | the amount of data a single user can request for some time. For now, | 597 | exact values are defined in constants `AVATAR_DATA_TRANSFER_LIMIT` and |
598 | the library will not allow an user to request more than | 598 | `AVATAR_DATA_TRANSFER_TIMEOUT` in file `Messenger.c`. |
599 | `10*TOX_AVATAR_MAX_DATA_LENGTH` in less than 20 minutes; | ||
600 | 599 | ||
601 | - Making the requester responsible for storing partial data and state | 600 | - Making the requester responsible for storing partial data and state |
602 | information; | 601 | information; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 61cfdf70..fc5ccafc 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -539,8 +539,8 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); | |||
539 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata) | 539 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata) |
540 | * | 540 | * |
541 | * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT) and 'hash' is the hash of | 541 | * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT) and 'hash' is the hash of |
542 | * the avatar data for caching purposes and it is exactly TOX_AVATAR_HASH_LENGTH long. If the | 542 | * the avatar data for caching purposes and it is exactly TOX_HASH_LENGTH long. If the image |
543 | * image format is NONE, the hash is zeroed. | 543 | * format is NONE, the hash is zeroed. |
544 | * | 544 | * |
545 | */ | 545 | */ |
546 | void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), | 546 | void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), |
@@ -556,12 +556,12 @@ void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint | |||
556 | * | 556 | * |
557 | * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT); 'hash' is the | 557 | * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT); 'hash' is the |
558 | * locally-calculated cryptographic hash of the avatar data and it is exactly | 558 | * locally-calculated cryptographic hash of the avatar data and it is exactly |
559 | * TOX_AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length | 559 | * TOX_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length |
560 | * of such data. | 560 | * of such data. |
561 | * | 561 | * |
562 | * If format is NONE, 'data' is NULL, 'datalen' is zero, and the hash is zeroed. The hash is | 562 | * If format is NONE, 'data' is NULL, 'datalen' is zero, and the hash is zeroed. The hash is |
563 | * always validated locally with the function tox_avatar_hash and ensured to match the image | 563 | * always validated locally with the function tox_hash and ensured to match the image data, |
564 | * data, so this value can be safely used to compare with cached avatars. | 564 | * so this value can be safely used to compare with cached avatars. |
565 | * | 565 | * |
566 | * WARNING: users MUST treat all avatar image data received from another peer as untrusted and | 566 | * WARNING: users MUST treat all avatar image data received from another peer as untrusted and |
567 | * potentially malicious. The library only ensures that the data which arrived is the same the | 567 | * potentially malicious. The library only ensures that the data which arrived is the same the |
@@ -601,7 +601,7 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt | |||
601 | * buf - destination buffer to the image data. Must have at least 'maxlen' bytes; | 601 | * buf - destination buffer to the image data. Must have at least 'maxlen' bytes; |
602 | * length - destination pointer to the image data length; | 602 | * length - destination pointer to the image data length; |
603 | * maxlen - length of the destination buffer 'buf'; | 603 | * maxlen - length of the destination buffer 'buf'; |
604 | * hash - destination pointer to the avatar hash (it must be exactly TOX_AVATAR_HASH_LENGTH bytes long). | 604 | * hash - destination pointer to the avatar hash (it must be exactly TOX_HASH_LENGTH bytes long). |
605 | * | 605 | * |
606 | * returns 0 on success; | 606 | * returns 0 on success; |
607 | * returns -1 on failure. | 607 | * returns -1 on failure. |