Send message made.

This commit is contained in:
Nicolás Ortega Froysa 2017-09-25 13:01:51 +02:00
parent 18ca002ef6
commit 59c97c8bb8
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF

View File

@ -23,6 +23,9 @@
std::map<std::string, struct channel_info> channels; std::map<std::string, struct channel_info> channels;
static std::mt19937_64 rand_dev {dht::crypto::random_device{}()};
static std::uniform_int_distribution<dht::Value::Id> rand_id;
int NeoComm_join_channel(const char *channel_name) { int NeoComm_join_channel(const char *channel_name) {
if(not node.isRunning()) if(not node.isRunning())
{ {
@ -94,3 +97,19 @@ struct message *NeoComm_get_next_message(const char *channel_name) {
void NeoComm_free_message(struct message *msg) { void NeoComm_free_message(struct message *msg) {
free(msg); free(msg);
} }
int NeoComm_send_message(const char *channel_name, const char *message) {
const dht::InfoHash chan_hash = channels[channel_name].hash;
const time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
if(channels.find(channel_name) == channels.end())
{
add_error("Not connected to channel");
return 0;
}
node.putSigned(chan_hash, dht::ImMessage(rand_id(rand_dev), message, now), [](bool sent) {
// TODO: Figure out what to do here for failed messages.
});
return 1;
}