0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd:Ⓜ️:resource: Obtain version information for request if possible.

This commit is contained in:
Jason Volk 2020-04-19 20:02:43 -07:00
parent 71b69d6fe9
commit 69f4c2b224
2 changed files with 31 additions and 1 deletions

View file

@ -47,6 +47,7 @@ struct ircd::m::resource::request
pair<string_view> authorization; // proffering any
string_view access_token; // proffering user
m::request::x_matrix x_matrix; // proferring server
pair<string_view> version; // enumeration
string_view node_id; // authenticated server
m::user::id user_id; // authenticated user or bridge pup

View file

@ -14,10 +14,11 @@ namespace ircd::m
extern conf::item<bool> x_matrix_verify_origin;
extern conf::item<bool> x_matrix_verify_destination;
static void cache_warm_origin(const resource::request &);
static pair<string_view> parse_version(const resource::request &);
static string_view authenticate_bridge(const resource::method &, const client &, resource::request &);
static user::id authenticate_user(const resource::method &, const client &, resource::request &);
static string_view authenticate_node(const resource::method &, const client &, resource::request &);
static void cache_warm_origin(const resource::request &);
}
decltype(ircd::m::cache_warmup_time)
@ -154,6 +155,10 @@ ircd::m::resource::request::request(const method &method,
m::request::x_matrix{authorization.first, authorization.second}:
m::request::x_matrix{}
}
,version
{
parse_version(*this)
}
,node_id
{
// Server X-Matrix header verified here. Similar to client auth, origin
@ -391,6 +396,30 @@ catch(const std::exception &e)
};
}
ircd::pair<ircd::string_view>
ircd::m::parse_version(const m::resource::request &request)
{
const auto &user_agent
{
request.head.user_agent
};
const auto &[primary, info]
{
split(user_agent, ' ')
};
const auto &[name, version]
{
split(primary, '/')
};
return
{
name, version
};
}
/// We can smoothly warmup some memory caches after daemon startup as the
/// requests trickle in from remote servers. This function is invoked after
/// a remote contacts and reveals its identity with the X-Matrix verification.