This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fbd266
commit 5811b8c
Showing
9 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod auth; | ||
pub mod sub; | ||
pub mod client; | ||
pub mod utils; | ||
|
||
pub use auth::*; | ||
pub use sub::*; | ||
pub use client::*; | ||
pub use utils::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::{AppInst, Address, Subscriber, Message, PskIds, KePks, MessageLinks, SeqState, Preparsed, utils, client}; | ||
|
||
use iota_streams::app_channels::api::tangle::{ | ||
Subscriber as Sub, | ||
Message as TangleMessage, | ||
Preparsed as PreparsedMessage, | ||
}; | ||
use iota_streams::app::transport::{ | ||
tangle::{ | ||
TangleAddress, | ||
AppInst as ApplicationInstance, | ||
MsgId as MessageIdentifier, | ||
} | ||
}; | ||
use iota_streams::ddml::types::Bytes; | ||
|
||
use std::mem; | ||
use std::ffi::CStr; | ||
use std::os::raw::{c_char, c_ulonglong}; | ||
use iota::client::Client; | ||
use crate::constants::*; | ||
|
||
/// Create a new subscriber | ||
#[no_mangle] | ||
pub extern "C" fn sub_new(seed: *const c_char , encoding: *const c_char, payload_length: *const c_ulonglong) -> *mut Subscriber { | ||
let c_seed = unsafe { | ||
CStr::from_ptr(seed) | ||
}; | ||
|
||
let c_encoding = unsafe { | ||
CStr::from_ptr(encoding) | ||
}; | ||
|
||
Client::get(); | ||
Client::add_node(URL).unwrap(); | ||
|
||
let sub = Sub::new(c_seed.to_str().unwrap(), c_encoding.to_str().unwrap(), payload_length as usize); | ||
Box::into_raw(Box::new(Subscriber{ sub })) | ||
} | ||
|
||
/// Handle Channel app instance announcement. | ||
#[no_mangle] | ||
pub extern "C" fn sub_unwrap_announce(subscriber: *mut Subscriber, message: *mut TangleMessage){ | ||
unsafe { | ||
let mut sub = Box::from_raw(subscriber); | ||
let msg = Box::from_raw(message); | ||
|
||
let parsed = msg.parse_header(); | ||
|
||
sub.sub.unwrap_announcement(parsed.unwrap()).unwrap(); | ||
mem::forget(sub); | ||
mem::forget(msg); | ||
} | ||
} | ||
|
||
/// Subscribe to a Channel app instance. | ||
#[no_mangle] | ||
pub extern "C" fn sub_subscribe(subscriber: *mut Subscriber, announcement_link: *mut Address) -> *mut Address { | ||
let mut sub = unsafe { Box::from_raw(subscriber) }; | ||
let unboxed_address = unsafe { Box::from_raw(announcement_link) }; | ||
let tangle_address = Address( | ||
TangleAddress::new(unboxed_address.0.appinst.clone(), unboxed_address.0.msgid.clone()) | ||
); | ||
std::mem::forget(unboxed_address); | ||
|
||
let msg = sub.sub.subscribe(&tangle_address.0).unwrap(); | ||
mem::forget(sub); | ||
|
||
let mut client = Client::get(); | ||
client::send_message(&mut client, &Message(msg.clone())); | ||
Box::into_raw(Box::new(Address(msg.link))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters