Add rust async functions#483
Conversation
|
|
||
| size_t i = 0; | ||
| while(addrs != nullptr && addrs[i] != nullptr) { | ||
| sa.push_back(dht::SockAddr(addrs[i], addrs_len[i])); |
|
|
||
| println!("Current node id: {}", dht.node_id()); | ||
|
|
||
| let mut stream = dht.get_async(&InfoHash::get("bob")); |
There was a problem hiding this comment.
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
22c89fb to
122c30c
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.