2018-01-22 19:05:45 +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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_V1_SEND_H
|
|
|
|
|
|
|
|
namespace ircd::m::v1
|
|
|
|
{
|
|
|
|
struct send;
|
|
|
|
};
|
|
|
|
|
2018-01-23 20:43:04 +01:00
|
|
|
/// A federation/v1/send request. This sends the provided transaction and
|
|
|
|
/// receives a response via the server::request ctx::future. This object
|
|
|
|
/// must stay in scope to complete the request until the future is resolved.
|
|
|
|
///
|
2018-01-22 19:05:45 +01:00
|
|
|
struct ircd::m::v1::send
|
|
|
|
:server::request
|
|
|
|
{
|
|
|
|
struct opts;
|
2018-01-23 20:43:04 +01:00
|
|
|
struct response;
|
2018-01-22 19:05:45 +01:00
|
|
|
|
2018-01-23 20:43:04 +01:00
|
|
|
operator json::object() const
|
|
|
|
{
|
|
|
|
return { in.content };
|
|
|
|
}
|
|
|
|
|
|
|
|
send(const string_view &txnid, // transaction ID (goes in URL)
|
|
|
|
const const_buffer &content, // full transaction (HTTP content out)
|
|
|
|
const mutable_buffer &head, // buffer for HTTP head in and out
|
|
|
|
opts); // options structure
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
|
2018-01-23 20:43:04 +01:00
|
|
|
/// Options for a federation send request.
|
|
|
|
///
|
2018-01-22 19:05:45 +01:00
|
|
|
struct ircd::m::v1::send::opts
|
|
|
|
{
|
2018-01-23 20:43:04 +01:00
|
|
|
/// The remote server to contact. Must be specified for this request.
|
2018-01-22 19:05:45 +01:00
|
|
|
net::hostport remote;
|
2018-01-23 20:43:04 +01:00
|
|
|
|
|
|
|
/// The m::request structure which helps compose this request. The fields
|
|
|
|
/// of this object are eventually used to sign the request for [Fed. 12.1]
|
|
|
|
/// Request Authentication. User does not have to fill anything in here;
|
|
|
|
/// anything not provided is derived automatically, but providing these
|
|
|
|
/// fields will override that derivation.
|
2018-01-22 19:05:45 +01:00
|
|
|
m::request request;
|
2018-01-23 20:43:04 +01:00
|
|
|
|
|
|
|
/// The lower-level server::out structure used by server:: when transmitting
|
|
|
|
/// data; providing anything here is optional and will override things.
|
2018-01-22 19:05:45 +01:00
|
|
|
server::out out;
|
2018-01-23 20:43:04 +01:00
|
|
|
|
|
|
|
/// The lower-level server::in structure used by server:: when receiving
|
|
|
|
/// data; providing anything here is optional and will override things.
|
2018-01-22 19:05:45 +01:00
|
|
|
server::in in;
|
2018-01-23 20:43:04 +01:00
|
|
|
|
|
|
|
/// The lower-level server::request::opts configuration to attach to
|
|
|
|
/// this request.
|
2018-01-22 19:05:45 +01:00
|
|
|
const struct server::request::opts *sopts {nullptr};
|
|
|
|
};
|
2018-01-23 20:43:04 +01:00
|
|
|
|
|
|
|
/// Helper for dealing with response content from a /send/.
|
|
|
|
struct ircd::m::v1::send::response
|
|
|
|
:json::object
|
|
|
|
{
|
|
|
|
/// A member of the response object is "pdus" and this helps iterate that object
|
|
|
|
/// which is used to convey errors keyed by the event_id; value is matrix error obj.
|
|
|
|
using pdus_closure = std::function<void (const id::event &, const json::object &)>;
|
|
|
|
void for_each_pdu(const pdus_closure &) const;
|
|
|
|
|
|
|
|
response(const json::object &object)
|
|
|
|
:json::object{object}
|
|
|
|
{}
|
|
|
|
};
|