mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd:Ⓜ️ Reorg / split / de-friend-inject various event interfaces.
This commit is contained in:
parent
482112b369
commit
1ab20cf721
9 changed files with 180 additions and 78 deletions
|
@ -29,36 +29,14 @@ namespace ircd::m
|
|||
bool cached(const id::event &);
|
||||
bool good(const id::event &);
|
||||
bool bad(const id::event &);
|
||||
|
||||
// Equality tests the event_id only! know this.
|
||||
bool operator==(const event &a, const event &b);
|
||||
|
||||
// Depth comparison; expect unstable sorting.
|
||||
bool operator<(const event &, const event &);
|
||||
bool operator>(const event &, const event &);
|
||||
bool operator<=(const event &, const event &);
|
||||
bool operator>=(const event &, const event &);
|
||||
|
||||
// Topological
|
||||
bool before(const event &a, const event &b); // A directly referenced by B
|
||||
|
||||
id::event make_id(const event &, id::event::buf &buf, const const_buffer &hash);
|
||||
id::event make_id(const event &, id::event::buf &buf);
|
||||
|
||||
// Informational pretty string condensed to single line.
|
||||
std::ostream &pretty_oneline(std::ostream &, const event &, const bool &content_keys = true);
|
||||
std::string pretty_oneline(const event &, const bool &content_keys = true);
|
||||
|
||||
// Informational pretty string on multiple lines.
|
||||
std::ostream &pretty(std::ostream &, const event &);
|
||||
std::string pretty(const event &);
|
||||
|
||||
// Informational content-oriented
|
||||
std::ostream &pretty_msgline(std::ostream &, const event &);
|
||||
std::string pretty_msgline(const event &);
|
||||
}
|
||||
|
||||
#include "event/event.h"
|
||||
#include "event/prev.h"
|
||||
#include "event/fetch.h"
|
||||
#include "event/index.h"
|
||||
#include "event/get.h"
|
||||
#include "event/cached.h"
|
||||
#include "event/prefetch.h"
|
||||
#include "event/conforms.h"
|
||||
#include "event/pretty.h"
|
||||
|
|
21
include/ircd/m/event/cached.h
Normal file
21
include/ircd/m/event/cached.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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_EVENT_CACHED_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
bool cached(const event::idx &, const event::fetch::opts &);
|
||||
bool cached(const event::idx &);
|
||||
|
||||
bool cached(const event::id &, const event::fetch::opts &);
|
||||
bool cached(const event::id &);
|
||||
}
|
|
@ -11,6 +11,41 @@
|
|||
#pragma once
|
||||
#define HAVE_IRCD_M_EVENT_EVENT_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
// Equality tests the event_id only! know this.
|
||||
bool operator==(const event &a, const event &b);
|
||||
|
||||
// Depth comparison; expect unstable sorting.
|
||||
bool operator<(const event &, const event &);
|
||||
bool operator>(const event &, const event &);
|
||||
bool operator<=(const event &, const event &);
|
||||
bool operator>=(const event &, const event &);
|
||||
|
||||
bool before(const event &a, const event &b); // A directly referenced by B
|
||||
|
||||
id::event make_id(const event &, id::event::buf &buf, const const_buffer &hash);
|
||||
id::event make_id(const event &, id::event::buf &buf);
|
||||
|
||||
json::object hashes(const mutable_buffer &, const event &);
|
||||
event signatures(const mutable_buffer &, const m::event &);
|
||||
event essential(event, const mutable_buffer &content);
|
||||
|
||||
bool verify_sha256b64(const event &, const string_view &);
|
||||
bool verify_hash(const event &, const sha256::buf &);
|
||||
bool verify_hash(const event &);
|
||||
|
||||
bool verify(const event &, const ed25519::pk &, const ed25519::sig &sig);
|
||||
bool verify(const event &, const ed25519::pk &, const string_view &origin, const string_view &pkid);
|
||||
bool verify(const event &, const string_view &origin, const string_view &pkid); // io/yield
|
||||
bool verify(const event &, const string_view &origin); // io/yield
|
||||
bool verify(const event &); // io/yield
|
||||
|
||||
sha256::buf hash(const event &);
|
||||
ed25519::sig sign(const event &, const ed25519::sk &);
|
||||
ed25519::sig sign(const event &);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
|
||||
/// The Main Event
|
||||
|
@ -48,9 +83,8 @@ struct ircd::m::event
|
|||
struct prev;
|
||||
struct fetch;
|
||||
struct conforms;
|
||||
using keys = json::keys<event>;
|
||||
|
||||
// Common convenience aliases
|
||||
using keys = json::keys<event>;
|
||||
using id = m::id::event;
|
||||
using idx = uint64_t;
|
||||
using closure = std::function<void (const event &)>;
|
||||
|
@ -62,36 +96,18 @@ struct ircd::m::event
|
|||
static constexpr size_t MAX_SIZE = 64_KiB;
|
||||
static conf::item<size_t> max_size;
|
||||
|
||||
friend event essential(event, const mutable_buffer &content);
|
||||
static void essential(json::iov &event, const json::iov &content, const closure_iov_mutable &);
|
||||
|
||||
static bool verify(const string_view &, const ed25519::pk &, const ed25519::sig &sig);
|
||||
static bool verify(const json::object &, const ed25519::pk &, const ed25519::sig &sig);
|
||||
friend bool verify(const event &, const ed25519::pk &, const ed25519::sig &sig);
|
||||
friend bool verify(const event &, const ed25519::pk &, const string_view &origin, const string_view &pkid);
|
||||
friend bool verify(const event &, const string_view &origin, const string_view &pkid); // io/yield
|
||||
friend bool verify(const event &, const string_view &origin); // io/yield
|
||||
friend bool verify(const event &); // io/yield
|
||||
|
||||
static ed25519::sig sign(const string_view &, const ed25519::sk &);
|
||||
static ed25519::sig sign(const string_view &);
|
||||
static ed25519::sig sign(const json::object &, const ed25519::sk &);
|
||||
static ed25519::sig sign(const json::object &);
|
||||
friend ed25519::sig sign(const event &, const ed25519::sk &);
|
||||
friend ed25519::sig sign(const event &);
|
||||
static ed25519::sig sign(json::iov &event, const json::iov &content, const ed25519::sk &);
|
||||
static ed25519::sig sign(json::iov &event, const json::iov &content);
|
||||
static json::object signatures(const mutable_buffer &, json::iov &event, const json::iov &content);
|
||||
friend event signatures(const mutable_buffer &, const m::event &);
|
||||
|
||||
friend bool verify_sha256b64(const event &, const string_view &);
|
||||
friend bool verify_hash(const event &, const sha256::buf &);
|
||||
friend bool verify_hash(const event &);
|
||||
|
||||
friend sha256::buf hash(const event &);
|
||||
static sha256::buf hash(json::iov &event, const string_view &content);
|
||||
static json::object hashes(const mutable_buffer &, json::iov &event, const string_view &content);
|
||||
friend json::object hashes(const mutable_buffer &, const event &);
|
||||
|
||||
using super_type::tuple;
|
||||
using super_type::operator=;
|
||||
|
|
|
@ -11,11 +11,22 @@
|
|||
#pragma once
|
||||
#define HAVE_IRCD_M_EVENT_FETCH_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
bool seek(event::fetch &, const event::idx &, std::nothrow_t);
|
||||
void seek(event::fetch &, const event::idx &);
|
||||
|
||||
bool seek(event::fetch &, const event::id &, std::nothrow_t);
|
||||
void seek(event::fetch &, const event::id &);
|
||||
}
|
||||
|
||||
struct ircd::m::event::fetch
|
||||
:event
|
||||
{
|
||||
struct opts;
|
||||
|
||||
using keys = event::keys;
|
||||
using view_closure = std::function<void (const string_view &)>;
|
||||
|
||||
static const opts default_opts;
|
||||
|
||||
|
@ -32,37 +43,6 @@ struct ircd::m::event::fetch
|
|||
|
||||
static bool event_id(const idx &, std::nothrow_t, const id::closure &);
|
||||
static void event_id(const idx &, const id::closure &);
|
||||
|
||||
friend bool index(const id &, std::nothrow_t, const closure_idx &);
|
||||
friend idx index(const id &, std::nothrow_t);
|
||||
friend idx index(const id &);
|
||||
friend idx index(const event &, std::nothrow_t);
|
||||
friend idx index(const event &);
|
||||
|
||||
friend bool seek(fetch &, const idx &, std::nothrow_t);
|
||||
friend void seek(fetch &, const idx &);
|
||||
friend bool seek(fetch &, const id &, std::nothrow_t);
|
||||
friend void seek(fetch &, const id &);
|
||||
|
||||
using view_closure = std::function<void (const string_view &)>;
|
||||
friend bool get(std::nothrow_t, const idx &, const string_view &key, const view_closure &);
|
||||
friend bool get(std::nothrow_t, const id &, const string_view &key, const view_closure &);
|
||||
friend void get(const idx &, const string_view &key, const view_closure &);
|
||||
friend void get(const id &, const string_view &key, const view_closure &);
|
||||
|
||||
friend const_buffer get(std::nothrow_t, const idx &, const string_view &key, const mutable_buffer &out);
|
||||
friend const_buffer get(std::nothrow_t, const id &, const string_view &key, const mutable_buffer &out);
|
||||
friend const_buffer get(const idx &, const string_view &key, const mutable_buffer &out);
|
||||
friend const_buffer get(const id &, const string_view &key, const mutable_buffer &out);
|
||||
|
||||
friend bool cached(const idx &, const opts & = default_opts);
|
||||
friend bool cached(const id &, const opts &);
|
||||
friend bool cached(const id &);
|
||||
|
||||
friend void prefetch(const idx &, const string_view &key);
|
||||
friend void prefetch(const idx &, const opts & = default_opts);
|
||||
friend void prefetch(const id &, const string_view &key);
|
||||
friend void prefetch(const id &, const opts & = default_opts);
|
||||
};
|
||||
|
||||
struct ircd::m::event::fetch::opts
|
||||
|
|
30
include/ircd/m/event/get.h
Normal file
30
include/ircd/m/event/get.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
// 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_EVENT_GET_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
// Fetch the value for a single property of an event into the closure
|
||||
bool get(std::nothrow_t, const event::idx &, const string_view &key, const event::fetch::view_closure &);
|
||||
bool get(std::nothrow_t, const event::id &, const string_view &key, const event::fetch::view_closure &);
|
||||
|
||||
// Throws if event or property in that event not found
|
||||
void get(const event::idx &, const string_view &key, const event::fetch::view_closure &);
|
||||
void get(const event::id &, const string_view &key, const event::fetch::view_closure &);
|
||||
|
||||
// Copies value into buffer returning view (empty for not found)
|
||||
const_buffer get(std::nothrow_t, const event::idx &, const string_view &key, const mutable_buffer &out);
|
||||
const_buffer get(std::nothrow_t, const event::id &, const string_view &key, const mutable_buffer &out);
|
||||
|
||||
const_buffer get(const event::idx &, const string_view &key, const mutable_buffer &out);
|
||||
const_buffer get(const event::id &, const string_view &key, const mutable_buffer &out);
|
||||
}
|
23
include/ircd/m/event/index.h
Normal file
23
include/ircd/m/event/index.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
// 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_EVENT_INDEX_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
bool index(const event::id &, std::nothrow_t, const event::closure_idx &);
|
||||
|
||||
event::idx index(const event::id &, std::nothrow_t);
|
||||
event::idx index(const event::id &);
|
||||
|
||||
event::idx index(const event &, std::nothrow_t);
|
||||
event::idx index(const event &);
|
||||
}
|
21
include/ircd/m/event/prefetch.h
Normal file
21
include/ircd/m/event/prefetch.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// 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_EVENT_PREFETCH_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
void prefetch(const event::idx &, const event::fetch::opts & = event::fetch::default_opts);
|
||||
void prefetch(const event::idx &, const string_view &key);
|
||||
|
||||
void prefetch(const event::id &, const event::fetch::opts & = event::fetch::default_opts);
|
||||
void prefetch(const event::id &, const string_view &key);
|
||||
}
|
27
include/ircd/m/event/pretty.h
Normal file
27
include/ircd/m/event/pretty.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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_EVENT_PRETTY_H
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
// Informational pretty string condensed to single line.
|
||||
std::ostream &pretty_oneline(std::ostream &, const event &, const bool &content_keys = true);
|
||||
std::string pretty_oneline(const event &, const bool &content_keys = true);
|
||||
|
||||
// Informational pretty string on multiple lines.
|
||||
std::ostream &pretty(std::ostream &, const event &);
|
||||
std::string pretty(const event &);
|
||||
|
||||
// Informational content-oriented
|
||||
std::ostream &pretty_msgline(std::ostream &, const event &);
|
||||
std::string pretty_msgline(const event &);
|
||||
}
|
|
@ -243,6 +243,12 @@ ircd::m::cached(const id::event &event_id,
|
|||
false;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::cached(const event::idx &event_idx)
|
||||
{
|
||||
return cached(event_idx, event::fetch::default_opts);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::cached(const event::idx &event_idx,
|
||||
const event::fetch::opts &opts)
|
||||
|
|
Loading…
Reference in a new issue