-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add rust async functions #483
base: master
Are you sure you want to change the base?
Conversation
|
||
size_t i = 0; | ||
while(addrs != nullptr && addrs[i] != nullptr) { | ||
sa.push_back(dht::SockAddr(addrs[i], addrs_len[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emplace_back
|
||
println!("Current node id: {}", dht.node_id()); | ||
|
||
let mut stream = dht.get_async(&InfoHash::get("bob")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho, we can do like reqwest crate. Async by default and a sync Dht builder if someone needs to do some sync operations. So we can have DhtRunner::new(); and DhtRunner::blocking::new(), then .get() for both versions (https://docs.rs/reqwest/0.10.1/reqwest/blocking/index.html vs https://docs.rs/reqwest/0.10.1/reqwest/)
If you want I can take some time to modify this :). I think adding _async everywhere is not the best way
For the get, "ok" in the callback will be false if the Dht is not running, this can occurs during a connectivity change too. |
Maybe a std::io::NotConnected makes more sense. |
Hey @AmarOk1412, |
Np I'm not available till Feb 26 so it will take time :) |
f05b60d
to
dfd0a09
Compare
87f1050
to
c290bf0
Compare
966e620
to
fe6676f
Compare
Hey, here is a first sketch of who async could be implemented.
I'm not quite sure about the Errors that could be raised, i.e. in what cases does get()'s done callback return ok=false? If the peer is not connected to the network, yet? Maybe we should raise a special Error (right now I am misusing std::io::Error).
Let me know what you think about it?
EDIT: oh, damn, I overwrote the dhtnode example - I will move that to a new file - done.