Skip to content

Commit

Permalink
chore: Sync all comments between header and source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 4, 2022
1 parent 0740510 commit 13e4ff4
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 63 deletions.
4 changes: 3 additions & 1 deletion toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ static bool ip4_is_local(const IP4 *ip4)
return ip4->uint8[0] == 127;
}

/** Is IP a local ip or not. */
/**
* Is IP a local ip or not.
*/
bool ip_is_local(const IP *ip)
{
if (net_family_is_ipv4(ip->family)) {
Expand Down
80 changes: 58 additions & 22 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int realloc_friendlist(Messenger *m, uint32_t num)
return 0;
}

/** return the friend id associated to that public key.
/** return the friend number associated to that public key.
* return -1 if no such friend.
*/
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk)
Expand Down Expand Up @@ -103,7 +103,7 @@ int getfriendcon_id(const Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].friendcon_id;
}

/*
/**
* return a uint16_t that represents the checksum of address of length len.
*/
static uint16_t address_checksum(const uint8_t *address, uint32_t len)
Expand Down Expand Up @@ -204,11 +204,16 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
return FAERR_NOMEM;
}

/*
/**
* Add a friend.
*
* Set the data that will be sent along with friend request.
* Address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes.
* data is the data and length is the length.
*
* @param address is the address of the friend (returned by getaddress of the friend
* you wish to add) it must be FRIEND_ADDRESS_SIZE bytes.
* TODO(irungentoo): add checksum.
* @param data is the data.
* @param length is the length.
*
* return the friend number if success.
* return FA_TOOLONG if message length is too long.
Expand Down Expand Up @@ -342,7 +347,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
new_receipts->next = nullptr;
return 0;
}
/*
/**
* return -1 on failure.
* return 0 if packet was received.
*/
Expand Down Expand Up @@ -475,14 +480,16 @@ int m_friend_exists(const Messenger *m, int32_t friendnumber)
return 1;
}

/** Send a message of type.
/** Send a message of type to an online friend.
*
* return -1 if friend not valid.
* return -2 if too large.
* return -3 if friend not online.
* return -4 if send failed (because queue is full).
* return -5 if bad type.
* return 0 if success.
*
* the value in message_id will be passed to your read_receipt callback when the other receives the message.
*/
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length,
uint32_t *message_id)
Expand Down Expand Up @@ -547,6 +554,9 @@ static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *n
}

/** Set the name and name_length of a friend.
* name must be a string of maximum MAX_NAME_LENGTH length.
* length must be at least 1 byte.
* length is the length of name with the NULL terminator.
*
* return 0 if success.
* return -1 if failure.
Expand All @@ -566,7 +576,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint1
return 0;
}

/** Set our nickname
/** Set our nickname.
* name must be a string of maximum MAX_NAME_LENGTH length.
* length must be at least 1 byte.
* length is the length of name with the NULL terminator.
Expand Down Expand Up @@ -597,10 +607,13 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length)
return 0;
}

/** Get our nickname and put it in name.
/**
* Get your nickname.
* m - The messenger context to use.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
*
* return the length of the name.
* return length of the name.
* return 0 on error.
*/
uint16_t getself_name(const Messenger *m, uint8_t *name)
{
Expand All @@ -614,7 +627,7 @@ uint16_t getself_name(const Messenger *m, uint8_t *name)
}

/** Get name of friendnumber and put it in name.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
*
* return length of name if success.
* return -1 if failure.
Expand Down Expand Up @@ -685,8 +698,11 @@ int m_set_userstatus(Messenger *m, uint8_t status)
return 0;
}

/** return the size of friendnumber's user status.
/**
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
*
* returns the length of friendnumber's status message, including null on success.
* returns -1 on failure.
*/
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber)
{
Expand All @@ -697,8 +713,12 @@ int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].statusmessage_length;
}

/** Copy the user status of friendnumber into buf, truncating if needed to maxlen
* bytes, use m_get_statusmessage_size to find out how much you need to allocate.
/** Copy friendnumber's status message into buf, truncating if size is over maxlen.
* Get the size you need to allocate from m_get_statusmessage_size.
* The self variant will copy our own status message.
*
* returns the length of the copied data on success
* returns -1 on failure.
*/
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
{
Expand Down Expand Up @@ -1771,12 +1791,21 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lo
}


/** TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets.
/** High level function to send custom lossy packets.
*
* TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets.
* Meanwhile, m_handle_lossy_packet routes custom packets to custom_lossy_packet_registerhandler
* as you would expect from its name.
*
* I.e. custom_lossy_packet_registerhandler's "custom lossy packet" and this "custom lossy packet"
* are not the same set of packets.
*
* return -1 if friend invalid.
* return -2 if length wrong.
* return -3 if first byte invalid.
* return -4 if friend offline.
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
Expand Down Expand Up @@ -1869,7 +1898,12 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
return -1;
}

/** Run this at startup. */
/** Run this at startup.
* return allocated instance of Messenger on success.
* return 0 if there are problems.
*
* if error is not NULL it will be set to one of the values in the enum above.
*/
Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsigned int *error)
{
if (!options) {
Expand Down Expand Up @@ -2013,7 +2047,9 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
return m;
}

/** Run this before closing shop. */
/** Run this before closing shop
* Free all datastructures.
*/
void kill_messenger(Messenger *m)
{
if (!m) {
Expand Down Expand Up @@ -2777,10 +2813,10 @@ static uint32_t m_state_plugins_size(const Messenger *m)
return size;
}

/*
* Registers a state plugin with the messenger
/** Registers a state plugin for saving, loadding, and getting the size of a section of the save
*
* returns true on success
* returns false on failure
* returns false on error
*/
bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb size_callback,
m_state_load_cb load_callback,
Expand Down Expand Up @@ -2820,13 +2856,13 @@ static uint32_t m_plugin_size(const Messenger *m, State_Type type)
return UINT32_MAX;
}

/** return size of the messenger data (for saving) */
/** return size of the messenger data (for saving). */
uint32_t messenger_size(const Messenger *m)
{
return m_state_plugins_size(m);
}

/** Save the messenger in data of size messenger_size(). */
/** Save the messenger in data (must be allocated memory of size at least Messenger_size()) */
uint8_t *messenger_save(const Messenger *m, uint8_t *data)
{
for (uint8_t i = 0; i < m->options.state_plugins_length; ++i) {
Expand Down
65 changes: 34 additions & 31 deletions toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,26 @@ struct Messenger {
*/
void getaddress(const Messenger *m, uint8_t *address);

/** Add a friend.
/**
* Add a friend.
*
* Set the data that will be sent along with friend request.
* address is the address of the friend (returned by getaddress of the friend
*
* @param address is the address of the friend (returned by getaddress of the friend
* you wish to add) it must be FRIEND_ADDRESS_SIZE bytes.
* TODO(irungentoo): add checksum.
* data is the data and length is the length.
* @param data is the data.
* @param length is the length.
*
* return the friend number if success.
* return -1 if message length is too long.
* return -2 if no message (message length must be >= 1 byte).
* return -3 if user's own key.
* return -4 if friend request already sent or already a friend.
* return -6 if bad checksum in address.
* return -7 if the friend was already there but the nospam was different.
* return FA_TOOLONG if message length is too long.
* return FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
* return FAERR_OWNKEY if user's own key.
* return FAERR_ALREADYSENT if friend request already sent or already a friend.
* return FAERR_BADCHECKSUM if bad checksum in address.
* return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different.
* (the nospam for that friend was set to the new one).
* return -8 if increasing the friend list size fails.
* return FAERR_NOMEM if increasing the friend list size fails.
*/
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);

Expand All @@ -330,16 +334,16 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
*/
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);

/** return the friend number associated to that client id.
/** return the friend number associated to that public key.
* return -1 if no such friend.
*/
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);

/** Copies the public key associated to that friend id into real_pk buffer.
* Make sure that real_pk is of size CRYPTO_PUBLIC_KEY_SIZE.
*
* return 0 if success
* return -1 if failure
* return 0 if success.
* return -1 if failure.
*/
int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk);

Expand All @@ -350,8 +354,8 @@ int getfriendcon_id(const Messenger *m, int32_t friendnumber);

/** Remove a friend.
*
* return 0 if success
* return -1 if failure
* return 0 if success.
* return -1 if failure.
*/
int m_delfriend(Messenger *m, int32_t friendnumber);

Expand Down Expand Up @@ -439,8 +443,11 @@ int m_get_self_name_size(const Messenger *m);
int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
int m_set_userstatus(Messenger *m, uint8_t status);

/** return the length of friendnumber's status message, including null on success.
* return -1 on failure.
/**
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
*
* returns the length of friendnumber's status message, including null on success.
* returns -1 on failure.
*/
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
int m_get_self_statusmessage_size(const Messenger *m);
Expand All @@ -450,7 +457,7 @@ int m_get_self_statusmessage_size(const Messenger *m);
* The self variant will copy our own status message.
*
* returns the length of the copied data on success
* retruns -1 on failure.
* returns -1 on failure.
*/
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
Expand Down Expand Up @@ -484,41 +491,32 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
*/
int m_get_istyping(const Messenger *m, int32_t friendnumber);

/** Set the function that will be executed when a friend request is received.
* Function format is `function(uint8_t * public_key, uint8_t * data, size_t length)`
*/
/** Set the function that will be executed when a friend request is received. */
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);

/** Set the function that will be executed when a message from a friend is received.
* Function format is: `function(uint32_t friendnumber, unsigned int type, uint8_t * message, uint32_t length)`
*/
/** Set the function that will be executed when a message from a friend is received. */
void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function);

/** Set the callback for name changes.
* `Function(uint32_t friendnumber, uint8_t *newname, size_t length)`
* You are not responsible for freeing newname.
*/
void m_callback_namechange(Messenger *m, m_friend_name_cb *function);

/** Set the callback for status message changes.
* `Function(uint32_t friendnumber, uint8_t *newstatus, size_t length)`
*
* You are not responsible for freeing newstatus
*/
void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function);

/** Set the callback for status type changes.
* `Function(uint32_t friendnumber, Userstatus kind)`
*/
void m_callback_userstatus(Messenger *m, m_friend_status_cb *function);

/** Set the callback for typing changes.
* `Function(uint32_t friendnumber, uint8_t is_typing)`
*/
void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);

/** Set the callback for read receipts.
* `Function(uint32_t friendnumber, uint32_t receipt)`
*
* If you are keeping a record of returns from m_sendmessage,
* receipt might be one of those values, meaning the message
Expand All @@ -529,7 +527,6 @@ void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);

/** Set the callback for connection status changes.
* `function(uint32_t friendnumber, uint8_t status)`
*
* Status:
* 0 -- friend went offline after being previously online.
Expand All @@ -547,7 +544,6 @@ void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionst


/** Set the callback for typing changes.
* Function(unsigned int connection_status (0 = not connected, 1 = TCP only, 2 = UDP + TCP))
*/
void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);

Expand Down Expand Up @@ -675,6 +671,13 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte,
void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler);

/** High level function to send custom lossy packets.
*
* TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets.
* Meanwhile, m_handle_lossy_packet routes custom packets to custom_lossy_packet_registerhandler
* as you would expect from its name.
*
* I.e. custom_lossy_packet_registerhandler's "custom lossy packet" and this "custom lossy packet"
* are not the same set of packets.
*
* return -1 if friend invalid.
* return -2 if length wrong.
Expand Down
Loading

0 comments on commit 13e4ff4

Please sign in to comment.