Compare commits
No commits in common. "ef1ddb1133ec784e566f69e5d580f6fc63a14333" and "1ca22e1aa438a5ce65e9d328a9af4197ad191d6d" have entirely different histories.
ef1ddb1133
...
1ca22e1aa4
@ -39,12 +39,11 @@ include_directories(
|
||||
|
||||
# Define files
|
||||
set(SRCS
|
||||
"src/channel.cpp"
|
||||
"src/node.cpp")
|
||||
|
||||
set(HDRS
|
||||
"include/neocomm.hpp"
|
||||
"include/neocomm/channel.hpp"
|
||||
"include/neocomm/message.hpp"
|
||||
"include/neocomm/node.hpp")
|
||||
|
||||
# Define C++ compiler flags
|
||||
@ -79,10 +78,7 @@ set_target_properties(${TARGET_NAME}
|
||||
PROPERTIES PUBLIC_HEADER "${HDRS}")
|
||||
|
||||
install(TARGETS ${TARGET_NAME}
|
||||
ARCHIVE DESTINATION "lib/"
|
||||
LIBRARY DESTINATION "lib/"
|
||||
PUBLIC_HEADER DESTINATION "include/neocomm/"
|
||||
ARCHIVE DESTINATION lib/
|
||||
LIBRARY DESTINATION lib/
|
||||
PUBLIC_HEADER DESTINATION include/
|
||||
CONFIGURATIONS release minsizerel)
|
||||
|
||||
install(FILES "include/neocomm.hpp"
|
||||
DESTINATION "include/")
|
||||
|
20
README
20
README
@ -72,26 +72,12 @@ policies.
|
||||
|
||||
# Contributing
|
||||
--------------
|
||||
NeoComm is free/libre software[0]. Before contributing any code, please look at
|
||||
the `CONTRIBUTING' file for contribution policy. You can send patch files with
|
||||
contributions to <nortega@themusicinnoise.net> or to the community via
|
||||
Bitmessage (see the 'Community' section below).
|
||||
NeoComm is free/libre software[0]. To contribute simply send a patch file to my
|
||||
e-mail: <nortega@themusicinnoise.net>. However, be sure to read the
|
||||
contributors guide in the `CONTRIBUTING' file before doing so.
|
||||
|
||||
[0] https://www.gnu.org/philosophy/free-sw.html
|
||||
|
||||
# Community
|
||||
-----------
|
||||
NeoComm uses Bitmessage[0] for community collaboration. To receive updates on
|
||||
NeoComm subscribe to the following address:
|
||||
|
||||
BM-NBHAvmbVbUnGxLDmGhZQ66uWUijd7uGi
|
||||
|
||||
There is also a public broadcast channel available:
|
||||
Chan name/passphrase: neocomm
|
||||
Chan address: BM-2cTDst8Xf8afFXFNdtT3qhU4vAJ4nXTYUW
|
||||
|
||||
[0] https://bitmessage.org/wiki/Main_Page
|
||||
|
||||
# License
|
||||
---------
|
||||
This project is licensed under the terms & conditions of the GNU Affero General
|
||||
|
4
TODO
4
TODO
@ -2,8 +2,8 @@
|
||||
------
|
||||
Roadmap:
|
||||
- v1.0-beta:
|
||||
[X] Node Connectivity
|
||||
[X] Channel Functionality
|
||||
[ ] Node Connectivity
|
||||
[ ] Channel Functionality
|
||||
[ ] Message Functionality
|
||||
- v1.0:
|
||||
[ ] Message Encryption
|
||||
|
@ -18,6 +18,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "message.hpp"
|
||||
#include "node.hpp"
|
||||
#include "neocomm/node.hpp"
|
@ -18,8 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "neocomm/message.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <opendht.h>
|
||||
@ -27,35 +25,12 @@
|
||||
namespace neocomm {
|
||||
|
||||
/**
|
||||
* @brief Represents the channel of a given node. Can be used
|
||||
* to send and receive messages.
|
||||
* @brief Object to contain channel information.
|
||||
*/
|
||||
class channel {
|
||||
public:
|
||||
/**
|
||||
* @brief Initialize a channel object (this should pretty
|
||||
* much only be done by the node object).
|
||||
*
|
||||
* @param name Name of the channel.
|
||||
* @param network A pointer to the OpenDHT node.
|
||||
*/
|
||||
channel(const std::string &name, dht::DhtRunner *network);
|
||||
~channel();
|
||||
|
||||
/**
|
||||
* @brief Get the name of the channel.
|
||||
*
|
||||
* @return The name of the channel.
|
||||
*/
|
||||
inline std::string get_name() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
const dht::InfoHash key;
|
||||
dht::DhtRunner *network;
|
||||
std::future<size_t> token;
|
||||
std::list<struct message> messages;
|
||||
struct channel {
|
||||
dht::InfoHash key; //!< The sha1 hash of the channel name.
|
||||
std::future<size_t> token; //!< Token used to leave channel.
|
||||
std::list<std::string> messages; //!< Messages received by channel.
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,31 +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 <opendht.h>
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
struct message {
|
||||
std::string alias;
|
||||
std::string msg;
|
||||
MSGPACK_DEFINE(alias, msg)
|
||||
};
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
#include "neocomm/channel.hpp"
|
||||
|
||||
#include <opendht.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace neocomm {
|
||||
|
||||
@ -34,10 +34,8 @@ public:
|
||||
* @brief Initalize the node.
|
||||
*
|
||||
* @param port Local port to bind to.
|
||||
* @param alias Set the alias of the user.
|
||||
*/
|
||||
node(const unsigned short port = 31133,
|
||||
const std::string &alias = "unknown");
|
||||
node(const unsigned short port = 31133);
|
||||
~node();
|
||||
|
||||
/**
|
||||
@ -67,67 +65,27 @@ public:
|
||||
/**
|
||||
* @brief Join a channel.
|
||||
*
|
||||
* @param name The name of the channel to join.
|
||||
*/
|
||||
void join_channel(const std::string &name);
|
||||
/**
|
||||
* @brief Leave an already joined channel.
|
||||
*
|
||||
* @param name Name of the channel.
|
||||
*
|
||||
* @note If the channel is already joined on this node
|
||||
* then it does nothing and returns a nullptr.
|
||||
*
|
||||
* @return Returns a pointer to the channel object.
|
||||
*/
|
||||
channel *join_channel(const std::string &name);
|
||||
/**
|
||||
* @brief Get a pointer to a channel object by name.
|
||||
*
|
||||
* @param name The name of the channel.
|
||||
*
|
||||
* @note If the channel has not been joined on this node
|
||||
* then it returns nullptr.
|
||||
*
|
||||
* @return A pointer to the channel object.
|
||||
*/
|
||||
channel *get_channel(const std::string &name);
|
||||
/**
|
||||
* @brief Leave a channel by name.
|
||||
*
|
||||
* @note If the channel has not been joined on this node
|
||||
* it does nothing.
|
||||
*
|
||||
* @param name The name of the channel.
|
||||
*/
|
||||
void leave_channel(const std::string &name);
|
||||
/**
|
||||
* @brief Leave a channel by pointer to the object.
|
||||
*
|
||||
* @note If the channel has not been joined on this node
|
||||
* it does nothing.
|
||||
*
|
||||
* @param chan The channel object.
|
||||
*/
|
||||
inline void leave_channel(channel *chan) {
|
||||
leave_channel(chan->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current alias for the user.
|
||||
*
|
||||
* @return The current alias of the user.
|
||||
*/
|
||||
inline std::string get_alias() const {
|
||||
return alias;
|
||||
}
|
||||
/**
|
||||
* @brief Set the alias of the user.
|
||||
*
|
||||
* @param alias The new alias of the user.
|
||||
*/
|
||||
inline void set_alias(const std::string &alias) {
|
||||
this->alias = alias;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string alias;
|
||||
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::vector<channel*> channels;
|
||||
std::map<std::string, struct channel> channels;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,36 +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/>.
|
||||
*/
|
||||
|
||||
#include "neocomm/channel.hpp"
|
||||
|
||||
using namespace neocomm;
|
||||
|
||||
channel::channel(const std::string &name,
|
||||
dht::DhtRunner *network) :
|
||||
name(name), key(dht::InfoHash::get(name)),
|
||||
network(network) {
|
||||
token = network->listen<struct message>(key,
|
||||
[&](struct message &&msg) {
|
||||
messages.push_back(msg);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
channel::~channel() {
|
||||
network->cancelListen(key, token.get());
|
||||
}
|
41
src/node.cpp
41
src/node.cpp
@ -17,12 +17,10 @@
|
||||
*/
|
||||
|
||||
#include "neocomm/node.hpp"
|
||||
#include "neocomm/message.hpp"
|
||||
|
||||
using namespace neocomm;
|
||||
|
||||
node::node(unsigned short port, const std::string &alias) :
|
||||
alias(alias) {
|
||||
node::node(unsigned short port) {
|
||||
// TODO: see about preserving an identity
|
||||
network.run(port, dht::crypto::generateIdentity(), true);
|
||||
}
|
||||
@ -31,33 +29,22 @@ node::~node() {
|
||||
network.join();
|
||||
}
|
||||
|
||||
channel *node::join_channel(const std::string &name) {
|
||||
// don't do anything if already joined
|
||||
void node::join_channel(const std::string &name) {
|
||||
if(get_channel(name))
|
||||
return nullptr;
|
||||
|
||||
channels.push_back(new channel(name, &network));
|
||||
return channels.back();
|
||||
}
|
||||
|
||||
channel *node::get_channel(const std::string &name) {
|
||||
for(auto i : channels)
|
||||
{
|
||||
if(i->get_name() == name)
|
||||
return i;
|
||||
}
|
||||
return nullptr;
|
||||
return;
|
||||
channels[name].key = dht::InfoHash::get(name);
|
||||
channels[name].token = network.listen<std::string>(
|
||||
channels[name].key,
|
||||
[&](std::string &&msg) {
|
||||
channels[name].messages.push_back(msg);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void node::leave_channel(const std::string &name) {
|
||||
for(auto i = channels.begin();
|
||||
i not_eq channels.end(); ++i)
|
||||
{
|
||||
if((*i)->get_name() == name)
|
||||
{
|
||||
delete *i;
|
||||
channels.erase(i);
|
||||
if(not get_channel(name))
|
||||
return;
|
||||
}
|
||||
}
|
||||
network.cancelListen(channels[name].key,
|
||||
channels[name].token.get());
|
||||
channels.erase(name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user