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 # 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
@ -78,7 +79,10 @@ 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/ PUBLIC_HEADER DESTINATION "include/neocomm/"
CONFIGURATIONS release minsizerel) CONFIGURATIONS release minsizerel)
install(FILES "include/neocomm.hpp"
DESTINATION "include/")

20
README
View File

@ -72,12 +72,26 @@ policies.
# Contributing # Contributing
-------------- --------------
NeoComm is free/libre software[0]. To contribute simply send a patch file to my NeoComm is free/libre software[0]. Before contributing any code, please look at
e-mail: <nortega@themusicinnoise.net>. However, be sure to read the the `CONTRIBUTING' file for contribution policy. You can send patch files with
contributors guide in the `CONTRIBUTING' file before doing so. 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 [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:
[ ] Node Connectivity [X] Node Connectivity
[ ] Channel Functionality [X] Channel Functionality
[ ] Message Functionality [ ] Message Functionality
- v1.0: - v1.0:
[ ] Message Encryption [ ] Message Encryption

View File

@ -18,6 +18,8 @@
#pragma once #pragma once
#include "neocomm/message.hpp"
#include <string> #include <string>
#include <list> #include <list>
#include <opendht.h> #include <opendht.h>
@ -25,12 +27,35 @@
namespace neocomm { 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 { class channel {
dht::InfoHash key; //!< The sha1 hash of the channel name. public:
std::future<size_t> token; //!< Token used to leave channel. /**
std::list<std::string> messages; //!< Messages received by channel. * @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 #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 "neocomm/channel.hpp"
#include <opendht.h> #include <opendht.h>
#include <map> #include <vector>
namespace neocomm { namespace neocomm {
@ -34,8 +34,10 @@ 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();
/** /**
@ -65,27 +67,67 @@ 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);
private: /**
inline struct channel *get_channel( * @brief Leave a channel by pointer to the object.
const std::string &name) { *
for(auto &i : channels) * @note If the channel has not been joined on this node
{ * it does nothing.
if(i.first == name) *
return &i.second; * @param chan The channel object.
} */
return nullptr; 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; 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/node.hpp"
#include "neocomm/message.hpp"
using namespace neocomm; 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 // TODO: see about preserving an identity
network.run(port, dht::crypto::generateIdentity(), true); network.run(port, dht::crypto::generateIdentity(), true);
} }
@ -29,22 +31,33 @@ node::~node() {
network.join(); 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)) if(get_channel(name))
return; return nullptr;
channels[name].key = dht::InfoHash::get(name);
channels[name].token = network.listen<std::string>( channels.push_back(new channel(name, &network));
channels[name].key, return channels.back();
[&](std::string &&msg) { }
channels[name].messages.push_back(msg);
return true; 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) { void node::leave_channel(const std::string &name) {
if(not get_channel(name)) for(auto i = channels.begin();
return; i not_eq channels.end(); ++i)
network.cancelListen(channels[name].key, {
channels[name].token.get()); if((*i)->get_name() == name)
channels.erase(name); {
delete *i;
channels.erase(i);
return;
}
}
} }