make requested messages coming to core, but not sending to client
This commit is contained in:
parent
7c447bd6f8
commit
db89ca7bc2
|
@ -1,5 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="AutoImportSettings">
|
||||||
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
|
</component>
|
||||||
<component name="CMakeSettings">
|
<component name="CMakeSettings">
|
||||||
<configurations>
|
<configurations>
|
||||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" ENABLED="true" />
|
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" ENABLED="true" />
|
||||||
|
@ -11,14 +14,12 @@
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e434c6bf-d215-476e-8569-84080f63e0f9" name="Default Changelist" comment="">
|
<list default="true" id="e434c6bf-d215-476e-8569-84080f63e0f9" name="Default Changelist" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/api/handlers.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/handlers.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/api/handlers.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/handlers.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/api/request.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/request.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/chat/front_conn.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/front_conn.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/api/response.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/response.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/chat/serv_conn.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/serv_conn.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/chat/serv_conn.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/serv_conn.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/db/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/db/mod.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/chat/serv_handler.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/serv_handler.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/db/types.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/db/types.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/chat/stay_awake.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/stay_awake.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/chat/types.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/types.rs" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -28,6 +29,14 @@
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="GitSEFilterConfiguration">
|
||||||
|
<file-type-list>
|
||||||
|
<filtered-out-file-type name="LOCAL_BRANCH" />
|
||||||
|
<filtered-out-file-type name="REMOTE_BRANCH" />
|
||||||
|
<filtered-out-file-type name="TAG" />
|
||||||
|
<filtered-out-file-type name="COMMIT_BY_MESSAGE" />
|
||||||
|
</file-type-list>
|
||||||
|
</component>
|
||||||
<component name="MacroExpansionManager">
|
<component name="MacroExpansionManager">
|
||||||
<option name="directoryName" value="8w8syaev" />
|
<option name="directoryName" value="8w8syaev" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -45,6 +54,7 @@
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
<property name="nodejs_package_manager_path" value="npm" />
|
<property name="nodejs_package_manager_path" value="npm" />
|
||||||
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
|
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
|
||||||
|
<property name="settings.editor.selected.configurable" value="language.rust.rustfmt" />
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="Run hole" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
<configuration name="Run hole" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
|
@ -62,6 +72,11 @@
|
||||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration default="true" type="GradleAppRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" PASS_PARENT_ENVS_2="true">
|
||||||
|
<method v="2">
|
||||||
|
<option name="com.jetbrains.cidr.cpp.gradle.execution.GradleNativeBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="Cargo.Run hole" />
|
<item itemvalue="Cargo.Run hole" />
|
||||||
|
@ -69,7 +84,9 @@
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
<component name="RustProjectSettings">
|
<component name="RustProjectSettings">
|
||||||
|
<option name="runRustfmtOnSave" value="true" />
|
||||||
<option name="toolchainHomeDirectory" value="/usr/bin" />
|
<option name="toolchainHomeDirectory" value="/usr/bin" />
|
||||||
|
<option name="useRustfmt" value="true" />
|
||||||
<option name="version" value="2" />
|
<option name="version" value="2" />
|
||||||
</component>
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
@ -85,10 +102,15 @@
|
||||||
<workItem from="1614190476350" duration="9000" />
|
<workItem from="1614190476350" duration="9000" />
|
||||||
<workItem from="1614277959074" duration="31000" />
|
<workItem from="1614277959074" duration="31000" />
|
||||||
<workItem from="1617097697890" duration="1371000" />
|
<workItem from="1617097697890" duration="1371000" />
|
||||||
|
<workItem from="1618752637415" duration="4677000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
|
<expand />
|
||||||
|
<select />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -22,6 +22,13 @@ use crate::db::types::Id;
|
||||||
|
|
||||||
pub fn start_app(server_sender: SP) -> Result<()> {
|
pub fn start_app(server_sender: SP) -> Result<()> {
|
||||||
server_sender.send(PackedMessage::ToFreenet(ClientHello::new("start_app_request".to_string(), 2.0).convert())).unwrap();
|
server_sender.send(PackedMessage::ToFreenet(ClientHello::new("start_app_request".to_string(), 2.0).convert())).unwrap();
|
||||||
|
server_sender.send(PackedMessage::ToFreenet("\n\
|
||||||
|
ClientGet\n\
|
||||||
|
URI=USK@B5CYo9jdAndaZ4IoKdJKCi28bY96f03FhUdY4PO6anY,9AHiE5ZdMJ9BuIXdv7hucus5VbVtwz9tKjj9LcPbtwM,AQACAAE/user-3/0\n\
|
||||||
|
Identifier=check\n\
|
||||||
|
ReturnType=direct\n\
|
||||||
|
EndMessage\n\
|
||||||
|
\n".to_string())).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
//sending *JSON*, what everything is OK
|
//sending *JSON*, what everything is OK
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,12 +58,21 @@ async fn connect_to_client(
|
||||||
.await
|
.await
|
||||||
.expect("err during the ws handshake");
|
.expect("err during the ws handshake");
|
||||||
|
|
||||||
|
let ss = server_sender.clone();
|
||||||
log::info!("connected to: {}", addr);
|
log::info!("connected to: {}", addr);
|
||||||
let (sender, receiver) = ws.split();
|
let (sender, receiver) = ws.split();
|
||||||
|
|
||||||
let t1 = task::spawn(connection_for_sending(receiver, server_sender, conn));
|
log::debug!("launching repeater...");
|
||||||
connection_for_receiving(sender, client_receiver, client_repeater).await?;
|
let t1 = task::spawn(connection_for_receiving(
|
||||||
|
sender,
|
||||||
|
client_receiver,
|
||||||
|
client_repeater,
|
||||||
|
));
|
||||||
|
let t2 = task::spawn(connection_for_sending(receiver, server_sender, conn));
|
||||||
|
let t3 = task::spawn(request_repeater(ss));
|
||||||
t1.await?;
|
t1.await?;
|
||||||
|
t3.await?;
|
||||||
|
t2.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -75,24 +84,34 @@ async fn connection_for_receiving(
|
||||||
server_sender: SP,
|
server_sender: SP,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
log::info!("Connection for receiving launched");
|
log::info!("Connection for receiving launched");
|
||||||
|
// let mut prev: PackedMessage = PackedMessage::FromFreenet("nothing".to_string());
|
||||||
while let Ok(res) = client_receiver.recv() {
|
while let Ok(res) = client_receiver.recv() {
|
||||||
//TODO call client get after receiving NodeHello
|
//TODO call client get after receiving NodeHello
|
||||||
|
// log::debug!("RES {:?}", &res);
|
||||||
|
// log::debug!("PREV {:?}", &prev);
|
||||||
|
// if res != &prev {
|
||||||
|
// prev = res.clone();
|
||||||
|
// log::debug!("they are different");
|
||||||
match res {
|
match res {
|
||||||
PackedMessage::FromCore(json) => {
|
PackedMessage::FromCore(json) => {
|
||||||
|
let j = json.clone();
|
||||||
sender
|
sender
|
||||||
.send(Message::Text(json))
|
.send(Message::Text(j))
|
||||||
.await
|
.await
|
||||||
.expect("Couldn't send message");
|
.expect("Couldn't send message");
|
||||||
}
|
}
|
||||||
PackedMessage::FromFreenet(response) => {
|
PackedMessage::FromFreenet(response) => {
|
||||||
|
let r = response.clone();
|
||||||
|
log::debug!("Got:\n {}", &response);
|
||||||
sender
|
sender
|
||||||
// TODO freenet_response_handler
|
// TODO freenet_response_handler
|
||||||
.send(Message::Text(response))
|
.send(Message::Text(r.to_string()))
|
||||||
.await
|
.await
|
||||||
.expect("Couldn't send messge");
|
.expect("Couldn't send messge");
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -102,6 +121,7 @@ async fn connection_for_sending(
|
||||||
server_sender: SP,
|
server_sender: SP,
|
||||||
conn: rusqlite::Connection,
|
conn: rusqlite::Connection,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
|
let ss = server_sender.clone();
|
||||||
log::info!("Connection for sending launched");
|
log::info!("Connection for sending launched");
|
||||||
let mut new_msg = receiver.next();
|
let mut new_msg = receiver.next();
|
||||||
loop {
|
loop {
|
||||||
|
|
|
@ -19,7 +19,9 @@ async fn connect_to_server(client_sender: SP, server_receiver: RP) -> io::Result
|
||||||
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
|
.unwrap_or_else(|| "127.0.0.1:9481".to_string());
|
||||||
|
|
||||||
let sr = client_sender.clone();
|
let sr = client_sender.clone();
|
||||||
let stream = TcpStream::connect(&addr).await.expect("Unable to connect to FCP");
|
let stream = TcpStream::connect(&addr)
|
||||||
|
.await
|
||||||
|
.expect("Unable to connect to FCP");
|
||||||
let (receiver, sender) = stream.into_split();
|
let (receiver, sender) = stream.into_split();
|
||||||
log::info!("Connected to FCP");
|
log::info!("Connected to FCP");
|
||||||
let t = task::spawn(server_responce_getter(receiver, client_sender));
|
let t = task::spawn(server_responce_getter(receiver, client_sender));
|
||||||
|
@ -30,17 +32,22 @@ async fn connect_to_server(client_sender: SP, server_receiver: RP) -> io::Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn server_responce_getter(mut receiver: OwnedReadHalf, client_sender: SP) -> io::Result<()> {
|
async fn server_responce_getter(mut receiver: OwnedReadHalf, client_sender: SP) -> io::Result<()> {
|
||||||
|
// let mut prev = [0; 1024];
|
||||||
loop {
|
loop {
|
||||||
// each freenet responce have an identifier and program will define what to do with request by this identifier
|
// each freenet responce have an identifier and program will define what to do with request by this identifier
|
||||||
//TODO create handle_fcp_response function
|
//TODO create handle_fcp_response function
|
||||||
let mut buffer = [0; 1024];
|
let mut buffer = [0; 1024];
|
||||||
match receiver.read(&mut buffer).await {
|
match receiver.read(&mut buffer).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
// if prev != buffer {
|
||||||
let received = String::from_utf8_lossy(&buffer[..]);
|
let received = String::from_utf8_lossy(&buffer[..]);
|
||||||
|
log::debug!("gotted {:?}", &received);
|
||||||
client_sender
|
client_sender
|
||||||
.send(PackedMessage::FromFreenet(received.to_string()))
|
.send(PackedMessage::FromFreenet(received.to_string()))
|
||||||
.expect("Falied to send message to client thread");
|
.expect("Falied to send message to client thread");
|
||||||
log::info!("Sended to client!");
|
log::info!("Sended to client! {}", received.chars().count());
|
||||||
|
// prev = buffer;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Err(e) => log::error!("Error: {} ", e),
|
Err(e) => log::error!("Error: {} ", e),
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ pub async fn to_server_sender(
|
||||||
log::info!("Message sended to client thread");
|
log::info!("Message sended to client thread");
|
||||||
}
|
}
|
||||||
PackedMessage::ToFreenet(req) => {
|
PackedMessage::ToFreenet(req) => {
|
||||||
|
log::debug!("SENDED {}", req);
|
||||||
sender.write(req.as_bytes()).await?;
|
sender.write(req.as_bytes()).await?;
|
||||||
log::info!("Message sended to freenet");
|
log::info!("Message sended to freenet");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,42 @@
|
||||||
use crate::chat::types::PackedMessage;
|
use crate::chat::types::PackedMessage;
|
||||||
use async_std::io;
|
use async_std::io;
|
||||||
use fcpv2::client::fcp_types::ClientGet;
|
use fcpv2::client::fcp_types::ClientGet;
|
||||||
use fcpv2::types::{traits::FcpRequest, ReturnType, SSK};
|
use fcpv2::types::{traits::FcpRequest, ReturnType, KEY, SSK, USK};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
type SP = Sender<PackedMessage>;
|
type SP = Sender<PackedMessage>;
|
||||||
|
|
||||||
pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
||||||
loop {
|
// loop {
|
||||||
//TODO create a field with tracked users
|
//TODO create a field with tracked users
|
||||||
let time = std::time::Duration::from_millis(1000);
|
log::debug!("Request Repeater Started!");
|
||||||
|
loop {
|
||||||
|
let time = std::time::Duration::from_millis(600);
|
||||||
std::thread::sleep(time);
|
std::thread::sleep(time);
|
||||||
|
log::debug!("enough sleep");
|
||||||
match ss.send(PackedMessage::ToFreenet(
|
match ss.send(PackedMessage::ToFreenet(
|
||||||
ClientGet::new_default(SSK{sign_key: "9Zq-H7vg1iN6852rcL3mQQaIfPZODnIJnKyIy1dE6mk".to_string(), decrypt_key: "n-vQibdLXPDMtW7k5ftbR9HVz4Tb184lUc~MiUGHWAM".to_string(),settings: Some("AQACAAE".to_string())},
|
ClientGet::new_default(
|
||||||
|
KEY::USK(
|
||||||
|
USK {
|
||||||
|
ssk: SSK {
|
||||||
|
sign_key: "B5CYo9jdAndaZ4IoKdJKCi28bY96f03FhUdY4PO6anY".to_string(),
|
||||||
|
decrypt_key: "9AHiE5ZdMJ9BuIXdv7hucus5VbVtwz9tKjj9LcPbtwM".to_string(),
|
||||||
|
settings: Some("AQACAAE".to_string()),
|
||||||
|
},
|
||||||
|
path: "user-3/0".to_string(),
|
||||||
|
}
|
||||||
|
),
|
||||||
"check",
|
"check",
|
||||||
ReturnType::Direct).convert()
|
ReturnType::Direct,
|
||||||
|
)
|
||||||
|
.convert(),
|
||||||
|
)) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => continue ,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}
|
||||||
// message: format!(
|
// message: format!(
|
||||||
// "ClientGet\n\
|
// "ClientGet\n\
|
||||||
// URI=KSK@msg23.txt\n\
|
// URI=KSK@msg23.txt\n\
|
||||||
|
@ -23,9 +45,3 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
||||||
// ReturnType=direct\n\
|
// ReturnType=direct\n\
|
||||||
// EndMessage\n\n"
|
// EndMessage\n\n"
|
||||||
// ),
|
// ),
|
||||||
)) {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(e) => log::error!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ use std::sync::mpsc::{Receiver, Sender};
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub enum PackedMessage {
|
pub enum PackedMessage {
|
||||||
ToFreenet(String),
|
ToFreenet(String),
|
||||||
FromFreenet(String),
|
FromFreenet(String),
|
||||||
|
|
Loading…
Reference in a new issue