-
Notifications
You must be signed in to change notification settings - Fork 24
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
An easy-to-use client mode #205
Comments
From the current architecture, In order to allow users to implement different protocols in the same way, from the user's perspective, the first object is no longer a stream, but a user-defined protocol trait. Therefore, at the framework level, the underlying stream needs to be hidden, and the session id is provided as an index for the protocol trait operation. Therefore, the operation object of |
That's what I thought, thanks. What would be neat for my use case is to have some kind of callback, eg.: let callback: Bytes = service_control
.send_message_to(1.into(), 0.into(), Bytes::from("query"))
.await?;
assert_eq!(Bytes::from("query_result: blablabla"), callback); I wonder how difficult would it be to implement this? Or do you have better idea? |
I think I probably know what you want. At present, you need to encapsulate it yourself. The easiest way is probably like this, you can change the channel to asynchronous, and then combine it with In fact, the essence of this problem is that at present, the framework only provides the writing of the server mode, and when you want to write a client directly based on the server, you will find that it is more cumbersome. A simple and easy-to-use client requires some work to implement, temporarily not available, maybe after the upgrade and refactor, will consider this |
Thanks @driftluo, I'll explore these possibilities. |
Thanks for the reporting. We'll consider how to refactor the code to ease reusing in such scenarios. Please subscribe nervosnetwork/ckb#1912 if you want to know the latest progress. |
@doitian This issue has nothing to do with ckb, it is a missing implementation of p2p itself |
Got it. Could you help to revise the title to make it more clear? |
This is a good candidate to be implemented as a middleware. The tentacle has no concept of request and response. It just knows incoming and outgoing messages streams. But the application layer can add logic to associate an incoming message with a pending outgoing message as the response. For example, the middleware stores all the pending outgoing messages as requests as well as the corresponding replying oneshot channel. Once a message is received, the middleware matches it against the requests. If a matching request is found, the response is sent via the replying oneshot channel and the request is removed from the waiting queue. The application is responsible to implement the request-response matching method. There are different strategies:
Since it is an extension of tentacle, we have no plan to implement such middleware yet. However, we'll keep this issue open to see who is interested to implement it. |
Hi there,
First of all, thanks for the lib.
I'm able to connect to different peers, then send messages from one to another.
One thing I couldn't achieve so far is, to use a the underlying stream (or substream) in order to forward the data via (
io::copy()
), would is this possible?Thank you.
The text was updated successfully, but these errors were encountered: