mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
ircd::server: Move into directory; various cleanup.
This commit is contained in:
parent
c83665ca6c
commit
56cefcb650
6 changed files with 187 additions and 131 deletions
58
include/ircd/server/link.h
Normal file
58
include/ircd/server/link.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
|
// Copyright (C) 2016-2018 Jason Volk
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice is present in all copies.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#define HAVE_IRCD_SERVER_LINK_H
|
||||||
|
|
||||||
|
/// A single connection to a remote node.
|
||||||
|
///
|
||||||
|
struct ircd::server::link
|
||||||
|
{
|
||||||
|
bool init {false}; ///< link is connecting
|
||||||
|
bool fini {false}; ///< link is disconnecting
|
||||||
|
std::shared_ptr<server::node> node; ///< backreference to node
|
||||||
|
std::exception_ptr eptr; ///< error from socket
|
||||||
|
std::shared_ptr<net::socket> socket; ///< link's socket
|
||||||
|
std::deque<struct request::tag> queue; ///< link's work queue
|
||||||
|
|
||||||
|
bool connected() const noexcept;
|
||||||
|
bool ready() const;
|
||||||
|
bool busy() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void handle_writable(const error_code &);
|
||||||
|
void wait_writable();
|
||||||
|
|
||||||
|
void handle_readable_success();
|
||||||
|
void handle_readable(const error_code &);
|
||||||
|
void wait_readable();
|
||||||
|
|
||||||
|
void handle_close(std::exception_ptr);
|
||||||
|
void handle_open(std::exception_ptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool close(const net::close_opts &);
|
||||||
|
bool open(const net::open_opts &);
|
||||||
|
|
||||||
|
void cancel(request &);
|
||||||
|
void submit(request &);
|
||||||
|
|
||||||
|
link(server::node &);
|
||||||
|
~link() noexcept;
|
||||||
|
};
|
46
include/ircd/server/node.h
Normal file
46
include/ircd/server/node.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
|
// Copyright (C) 2016-2018 Jason Volk
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice is present in all copies.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#define HAVE_IRCD_SERVER_NODE_H
|
||||||
|
|
||||||
|
/// Remote entity.
|
||||||
|
///
|
||||||
|
struct ircd::server::node
|
||||||
|
:std::enable_shared_from_this<ircd::server::node>
|
||||||
|
{
|
||||||
|
std::exception_ptr eptr;
|
||||||
|
net::remote remote;
|
||||||
|
std::list<link> links;
|
||||||
|
ctx::dock dock;
|
||||||
|
|
||||||
|
void handle_resolve(std::weak_ptr<node>, std::exception_ptr, const ipport &);
|
||||||
|
void resolve(const hostport &);
|
||||||
|
|
||||||
|
public:
|
||||||
|
link &link_add(const size_t &num = 1);
|
||||||
|
void link_del(const size_t &num = 1);
|
||||||
|
link &link_get();
|
||||||
|
|
||||||
|
void cancel(request &);
|
||||||
|
void submit(request &);
|
||||||
|
|
||||||
|
node();
|
||||||
|
~node() noexcept;
|
||||||
|
};
|
|
@ -18,41 +18,29 @@
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#define HAVE_IRCD_SERVER_H
|
#define HAVE_IRCD_SERVER_REQUEST_H
|
||||||
|
|
||||||
/// The interface for when IRCd plays the role of client to other servers
|
/// The interface for when IRCd plays the role of client to other servers
|
||||||
///
|
///
|
||||||
namespace ircd::server
|
namespace ircd::server
|
||||||
{
|
{
|
||||||
struct init;
|
|
||||||
struct node;
|
|
||||||
struct link;
|
|
||||||
struct request;
|
|
||||||
struct out;
|
|
||||||
struct in;
|
struct in;
|
||||||
|
struct out;
|
||||||
IRCD_EXCEPTION(ircd::error, error);
|
struct request;
|
||||||
|
|
||||||
extern ircd::log::log log;
|
|
||||||
extern std::map<string_view, std::shared_ptr<node>> nodes;
|
|
||||||
|
|
||||||
bool exists(const net::hostport &);
|
|
||||||
node &find(const net::hostport &);
|
|
||||||
node &get(const net::hostport &);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ircd::server::out
|
|
||||||
{
|
|
||||||
const_buffer head;
|
|
||||||
const_buffer content;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ircd::server::in
|
struct ircd::server::in
|
||||||
{
|
{
|
||||||
mutable_buffer head;
|
mutable_buffer head;
|
||||||
mutable_buffer content;
|
mutable_buffer content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ircd::server::out
|
||||||
|
{
|
||||||
|
const_buffer head;
|
||||||
|
const_buffer content;
|
||||||
|
};
|
||||||
|
|
||||||
/// This is a handle for being a client to another server. This handle will
|
/// This is a handle for being a client to another server. This handle will
|
||||||
/// attempt to find an existing connection pool for the remote server otherwise
|
/// attempt to find an existing connection pool for the remote server otherwise
|
||||||
/// one will be created. Then it will multiplex your requests and demultiplex
|
/// one will be created. Then it will multiplex your requests and demultiplex
|
||||||
|
@ -105,75 +93,3 @@ struct ircd::server::request::tag
|
||||||
tag &operator=(const tag &) = delete;
|
tag &operator=(const tag &) = delete;
|
||||||
~tag() noexcept;
|
~tag() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Internal representation of a remote server.
|
|
||||||
///
|
|
||||||
struct ircd::server::node
|
|
||||||
:std::enable_shared_from_this<ircd::server::node>
|
|
||||||
{
|
|
||||||
std::exception_ptr eptr;
|
|
||||||
net::remote remote;
|
|
||||||
std::list<link> links;
|
|
||||||
ctx::dock dock;
|
|
||||||
|
|
||||||
void handle_resolve(std::weak_ptr<node>, std::exception_ptr, const ipport &);
|
|
||||||
void resolve(const hostport &);
|
|
||||||
|
|
||||||
public:
|
|
||||||
link &link_add(const size_t &num = 1);
|
|
||||||
void link_del(const size_t &num = 1);
|
|
||||||
link &link_get();
|
|
||||||
|
|
||||||
void cancel(request &);
|
|
||||||
void submit(request &);
|
|
||||||
|
|
||||||
node();
|
|
||||||
~node() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Internal representation of a single connection to a remote.
|
|
||||||
///
|
|
||||||
struct ircd::server::link
|
|
||||||
{
|
|
||||||
bool init {false}; ///< link is connecting
|
|
||||||
bool fini {false}; ///< link is disconnecting
|
|
||||||
std::shared_ptr<server::node> node; ///< backreference to node
|
|
||||||
std::exception_ptr eptr; ///< error from socket
|
|
||||||
std::shared_ptr<net::socket> socket; ///< link's socket
|
|
||||||
std::deque<struct request::tag> queue; ///< link's work queue
|
|
||||||
|
|
||||||
bool connected() const noexcept;
|
|
||||||
bool ready() const;
|
|
||||||
bool busy() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void handle_writable(const error_code &);
|
|
||||||
void wait_writable();
|
|
||||||
|
|
||||||
void handle_readable_success();
|
|
||||||
void handle_readable(const error_code &);
|
|
||||||
void wait_readable();
|
|
||||||
|
|
||||||
void handle_close(std::exception_ptr);
|
|
||||||
void handle_open(std::exception_ptr);
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool close(const net::close_opts &);
|
|
||||||
bool open(const net::open_opts &);
|
|
||||||
|
|
||||||
void cancel(request &);
|
|
||||||
void submit(request &);
|
|
||||||
|
|
||||||
link(server::node &);
|
|
||||||
~link() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Subsystem initialization / destruction from ircd::main
|
|
||||||
///
|
|
||||||
struct ircd::server::init
|
|
||||||
{
|
|
||||||
void interrupt();
|
|
||||||
|
|
||||||
init();
|
|
||||||
~init() noexcept;
|
|
||||||
};
|
|
53
include/ircd/server/server.h
Normal file
53
include/ircd/server/server.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
|
// Copyright (C) 2016-2018 Jason Volk
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice is present in all copies.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#define HAVE_IRCD_SERVER_H
|
||||||
|
|
||||||
|
/// The interface for when IRCd plays the role of client to other nodes
|
||||||
|
///
|
||||||
|
namespace ircd::server
|
||||||
|
{
|
||||||
|
struct init;
|
||||||
|
struct link;
|
||||||
|
struct node;
|
||||||
|
|
||||||
|
IRCD_EXCEPTION(ircd::error, error);
|
||||||
|
|
||||||
|
extern ircd::log::log log;
|
||||||
|
extern std::map<string_view, std::shared_ptr<node>> nodes;
|
||||||
|
|
||||||
|
bool exists(const net::hostport &);
|
||||||
|
node &find(const net::hostport &);
|
||||||
|
node &get(const net::hostport &);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "request.h"
|
||||||
|
#include "link.h"
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
/// Subsystem initialization / destruction from ircd::main
|
||||||
|
///
|
||||||
|
struct ircd::server::init
|
||||||
|
{
|
||||||
|
void interrupt();
|
||||||
|
|
||||||
|
init();
|
||||||
|
~init() noexcept;
|
||||||
|
};
|
42
ircd/ircd.cc
42
ircd/ircd.cc
|
@ -1,27 +1,21 @@
|
||||||
/*
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
* charybdis: A slightly useful ircd.
|
// Copyright (C) 2016-2018 Jason Volk
|
||||||
* ircd.c: Starts up and runs the ircd.
|
//
|
||||||
*
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
* Copyright (C) 1996-2002 Hybrid Development Team
|
// copyright notice and this permission notice is present in all copies.
|
||||||
* Copyright (C) 2002-2008 ircd-ratbox development team
|
//
|
||||||
* Copyright (C) 2005-2013 charybdis development team
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
*
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* This program is free software; you can redistribute it and/or modify
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* it under the terms of the GNU General Public License as published by
|
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (at your option) any later version.
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
*
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* This program is distributed in the hope that it will be useful,
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* GNU General Public License for more details.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
||||||
* USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ircd/asio.h>
|
#include <ircd/asio.h>
|
||||||
#include <ircd/m/m.h>
|
#include <ircd/m/m.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <ircd/server.h>
|
#include <ircd/server/server.h>
|
||||||
#include <ircd/asio.h>
|
#include <ircd/asio.h>
|
||||||
|
|
||||||
namespace ircd::server
|
namespace ircd::server
|
||||||
|
@ -221,10 +221,8 @@ ircd::server::request::tag::read_head(const const_buffer &buffer,
|
||||||
{
|
{
|
||||||
pos + size(terminator)
|
pos + size(terminator)
|
||||||
};
|
};
|
||||||
assert(addl_head_bytes <= size(buffer));
|
|
||||||
|
|
||||||
// The head bytes accounting can be updated and this will be the final
|
assert(addl_head_bytes <= size(buffer));
|
||||||
// value of what is legitimate head in the req.in.head buffer.
|
|
||||||
head_read += addl_head_bytes;
|
head_read += addl_head_bytes;
|
||||||
|
|
||||||
// Setup the capstan and mark the end of the tape
|
// Setup the capstan and mark the end of the tape
|
||||||
|
@ -232,25 +230,19 @@ ircd::server::request::tag::read_head(const const_buffer &buffer,
|
||||||
parse::capstan pc{pb};
|
parse::capstan pc{pb};
|
||||||
pc.read += head_read;
|
pc.read += head_read;
|
||||||
|
|
||||||
// The HTTP head is parsed here and saved in the user's object but they
|
|
||||||
// do not know about it yet and shouldn't be touching it.
|
|
||||||
req.head = http::response::head{pc};
|
req.head = http::response::head{pc};
|
||||||
assert(pb.completed() == head_read);
|
assert(pb.completed() == head_read);
|
||||||
|
|
||||||
// As stated, the buffer may contain data past the head, which includes
|
|
||||||
// our content or the next response which doesn't even belong to us.
|
|
||||||
const size_t overrun_length
|
const size_t overrun_length
|
||||||
{
|
{
|
||||||
size(buffer) - addl_head_bytes
|
size(buffer) - addl_head_bytes
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate the amount of overrun which belongs to our content.
|
|
||||||
const size_t &content_read
|
const size_t &content_read
|
||||||
{
|
{
|
||||||
std::min(req.head.content_length, overrun_length)
|
std::min(req.head.content_length, overrun_length)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Where the partial content would be written to
|
|
||||||
const const_buffer partial_content
|
const const_buffer partial_content
|
||||||
{
|
{
|
||||||
data(req.in.head) + head_read, content_read
|
data(req.in.head) + head_read, content_read
|
||||||
|
@ -268,8 +260,6 @@ ircd::server::request::tag::read_head(const const_buffer &buffer,
|
||||||
data(req.in.head) + head_read + content_read, overrun_length - content_read
|
data(req.in.head) + head_read + content_read, overrun_length - content_read
|
||||||
};
|
};
|
||||||
|
|
||||||
// When lucky, the content was recieved already (or there is no content) and
|
|
||||||
// we can notify the user in one shot.
|
|
||||||
if(this->content_read == req.head.content_length)
|
if(this->content_read == req.head.content_length)
|
||||||
{
|
{
|
||||||
p.set_value(http::status(req.head.status));
|
p.set_value(http::status(req.head.status));
|
||||||
|
@ -411,8 +401,7 @@ ircd::server::node::link_get()
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else return links.back();
|
||||||
return links.back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::server::link &
|
ircd::server::link &
|
||||||
|
|
Loading…
Reference in a new issue