Connect may give error.

This commit is contained in:
Nicolás Ortega Froysa
2017-09-20 21:01:07 +02:00
parent 485e38ed80
commit 3eb8a5e887
2 changed files with 29 additions and 3 deletions

@ -18,6 +18,7 @@
#include "neocomm.h"
#include "globals.hpp"
#include "error.hpp"
#include <opendht.h>
@ -26,7 +27,7 @@
#define DEFAULT_PORT 1335
static dht::DhtRunner node;
dht::DhtRunner node;
void NeoComm_init(unsigned short port) {
if(port == 0)
@ -38,13 +39,24 @@ void NeoComm_deinit() {
node.join();
}
void NeoComm_connect(const char *address, const unsigned short port) {
int NeoComm_connect(const char *address, const unsigned short port) {
if(not node.isRunning())
{
add_error("NeoComm must be initialized.");
return 0;
}
node.bootstrap(address, std::to_string(port));
return 1;
}
// NOTICE: When the new OpenDHT release comes out this code should work.
// Meanwhile just keep it commented out.
/*int NeoComm_import_nodes(const char *node_file) {
if(not node.isRunning())
{
add_error("NeoComm must be initialized.");
return 0;
}
msgpack::unpacker upak;
{
std::ifstream import_file(node_file, std::ios::binary bitor
@ -72,6 +84,10 @@ void NeoComm_connect(const char *address, const unsigned short port) {
}*/
/*int NeoComm_export_nodes(const char *node_file) {
if(not node.isRunning())
{
add_error("NeoComm must be initialized.");
}
std::ofstream export_file(node_file, std::ios::binary);
if(not export_file.is_open())
{