0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

modules/federation/sender: Unified EDU/PDU path when room_id is available.

This commit is contained in:
Jason Volk 2018-03-14 15:55:27 -07:00
parent 02b6df94f4
commit 56b23af467
2 changed files with 61 additions and 25 deletions

View file

@ -105,7 +105,7 @@ send(const m::event &event)
};
if(room_id)
send(event, room_id);
return send(event, room_id);
}
void
@ -153,32 +153,45 @@ node::flush()
try
{
if(q.empty())
return false;
return true;
if(curtxn)
return false;
return true;
const auto pdus
size_t pdus{0}, edus{0};
for(const auto &unit : q) switch(unit->type)
{
std::count_if(begin(q), end(q), [](const auto &p)
{
return p->type == unit::PDU;
})
};
case unit::PDU: ++pdus; break;
case unit::EDU: ++edus; break;
default: break;
}
std::vector<json::value> pdu(pdus);
for(ssize_t i(0); i < pdus; ++i)
pdu.at(i) = string_view{q.at(i)->s};
std::string content
size_t pc(0), ec(0);
std::vector<json::value> units(pdus + edus);
for(const auto &unit : q) switch(unit->type)
{
m::txn::create({pdu.data(), pdu.size()}, {})
};
case unit::PDU:
units.at(pc++) = string_view{unit->s};
break;
case unit::EDU:
units.at(pdus + ec++) = string_view{unit->s};
break;
default:
break;
}
m::v1::send::opts opts;
opts.remote = id.host();
opts.sopts = &sopts;
std::string content
{
m::txn::create({ units.data(), pc }, { units.data() + pdus, ec })
};
txns.emplace_back(*this, std::move(content), std::move(opts));
q.clear();
recv_action.notify_one();
return true;

View file

@ -23,19 +23,42 @@ struct unit
{
enum type { PDU, EDU, FAILURE };
std::string s;
enum type type;
std::string s;
unit(std::string s, const enum type &type)
:s{std::move(s)}
,type{type}
{}
unit(const m::event &event)
:unit{json::strung{event}, PDU}
{}
unit(std::string s, const enum type &type);
unit(const m::event &event);
};
unit::unit(std::string s, const enum type &type)
:type{type}
,s{std::move(s)}
{
}
unit::unit(const m::event &event)
:type{json::get<"event_id"_>(event)? PDU : EDU}
,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 {};
}
}()}
{
}
struct txndata
{
std::string content;