Compare commits

..

No commits in common. "ef1ddb1133ec784e566f69e5d580f6fc63a14333" and "1ca22e1aa438a5ce65e9d328a9af4197ad191d6d" have entirely different histories.

9 changed files with 49 additions and 216 deletions

View File

@ -39,12 +39,11 @@ include_directories(
# Define files # Define files
set(SRCS set(SRCS
"src/channel.cpp"
"src/node.cpp") "src/node.cpp")
set(HDRS set(HDRS
"include/neocomm.hpp"
"include/neocomm/channel.hpp" "include/neocomm/channel.hpp"
"include/neocomm/message.hpp"
"include/neocomm/node.hpp") "include/neocomm/node.hpp")
# Define C++ compiler flags # Define C++ compiler flags
@ -79,10 +78,7 @@ set_target_properties(${TARGET_NAME}
PROPERTIES PUBLIC_HEADER "${HDRS}") PROPERTIES PUBLIC_HEADER "${HDRS}")
install(TARGETS ${TARGET_NAME} install(TARGETS ${TARGET_NAME}
ARCHIVE DESTINATION "lib/" ARCHIVE DESTINATION lib/
LIBRARY DESTINATION "lib/" LIBRARY DESTINATION lib/
PUBLIC_HEADER DESTINATION "include/neocomm/" PUBLIC_HEADER DESTINATION include/
CONFIGURATIONS release minsizerel) CONFIGURATIONS release minsizerel)
install(FILES "include/neocomm.hpp"
DESTINATION "include/")

20
README
View File

@ -72,26 +72,12 @@ policies.
# Contributing # Contributing
-------------- --------------
NeoComm is free/libre software[0]. Before contributing any code, please look at NeoComm is free/libre software[0]. To contribute simply send a patch file to my
the `CONTRIBUTING' file for contribution policy. You can send patch files with e-mail: <nortega@themusicinnoise.net>. However, be sure to read the
contributions to <nortega@themusicinnoise.net> or to the community via contributors guide in the `CONTRIBUTING' file before doing so.
Bitmessage (see the 'Community' section below).
[0] https://www.gnu.org/philosophy/free-sw.html [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 # License
--------- ---------
This project is licensed under the terms & conditions of the GNU Affero General This project is licensed under the terms & conditions of the GNU Affero General

4
TODO
View File

@ -2,8 +2,8 @@
------ ------
Roadmap: Roadmap:
- v1.0-beta: - v1.0-beta:
[X] Node Connectivity [ ] Node Connectivity
[X] Channel Functionality [ ] Channel Functionality
[ ] Message Functionality [ ] Message Functionality
- v1.0: - v1.0:
[ ] Message Encryption [ ] Message Encryption

View File

@ -18,6 +18,4 @@
#pragma once #pragma once
#include "channel.hpp" #include "neocomm/node.hpp"
#include "message.hpp"
#include "node.hpp"

View File

@ -18,8 +18,6 @@
#pragma once #pragma once
#include "neocomm/message.hpp"
#include <string> #include <string>
#include <list> #include <list>
#include <opendht.h> #include <opendht.h>
@ -27,35 +25,12 @@
namespace neocomm { namespace neocomm {
/** /**
* @brief Represents the channel of a given node. Can be used * @brief Object to contain channel information.
* to send and receive messages.
*/ */
class channel { struct channel {
public: dht::InfoHash key; //!< The sha1 hash of the channel name.
/** std::future<size_t> token; //!< Token used to leave channel.
* @brief Initialize a channel object (this should pretty std::list<std::string> messages; //!< Messages received by channel.
* 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;
}; };
} }

View File

@ -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)
};
}

View File

@ -21,7 +21,7 @@
#include "neocomm/channel.hpp" #include "neocomm/channel.hpp"
#include <opendht.h> #include <opendht.h>
#include <vector> #include <map>
namespace neocomm { namespace neocomm {
@ -34,10 +34,8 @@ public:
* @brief Initalize the node. * @brief Initalize the node.
* *
* @param port Local port to bind to. * @param port Local port to bind to.
* @param alias Set the alias of the user.
*/ */
node(const unsigned short port = 31133, node(const unsigned short port = 31133);
const std::string &alias = "unknown");
~node(); ~node();
/** /**
@ -67,67 +65,27 @@ public:
/** /**
* @brief Join a channel. * @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. * @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); 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: 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; dht::DhtRunner network;
std::vector<channel*> channels; std::map<std::string, struct channel> channels;
}; };
} }

View File

@ -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());
}

View File

@ -17,12 +17,10 @@
*/ */
#include "neocomm/node.hpp" #include "neocomm/node.hpp"
#include "neocomm/message.hpp"
using namespace neocomm; using namespace neocomm;
node::node(unsigned short port, const std::string &alias) : node::node(unsigned short port) {
alias(alias) {
// TODO: see about preserving an identity // TODO: see about preserving an identity
network.run(port, dht::crypto::generateIdentity(), true); network.run(port, dht::crypto::generateIdentity(), true);
} }
@ -31,33 +29,22 @@ node::~node() {
network.join(); network.join();
} }
channel *node::join_channel(const std::string &name) { void node::join_channel(const std::string &name) {
// don't do anything if already joined
if(get_channel(name)) if(get_channel(name))
return nullptr; return;
channels[name].key = dht::InfoHash::get(name);
channels.push_back(new channel(name, &network)); channels[name].token = network.listen<std::string>(
return channels.back(); channels[name].key,
} [&](std::string &&msg) {
channels[name].messages.push_back(msg);
channel *node::get_channel(const std::string &name) { return true;
for(auto i : channels) });
{
if(i->get_name() == name)
return i;
}
return nullptr;
} }
void node::leave_channel(const std::string &name) { void node::leave_channel(const std::string &name) {
for(auto i = channels.begin(); if(not get_channel(name))
i not_eq channels.end(); ++i)
{
if((*i)->get_name() == name)
{
delete *i;
channels.erase(i);
return; return;
} network.cancelListen(channels[name].key,
} channels[name].token.get());
channels.erase(name);
} }