-
Notifications
You must be signed in to change notification settings - Fork 125
[WIP] Various IDE improvements and new features #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 78 commits
ddb4779
bbc07cc
dc4b1d5
dc079fa
c1d86d2
207a4ad
4636373
e311df9
3780ce1
e518ef4
295040c
7adf64e
4943255
0bd03b9
fe577dc
dedc17b
8812f3d
c1cbde9
b4f93ae
41e1964
6facfce
3ac17ee
24ad838
5d141eb
95b78ca
9b0b5ad
bb6ddb2
a4dce76
f84219c
d9e067c
a069cef
92c92c3
ca86115
4e1a547
26ea0af
872b3c1
2cbc865
c3a2c6f
5ed232e
91b91c4
ba54ed7
e4810ec
f886f8b
93a78c7
9ef451a
5df2a04
b6ba6f6
f27499c
cf53b8e
158b9ad
195af4d
91f4ff9
82e6063
849b18d
33a2e63
ed8b1b6
1b1242d
ebfdd1b
ca1d9d6
137f9a2
f79e966
f2fa93a
5600499
7e6ceaf
e8bddf0
ede8451
3572fea
be04342
7d434b5
bac27bf
9ca7602
b373c14
e84688f
2cc9233
c39ece5
f83a088
8b4563f
eaeef45
82b0eb8
a492472
f50a367
a1e6d9f
b144843
aaa3ea5
dc6ead0
1f0ae07
e562bca
65c99d9
a299c14
eb05efc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,58 +4,76 @@ | |
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| use crate::VerificationRequest; | ||
| use crate::{ServerMessage, VerificationRequest}; | ||
| use futures_util::{ | ||
| sink::SinkExt, | ||
| stream::{Stream, StreamExt}, | ||
| }; | ||
| use prusti_common::config; | ||
| use reqwest::Client; | ||
| use url::{ParseError, Url}; | ||
| use viper::VerificationResult; | ||
| use tokio_tungstenite::{ | ||
| connect_async, | ||
| tungstenite::{error::Error, Message}, | ||
| }; | ||
| use url::Url; | ||
|
|
||
| pub struct PrustiClient { | ||
| client: Client, | ||
| server_url: Url, | ||
| } | ||
| pub struct PrustiClient; | ||
|
|
||
| impl PrustiClient { | ||
| pub fn new<S: ToString>(server_address: S) -> Result<Self, ParseError> { | ||
| pub async fn verify<S: ToString>( | ||
| server_address: S, | ||
| request: VerificationRequest, | ||
| ) -> impl Stream<Item = ServerMessage> { | ||
| // TODO: do proper error handling | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How "improper" is it? For example, is it just resilience against the server unexpectedly quitting? If we panic in such a case that might be ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Atm, we panic if the server address is invalid and if the connection is torn down/fails somehow unexpectedly. However, this was basically the same before: just that there this method returned a result which was |
||
| let mut address = server_address.to_string(); | ||
| if !address.starts_with("http") { | ||
| address = format!("http://{address}"); | ||
| if !address.starts_with("ws") { | ||
| address = format!("ws://{address}"); | ||
| } | ||
| Ok(Self { | ||
| client: Client::new(), | ||
| server_url: Url::parse(address.as_str())?, | ||
| }) | ||
| } | ||
|
|
||
| pub async fn verify( | ||
| &self, | ||
| request: VerificationRequest, | ||
| ) -> reqwest::Result<VerificationResult> { | ||
| let server_url = Url::parse(address.as_str()).unwrap(); | ||
|
|
||
| let use_json = config::json_communication(); | ||
| let base = self.client.post( | ||
| self.server_url | ||
| .join(if use_json { "json/" } else { "bincode/" }) | ||
| .unwrap() | ||
| .join("verify/") | ||
| .unwrap(), | ||
| ); | ||
| let response = if use_json { | ||
| base.json(&request) | ||
| .send() | ||
| .await? | ||
| .error_for_status()? | ||
| .json() | ||
| .await? | ||
|
|
||
| let uri = server_url | ||
| .join(if use_json { "json/" } else { "bincode/" }) | ||
| .unwrap() | ||
| .join("verify/") | ||
| .unwrap(); | ||
| let (mut socket, _) = connect_async(uri).await.unwrap(); | ||
| let msg = if use_json { | ||
| Message::text( | ||
| serde_json::to_string(&request) | ||
| .expect("error encoding verification request in json"), | ||
| ) | ||
| } else { | ||
| let bytes = base | ||
| .body(bincode::serialize(&request).expect("error encoding verification request")) | ||
| .send() | ||
| .await? | ||
| .error_for_status()? | ||
| .bytes() | ||
| .await?; | ||
| bincode::deserialize(&bytes).expect("error decoding verification result") | ||
| Message::binary( | ||
| bincode::serialize(&request) | ||
| .expect("error encoding verification request as binary"), | ||
| ) | ||
| }; | ||
| socket.send(msg).await.unwrap(); | ||
| let json_map = |ws_msg| { | ||
| if let Message::Text(json) = ws_msg { | ||
| serde_json::from_str(&json).expect("error decoding verification result from json") | ||
| } else { | ||
| panic!("Invalid response from the server."); | ||
| } | ||
| }; | ||
| let bin_map = |ws_msg| { | ||
| if let Message::Binary(bytes) = ws_msg { | ||
| bincode::deserialize(&bytes).expect("error decoding verification result") | ||
| } else { | ||
| panic!("Invalid response from the server."); | ||
| } | ||
| }; | ||
| let filter_close = |msg_result: Result<Message, Error>| async { | ||
| let msg = msg_result.unwrap(); | ||
| match msg { | ||
| Message::Close(_) => None, | ||
| _ => Some(msg), | ||
| } | ||
| }; | ||
| Ok(response) | ||
| socket | ||
| .filter_map(filter_close) | ||
| .map(if use_json { json_map } else { bin_map }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.