Skip to content

Commit

Permalink
feat(chatffi): tor configuration (#5752)
Browse files Browse the repository at this point in the history
Description
---
Allow more configuration options for TOR

Motivation and Context
---
Mobile doesn't align with the tor transport config defaults that were
being applied, so let's allow for a specific configuration.

How Has This Been Tested?
---
CI

Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify
  • Loading branch information
brianp authored Sep 12, 2023
1 parent 3fa6a23 commit 1eeb4a9
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 52 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions base_layer/chat_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ tari_common = { path = "../../common" }
tari_common_types = { path = "../common_types" }
tari_comms = { path = "../../comms/core" }
tari_contacts = { path = "../contacts" }
tari_p2p = { path = "../p2p" }
tari_shutdown = { path = "../../infrastructure/shutdown" }
tari_utilities = { version = "0.5" }

libc = "0.2.65"
libsqlite3-sys = { version = "0.25.1", features = ["bundled"], optional = true }
Expand Down
93 changes: 70 additions & 23 deletions base_layer/chat_ffi/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@

struct ApplicationConfig;

struct ChatMessages;
struct ChatByteVector;

struct ChatClientFFI;

struct ClientFFI;
struct ChatMessages;

struct TariAddress;

struct TransportConfig;

struct ChatFFIContactsLivenessData {
const char *address;
uint64_t last_seen;
Expand Down Expand Up @@ -52,24 +56,24 @@ extern "C" {
* # Safety
* The ```destroy_client``` method must be called when finished with a ClientFFI to prevent a memory leak
*/
struct ClientFFI *create_chat_client(struct ApplicationConfig *config,
int *error_out,
CallbackContactStatusChange callback_contact_status_change,
CallbackMessageReceived callback_message_received);
struct ChatClientFFI *create_chat_client(struct ApplicationConfig *config,
int *error_out,
CallbackContactStatusChange callback_contact_status_change,
CallbackMessageReceived callback_message_received);

/**
* Frees memory for a ClientFFI
* Frees memory for a ChatClientFFI
*
* ## Arguments
* `client` - The pointer of a ClientFFI
* `client` - The pointer of a ChatClientFFI
*
* ## Returns
* `()` - Does not return a value, equivalent to void in C
*
* # Safety
* None
*/
void destroy_client_ffi(struct ClientFFI *client);
void destroy_chat_client_ffi(struct ChatClientFFI *client);

/**
* Creates a Chat Client config
Expand All @@ -89,6 +93,7 @@ struct ApplicationConfig *create_chat_config(const char *network_str,
const char *public_address,
const char *datastore_path,
const char *identity_file_path,
struct TransportConfig *tor_transport_config,
const char *log_path,
int *error_out);

Expand All @@ -104,7 +109,7 @@ struct ApplicationConfig *create_chat_config(const char *network_str,
* # Safety
* None
*/
void destroy_config(struct ApplicationConfig *config);
void destroy_chat_config(struct ApplicationConfig *config);

/**
* Sends a message over a client
Expand All @@ -121,10 +126,10 @@ void destroy_config(struct ApplicationConfig *config);
* # Safety
* The ```receiver``` should be destroyed after use
*/
void send_message(struct ClientFFI *client,
struct TariAddress *receiver,
const char *message_c_char,
int *error_out);
void send_chat_message(struct ChatClientFFI *client,
struct TariAddress *receiver,
const char *message_c_char,
int *error_out);

/**
* Add a contact
Expand All @@ -140,7 +145,7 @@ void send_message(struct ClientFFI *client,
* # Safety
* The ```address``` should be destroyed after use
*/
void add_contact(struct ClientFFI *client, struct TariAddress *receiver, int *error_out);
void add_chat_contact(struct ChatClientFFI *client, struct TariAddress *receiver, int *error_out);

/**
* Check the online status of a contact
Expand All @@ -156,7 +161,7 @@ void add_contact(struct ClientFFI *client, struct TariAddress *receiver, int *er
* # Safety
* The ```address``` should be destroyed after use
*/
int check_online_status(struct ClientFFI *client, struct TariAddress *receiver, int *error_out);
int check_online_status(struct ChatClientFFI *client, struct TariAddress *receiver, int *error_out);

/**
* Get a ptr to all messages from or to address
Expand All @@ -175,11 +180,11 @@ int check_online_status(struct ClientFFI *client, struct TariAddress *receiver,
* The ```address``` should be destroyed after use
* The returned pointer to ```*mut ChatMessages``` should be destroyed after use
*/
struct ChatMessages *get_messages(struct ClientFFI *client,
struct TariAddress *address,
int *limit,
int *page,
int *error_out);
struct ChatMessages *get_chat_messages(struct ChatClientFFI *client,
struct TariAddress *address,
int *limit,
int *page,
int *error_out);

/**
* Frees memory for messages
Expand All @@ -193,7 +198,7 @@ struct ChatMessages *get_messages(struct ClientFFI *client,
* # Safety
* None
*/
void destroy_messages(struct ChatMessages *messages_ptr);
void destroy_chat_messages(struct ChatMessages *messages_ptr);

/**
* Creates a TariAddress and returns a ptr
Expand Down Expand Up @@ -224,11 +229,53 @@ struct TariAddress *create_tari_address(const char *receiver_c_char, int *error_
*/
void destroy_tari_address(struct TariAddress *address);

/**
* Creates a tor transport config
*
* ## Arguments
* `control_server_address` - The pointer to a char array
* `tor_cookie` - The pointer to a ChatByteVector containing the contents of the tor cookie file, can be null
* `tor_port` - The tor port
* `tor_proxy_bypass_for_outbound` - Whether tor will use a direct tcp connection for a given bypass address instead of
* the tor proxy if tcp is available, if not it has no effect
* `socks_password` - The pointer to a char array containing the socks password, can be null
* `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
* as an out parameter.
*
* ## Returns
* `*mut TransportConfig` - Returns a pointer to a tor TransportConfig, null on error.
*
* # Safety
* The ```destroy_chat_tor_transport_config``` method must be called when finished with a TransportConfig to prevent a
* memory leak
*/
struct TransportConfig *create_chat_tor_transport_config(const char *control_server_address,
const struct ChatByteVector *tor_cookie,
unsigned short tor_port,
bool tor_proxy_bypass_for_outbound,
const char *socks_username,
const char *socks_password,
int *error_out);

/**
* Frees memory for a TransportConfig
*
* ## Arguments
* `transport` - The pointer to a TransportConfig
*
* ## Returns
* `()` - Does not return a value, equivalent to void in C
*
* # Safety
* None
*/
void destroy_chat_tor_transport_config(struct TransportConfig *transport);

/**
* Frees memory for a ChatFFIMessage
*
* ## Arguments
* `address` - The pointer of a ChatFFIMessage
* `transport` - The pointer to a ChatFFIMessage
*
* ## Returns
* `()` - Does not return a value, equivalent to void in C
Expand Down
Loading

0 comments on commit 1eeb4a9

Please sign in to comment.