Skip to content

Commit

Permalink
(#12) Add InnerPipe object + lots of coding
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Feb 22, 2024
1 parent ac77c0f commit 75f8f56
Show file tree
Hide file tree
Showing 16 changed files with 645 additions and 254 deletions.
24 changes: 12 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ desktop.ini
/venv
/.venv

# Build files (from mkdocs)
/site
/build
/MANIFEST

## Temporary files
*~
\#*
Expand All @@ -30,7 +25,7 @@ tmp
**/target
.pre-commit*

## Editors
## Editors
*.swp
*.swo
Session.vim
Expand Down Expand Up @@ -62,12 +57,6 @@ __pycache__/
*.py[cod]
*$py.class

## DTP specific directories
dtp-dev/
move/build/
sui.log.*
dtp.code-workspace

## Backup files generated by rustfmt.
**/*.rs.bk

Expand All @@ -76,3 +65,14 @@ dtp.code-workspace

# Never ignore .gitkeep files
!**/.gitkeep

## Ignore move build artifacts, except the
## dependencies source code which is useful for
## navigating the codebase.
**/move/build/
##**/move/build/**/bytecode_modules
##**/move/build/**/source_maps
##**/move/build/**/BuildInfo.yaml
##**/move/build/**/locks
sui.log.*
dtp.code-workspace
4 changes: 2 additions & 2 deletions move/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "FA9336FF6499B350AB49B625945807D2D89B2838A1E767BD6F7E88902749F374"
manifest_digest = "35FE1502BC14EFEDAB6AFA49C85DAC68F88728353F8817BFC5DA504FB2C13E6F"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"

dependencies = [
Expand All @@ -23,6 +23,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.18.1"
compiler-version = "1.19.0"
edition = "legacy"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dtp"
version = "0.0.1"
edition = "2024.alpha"
# edition = "2024.alpha"

[dependencies]
MoveStdlib = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "framework/testnet" }
Expand Down
54 changes: 0 additions & 54 deletions move/sources/basic_types.move

This file was deleted.

2 changes: 1 addition & 1 deletion move/sources/client_registry.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module dtp::client_registry {
// 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.
public struct Registry has key, store {
struct Registry has key, store {
id: UID,
localhost_blob: vector<u8>,
}
Expand Down
4 changes: 3 additions & 1 deletion move/sources/errors.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module dtp::errors {
public fun EHostAddressMismatch2() : u64 { 3 }
public fun EPipeInstanceSame() : u64 { 4 }
public fun EServiceIdxOutOfRange() : u64 { 5 }

public fun EInvalidAccessOnNone() : u64 { 6 }
public fun EHostNotOwner() : u64 { 7 }

// === Structs ===

// === Public-Mutative Functions ===
Expand Down
82 changes: 51 additions & 31 deletions move/sources/host.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,43 @@
// Typical next step with the DTP API will be ping or
// create a connection with that Host object.
//
#[allow(unused_field, unused_use, lint(share_owned))]
#[allow(unused_field, unused_use)]
module dtp::host {

use sui:: {
object::{Self, UID, ID},
transfer::{Self},
tx_context::{TxContext},
linked_table::{LinkedTable},
dynamic_field as df,
};

use dtp:: {
service_type::{ServiceType},
stats::{ConnectionAcceptedStats, ConnectionRejectedStats, ConnectionClosedStats},
basic_types::{WeakID},
consts::{Self},
errors::{Self},
};
// === Imports ===
use sui::object::{Self, UID, ID, uid_to_address};

//use sui::transfer::{Self};
use sui::tx_context::{Self,TxContext};
use sui::linked_table::{LinkedTable};

//use dtp::service_type::{ServiceType};
use dtp::stats::{ConnectionAcceptedStats, ConnectionRejectedStats, ConnectionClosedStats};
use dtp::weak_ref::{WeakRef};
use dtp::consts::{Self};
//use dtp::errors::{Self};

// === Friends ===
friend dtp::transport_control;

#[test_only]
friend dtp::test_host;

#[test_only]
friend dtp::test_transport_control;

// === Errors ===

// Public Shared Object
public struct AdminCap has key, store {
id: UID,
}
// === Constants ===

public struct Connection has store {
tctrl_id: WeakID,
service_id: WeakID,
// === Structs ===

// Public Shared Object
struct Connection has store {
tctrl_id: WeakRef,
}

public struct Service has store {
struct Service has store {
service_idx: u8,

// Each connection requested increments one member of either con_accepted or con_rejected.
Expand All @@ -59,7 +60,7 @@ module dtp::host {
cons_recent_closed: LinkedTable<ID,Connection>,
}

public struct HostConfig has store {
struct HostConfig has store {
// Configurations that can be changed only by the AdminCap.

// Maximum number of connection allowed for the whole host.
Expand All @@ -76,11 +77,13 @@ module dtp::host {

}

public struct Host has key, store {
struct Host has key, store {
id: UID,

flgs: u8, // DTP version+esc flags always after UID.

owner: address,

// Creation timestamp (UTC)
// TODO

Expand All @@ -106,20 +109,37 @@ module dtp::host {
// TODO
}

// Constructors
fun init(_ctx: &mut TxContext) { /* NOOP */ }
// === Public-Mutative Functions ===

// === Public-View Functions ===

// === Admin Functions ===

// === Public-Friend Functions ===

public(friend) fun new(ctx: &mut TxContext) : Host {
Host {
id: object::new(ctx),
flgs: 0,
owner: tx_context::sender(ctx),
config: HostConfig {
max_con: consts::MAX_CONNECTION_PER_HOST(),
},
}
}

public entry fun create( ctx: &mut TxContext ) { transfer::share_object<Host>(new(ctx)); }
public(friend) fun owner(host: &Host): address {
host.owner
}

public(friend) fun is_caller_owner(host: &Host, ctx: &TxContext): bool {
tx_context::sender(ctx) == host.owner
}

// === Private Functions ===

// === Test Functions ===

}

#[test_only]
Expand All @@ -143,7 +163,7 @@ module dtp::test_host {
let new_host = host::new( ctx );

// admnistrator address must be the creator.
assert!(host::adm(&new_host) == creator, 1);
assert!(host::owner(&new_host) == creator, 1);

transfer::share_object( new_host );
};
Expand Down
82 changes: 82 additions & 0 deletions move/sources/inner_pipe.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// A Pipes is a uni-directional data stream.
//
// It is own by the endpoint transmiting data.
//
// Used only for simple transaction (no consensus).
//
#[allow(unused_field, unused_use)]
module dtp::inner_pipe {

// === Imports ===
use sui::object::{Self, UID, uid_to_address};
use sui::transfer::{Self};
use sui::tx_context::{TxContext};
use dtp::weak_ref::{Self,WeakRef};
//use dtp::errors::{Self};
use dtp::pipe_sync_data::{Self,PipeSyncData};

// === Friends ===
friend dtp::host;
friend dtp::pipe;

#[test_only]
friend dtp::tests_pipe;

// === Errors ===

// === Constants ===

// === Structs ===

struct InnerPipe has key, store {
id: UID,
flgs: u8, // DTP version+esc flags always after UID.

pipe_id: WeakRef,

sync_data: PipeSyncData,
}

// === Public-Mutative Functions ===
public entry fun send(
_self: &mut InnerPipe,
_data: vector<u8>,
_ctx: &mut TxContext )
{
// TODO Emit the event. Add sequential number logic.
}

// === Public-View Functions ===

// === Admin Functions ===

// === Public-Friend Functions ===

public(friend) fun new( pipe_address: address, ctx: &mut TxContext ): InnerPipe {
let new_obj = InnerPipe {
id: object::new(ctx),
flgs: 0u8,
pipe_id: weak_ref::new_from_address(pipe_address),
sync_data: pipe_sync_data::new(),
};
new_obj
}

public(friend) fun new_transfered( pipe_address: address, recipient: address, ctx: &mut TxContext ): WeakRef
{
let new_obj = new(pipe_address,ctx);
let new_obj_ref = weak_ref::new_from_address(uid_to_address(&new_obj.id));
transfer::transfer(new_obj, recipient);
new_obj_ref
}

public(friend) fun delete( self: InnerPipe ) {
let InnerPipe { id, flgs: _, pipe_id: _, sync_data: _ } = self;
object::delete(id);
}

// === Private Functions ===

// === Test Functions ===

}
Loading

0 comments on commit 75f8f56

Please sign in to comment.