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"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="CMakeSettings">
|
||||
<configurations>
|
||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" ENABLED="true" />
|
||||
|
@ -11,14 +14,12 @@
|
|||
<component name="ChangeListManager">
|
||||
<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$/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/request.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/request.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/front_conn.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/chat/front_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/db/types.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/db/types.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/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>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -28,6 +29,14 @@
|
|||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</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">
|
||||
<option name="directoryName" value="8w8syaev" />
|
||||
</component>
|
||||
|
@ -45,6 +54,7 @@
|
|||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="nodejs_package_manager_path" value="npm" />
|
||||
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
|
||||
<property name="settings.editor.selected.configurable" value="language.rust.rustfmt" />
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Run hole" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||
|
@ -62,6 +72,11 @@
|
|||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
</method>
|
||||
</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>
|
||||
<list>
|
||||
<item itemvalue="Cargo.Run hole" />
|
||||
|
@ -69,7 +84,9 @@
|
|||
</recent_temporary>
|
||||
</component>
|
||||
<component name="RustProjectSettings">
|
||||
<option name="runRustfmtOnSave" value="true" />
|
||||
<option name="toolchainHomeDirectory" value="/usr/bin" />
|
||||
<option name="useRustfmt" value="true" />
|
||||
<option name="version" value="2" />
|
||||
</component>
|
||||
<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="1614277959074" duration="31000" />
|
||||
<workItem from="1617097697890" duration="1371000" />
|
||||
<workItem from="1618752637415" duration="4677000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
<select />
|
||||
</component>
|
||||
</project>
|
|
@ -22,6 +22,13 @@ use crate::db::types::Id;
|
|||
|
||||
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("\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(())
|
||||
//sending *JSON*, what everything is OK
|
||||
}
|
||||
|
|
|
@ -58,12 +58,21 @@ async fn connect_to_client(
|
|||
.await
|
||||
.expect("err during the ws handshake");
|
||||
|
||||
let ss = server_sender.clone();
|
||||
log::info!("connected to: {}", addr);
|
||||
let (sender, receiver) = ws.split();
|
||||
|
||||
let t1 = task::spawn(connection_for_sending(receiver, server_sender, conn));
|
||||
connection_for_receiving(sender, client_receiver, client_repeater).await?;
|
||||
log::debug!("launching repeater...");
|
||||
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?;
|
||||
t3.await?;
|
||||
t2.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -75,24 +84,34 @@ async fn connection_for_receiving(
|
|||
server_sender: SP,
|
||||
) -> io::Result<()> {
|
||||
log::info!("Connection for receiving launched");
|
||||
// let mut prev: PackedMessage = PackedMessage::FromFreenet("nothing".to_string());
|
||||
while let Ok(res) = client_receiver.recv() {
|
||||
//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 {
|
||||
PackedMessage::FromCore(json) => {
|
||||
let j = json.clone();
|
||||
sender
|
||||
.send(Message::Text(json))
|
||||
.send(Message::Text(j))
|
||||
.await
|
||||
.expect("Couldn't send message");
|
||||
}
|
||||
PackedMessage::FromFreenet(response) => {
|
||||
let r = response.clone();
|
||||
log::debug!("Got:\n {}", &response);
|
||||
sender
|
||||
// TODO freenet_response_handler
|
||||
.send(Message::Text(response))
|
||||
.send(Message::Text(r.to_string()))
|
||||
.await
|
||||
.expect("Couldn't send messge");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// }
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -102,6 +121,7 @@ async fn connection_for_sending(
|
|||
server_sender: SP,
|
||||
conn: rusqlite::Connection,
|
||||
) -> io::Result<()> {
|
||||
let ss = server_sender.clone();
|
||||
log::info!("Connection for sending launched");
|
||||
let mut new_msg = receiver.next();
|
||||
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());
|
||||
|
||||
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();
|
||||
log::info!("Connected to FCP");
|
||||
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<()> {
|
||||
// let mut prev = [0; 1024];
|
||||
loop {
|
||||
// each freenet responce have an identifier and program will define what to do with request by this identifier
|
||||
//TODO create handle_fcp_response function
|
||||
let mut buffer = [0; 1024];
|
||||
match receiver.read(&mut buffer).await {
|
||||
Ok(_) => {
|
||||
// if prev != buffer {
|
||||
let received = String::from_utf8_lossy(&buffer[..]);
|
||||
log::debug!("gotted {:?}", &received);
|
||||
client_sender
|
||||
.send(PackedMessage::FromFreenet(received.to_string()))
|
||||
.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),
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ pub async fn to_server_sender(
|
|||
log::info!("Message sended to client thread");
|
||||
}
|
||||
PackedMessage::ToFreenet(req) => {
|
||||
log::debug!("SENDED {}", req);
|
||||
sender.write(req.as_bytes()).await?;
|
||||
log::info!("Message sended to freenet");
|
||||
}
|
||||
|
|
|
@ -1,20 +1,42 @@
|
|||
use crate::chat::types::PackedMessage;
|
||||
use async_std::io;
|
||||
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;
|
||||
|
||||
type SP = Sender<PackedMessage>;
|
||||
|
||||
pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
||||
loop {
|
||||
// loop {
|
||||
//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);
|
||||
log::debug!("enough sleep");
|
||||
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",
|
||||
ReturnType::Direct).convert()
|
||||
ReturnType::Direct,
|
||||
)
|
||||
.convert(),
|
||||
)) {
|
||||
Ok(_) => {},
|
||||
Err(e) => continue ,
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
// message: format!(
|
||||
// "ClientGet\n\
|
||||
// URI=KSK@msg23.txt\n\
|
||||
|
@ -23,9 +45,3 @@ pub async fn request_repeater(ss: SP) -> io::Result<()> {
|
|||
// ReturnType=direct\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 {
|
||||
ToFreenet(String),
|
||||
FromFreenet(String),
|
||||
|
|
Loading…
Reference in a new issue