Skip to content

Commit

Permalink
fix: chat ffi seed peers (#5786)
Browse files Browse the repository at this point in the history
Description
---
Previously we reconfigured the configuration (:D) for chat to allow for
easier seed peer setting in the FFI, but I forgot to apply the boolean
for using DNS peers.

Motivation and Context
---
Get peers on ffi.

How Has This Been Tested?
---
With disposable tests in cucumber locally, and 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 20, 2023
1 parent 5901b4a commit c04996f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion base_layer/chat_ffi/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ struct ChatMessages *get_chat_messages(struct ChatClientFFI *client,
* `message` should be destroyed eventually
*/
void add_chat_message_metadata(struct Message *message,
const int *metadata_type,
int metadata_type,
const char *data,
int *error_out);

Expand Down
6 changes: 5 additions & 1 deletion base_layer/chat_ffi/src/application_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use tari_chat_client::{
networking::Multiaddr,
};
use tari_common::configuration::{MultiaddrList, Network};
use tari_p2p::TransportConfig;
use tari_p2p::{PeerSeedsConfig, TransportConfig};

use crate::error::{InterfaceError, LibChatError};

Expand Down Expand Up @@ -175,6 +175,10 @@ pub unsafe extern "C" fn create_chat_config(

let config = ApplicationConfig {
chat_client: chat_client_config,
peer_seeds: PeerSeedsConfig {
dns_seeds_use_dnssec: true,
..PeerSeedsConfig::default()
},
..ApplicationConfig::default()
};

Expand Down
17 changes: 13 additions & 4 deletions base_layer/chat_ffi/src/message_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{ffi::CStr, ptr};
use std::{convert::TryFrom, ffi::CStr, ptr};

use libc::{c_char, c_int};
use tari_contacts::contacts_service::types::{Message, MessageMetadata, MessageMetadataType};
Expand All @@ -45,7 +45,7 @@ use crate::error::{InterfaceError, LibChatError};
#[no_mangle]
pub unsafe extern "C" fn add_chat_message_metadata(
message: *mut Message,
metadata_type: *const c_int,
metadata_type: c_int,
data: *const c_char,
error_out: *mut c_int,
) {
Expand All @@ -58,7 +58,16 @@ pub unsafe extern "C" fn add_chat_message_metadata(
return;
}

let metadata_type = match MessageMetadataType::from_byte(metadata_type as u8) {
let metadata_byte = match u8::try_from(metadata_type) {
Ok(byte) => byte,
Err(e) => {
error = LibChatError::from(InterfaceError::InvalidArgument(e.to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return;
},
};

let metadata_type = match MessageMetadataType::from_byte(metadata_byte) {
Some(t) => t,
None => {
error = LibChatError::from(InterfaceError::InvalidArgument(
Expand Down Expand Up @@ -106,7 +115,7 @@ mod test {

let error_out = Box::into_raw(Box::new(0));

unsafe { add_chat_message_metadata(message_ptr, 1 as *const c_int, data_char, error_out) }
unsafe { add_chat_message_metadata(message_ptr, 0 as c_int, data_char, error_out) }

let message = unsafe { Box::from_raw(message_ptr) };
assert_eq!(message.metadata.len(), 1)
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/src/chat_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern "C" {
pub fn send_chat_message(client: *mut ClientFFI, message: *mut c_void, error_out: *const c_int);
pub fn add_chat_message_metadata(
message: *mut c_void,
metadata_type: *const c_int,
metadata_type: c_int,
data: *const c_char,
error_out: *const c_int,
) -> *mut c_void;
Expand Down Expand Up @@ -164,7 +164,7 @@ impl ChatClient for ChatFFI {

fn add_metadata(&self, message: Message, metadata_type: MessageMetadataType, data: String) -> Message {
let message_ptr = Box::into_raw(Box::new(message)) as *mut c_void;
let message_type = metadata_type.as_byte() as *const c_int;
let message_type = i32::from(metadata_type.as_byte());

let data_c_str = CString::new(data).unwrap();
let data_c_char: *const c_char = CString::into_raw(data_c_str) as *const c_char;
Expand Down

0 comments on commit c04996f

Please sign in to comment.