SNode.C
Loading...
Searching...
No Matches
echoserver.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "core/SNodeC.h"
21#include "model/servers.h"
22
23#ifndef DOXYGEN_SHOULD_SKIP_THIS
24
25#include "log/Logger.h"
26
27#include <string>
28
29#if (STREAM_TYPE == TLS)
30
31#include <map>
32#include <utility>
33#include <variant>
34
35#endif
36
37#endif /* DOXYGEN_SHOULD_SKIP_THIS */
38
39// IWYU pragma: no_include "core/socket/stream/tls/ssl_utils.h"
40
41int main(int argc, char* argv[]) {
42 core::SNodeC::init(argc, argv);
43
44 using SocketServer = apps::echo::model::STREAM::EchoSocketServer;
45 const SocketServer server = apps::echo::model::STREAM::getServer();
46
47#if (STREAM_TYPE == TLS)
48 std::string cert = "/home/voc/projects/snodec/snode.c/certs/snode.c_-_server.pem";
49 std::string key = "/home/voc/projects/snodec/snode.c/certs/Volker_Christian_-_Web_-_snode.c_-_server.key.encrypted.pem";
50 std::string pass = "snode.c";
51
52 std::map<std::string, std::map<std::string, std::variant<std::string, bool, ssl_option_t>>> sniCerts = {
53 {"snodec.home.vchrist.at", {{"Cert", cert}, {"CertKey", key}, {"CertKeyPassword", pass}}},
54 {"www.vchrist.at", {{"Cert", cert}, {"CertKey", key}, {"CertKeyPassword", pass}}}};
55
56 server.getConfig().addSniCerts(sniCerts);
57#endif
58
59 // server.getConfig().setDisabled();
60 // server.getConfig().setDisabled(false);
61
62 server.listen([instanceName = server.getConfig().getInstanceName()](const SocketServer::SocketAddress& socketAddress,
63 const core::socket::State& state) {
64 switch (state) {
65 case core::socket::State::OK:
66 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
67 break;
68 case core::socket::State::DISABLED:
69 VLOG(1) << instanceName << ": disabled";
70 break;
71 case core::socket::State::ERROR:
72 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
73 break;
74 case core::socket::State::FATAL:
75 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
76 break;
77 }
78 });
79
80 return core::SNodeC::start();
81}
82
83/*
84#if (NET_TYPE == IN) // in
85#if (STREAM_TYPE == LEGACY)
86 server.listen(8080, 5, [](const SocketServer::Socket& socket, int errnum) {
87#elif (STREAM_TYPE == TLS)
88 server.listen(8088, 5, [](const SocketServer::Socket& socket, int errnum) {
89#endif
90#elif (NET_TYPE == IN6) // in6
91#if (STREAM_TYPE == LEGACY)
92 server.listen(8080, 5, [](const SocketServer::Socket& socket, int errnum) {
93#elif (STREAM_TYPE == TLS)
94 server.listen(8088, 5, [](const SocketServer::Socket& socket, int errnum) {
95#endif
96#elif (NET_TYPE == L2) //
97 // ATLAS: 10:3D:1C:AC:BA:9C
98 // TITAN: A4:B1:C1:2C:82:37
99 // USB: 44:01:BB:A3:63:32
100
101 // server.listen("A4:B1:C1:2C:82:37", 0x1023, 5, [](const SocketServer::Socket& socket, int errnum) { // titan
102 server.listen("10:3D:1C:AC:BA:9C", 0x1023, 5, [](const SocketServer::Socket& socket, int errnum) { // titan
103#elif (NET_TYPE == RC) // rf
104 // server.listen("A4:B1:C1:2C:82:37", 1, 5, [](const SocketServer::Socket& socket, int errnum) { // titan
105 server.listen("10:3D:1C:AC:BA:9C", 1, 5, [](const SocketServer::Socket& socket, int errnum) { // titan
106#elif (NET_TYPE == UN) // un
107 server.listen("/tmp/testme", 5, [](const SocketServer::Socket& socket, int errnum) { // titan
108#endif
109 if (errnum != 0) {
110 PLOG(FATAL) << "listen";
111 } else {
112 VLOG(1) << "snode.c listening on " << socket.getBindAddress().toString();
113 }
114
115#ifdef NET_TYPE
116 });
117#endif
118*/
int main(int argc, char *argv[])