bee_tangle/
lib.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! A crate that contains foundational building blocks for the IOTA Tangle.
5
6#![deny(missing_docs)]
7
8/// Types used for tangle configuration.
9pub mod config;
10/// Types that represent tangle events.
11pub mod event;
12/// Message flags.
13pub mod flags;
14/// Message data, including message flags.
15pub mod metadata;
16/// Types used to represent SEPs (Solid Entry Points).
17pub mod solid_entry_point;
18/// Types used for interoperation with a node's storage layer.
19pub mod storage;
20/// Milestone-enabled tangle type.
21pub mod tangle;
22/// The overall `TangleWorker` type. Used as part of the bee runtime in a node.
23pub mod tangle_worker;
24/// A worker that periodically cleans the tip pool.
25pub mod tip_pool_cleaner_worker;
26/// Common tangle traversal functionality.
27pub mod traversal;
28/// Types used to represent unreferenced messages.
29pub mod unreferenced_message;
30/// The URTS tips pool.
31pub mod urts;
32
33mod conflict;
34mod vec_set;
35mod vertex;
36mod vertices;
37
38pub use conflict::ConflictReason;
39pub use tangle::Tangle;
40pub use tangle_worker::TangleWorker;
41
42use tip_pool_cleaner_worker::TipPoolCleanerWorker;
43
44use crate::vec_set::VecSet;
45
46use bee_message::Message;
47use bee_runtime::node::{Node, NodeBuilder};
48
49use std::{ops::Deref, sync::Arc};
50
51/// A thread-safe reference to a `Message`.
52#[derive(Clone)]
53pub struct MessageRef(pub(crate) Arc<Message>);
54
55impl Deref for MessageRef {
56    type Target = Message;
57
58    fn deref(&self) -> &Self::Target {
59        &*self.0
60    }
61}
62
63/// Initiate the tangle on top of the given node builder.
64pub fn init<N: Node>(tangle_config: &config::TangleConfig, node_builder: N::Builder) -> N::Builder
65where
66    N::Backend: storage::StorageBackend,
67{
68    node_builder
69        .with_worker_cfg::<TangleWorker>(tangle_config.clone())
70        .with_worker::<TipPoolCleanerWorker>()
71}