diff --git a/src/lib.rs b/src/lib.rs index 027ffaf..33285db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ mod types; +use types::fcp_types; #[cfg(test)] mod tests { diff --git a/src/types/client/fcp_types.rs b/src/types/client/fcp_types.rs new file mode 100644 index 0000000..2ac6483 --- /dev/null +++ b/src/types/client/fcp_types.rs @@ -0,0 +1,152 @@ +use super::types::*; +impl ClientHello { + fn new(name: String, exp_ver: f32) -> Self { + ClientHello { + name: name, + expected_version: exp_ver, + } + } + fn string(self) -> String { + return format!( + "ClientHello\n\ + Name={}\n\ + ExpectedVersion={}\n\ + EndMessage\n\n", + self.name, self.expected_version + ); + } +} + +pub struct ClientHello { + name: String, + expected_version: f32, +} + +#[test] +fn client_hello_parses() { + let hello = ClientHello::new("user name".to_string(), 2.0); + assert_eq!( + hello.string(), + "ClientHello\nName=user name\nExpectedVersion=2\nEndMessage\n\n" + ); +} + +// TODO not implemented ListPeer +pub struct ListPeer { + message_name: String, + node_identifier: NodeIdentifier, + with_volatile: Option, + with_metadata: Option, +} +pub struct ListPeers { + message_name: String, + with_volatile: Option, + with_metadata: Option, +} + +pub struct ListPeerNotes { + message_name: String, + node_identifier: NodeIdentifier, +} +pub struct AddPeer { + message_name: String, + trust: TrustLevel, + visibility: VisibilityLevel, + file: Option, + url: Option, + raw: Option, +} +pub struct ModifyPeer { + message_name: String, + node_identifier: NodeIdentifier, + allow_local_addresses: Option, + is_disabled: Option, + is_listen_only: Option, + is_burst_only: Option, + ignore_source_port: Option, +} +pub struct ModifyPeerNote { + message_name: String, + node_text: String, + peer_note_type: i32, +} +pub struct RemovePeer { + message_name: String, + node_identifier: NodeIdentifier, +} + +pub struct GetNode { + message_name: String, + identifier: Option, + give_opennet_ref: Option, + with_private: Option, + with_volatile: Option, +} + +pub struct GenerateSSK { + message_name: String, + identifier: Option, +} + +pub struct ClientPut { + message_name: String, + uri: String, //TODO create key type + content_type: Option, + identifier: Option, + verbosity: Option, + max_retries: Option, + priority_class: Option, + get_chk_only: Option, + global: Option, + dont_compress: Option, + codecs: Option>, + client_token: Option, + persistence: Option>, + early_encode: Option, + upload_ffrom: Option, + data_length: u64, + filename: String, + target_uri: Option, // cloning uri if does not exists + file_hash: Option, //TODO SHAA256 type + binary_blob: Option, + fork_on_cacheable: Option, + extra_inserts_single_block: Option, + extra_inserts_splitfile_header_block: Option, + compatibility_mode: Option, //TODO create enum??? + local_request_only: Option, + override_splitfile_crypto_key: Option, //key in hex + real_time_flag: Option, + metadata_threshold: Option, + data: Option, // Data fromdirect +} + +pub struct ClientGet { + message_name: String, + ignore_ds: Option, + ds_only: Option, + uri: String, //FIXME freenet uri type + identifier: String, + verbosity: Option, + max_size: Option, + max_retries: Option, + priority_class: Option, + persistence: Option, + client_token: Option, + global: Option, + return_type: Option, + binary_blob: Option, + filter_data: Option, + allowed_mime_types: Option>, + filename: Option>, + temp_filename: Option>, + real_time_flag: Option, + initial_metadata_data_length: u64, +} + +pub struct Disconnect { + message_name: String, +} + +pub struct Shutdown { + message_name: String, +} diff --git a/src/types/client/mod.rs b/src/types/client/mod.rs index fe642b3..87c62fa 100644 --- a/src/types/client/mod.rs +++ b/src/types/client/mod.rs @@ -1,2 +1,2 @@ -mod types; -pub use types::*; +pub mod fcp_types; +pub mod types; diff --git a/src/types/client/types.rs b/src/types/client/types.rs index 0534659..c98ae51 100644 --- a/src/types/client/types.rs +++ b/src/types/client/types.rs @@ -1,6 +1,6 @@ -use std::ffi::OsStr; -use std::net::Ipv4Addr; -use std::path::Path; +pub use std::ffi::OsStr; +pub use std::net::Ipv4Addr; +pub use std::path::Path; pub enum NodeIdentifier { Name(String), Identity(String), @@ -71,128 +71,3 @@ pub enum Priority { F, // 5 G, // 6 } - -pub struct ClientHello { - message_name: String, - name: String, - expected_version: f32, -} -// TODO not implemented ListPeer -pub struct ListPeer { - message_name: String, - node_identifier: NodeIdentifier, - with_volatile: Option, - with_metadata: Option, -} -pub struct ListPeers { - message_name: String, - with_volatile: Option, - with_metadata: Option, -} - -pub struct ListPeerNotes { - message_name: String, - node_identifier: NodeIdentifier, -} -pub struct AddPeer { - message_name: String, - trust: TrustLevel, - visibility: VisibilityLevel, - file: Option, - url: Option, - raw: Option, -} -pub struct ModifyPeer { - message_name: String, - node_identifier: NodeIdentifier, - allow_local_addresses: Option, - is_disabled: Option, - is_listen_only: Option, - is_burst_only: Option, - ignore_source_port: Option, -} -pub struct ModifyPeerNote { - message_name: String, - node_text: String, - peer_note_type: i32, -} -pub struct RemovePeer { - message_name: String, - node_identifier: NodeIdentifier, -} - -pub struct GetNode { - message_name: String, - identifier: Option, - give_opennet_ref: Option, - with_private: Option, - with_volatile: Option, -} - -pub struct GenerateSSK { - message_name: String, - identifier: Option, -} - -pub struct ClientPut { - message_name: String, - uri: String, //TODO create key type - content_type: Option, - identifier: Option, - verbosity: Option, - max_retries: Option, - priority_class: Option, - get_chk_only: Option, - global: Option, - dont_compress: Option, - codecs: Option>, - client_token: Option, - persistence: Option>, - early_encode: Option, - upload_ffrom: Option, - data_length: u64, - filename: String, - target_uri: Option, // cloning uri if does not exists - file_hash: Option, //TODO SHAA256 type - binary_blob: Option, - fork_on_cacheable: Option, - extra_inserts_single_block: Option, - extra_inserts_splitfile_header_block: Option, - compatibility_mode: Option, //TODO create enum??? - local_request_only: Option, - override_splitfile_crypto_key: Option, //key in hex - real_time_flag: Option, - metadata_threshold: Option, - data: Option, // Data fromdirect -} - -pub struct ClientGet { - message_name: String, - ignore_ds: Option, - ds_only: Option, - uri: String, //FIXME freenet uri type - identifier: String, - verbosity: Option, - max_size: Option, - max_retries: Option, - priority_class: Option, - persistence: Option, - client_token: Option, - global: Option, - return_type: Option, - binary_blob: Option, - filter_data: Option, - allowed_mime_types: Option>, - filename: Option>, - temp_filename: Option>, - real_time_flag: Option, - initial_metadata_data_length: u64, -} - -pub struct Disconnect { - message_name: String, -} - -pub struct Shutdown { - message_name: String, -}