Skip to content

Commit

Permalink
Updating toxcore to 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dvor committed Jan 4, 2017
1 parent 8b580d6 commit b2e0737
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 43 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.1.0"
s.version = "0.1.1"
s.summary = "Cocoapods wrapper for toxcore"
s.homepage = "https://github.com/Antidote-for-Tox/toxcore"
s.license = 'GPLv3'
Expand Down
1 change: 1 addition & 0 deletions toxcore/toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef struct {
uint16_t tcp_server_port;

uint8_t hole_punching_enabled;
bool local_discovery_enabled;

logger_cb *log_callback;
void *log_user_data;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/toxcore/Messenger.m
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
m->onion = new_onion(m->dht);
m->onion_a = new_onion_announce(m->dht);
m->onion_c = new_onion_client(m->net_crypto);
m->fr_c = new_friend_connections(m->onion_c);
m->fr_c = new_friend_connections(m->onion_c, options->local_discovery_enabled);

if (!(m->onion && m->onion_a && m->onion_c)) {
kill_friend_connections(m->fr_c);
Expand Down
4 changes: 3 additions & 1 deletion toxcore/toxcore/friend_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ typedef struct {
void *fr_request_object;

uint64_t last_LANdiscovery;

bool local_discovery_enabled;
} Friend_Connections;

/* return friendcon_id corresponding to the real public key on success.
Expand Down Expand Up @@ -197,7 +199,7 @@ void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_call
const uint8_t *, uint16_t, void *), void *object);

/* Create new friend_connections instance. */
Friend_Connections *new_friend_connections(Onion_Client *onion_c);
Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled);

/* main friend_connections loop. */
void do_friend_connections(Friend_Connections *fr_c, void *userdata);
Expand Down
17 changes: 13 additions & 4 deletions toxcore/toxcore/friend_connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
}

/* Create new friend_connections instance. */
Friend_Connections *new_friend_connections(Onion_Client *onion_c)
Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled)
{
if (!onion_c) {
return NULL;
Expand All @@ -826,9 +826,13 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
temp->dht = onion_c->dht;
temp->net_crypto = onion_c->c;
temp->onion_c = onion_c;
temp->local_discovery_enabled = local_discovery_enabled;

new_connection_handler(temp->net_crypto, &handle_new_connections, temp);
LANdiscovery_init(temp->dht);

if (temp->local_discovery_enabled) {
LANdiscovery_init(temp->dht);
}

return temp;
}
Expand Down Expand Up @@ -889,7 +893,9 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
}
}

LANdiscovery(fr_c);
if (fr_c->local_discovery_enabled) {
LANdiscovery(fr_c);
}
}

/* Free everything related with friend_connections. */
Expand All @@ -905,6 +911,9 @@ void kill_friend_connections(Friend_Connections *fr_c)
kill_friend_connection(fr_c, i);
}

LANdiscovery_kill(fr_c->dht);
if (fr_c->local_discovery_enabled) {
LANdiscovery_kill(fr_c->dht);
}

free(fr_c);
}
32 changes: 15 additions & 17 deletions toxcore/toxcore/tox.api.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ 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 = 0;
const VERSION_PATCH = 1;

/**
* A macro to check at preprocessing time whether the client code is compatible
* with the installed version of Tox. Leading zeros in the version number are
* 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.
*/
Expand All @@ -202,13 +202,6 @@ const VERSION_PATCH = 0;
) \
)

/**
* A macro to make compilation fail if the client code is not compatible with
* the installed version of Tox.
*/
#define TOX_VERSION_REQUIRE(MAJOR, MINOR, PATCH) \
typedef char tox_required_version[TOX_IS_COMPATIBLE(MAJOR, MINOR, PATCH) ? 1 : -1]

static namespace version {

/**
Expand Down Expand Up @@ -435,19 +428,17 @@ typedef void log_cb(LOG_LEVEL level, string file, uint32_t line, string func, st

static class options {
/**
* This struct contains all the startup options for Tox. You can either
* allocate this object yourself, and pass it to $default, or call $new to get
* a new default options object.
* This struct contains all the startup options for Tox. You must $new to
* allocate an object of this type.
*
* If you allocate it yourself, be aware that your binary will rely on the
* memory layout of this struct. In particular, if additional fields are added
* in future versions of the API, code that allocates it itself will become
* incompatible.
* WARNING: Although this struct happens to be visible in the API, it is
* effectively private. Do not allocate this yourself or access members
* directly, as it *will* break binary compatibility frequently.
*
* @deprecated The memory layout of this struct (size, alignment, and field
* order) is not part of the ABI. To remain compatible, prefer to use $new to
* allocate the object and accessor functions to set the members. The struct
* will become opaque (i.e. the definition will become private) in v0.1.0.
* will become opaque (i.e. the definition will become private) in v0.2.0.
*/
struct this [get, set] {
/**
Expand All @@ -469,6 +460,13 @@ static class options {
*/
bool udp_enabled;

/**
* Enable local network peer discovery.
*
* Disabling this will cause Tox to not look for peers on the local network.
*/
bool local_discovery_enabled;

namespace proxy {
/**
* Pass communications through a proxy.
Expand Down
35 changes: 19 additions & 16 deletions toxcore/toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ 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 0
#define TOX_VERSION_PATCH 1

uint32_t tox_version_patch(void);

Expand All @@ -205,13 +205,6 @@ uint32_t tox_version_patch(void);
) \
)

/**
* A macro to make compilation fail if the client code is not compatible with
* the installed version of Tox.
*/
#define TOX_VERSION_REQUIRE(MAJOR, MINOR, PATCH) \
typedef char tox_required_version[TOX_IS_COMPATIBLE(MAJOR, MINOR, PATCH) ? 1 : -1]

/**
* Return whether the compiled library version is compatible with the passed
* version numbers.
Expand Down Expand Up @@ -484,19 +477,17 @@ typedef void tox_log_cb(Tox *tox, TOX_LOG_LEVEL level, const char *file, uint32_


/**
* This struct contains all the startup options for Tox. You can either
* allocate this object yourself, and pass it to tox_options_default, or call tox_options_new to get
* a new default options object.
* This struct contains all the startup options for Tox. You must tox_options_new to
* allocate an object of this type.
*
* If you allocate it yourself, be aware that your binary will rely on the
* memory layout of this struct. In particular, if additional fields are added
* in future versions of the API, code that allocates it itself will become
* incompatible.
* WARNING: Although this struct happens to be visible in the API, it is
* effectively private. Do not allocate this yourself or access members
* directly, as it *will* break binary compatibility frequently.
*
* @deprecated The memory layout of this struct (size, alignment, and field
* order) is not part of the ABI. To remain compatible, prefer to use tox_options_new to
* allocate the object and accessor functions to set the members. The struct
* will become opaque (i.e. the definition will become private) in v0.1.0.
* will become opaque (i.e. the definition will become private) in v0.2.0.
*/
struct Tox_Options {

Expand All @@ -521,6 +512,14 @@ struct Tox_Options {
bool udp_enabled;


/**
* Enable local network peer discovery.
*
* Disabling this will cause Tox to not look for peers on the local network.
*/
bool local_discovery_enabled;


/**
* Pass communications through a proxy.
*/
Expand Down Expand Up @@ -635,6 +634,10 @@ bool tox_options_get_udp_enabled(const struct Tox_Options *options);

void tox_options_set_udp_enabled(struct Tox_Options *options, bool udp_enabled);

bool tox_options_get_local_discovery_enabled(const struct Tox_Options *options);

void tox_options_set_local_discovery_enabled(struct Tox_Options *options, bool local_discovery_enabled);

TOX_PROXY_TYPE tox_options_get_proxy_type(const struct Tox_Options *options);

void tox_options_set_proxy_type(struct Tox_Options *options, TOX_PROXY_TYPE type);
Expand Down
3 changes: 3 additions & 0 deletions toxcore/toxcore/tox.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
ACCESSORS(size_t, savedata_, length)
ACCESSORS(tox_log_cb *, log_, callback)
ACCESSORS(void *, log_, user_data)
ACCESSORS(bool, , local_discovery_enabled)

const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options)
{
Expand All @@ -153,6 +154,7 @@ void tox_options_default(struct Tox_Options *options)
options->udp_enabled = 1;
options->proxy_type = TOX_PROXY_TYPE_NONE;
options->hole_punching_enabled = true;
options->local_discovery_enabled = true;
}
}

Expand Down Expand Up @@ -218,6 +220,7 @@ void tox_options_free(struct Tox_Options *options)
m_options.port_range[1] = options->end_port;
m_options.tcp_server_port = options->tcp_port;
m_options.hole_punching_enabled = options->hole_punching_enabled;
m_options.local_discovery_enabled = options->local_discovery_enabled;

m_options.log_callback = (logger_cb *)options->log_callback;
m_options.log_user_data = options->log_user_data;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/toxencryptsave/toxencryptsave.api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" {
* prefer the advanced API and reuse pass-key objects.
*
* To use the second part, first derive an encryption key from a password with
* ${pass_Key.derive}, then use the derived key to encrypt the data.
* ${tox.pass_Key.derive}, then use the derived key to encrypt the data.
*
* The encrypted data is prepended with a magic number, to aid validity
* checking (no guarantees are made of course). Any data to be decrypted must
Expand Down
2 changes: 1 addition & 1 deletion toxcore/toxencryptsave/toxencryptsave.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
* prefer the advanced API and reuse pass-key objects.
*
* To use the second part, first derive an encryption key from a password with
* <unresolved>, then use the derived key to encrypt the data.
* tox_pass_key_derive, then use the derived key to encrypt the data.
*
* The encrypted data is prepended with a magic number, to aid validity
* checking (no guarantees are made of course). Any data to be decrypted must
Expand Down

0 comments on commit b2e0737

Please sign in to comment.