Start adding code.
This commit is contained in:
parent
fac59cfd2f
commit
8961bce658
83
CMakeLists.txt
Normal file
83
CMakeLists.txt
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(NeoComm)
|
||||||
|
|
||||||
|
# Binary filename
|
||||||
|
set(TARGET_NAME "neocomm")
|
||||||
|
set(TARGET_VERSION "1.0-beta")
|
||||||
|
|
||||||
|
# Use DEBUG by default
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "debug")
|
||||||
|
endif()
|
||||||
|
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
|
||||||
|
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
|
option(BUILD_SHARED_LIB "Build a dynamic library." OFF)
|
||||||
|
|
||||||
|
find_package(GnuTLS REQUIRED)
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(OPENDHT REQUIRED opendht>=1.4.0)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
"include/"
|
||||||
|
SYSTEM ${OPENDHT_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# Define files
|
||||||
|
set(SRCS
|
||||||
|
src/channel.cpp
|
||||||
|
src/message.cpp
|
||||||
|
src/node.cpp)
|
||||||
|
|
||||||
|
set(HDRS
|
||||||
|
include/neocomm/channel.hpp
|
||||||
|
include/neocomm/message.hpp
|
||||||
|
include/neocomm/node.hpp)
|
||||||
|
|
||||||
|
# Define C++ compiler flags
|
||||||
|
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors -pedantic-errors -fno-elide-constructors")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3")
|
||||||
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
|
||||||
|
|
||||||
|
add_definitions(-DVERSION="${TARGET_VERSION}")
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "debug" OR CMAKE_BUILD_TYPE STREQUAL "relwithdebinfo")
|
||||||
|
add_definitions(-DDEBUG)
|
||||||
|
else()
|
||||||
|
add_definitions(-DNDEBUG)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Create the executable
|
||||||
|
if(${BUILD_SHARED_LIB})
|
||||||
|
add_library(${TARGET_NAME} SHARED ${SRCS})
|
||||||
|
target_link_libraries(${TARGET_NAME}
|
||||||
|
${GNUTLS_LIBRARIES}
|
||||||
|
${OPENDHT_LIBRARIES})
|
||||||
|
else()
|
||||||
|
add_library(${TARGET_NAME} STATIC ${SRCS})
|
||||||
|
endif()
|
||||||
|
set_target_properties(${TARGET_NAME}
|
||||||
|
PROPERTIES PUBLIC_HEADER ${HDRS})
|
||||||
|
|
||||||
|
install(TARGETS ${TARGET_NAME}
|
||||||
|
ARCHIVE DESTINATION lib/
|
||||||
|
LIBRARY DESTINATION lib/
|
||||||
|
PUBLIC_HEADER DESTINATION include/neocomm/
|
||||||
|
CONFIGURATIONS release minsizerel)
|
0
include/neocomm/channel.hpp
Normal file
0
include/neocomm/channel.hpp
Normal file
0
include/neocomm/message.hpp
Normal file
0
include/neocomm/message.hpp
Normal file
47
include/neocomm/node.hpp
Normal file
47
include/neocomm/node.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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 {
|
||||||
|
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();
|
||||||
|
|
||||||
|
private:
|
||||||
|
dht::DhtRunner dht_node;
|
||||||
|
};
|
||||||
|
}
|
0
src/channel.cpp
Normal file
0
src/channel.cpp
Normal file
0
src/message.cpp
Normal file
0
src/message.cpp
Normal file
27
src/node.cpp
Normal file
27
src/node.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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/node.hpp"
|
||||||
|
|
||||||
|
neocomm::node::node(unsigned short port) {
|
||||||
|
dht_node.run(port, dht::crypto::generateIdentity(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
neocomm::node::~node() {
|
||||||
|
dht_node.join();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user