Skip to content

Commit

Permalink
Updating toxcore to 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dvor committed Jan 4, 2017
1 parent ae007a3 commit 8b580d6
Show file tree
Hide file tree
Showing 13 changed files with 699 additions and 173 deletions.
2 changes: 1 addition & 1 deletion toxcore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "toxcore"
s.version = "0.0.5"
s.version = "0.1.0"
s.summary = "Cocoapods wrapper for toxcore"
s.homepage = "https://github.com/Antidote-for-Tox/toxcore"
s.license = 'GPLv3'
Expand Down
2 changes: 1 addition & 1 deletion toxcore/toxav/bwcontroller.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void send_update(BWController *bwc)
b_msg->lost = htonl(bwc->cycle.lost);
b_msg->recv = htonl(bwc->cycle.recv);

if (-1 == send_custom_lossy_packet(bwc->m, bwc->friend_number, p_msg, sizeof(p_msg))) {
if (-1 == m_send_custom_lossy_packet(bwc->m, bwc->friend_number, p_msg, sizeof(p_msg))) {
LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %d)! std error: %s", sizeof(p_msg), strerror(errno));
}
}
Expand Down
10 changes: 5 additions & 5 deletions toxcore/toxav/rtp.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log

memcpy(rdata + 1 + sizeof(struct RTPHeader), data, length);

if (-1 == send_custom_lossy_packet(session->m, session->friend_number, rdata, sizeof(rdata))) {
if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, sizeof(rdata))) {
LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", sizeof(rdata), strerror(errno));
}
} else {
Expand All @@ -164,8 +164,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log
while ((length - sent) + sizeof(struct RTPHeader) + 1 > MAX_CRYPTO_DATA_SIZE) {
memcpy(rdata + 1 + sizeof(struct RTPHeader), data + sent, piece);

if (-1 == send_custom_lossy_packet(session->m, session->friend_number,
rdata, piece + sizeof(struct RTPHeader) + 1)) {
if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number,
rdata, piece + sizeof(struct RTPHeader) + 1)) {
LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s",
piece + sizeof(struct RTPHeader) + 1, strerror(errno));
}
Expand All @@ -180,8 +180,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log
if (piece) {
memcpy(rdata + 1 + sizeof(struct RTPHeader), data + sent, piece);

if (-1 == send_custom_lossy_packet(session->m, session->friend_number, rdata,
piece + sizeof(struct RTPHeader) + 1)) {
if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata,
piece + sizeof(struct RTPHeader) + 1)) {
LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s",
piece + sizeof(struct RTPHeader) + 1, strerror(errno));
}
Expand Down
2 changes: 1 addition & 1 deletion toxcore/toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_cal
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);


/* Set handlers for custom lossless packets.
Expand Down
14 changes: 9 additions & 5 deletions toxcore/toxcore/Messenger.m
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int
}


int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
if (friend_not_valid(m, friendnumber)) {
return -1;
Expand Down Expand Up @@ -2663,9 +2663,9 @@ static uint32_t friend_size()
data++; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
data++; // padding
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
Expand Down Expand Up @@ -2700,9 +2700,9 @@ static uint32_t saved_friendslist_size(const Messenger *m)
data++; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
data++; // padding
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
Expand Down Expand Up @@ -2752,7 +2752,9 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
uint8_t *next_data = friend_save(&temp, cur_data);
#ifdef TOX_DEBUG
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(cur_data, &temp, friend_size()) == 0);
#endif
#endif
cur_data = next_data;
num++;
Expand Down Expand Up @@ -2782,9 +2784,9 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
data++; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
data++; // padding
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
Expand Down Expand Up @@ -2812,7 +2814,9 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
const uint8_t *next_data = friend_load(&temp, cur_data);
#ifdef TOX_DEBUG
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(&temp, cur_data, friend_size()) == 0);
#endif
#endif
cur_data = next_data;

Expand Down Expand Up @@ -2988,7 +2992,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
break;

case MESSENGER_STATE_TYPE_STATUSMESSAGE:
if ((length > 0) && (length < MAX_STATUSMESSAGE_LENGTH)) {
if ((length > 0) && (length <= MAX_STATUSMESSAGE_LENGTH)) {
m_set_statusmessage(m, data, length);
}

Expand Down
6 changes: 3 additions & 3 deletions toxcore/toxcore/net_crypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
* return -1 on failure.
* return 0 on success.
*/
static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
{
if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) {
return -1;
Expand Down Expand Up @@ -1542,7 +1542,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons

case NET_PACKET_CRYPTO_DATA: {
if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) {
return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata);
return handle_data_packet_core(c, crypt_connection_id, packet, length, udp, userdata);
}

return -1;
Expand Down
27 changes: 19 additions & 8 deletions toxcore/toxcore/tox.api.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,34 @@ const VERSION_MAJOR = 0;
* breaking the API or ABI. Set to 0 when the major version number is
* incremented.
*/
const VERSION_MINOR = 0;
const VERSION_MINOR = 1;

/**
* The patch or revision number. Incremented when bugfixes are applied without
* changing any functionality or API or ABI.
*/
const VERSION_PATCH = 5;
const VERSION_PATCH = 0;

/**
* A macro to check at preprocessing time whether the client code is compatible
* with the installed version of Tox.
* with the installed version of Tox. Leading zeros in the version number are
* ignored. E.g. 0.1.5 is to 0.1.4 what 1.5 is to 1.4, that is: it can add new
* features, but can't break the API.
*/
#define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
(TOX_VERSION_MAJOR == MAJOR && \
(TOX_VERSION_MINOR > MINOR || \
(TOX_VERSION_MINOR == MINOR && \
TOX_VERSION_PATCH >= PATCH)))
#define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
(TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \
/* 1.x.x, 2.x.x, etc. with matching major version. */ \
TOX_VERSION_MINOR > MINOR || \
TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \
) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \
/* 0.x.x makes minor behave like major above. */ \
(TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \
TOX_VERSION_PATCH >= PATCH \
) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \
/* 0.0.x and 0.0.y are only compatible if x == y. */ \
TOX_VERSION_PATCH == PATCH \
) \
)

/**
* A macro to make compilation fail if the client code is not compatible with
Expand Down
29 changes: 20 additions & 9 deletions toxcore/toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,38 @@ uint32_t tox_version_major(void);
* breaking the API or ABI. Set to 0 when the major version number is
* incremented.
*/
#define TOX_VERSION_MINOR 0
#define TOX_VERSION_MINOR 1

uint32_t tox_version_minor(void);

/**
* The patch or revision number. Incremented when bugfixes are applied without
* changing any functionality or API or ABI.
*/
#define TOX_VERSION_PATCH 5
#define TOX_VERSION_PATCH 0

uint32_t tox_version_patch(void);

/**
* A macro to check at preprocessing time whether the client code is compatible
* with the installed version of Tox.
*/
#define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
(TOX_VERSION_MAJOR == MAJOR && \
(TOX_VERSION_MINOR > MINOR || \
(TOX_VERSION_MINOR == MINOR && \
TOX_VERSION_PATCH >= PATCH)))
* with the installed version of Tox. Leading zeros in the version number are
* ignored. E.g. 0.1.5 is to 0.1.4 what 1.5 is to 1.4, that is: it can add new
* features, but can't break the API.
*/
#define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
(TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \
/* 1.x.x, 2.x.x, etc. with matching major version. */ \
TOX_VERSION_MINOR > MINOR || \
TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \
) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \
/* 0.x.x makes minor behave like major above. */ \
(TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \
TOX_VERSION_PATCH >= PATCH \
) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \
/* 0.0.x and 0.0.y are only compatible if x == y. */ \
TOX_VERSION_PATCH == PATCH \
) \
)

/**
* A macro to make compilation fail if the client code is not compatible with
Expand Down
8 changes: 2 additions & 6 deletions toxcore/toxcore/tox.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ uint32_t tox_version_patch(void)

bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
{
return (TOX_VERSION_MAJOR == major && /* Force the major version */
(TOX_VERSION_MINOR > minor || /* Current minor version must be newer than requested -- or -- */
(TOX_VERSION_MINOR == minor && TOX_VERSION_PATCH >= patch) /* the patch must be the same or newer */
)
);
return TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch);
}


Expand Down Expand Up @@ -1593,7 +1589,7 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
return 0;
}

int ret = send_custom_lossy_packet(m, friend_number, data, length);
int ret = m_send_custom_lossy_packet(m, friend_number, data, length);

set_custom_packet_error(ret, error);

Expand Down
Loading

0 comments on commit 8b580d6

Please sign in to comment.