Compare commits

..

10 Commits

Author SHA1 Message Date
Nicolás Ortega Froysa
ef1ddb1133
Moved main header file. 2018-12-23 14:22:17 +01:00
Nicolás Ortega Froysa
b6bd1a9b82
Adding Bitmessage as a means of collaboration. 2018-09-15 12:19:52 +02:00
Nicolás Ortega Froysa
9fb5855de8
Added new header files to main include file. 2018-09-04 18:03:07 +02:00
Nicolás Ortega Froysa
7dc2795f15
Documented channel class. 2018-09-04 15:59:03 +02:00
Nicolás Ortega Froysa
04388c04b8
Added documentation. 2018-09-04 15:57:52 +02:00
Nicolás Ortega Froysa
15067ab4ec
Changed channel to a class.
I believe this interface is better to work with. Later I'll add the
"send message" interfaces to the channel class.
2018-09-04 15:52:10 +02:00
Nicolás Ortega Froysa
93fa26aa1a
Add channel.cpp and message.hpp 2018-09-04 15:51:41 +02:00
Nicolás Ortega Froysa
5b8ea48058
Adding a message object. 2018-09-02 12:33:23 +02:00
Nicolás Ortega Froysa
414375d0e6
Update TODO 2018-09-02 12:33:03 +02:00
Nicolás Ortega Froysa
c5ffedb844
Properly install header files. 2018-09-02 12:08:50 +02:00
9 changed files with 216 additions and 49 deletions

View File

@ -39,11 +39,12 @@ 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
@ -78,7 +79,10 @@ set_target_properties(${TARGET_NAME}
PROPERTIES PUBLIC_HEADER "${HDRS}")
install(TARGETS ${TARGET_NAME}
ARCHIVE DESTINATION lib/
LIBRARY DESTINATION lib/
PUBLIC_HEADER DESTINATION include/
ARCHIVE DESTINATION "lib/"
LIBRARY DESTINATION "lib/"
PUBLIC_HEADER DESTINATION "include/neocomm/"
CONFIGURATIONS release minsizerel)
install(FILES "include/neocomm.hpp"
DESTINATION "include/")

20
README
View File

@ -72,12 +72,26 @@ policies.
# Contributing
--------------
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.
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).
[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
View File

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

View File

@ -18,6 +18,8 @@
#pragma once
#include "neocomm/message.hpp"
#include <string>
#include <list>
#include <opendht.h>
@ -25,12 +27,35 @@
namespace neocomm {
/**
* @brief Object to contain channel information.
* @brief Represents the channel of a given node. Can be used
* to send and receive 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.
};
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;
};
}

View File

@ -0,0 +1,31 @@
/*
* 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

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

View File

@ -21,7 +21,7 @@
#include "neocomm/channel.hpp"
#include <opendht.h>
#include <map>
#include <vector>
namespace neocomm {
@ -34,8 +34,10 @@ 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);
node(const unsigned short port = 31133,
const std::string &alias = "unknown");
~node();
/**
@ -65,27 +67,67 @@ 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);
private:
inline struct channel *get_channel(
const std::string &name) {
for(auto &i : channels)
{
if(i.first == name)
return &i.second;
}
return nullptr;
/**
* @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;
dht::DhtRunner network;
std::map<std::string, struct channel> channels;
std::vector<channel*> channels;
};
}

36
src/channel.cpp Normal file
View File

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