2016-08-16 16:51:22 +02:00
|
|
|
/*
|
2017-11-13 23:09:33 +01:00
|
|
|
* This file is part of the Flowee project
|
2019-03-09 16:36:13 +01:00
|
|
|
* Copyright (C) 2016, 2019 Tom Zander <tomz@freedommail.ch>
|
2016-08-16 16:51:22 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2018-02-15 19:50:12 +01:00
|
|
|
#ifndef APISERVER_H
|
|
|
|
|
#define APISERVER_H
|
2016-08-16 16:51:22 +02:00
|
|
|
|
2019-04-09 17:24:38 +02:00
|
|
|
#include <streaming/BufferPool.h>
|
|
|
|
|
#include <networkmanager/NetworkManager.h>
|
|
|
|
|
#include <networkmanager/NetworkService.h>
|
2016-08-16 16:51:22 +02:00
|
|
|
|
2018-02-10 22:48:07 +01:00
|
|
|
#include <univalue.h>
|
2016-08-16 16:51:22 +02:00
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <boost/thread/mutex.hpp>
|
2018-02-18 00:19:14 +01:00
|
|
|
#include <boost/asio/deadline_timer.hpp>
|
2016-08-16 16:51:22 +02:00
|
|
|
|
2018-02-15 19:50:12 +01:00
|
|
|
namespace Api {
|
2016-08-16 16:51:22 +02:00
|
|
|
|
2019-03-09 16:36:13 +01:00
|
|
|
class SessionData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SessionData() {}
|
|
|
|
|
virtual ~SessionData();
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-16 16:51:22 +02:00
|
|
|
class Server {
|
|
|
|
|
public:
|
|
|
|
|
Server(boost::asio::io_service &service);
|
2018-02-17 14:27:49 +01:00
|
|
|
|
|
|
|
|
void addService(NetworkService *service);
|
2016-08-16 16:51:22 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void newConnection(NetworkConnection &connection);
|
|
|
|
|
void connectionRemoved(const EndPoint &endPoint);
|
2019-03-26 19:37:33 +01:00
|
|
|
void incomingMessage(const Message &message);
|
2016-08-16 16:51:22 +02:00
|
|
|
|
|
|
|
|
void checkConnections(boost::system::error_code error);
|
|
|
|
|
|
|
|
|
|
class Connection {
|
|
|
|
|
public:
|
|
|
|
|
Connection(NetworkConnection && connection);
|
2019-03-09 16:36:13 +01:00
|
|
|
~Connection();
|
2016-08-16 16:51:22 +02:00
|
|
|
void incomingMessage(const Message &message);
|
|
|
|
|
|
|
|
|
|
NetworkConnection m_connection;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void sendFailedMessage(const Message &origin, const std::string &failReason);
|
|
|
|
|
|
|
|
|
|
Streaming::BufferPool m_bufferPool;
|
2019-03-09 16:36:13 +01:00
|
|
|
std::map<uint32_t, SessionData*> m_properties;
|
2016-08-16 16:51:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NewConnection {
|
|
|
|
|
NetworkConnection connection;
|
2019-03-26 19:37:33 +01:00
|
|
|
boost::posix_time::ptime initialConnectionTime;
|
2016-08-16 16:51:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NetworkManager m_networkManager;
|
|
|
|
|
|
|
|
|
|
mutable boost::mutex m_mutex; // protects the next 4 vars.
|
|
|
|
|
std::list<Connection*> m_connections;
|
|
|
|
|
std::list<NewConnection> m_newConnections;
|
|
|
|
|
bool m_timerRunning;
|
|
|
|
|
boost::asio::deadline_timer m_newConnectionTimeout;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|