Skip to content

Commit

Permalink
ircd::m::resource: Obtain version information for request if possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Apr 20, 2020
1 parent 71b69d6 commit 69f4c2b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/ircd/m/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion matrix/resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 69f4c2b

Please sign in to comment.