Skip to content

Commit

Permalink
Various fixes, prepare for DTP POC
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Mar 19, 2024
1 parent 0a11c3d commit c3f186f
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 105 deletions.
25 changes: 7 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,18 @@ documentation = "https://docs.dtp.dev"
default-run = "dtp-server"

[workspace.dependencies]
# By default, DTP is built using a local repo of Sui (devnet branch).
# DTP uses Suibase for both development and production.
#
# This make sure that your localnet, DTP and your app are all
# built and tested using the *same* binaries, saving you from chasing
# unnecessary problems of unmatching versions.
# This allows to keep multiple SDKs, dependencies and binaries in-sync.
#
# The local version is initialized by the script:
# dtp/script/init-localnet
# After installing Suibase, type "dtp start" to enable and start the DTP services daemon.
#
# The development environment is further explained here:
# The DTP SDK is built using the Suibase active workdir.
#
# https://github.com/mario4tier/dtp/tree/main/script
# As an example, if you did "mainnet set-active", the SDK will be built to be version compatible with mainnet
# (most of the time, this version will also work with devnet/testnet).
#
# This is all initialized by a single bash script:
# dtp/script/init-localnet
#
# A re-initialization and a single local copy of everything local is a
# bit "old-school", but it works *SOLID* and keeps your edit/debug cycles
# fast.
#
# If you are not comfortable with this way of doing and
# prefer to have the "typical" rust way then comment out
# the "path" dependencies and un-comment out the "git" ones.
# If you want to build to maximize testnet compatibility, you can do "testnet set-active" first and rebuild your Rust app.
sui-sdk = { path = "../dtp-dev/sui-devnet-branch/crates/sui-sdk/" }
sui-json-rpc-types = { path = "../dtp-dev/sui-devnet-branch/crates/sui-json-rpc-types/" }
sui-keys = { path = "../dtp-dev/sui-devnet-branch/crates/sui-keys/" }
Expand Down
2 changes: 1 addition & 1 deletion crates/dtp-core/src/network/transport_control_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) async fn create_best_effort_transport_control_on_network(
None => bail!(DTPError::DTPMissingServerAdminAddress),
};

/* Params must match. See tranport_control.move
/* Params must match. See transport_control.move
cli_host: ID,
srv_host: ID,
server_adm: address,
Expand Down
8 changes: 3 additions & 5 deletions crates/dtp-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
// There is a one-to-one relationship between a Sui client address
// and a DTP instance.
//
// Sui SDK and DTP SDK can co-exist and be used indepedently.
//
//
// Sui SDK and DTP SDK can co-exist and be used independently.

use anyhow::bail;
use dtp_core::{
Expand Down Expand Up @@ -127,10 +125,10 @@ impl DTP {
//
// Create a new DTP Host on the Sui network.
//
// The Host shared objects created on the network are retreiveable
// The Host shared objects created on the network are retrievable
// as a read-only DTP::Host by everyone with get_host_by_id()
//
// To edit/modify the Host shared object, the DTP appplication
// To edit/modify the Host shared object, the DTP application
// must have the administrator capability for it. Any DTP
// application with the same client address and keystore as
// the creator of the DTP Host object has such capability.
Expand Down
5 changes: 0 additions & 5 deletions move/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,3 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testn
dependencies = [
{ name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.18.1"
edition = "legacy"
flavor = "sui"
5 changes: 5 additions & 0 deletions move/Suibase.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[meta]
creation_timestamp = "1710097915270737 2024-03-10 15:11:55.270737012 -04:00"

[packages]
dtp = { uuid = "AJE3IMZDUQXBRYQEC7FRNM7BHQ", uuid_custom = false }
53 changes: 27 additions & 26 deletions move/sources/api.move
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ module dtp::api {
// Create a new Host
//
// Returns the "Host Address", which serve a similar purpose as an "IP address".
public fun create_host( args: &vector<u8>, ctx: &mut TxContext) : (address, vector<u8>)
public fun create_host( args: vector<u8>, ctx: &mut TxContext) : (address, vector<u8>)
//public fun create_host( ctx: &mut TxContext) : address
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let (host_addr, kvalues) = dtp::api_impl::create_host(&kvargs,ctx);
(host_addr, kvalues::to_bytes(&kvalues))
}

// Functions to add services to an Host.
public fun add_service_ping(host: &mut Host, args: &vector<u8>, ctx: &mut TxContext) : vector<u8>
public fun add_service_ping(host: &mut Host, args: vector<u8>, ctx: &mut TxContext) : vector<u8>
{
let kvargs = kvalues::from_bytes(args);
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 fun add_service_json_rpc(host: &mut Host, args: &vector<u8>, ctx: &mut TxContext) : vector<u8>
public fun add_service_json_rpc(host: &mut Host, args: vector<u8>, ctx: &mut TxContext) : vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::add_service_json_rpc(host, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}
Expand All @@ -65,39 +66,39 @@ module dtp::api {
// IDs of all objects needed to start exchanging data (TransportControl, Pipes, InnerPipes...).
// (These IDs can also be recovered through slow discovery).
//
public fun open_connection(service_idx: u8, cli_host: &mut Host, srv_host: &mut Host, args: &vector<u8>, ctx: &mut TxContext): (ConnObjects, vector<u8>)
public fun open_connection(service_idx: u8, cli_host: &mut Host, srv_host: &mut Host, args: vector<u8>, ctx: &mut TxContext): 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))
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::open_connection(service_idx, cli_host, srv_host, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

// Transmit a request toward the server.
//
// The encoding of the 'data' depends on the service.
public fun send_request(service_idx: u8, data: &vector<u8>, ipipe: &mut InnerPipe, args: &vector<u8>, ctx: &mut TxContext): vector<u8>
public fun send_request(service_idx: u8, data: &vector<u8>, ipipe: &mut InnerPipe, args: vector<u8>, ctx: &mut TxContext): vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::send_request(service_idx, data, ipipe, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

// Transmit a response toward the client.
//
// The encoding of the 'data' depends on the service.
public fun send_response(service_idx: u8, data: &vector<u8>, seq_number: u64, ipipe: &mut InnerPipe, args: &vector<u8>, ctx: &mut TxContext): vector<u8>
public fun send_response(service_idx: u8, data: &vector<u8>, seq_number: u64, ipipe: &mut InnerPipe, args: vector<u8>, ctx: &mut TxContext): vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::send_response(service_idx, data, seq_number, ipipe, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

// Transmit a notification toward the peer (no response expected).
//
// The encoding of the 'data' depends on the service.
public fun send_notification(service_idx: u8, data: &vector<u8>, ipipe: &mut InnerPipe, args: &vector<u8>, ctx: &mut TxContext): vector<u8>
public fun send_notification(service_idx: u8, data: &vector<u8>, ipipe: &mut InnerPipe, args: vector<u8>, ctx: &mut TxContext): vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::send_notification(service_idx, data, ipipe,&kvargs, ctx);
kvalues::to_bytes(&ret_value)
}
Expand All @@ -108,16 +109,16 @@ module dtp::api {
// Any end-point must perform the following two steps from time to time:
// 1) Call fast_sync_ipipe() for every owned ipipe with its related owned pipe.
// 2) Call slow_sync_pipe() for the owned pipe and shared transport control.
public fun fast_sync_ipipe(ipipe: &mut InnerPipe, pipe: &mut Pipe, args: &vector<u8>, ctx: &mut TxContext) : vector<u8>
public fun fast_sync_ipipe(ipipe: &mut InnerPipe, pipe: &mut Pipe, args: vector<u8>, ctx: &mut TxContext) : vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::fast_sync_ipipe(ipipe, pipe, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

public fun slow_sync_pipe(pipe: &mut Pipe, tc: &mut TransportControl, args: &vector<u8>, ctx: &mut TxContext) : vector<u8>
public fun slow_sync_pipe(pipe: &mut Pipe, tc: &mut TransportControl, args: vector<u8>, ctx: &mut TxContext) : vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::slow_sync_pipe(pipe, tc, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}
Expand Down Expand Up @@ -152,21 +153,21 @@ module dtp::api {
// transfered to the DTP DAO for disposal.
//

public(friend) fun close_ipipe(ipipe: InnerPipe, pipe: &mut Pipe, args: &vector<u8>, ctx: &mut TxContext ) : vector<u8> {
let kvargs = kvalues::from_bytes(args);
public(friend) fun close_ipipe(ipipe: InnerPipe, pipe: &mut Pipe, args: vector<u8>, ctx: &mut TxContext ) : vector<u8> {
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::close_ipipe(ipipe, pipe, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

public(friend) fun close_pipe(pipe: &mut Pipe, tc: &mut TransportControl, args: &vector<u8>, ctx: &mut TxContext) : vector<u8> {
let kvargs = kvalues::from_bytes(args);
public(friend) fun close_pipe(pipe: &mut Pipe, tc: &mut TransportControl, args: vector<u8>, ctx: &mut TxContext) : vector<u8> {
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::close_pipe(pipe, tc, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}

public fun close_connection(service_idx: u8, host: &mut Host, peer_host: &Host, tc: &mut TransportControl, args: &vector<u8>, ctx: &mut TxContext): vector<u8>
public fun close_connection(service_idx: u8, host: &mut Host, peer_host: &Host, tc: &mut TransportControl, args: vector<u8>, ctx: &mut TxContext): vector<u8>
{
let kvargs = kvalues::from_bytes(args);
let kvargs = kvalues::from_bytes(&args);
let ret_value = dtp::api_impl::close_connection(service_idx, host, peer_host, tc, &kvargs, ctx);
kvalues::to_bytes(&ret_value)
}
Expand Down
5 changes: 2 additions & 3 deletions move/sources/api_impl.move
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module dtp::api_impl {
// Functions to add services to an Host.
public(friend) fun add_service_ping(_host: &mut Host, _kvargs: &KValues, _ctx: &mut TxContext) : KValues
{

kvalues::new()
}

Expand All @@ -52,7 +51,7 @@ module dtp::api_impl {


// 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)
public(friend) fun open_connection(service_idx: u8, cli_host: &mut Host, srv_host: &mut Host, _kvargs: &KValues, ctx: &mut TxContext): KValues
{
let conn = conn_objects::new();

Expand All @@ -63,7 +62,7 @@ module dtp::api_impl {
//host::add_connection(cli_host, &conn.transport_control);
//host::add_connection(srv_host, &conn.transport_control);

(conn, kvalues::new())
kvalues::new()
}

// Can this be replaced with a an array of _ipipe objects instead of calling multiple times?
Expand Down
42 changes: 25 additions & 17 deletions move/sources/client_registry.move
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
module dtp::client_registry {
use sui::object::{Self, UID};
module dtp::user_registry {
use sui::object::{Self, UID, ID};
use sui::transfer;
use sui::tx_context::{Self, TxContext};

const REGISTRY_INVALID_ADDRESS: address = @0x0;

//
// Owned object. Intended as storage of useful key-value for a DTP client.
//
// As an example, this is how a client find its own localhost (stored in the blob)
// As an example, this is how a client find its own localhost.
//
// DTP will be tested with only one client registry owned per Sui address.
//
// It might work with more than one, but it is not intended to be supported
// on short term (the DTP SDK will prevent to create more than one).
//
// TODO Add general purpose key-value once problem with validators are iron out.
struct Registry has key, store {
struct UserRegistry has key, store {
id: UID,
localhost_blob: vector<u8>,
host_addr: address,
}

// Constructors
fun init(_ctx: &mut TxContext) { /* NOOP */ }

public(friend) fun new(ctx: &mut TxContext) : Registry {
Registry {
public fun new(ctx: &mut TxContext) : UserRegistry {
UserRegistry {
id: object::new(ctx),
localhost_blob: vector[],
host_addr: REGISTRY_INVALID_ADDRESS
}
}

public(friend) fun delete(object: Registry) {
let Registry { id, localhost_blob: _ } = object;
public fun delete(self: UserRegistry) {
let UserRegistry { id, host_addr: _ } = self;
object::delete(id);
}

public entry fun create( ctx: &mut TxContext ) {
public fun new_and_transfer( localhost_id: ID, ctx: &mut TxContext ) {
let new_obj = new(ctx);
set_host_addr_with_id(&mut new_obj, &localhost_id);
transfer::transfer(new_obj, tx_context::sender(ctx));
}

public entry fun set_localhost_blob( registry: &mut Registry, blob : vector<u8> ) {
registry.localhost_blob = blob;
public fun set_host_addr( registry: &mut UserRegistry, host_addr: address ) {
registry.host_addr = host_addr;
}

public fun set_host_addr_with_id( registry: &mut UserRegistry, host_id: &ID ) {
registry.host_addr = object::id_to_address(host_id);
}

public fun get_host_addr( registry: &UserRegistry ): address {
registry.host_addr
}
}
8 changes: 4 additions & 4 deletions move/sources/events.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module dtp::events {
// === Constants ===

// === Structs ===
struct ConReq has copy, drop {
service_idx: u8, // Service Type
conn: ConnObjects, // All Connection Objects (TransportControl, Pipe etc...)
struct ConnReq has copy, drop {
service_idx: u8, // Service Type
conn: ConnObjects, // Info to get the connection started (e.g. Pipes and InnerPipes addresses).
}


Expand All @@ -29,7 +29,7 @@ module dtp::events {

// === Public-Friend Functions ===
public(friend) fun emit_conn_req( service_idx: u8, conn: ConnObjects ) {
event::emit(ConReq { service_idx, conn });
event::emit(ConnReq { service_idx, conn });
}

// === Private Functions ===
Expand Down
Loading

0 comments on commit c3f186f

Please sign in to comment.