-
Notifications
You must be signed in to change notification settings - Fork 2
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
Handler track request/reply #2
Comments
Hi. I'm new to programming on rust, and if it's possible, I'd like to receive answers to some (may be stupid) questions about this issue. ID attributeI'm not very familiar with JSON-RPC, but quick look to the spec told me, that
not quite right. JSON-RPC 2.0 says:
Method attributeSame question about
According to the specification, there can be no valid request without a method attribute. So, if it doesn’t bother you, then I would like to hear the answers to these questions (and maybe later some others, also may be stupid). |
Hello! Hey, nothing is stupid. It is very positive that you read the JSON-RPC specification and now have questions about it.
This change aims to send a request and receive a response to the process with a future. According to the specification, if the request will not contain id, then it will be a notification. If it is a notification, then we should not track it in the futures queue, because there will never be a reply for it. To keep it possible to track request x response, it is mandatory we have an id. If the user wants to send a notification, he can use the following method: Line 34 in 6f15176
This method will return a raw notification message.
The message handler futures-jsonrpc/src/handler.rs Line 40 in 6f15176
Will receive anything. It will need a way to classify if the incoming message is a reply from a previous request or a new request. If the method attribute is mandatory for a request, then, if we don't have it, necessarily we received a response object. |
Hi again, sorry for big gap between messages. Thank you for your answer. Should I create new type for parsing message without method, or i should just make JrpcRequest's method attribute Option? And it's not clear for me with
what does this "future" mean? It's just generic Future trait, or Future, that returned by
type? I'm not sure, if I'm suppose to understand this by myself. I've read your code of this project a couple time, and it seemed clear for me, but this task is quite hard to understand. |
Hello! The proposed solution is indeed not very strict in a way we can maybe bring different perspectives.
To avoid the creation of a specific type only to check that, we can use standard use serde_json::{json, Value};
fn main() {
let js = json!({
"some_attribute": "some value",
"other": 43,
});
if let Value::Number(n) = &js["other"] {
println!("Other exist and is {}", n);
}
if let Value::Null = &js["method"] {
println!("Method does not exist");
}
if let None = js.get("method") {
println!("Also other way");
}
}
Here, we can mirror the behavior of futures-jsonrpc/src/handler.rs Line 24 in 72adb23
We receive an implementation of As for the future, it's less strict in the definition because we can either receive a concrete implementation of The advantage of using But, in this case, we need only one future with any data we store there. It's like this because a registered request will have one, and only one reply. This means we don't really have an advantage of using If we opt to use If we opt to store only a What do you think is the best option? |
Hi,
Is it a valid JSON RPC call without |
Hello, alfredo, Via the same interface, we will receive anything, including replies and requests. To differentiate between these two, we check for the |
Minimal solution
Create a new attribute
hm_requests
ofJrpcHandler
asHashMap<String, Implementation of JrpcMethodTrait>
hm_methods
as referenceCreate a new method
register_request
ofJrpcHandler
that will receive an implementation ofToString
and a future, and will register this information tohm_requests
register_method
as referenceUuid
, will be the key for theHashMap
Create a new method
wait_for_request_reply
ofJrpcHandler
that will receive one implementation ofJrpcRequest
and a futurehm_requests
via the createdregister_request
method using theget_id
method ofJrpcRequest
get_id
isNone
, this is not a valid request, according to the JsonRpc specification. Therefore, we need a newErrorVariant
for thatChange
handle_message
method ofJrpcHandler
to check if the parsed message Json containsmethod
attribute.hm_methods
.hm_requests
, and delete theHashMap
associated register after the retrieval of the generated futureOptimal solution
hm_requests
The text was updated successfully, but these errors were encountered: