Had to rewrite this entire bitch.
This commit is contained in:
@ -19,28 +19,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "identity.hpp"
|
||||
#include <list>
|
||||
#include <opendht.h>
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
/**
|
||||
* @brief Container class of all data and basic functions pertaining to
|
||||
* channel functionality.
|
||||
*/
|
||||
class channel {
|
||||
public:
|
||||
/**
|
||||
* @brief Initialize the channel class and start receiving messages
|
||||
* for the given ID.
|
||||
*
|
||||
* @param chan_id The ID of the channel.
|
||||
*/
|
||||
channel(const std::string &chan_id); // TODO
|
||||
~channel(); // TODO
|
||||
private:
|
||||
const std::string chan_id;
|
||||
std::vector<message> msgs; // messages to and from the channel
|
||||
struct channel {
|
||||
dht::InfoHash key;
|
||||
std::future<size_t> token;
|
||||
std::list<std::string> messages;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
#include "identity.hpp"
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
/**
|
||||
* @brief Container for data of a user message.
|
||||
*/
|
||||
class message {
|
||||
private:
|
||||
const std::string text;
|
||||
const struct tm time_stamp;
|
||||
const identity from;
|
||||
};
|
||||
|
||||
}
|
@ -18,17 +18,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
/**
|
||||
* @brief Container class for data pertaining to a user.
|
||||
*/
|
||||
class identity {
|
||||
public:
|
||||
private:
|
||||
const std::string id;
|
||||
std::string nick;
|
||||
std::string client_info;
|
||||
};
|
||||
|
||||
}
|
||||
#include "node.hpp"
|
@ -18,89 +18,39 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "identity.hpp"
|
||||
#include "channel.hpp"
|
||||
#include "neocomm/channel.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <opendht.h>
|
||||
#include <map>
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
/**
|
||||
* @brief NeoComm node object.
|
||||
*
|
||||
* @details Contains the necessary interfaces to create a
|
||||
* NeoComm node and connect to a NeoComm network.
|
||||
*/
|
||||
class node {
|
||||
public:
|
||||
/**
|
||||
* @brief Initialize a NeoComm node.
|
||||
*
|
||||
* @param port Listen on a given port (8085 by default).
|
||||
*/
|
||||
node(unsigned short port = 8085);
|
||||
/**
|
||||
* @brief Initialize a NeoComm node inputting a list of
|
||||
* known nodes from a file.
|
||||
*
|
||||
* @param node_file Path to file containing node list.
|
||||
* @param port Listen on a given port (8085 by default).
|
||||
*/
|
||||
node(const std::string &node_file,
|
||||
unsigned short port = 8085);
|
||||
node(const unsigned short port = 31133);
|
||||
~node();
|
||||
|
||||
/**
|
||||
* @brief Connect the node to a given address.
|
||||
*
|
||||
* @param address The IP or domain name of the other node.
|
||||
* @param port The port of the other node.
|
||||
*/
|
||||
void connect(const std::string &address,
|
||||
unsigned short port);
|
||||
/**
|
||||
* @brief Import and connect to a list of nodes from a
|
||||
* previous session.
|
||||
*
|
||||
* @param node_file File containing the node list.
|
||||
*/
|
||||
void import_nodes(const std::string &node_file);
|
||||
/**
|
||||
* @brief Export currently connected nodes to a file.
|
||||
*
|
||||
* @param node_file File to export nodes to.
|
||||
*/
|
||||
void export_nodes(const std::string &node_file);
|
||||
|
||||
/**
|
||||
* @brief Join and receive messages from a channel.
|
||||
*
|
||||
* @param chan_id The ID of the channel.
|
||||
*/
|
||||
void join_channel(const std::string &chan_id); // TODO
|
||||
/**
|
||||
* @brief Retrieve the channel object.
|
||||
*
|
||||
* @param chan_id The ID of the channel.
|
||||
*
|
||||
* @return The channel object.
|
||||
*/
|
||||
channel* get_channel(const std::string &chan_id); // TODO
|
||||
/**
|
||||
* @brief Leave a channel.
|
||||
*
|
||||
* @param chan_id The ID of the channel.
|
||||
*/
|
||||
void leave_channel(const std::string &chan_id); // TODO
|
||||
inline void connect(const std::string &address,
|
||||
const std::string &port) {
|
||||
network.bootstrap(address, port);
|
||||
}
|
||||
void import_nodes(const std::string &file_path); // TODO
|
||||
void export_nodes(const std::string &file_path); // TODO
|
||||
|
||||
void join_channel(const std::string &name);
|
||||
void leave_channel(const std::string &name);
|
||||
private:
|
||||
unsigned int pm_timeout; // timeout for private message reception confirmation
|
||||
unsigned int chan_timeout; // timeout for channel presence message
|
||||
std::vector<channel> channels; // channels connected to via the node
|
||||
std::vector<identity> identities; // known users on the network
|
||||
dht::DhtRunner dht_node; // the actual OpenDHT node
|
||||
inline struct channel *get_channel(
|
||||
const std::string &name) {
|
||||
for(auto &i : channels)
|
||||
{
|
||||
if(i.first == name)
|
||||
return &i.second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
dht::DhtRunner network;
|
||||
std::map<std::string, struct channel> channels;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user