Skip to content

Commit

Permalink
Add errors.move, start coding Host and Transport Control
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Feb 19, 2024
1 parent 8e33082 commit ac77c0f
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 132 deletions.
6 changes: 3 additions & 3 deletions move/sources/consts.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module dtp::consts {
//
// If you need more connections, consider creating additional hosts.
const C_MAX_CONNECTION_PER_SERVICE: u16 = 4096;
public(friend) fun MAX_CONNECTION_PER_SERVICE() : u16 { C_MAX_CONNECTION_PER_SERVICE }
public fun MAX_CONNECTION_PER_SERVICE() : u16 { C_MAX_CONNECTION_PER_SERVICE }

const C_MAX_SERVICE_PER_HOST: u8 = 16;
public(friend) fun MAX_SERVICE_PER_HOST() : u8 { C_MAX_SERVICE_PER_HOST }
public fun MAX_SERVICE_PER_HOST() : u8 { C_MAX_SERVICE_PER_HOST }

public(friend) fun MAX_CONNECTION_PER_HOST() : u32 {
public fun MAX_CONNECTION_PER_HOST() : u32 {
(C_MAX_CONNECTION_PER_SERVICE as u32) * (C_MAX_SERVICE_PER_HOST as u32)
}
}
33 changes: 33 additions & 0 deletions move/sources/errors.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module dtp::errors {
// === Imports ===

// === Friends ===

// === Errors ===

// === Constants ===
// TODO Could error code be 32 bits?
// TODO Refactor once public consts are supported.
// TODO Consider public(package) once available.
public fun EOnePipeRequired() : u64 { 1 }
public fun EHostAddressMismatch1() : u64 { 2 }
public fun EHostAddressMismatch2() : u64 { 3 }
public fun EPipeInstanceSame() : u64 { 4 }
public fun EServiceIdxOutOfRange() : u64 { 5 }

// === Structs ===

// === Public-Mutative Functions ===

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

// === Admin Functions ===

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

// === Private Functions ===

// === Test Functions ===


}
37 changes: 23 additions & 14 deletions move/sources/host.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module dtp::host {
service_type::{ServiceType},
stats::{ConnectionAcceptedStats, ConnectionRejectedStats, ConnectionClosedStats},
basic_types::{WeakID},
consts::{Self},
errors::{Self},
};

#[test_only]
Expand All @@ -40,7 +42,7 @@ module dtp::host {
}

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

// Each connection requested increments one member of either con_accepted or con_rejected.
con_accepted: ConnectionAcceptedStats,
Expand Down Expand Up @@ -70,7 +72,7 @@ module dtp::host {
//
// The protocol will progressively close LRU connections until eventual
// respect the new limit.
max_con: u16,
max_con: u32,

}

Expand All @@ -79,24 +81,29 @@ module dtp::host {

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

// Creation timestamp (UTC)
// TODO

// Settings that may change from time to time.
//
// Last SLA Update timestamp (UTC)
// TODO

// Aggregated connections statistic (updated periodically).
// Last Server Heartbeat timestamp (UTC)
// TODO

// *************************************************************
// Information that do not change for the lifetime of the Node.
// *************************************************************
// Last Config Update timestamp (UTC) - For debugging purpose.
// TODO

// Creation time info
// Last Protocol Sync timestamp (UTC) - For debugging purpose.
// TODO

// Service Level Agreements
// Settings controlled by AdminCap.
config: HostConfig,

// Aggregated connections statistic (updated periodically).
// TODO

// Future proofing.
// Service Level Agreements
// TODO
}

// Constructors
Expand All @@ -105,12 +112,14 @@ module dtp::host {
public(friend) fun new(ctx: &mut TxContext) : Host {
Host {
id: object::new(ctx),
flgs: 0
flgs: 0,
config: HostConfig {
max_con: consts::MAX_CONNECTION_PER_HOST(),
},
}
}

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

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

#[test_only]
Expand Down
103 changes: 71 additions & 32 deletions move/sources/service_type.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,102 @@ module dtp::service_type {
//
// Intended to mimic https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
//
// Keep in mind that DTP provide "layer 7" services, so it will not
// match exactly IANA RFC numbers.abort
//
// As an example, DTP can add gRPC specific functionality, while in the IP
// world it is served by HTTPS.
//
// Example:
// <Host ID Address>:443 --> HTTPS server
// <Host ID Address>:22 --> SSH

port: u32,

// The end-user and DTP API uses the protocol port.
// The end-users and DTP API uses the protocol_port.
//
// The DTP SDKs convert the port to idx when interacting
// with the Move modules.
// The DTP SDKs convert the port to ServiceTypeIdx when
// interacting with the Move modules.
//
// This is to optimize fast service object access using a vector.
//
// [1..254] (0 and 255 reserved)
// [0..SERVICE_TYPE.length - 1]
// where SERVICE_TYPE.length <= 256
// 0 means invalid
// 255 is for future use.
idx: u8,
}

// TODO Searcheable list of supported type.

// Think hard before adding a new type... these are forever.
// Add new Service only at the end of the list.

// Invalid Service Type
const C_SERVICE_TYPE_INVALID_IDX: u8 = 0;
const C_SERVICE_TYPE_INVALID_NAME: vector<u8> = b"Invalid";
const C_SERVICE_TYPE_INVALID_PORT: u32 = 0;

// UDP Tunelling.
const SERVICE_TYPE_UDP_IDX: u8 = 1;
const SERVICE_TYPE_UDP_NAME: vector<u8> = b"UDP";
const SERVICE_TYPE_UDP_PORT: u32 = 1;
const C_SERVICE_TYPE_UDP_IDX: u8 = 1;
const C_SERVICE_TYPE_UDP_NAME: vector<u8> = b"UDP";
const C_SERVICE_TYPE_UDP_PORT: u32 = 1;

// Remote Procedure Call (RPC)
const SERVICE_TYPE_JSON_RPC_2_0_IDX: u8 = 2;
const SERVICE_TYPE_JSON_RPC_2_0_NAME: vector<u8> = b"JSON-RPC 2.0";
const SERVICE_TYPE_JSON_RPC_2_0_PORT: u32 = 2;
const C_SERVICE_TYPE_JSON_RPC_2_0_IDX: u8 = 2;
const C_SERVICE_TYPE_JSON_RPC_2_0_NAME: vector<u8> = b"JSON-RPC 2.0";
const C_SERVICE_TYPE_JSON_RPC_2_0_PORT: u32 = 2;

// GraphQL Service
const SERVICE_TYPE_GRAPHQL_IDX: u8 = 3;
const SERVICE_TYPE_GRAPHQL_NAME: vector<u8> = b"GRAPHQL";
const SERVICE_TYPE_GRAPHQL_PORT: u32 = 3;
const C_SERVICE_TYPE_GRAPHQL_IDX: u8 = 3;
const C_SERVICE_TYPE_GRAPHQL_NAME: vector<u8> = b"GRAPHQL";
const C_SERVICE_TYPE_GRAPHQL_PORT: u32 = 3;

// HTTP (optionally encrypted)
const SERVICE_TYPE_HTTP_IDX: u8 = 4;
const SERVICE_TYPE_HTTP_NAME: vector<u8> = b"HTTP";
const SERVICE_TYPE_HTTP_PORT: u32 = 80;
const C_SERVICE_TYPE_HTTP_IDX: u8 = 4;
const C_SERVICE_TYPE_HTTP_NAME: vector<u8> = b"HTTP";
const C_SERVICE_TYPE_HTTP_PORT: u32 = 80;

// HTTPS (always encrypted)
const SERVICE_TYPE_HTTPS_IDX: u8 = 5;
const SERVICE_TYPE_HTTPS_NAME: vector<u8> = b"HTTPS";
const SERVICE_TYPE_HTTPS_PORT: u32 = 443;
const C_SERVICE_TYPE_HTTPS_IDX: u8 = 5;
const C_SERVICE_TYPE_HTTPS_NAME: vector<u8> = b"HTTPS";
const C_SERVICE_TYPE_HTTPS_PORT: u32 = 443;

// Secure Shell Protocol
const SERVICE_TYPE_SSH_IDX: u16 = 6;
const SERVICE_TYPE_SSH_NAME: vector<u8> = b"SSH";
const SERVICE_TYPE_SSH_PORT: u32 = 22;
// Ping (ICMP Echo Request/Reply)
const C_SERVICE_TYPE_ECHO_IDX: u8 = 7;
const C_SERVICE_TYPE_ECHO_NAME: vector<u8> = b"ECHO";
const C_SERVICE_TYPE_ECHO_PORT: u32 = 7;

// gRPC
const C_SERVICE_TYPE_GRPC_IDX: u8 = 8;
const C_SERVICE_TYPE_GRPC_NAME: vector<u8> = b"GRPC";
const C_SERVICE_TYPE_GRPC_PORT: u32 = 8;

// Ping
const SERVICE_TYPE_ECHO_IDX: u16 = 7;
const SERVICE_TYPE_ECHO_NAME: vector<u8> = b"ECHO";
const SERVICE_TYPE_ECHO_PORT: u32 = 7;
// Discard Protocol
//
// Connection used to send any data. No guarantees of being process
// by the receiver. Data retention time is minimized (drop on network
// as soon as possible). Sender pays all costs.
//
// Intended for testing/benchmarking of sender.
const C_SERVICE_TYPE_DISCARD_IDX: u8 = 9;
const C_SERVICE_TYPE_DISCARD_NAME: vector<u8> = b"DISCARD";
const C_SERVICE_TYPE_DISCARD_PORT: u32 = 9;

// [10..20] Available

// File Transfer
const SERVICE_TYPE_FTP_IDX: u16 = 8;
const SERVICE_TYPE_FTP_NAME: vector<u8> = b"FTP";
const SERVICE_TYPE_FTP_PORT: u32 = 21;
const C_SERVICE_TYPE_FTP_IDX: u8 = 21;
const C_SERVICE_TYPE_FTP_NAME: vector<u8> = b"FTP";
const C_SERVICE_TYPE_FTP_PORT: u32 = 21;

// Secure Shell Protocol
const C_SERVICE_TYPE_SSH_IDX: u8 = 22;
const C_SERVICE_TYPE_SSH_NAME: vector<u8> = b"SSH";
const C_SERVICE_TYPE_SSH_PORT: u32 = 22;

// !!! Update SERVICE_TYPE_MAX_IDX when appending new service types. !!!
const C_SERVICE_TYPE_MAX_IDX: u8 = C_SERVICE_TYPE_SSH_IDX;

public fun SERVICE_TYPE_MAX_IDX() : u8 {
C_SERVICE_TYPE_MAX_IDX
}
}
Loading

0 comments on commit ac77c0f

Please sign in to comment.