2018-03-14 21:36:13 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// 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. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
//
|
|
|
|
// Internal header for sender.cc only.
|
|
|
|
// Do not include.
|
|
|
|
//
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
struct txn;
|
|
|
|
struct node;
|
|
|
|
|
|
|
|
struct unit
|
|
|
|
:std::enable_shared_from_this<unit>
|
|
|
|
{
|
|
|
|
enum type { PDU, EDU, FAILURE };
|
|
|
|
|
|
|
|
enum type type;
|
2018-03-14 23:55:27 +01:00
|
|
|
std::string s;
|
2018-03-14 21:36:13 +01:00
|
|
|
|
2018-03-14 23:55:27 +01:00
|
|
|
unit(std::string s, const enum type &type);
|
|
|
|
unit(const m::event &event);
|
2018-03-14 21:36:13 +01:00
|
|
|
};
|
|
|
|
|
2018-03-14 23:55:27 +01:00
|
|
|
unit::unit(std::string s, const enum type &type)
|
|
|
|
:type{type}
|
|
|
|
,s{std::move(s)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unit::unit(const m::event &event)
|
2019-07-06 07:01:34 +02:00
|
|
|
:type{event.event_id? PDU : EDU}
|
2018-03-14 23:55:27 +01:00
|
|
|
,s{[this, &event]() -> std::string
|
|
|
|
{
|
|
|
|
switch(this->type)
|
|
|
|
{
|
|
|
|
case PDU:
|
|
|
|
return json::strung{event};
|
|
|
|
|
|
|
|
case EDU:
|
|
|
|
return json::strung{json::members
|
|
|
|
{
|
|
|
|
{ "content", json::get<"content"_>(event) },
|
|
|
|
{ "edu_type", json::get<"type"_>(event) },
|
|
|
|
}};
|
|
|
|
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-14 21:36:13 +01:00
|
|
|
struct txndata
|
|
|
|
{
|
|
|
|
std::string content;
|
|
|
|
string_view txnid;
|
|
|
|
char txnidbuf[64];
|
|
|
|
|
|
|
|
txndata(std::string content)
|
|
|
|
:content{std::move(content)}
|
|
|
|
,txnid{m::txn::create_id(txnidbuf, this->content)}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct node
|
|
|
|
{
|
|
|
|
std::deque<std::shared_ptr<unit>> q;
|
2019-05-27 02:44:12 +02:00
|
|
|
std::array<char, rfc3986::DOMAIN_BUFSIZE> rembuf;
|
|
|
|
string_view remote;
|
2018-03-14 21:36:13 +01:00
|
|
|
m::node::room room;
|
|
|
|
server::request::opts sopts;
|
|
|
|
txn *curtxn {nullptr};
|
2018-03-16 00:44:51 +01:00
|
|
|
bool err {false};
|
2018-03-14 21:36:13 +01:00
|
|
|
|
|
|
|
bool flush();
|
|
|
|
void push(std::shared_ptr<unit>);
|
|
|
|
|
2019-05-27 02:44:12 +02:00
|
|
|
node(const string_view &remote)
|
2019-06-06 12:49:11 +02:00
|
|
|
:remote{ircd::strlcpy{mutable_buffer{rembuf}, remote}}
|
2019-05-27 02:44:12 +02:00
|
|
|
,room{this->remote}
|
2018-03-14 21:36:13 +01:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct txn
|
|
|
|
:txndata
|
2020-03-06 04:35:20 +01:00
|
|
|
,m::fed::send
|
2018-03-14 21:36:13 +01:00
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
steady_point timeout;
|
|
|
|
char headers[8_KiB];
|
|
|
|
|
|
|
|
txn(struct node &node,
|
|
|
|
std::string content,
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::send::opts opts)
|
2018-03-14 21:36:13 +01:00
|
|
|
:txndata{std::move(content)}
|
2018-03-16 00:44:51 +01:00
|
|
|
,send{this->txnid, string_view{this->content}, this->headers, std::move(opts)}
|
2018-03-14 21:36:13 +01:00
|
|
|
,node{&node}
|
|
|
|
,timeout{now<steady_point>()} //TODO: conf
|
|
|
|
{}
|
|
|
|
};
|