Connect may give error.
This commit is contained in:
parent
485e38ed80
commit
3eb8a5e887
@ -40,8 +40,11 @@ void NeoComm_deinit();
|
|||||||
*
|
*
|
||||||
* @param address DNS/IP of the node.
|
* @param address DNS/IP of the node.
|
||||||
* @param port Port of the foreign node.
|
* @param port Port of the foreign node.
|
||||||
|
*
|
||||||
|
* @return 1 upon success, 0 upon failure. Use NeoComm_get_last_error for a
|
||||||
|
* text description of the error.
|
||||||
*/
|
*/
|
||||||
void NeoComm_connect(const char *address, const unsigned short port);
|
int NeoComm_connect(const char *address, const unsigned short port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Import a list of nodes from a node file and connect to them.
|
* @brief Import a list of nodes from a node file and connect to them.
|
||||||
@ -73,6 +76,13 @@ int NeoComm_export_nodes(const char *node_file);
|
|||||||
*/
|
*/
|
||||||
int NeoComm_join_channel(const char *channel_name);
|
int NeoComm_join_channel(const char *channel_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Leave a channel.
|
||||||
|
*
|
||||||
|
* @param channel_name Name of the channel to disconnect from.
|
||||||
|
*/
|
||||||
|
void NeoComm_leave_channel(const char *channel_name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the last error that occurred in text.
|
* @brief Get the last error that occurred in text.
|
||||||
*
|
*
|
||||||
|
20
src/node.cpp
20
src/node.cpp
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "neocomm.h"
|
#include "neocomm.h"
|
||||||
|
|
||||||
|
#include "globals.hpp"
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
|
|
||||||
#include <opendht.h>
|
#include <opendht.h>
|
||||||
@ -26,7 +27,7 @@
|
|||||||
|
|
||||||
#define DEFAULT_PORT 1335
|
#define DEFAULT_PORT 1335
|
||||||
|
|
||||||
static dht::DhtRunner node;
|
dht::DhtRunner node;
|
||||||
|
|
||||||
void NeoComm_init(unsigned short port) {
|
void NeoComm_init(unsigned short port) {
|
||||||
if(port == 0)
|
if(port == 0)
|
||||||
@ -38,13 +39,24 @@ void NeoComm_deinit() {
|
|||||||
node.join();
|
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));
|
node.bootstrap(address, std::to_string(port));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTICE: When the new OpenDHT release comes out this code should work.
|
// NOTICE: When the new OpenDHT release comes out this code should work.
|
||||||
// Meanwhile just keep it commented out.
|
// Meanwhile just keep it commented out.
|
||||||
/*int NeoComm_import_nodes(const char *node_file) {
|
/*int NeoComm_import_nodes(const char *node_file) {
|
||||||
|
if(not node.isRunning())
|
||||||
|
{
|
||||||
|
add_error("NeoComm must be initialized.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
msgpack::unpacker upak;
|
msgpack::unpacker upak;
|
||||||
{
|
{
|
||||||
std::ifstream import_file(node_file, std::ios::binary bitor
|
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) {
|
/*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);
|
std::ofstream export_file(node_file, std::ios::binary);
|
||||||
if(not export_file.is_open())
|
if(not export_file.is_open())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user