-
Notifications
You must be signed in to change notification settings - Fork 0
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
30301f2
commit 8b875cb
Showing
13 changed files
with
537 additions
and
196 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module dtp::api { | ||
|
||
// === Imports === | ||
use sui::tx_context::{TxContext}; | ||
|
||
use dtp::kvalues::{Self}; | ||
use dtp::host::{Host}; | ||
use dtp::conn_objects::{ConnObjects}; | ||
|
||
// === Friends === | ||
|
||
// === Errors === | ||
|
||
// === Constants === | ||
|
||
// === Structs === | ||
|
||
// === Public-Mutative Functions === | ||
|
||
// === Public-View Functions === | ||
|
||
// === Admin Functions === | ||
|
||
// === Public-Friend Functions === | ||
|
||
// Functions to add services to an Host. | ||
public entry fun add_service_ping(host: &mut Host, args: vector<u8>, ctx: &mut TxContext) : vector<u8> | ||
{ | ||
let kvargs = kvalues::from_bytes(&args); | ||
let ret_value = dtp::api_impl::add_service_ping(host, &kvargs, ctx); | ||
kvalues::to_bytes(&ret_value) | ||
} | ||
|
||
// JSON-RPC 2.0 service | ||
public entry fun add_service_json_rpc(host: &mut Host, args: vector<u8>, ctx: &mut TxContext) : vector<u8> | ||
{ | ||
let kvargs = kvalues::from_bytes(&args); | ||
let ret_value = dtp::api_impl::add_service_json_rpc(host, &kvargs, ctx); | ||
kvalues::to_bytes(&ret_value) | ||
} | ||
|
||
// Returns IDs of objects needed to start exchanging data (TransportControl, Pipes, InnerPipes...). | ||
public entry fun open_connection(service_idx: u8, cli_host: &mut Host, srv_host: &mut Host, args: vector<u8>, ctx: &mut TxContext): (ConnObjects, vector<u8>) | ||
{ | ||
let kvargs = kvalues::from_bytes(&args); | ||
let (conn_objects, ret_value) = dtp::api_impl::open_connection(service_idx, cli_host, srv_host, &kvargs, ctx); | ||
(conn_objects, kvalues::to_bytes(&ret_value)) | ||
} | ||
|
||
// === Private Functions === | ||
|
||
// === Test Functions === | ||
|
||
} |
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,61 @@ | ||
module dtp::api_impl { | ||
|
||
// === Imports === | ||
use sui::tx_context::{TxContext}; | ||
|
||
use dtp::host::{Host}; | ||
use dtp::transport_control::{Self}; | ||
use dtp::conn_objects::{Self,ConnObjects}; | ||
use dtp::kvalues::{Self,KValues}; | ||
|
||
// === Friends === | ||
friend dtp::api; | ||
|
||
// === Errors === | ||
|
||
// === Constants === | ||
|
||
// === Structs === | ||
|
||
// === Public-Mutative Functions === | ||
|
||
// === Public-View Functions === | ||
|
||
// === Admin Functions === | ||
|
||
// === Public-Friend Functions === | ||
|
||
|
||
// Functions to add services to an Host. | ||
public(friend) fun add_service_ping(_host: &mut Host, _kvargs: &KValues, _ctx: &mut TxContext) : KValues | ||
{ | ||
kvalues::new() | ||
} | ||
|
||
// JSON-RPC 2.0 service | ||
public(friend) fun add_service_json_rpc(_host: &mut Host, _kvargs: &KValues, _ctx: &mut TxContext) : KValues | ||
{ | ||
kvalues::new() | ||
} | ||
|
||
|
||
// Returns IDs of objects needed to start exchanging data (TransportControl, Pipes, InnerPipes...). | ||
public(friend) fun open_connection(service_idx: u8, cli_host: &mut Host, srv_host: &mut Host, _kvargs: &KValues, ctx: &mut TxContext): (ConnObjects, KValues) | ||
{ | ||
let conn = conn_objects::new(); | ||
|
||
// Create the connection. Will emit an event on success | ||
transport_control::create_best_effort(service_idx, cli_host, srv_host, &mut conn, ctx); | ||
|
||
// TODO Add references in Host object for slow discovery. | ||
//host::add_connection(cli_host, &conn.transport_control); | ||
//host::add_connection(srv_host, &conn.transport_control); | ||
|
||
(conn, kvalues::new()) | ||
} | ||
|
||
// === Private Functions === | ||
|
||
// === Test Functions === | ||
|
||
} |
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,71 @@ | ||
module dtp::conn_objects { | ||
// === Imports === | ||
use std::vector; | ||
|
||
// === Friends === | ||
friend dtp::api_impl; | ||
friend dtp::host; | ||
friend dtp::transport_control; | ||
friend dtp::pipe; | ||
friend dtp::inner_pipe; | ||
|
||
// === Errors === | ||
|
||
// === Constants === | ||
|
||
// === Structs === | ||
struct ConnObjects has drop, copy, store { | ||
// References to all objects needed to exchange data | ||
// through a connection. | ||
// | ||
// If an end-point loose these references, they can be | ||
// re-discovered using one of the related Host object. | ||
tc: address, // TransportControl | ||
cli_tx_pipe: address, | ||
srv_tx_pipe: address, | ||
cli_tx_ipipes: vector<address>, | ||
srv_tx_ipipes: vector<address>, | ||
} | ||
|
||
// === Public-Mutative Functions === | ||
|
||
// === Public-View Functions === | ||
|
||
// === Admin Functions === | ||
|
||
// === Public-Friend Functions === | ||
public(friend) fun new(): ConnObjects { | ||
ConnObjects{ | ||
tc: @0x0, | ||
cli_tx_pipe: @0x0, | ||
srv_tx_pipe: @0x0, | ||
cli_tx_ipipes: vector::empty(), | ||
srv_tx_ipipes: vector::empty(), | ||
} | ||
} | ||
|
||
public(friend) fun set_tc(self: &mut ConnObjects, tc: address) { | ||
self.tc = tc; | ||
} | ||
|
||
public(friend) fun set_cli_tx_pipe(self: &mut ConnObjects, cli_tx_pipe: address) { | ||
self.cli_tx_pipe = cli_tx_pipe; | ||
} | ||
|
||
public(friend) fun set_srv_tx_pipe(self: &mut ConnObjects, srv_tx_pipe: address) { | ||
self.srv_tx_pipe = srv_tx_pipe; | ||
} | ||
|
||
public(friend) fun add_cli_tx_ipipe(self: &mut ConnObjects, cli_tx_ipipe: address) { | ||
vector::push_back(&mut self.cli_tx_ipipes, cli_tx_ipipe); | ||
} | ||
|
||
public(friend) fun add_srv_tx_ipipe(self: &mut ConnObjects, srv_tx_ipipe: address) { | ||
vector::push_back(&mut self.srv_tx_ipipes, srv_tx_ipipe); | ||
} | ||
|
||
// === Private Functions === | ||
|
||
// === Test Functions === | ||
|
||
} |
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
Oops, something went wrong.