Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix Bridge (rebased 23082023) #591

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

MathJud
Copy link
Member

@MathJud MathJud commented Aug 23, 2023

qaul-matrix bridge integration.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
By this commit, We have achieved a very initial milestone of connecting
the Matrix with Qaul. Currently, In Qaul we have a separate thread
running which listens for any activity into the Matrix room and
forwards the messagess into the Qaul feel list.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
By this commit, The integration is completed for two way communications
and basic functionality where from the qaul you can send Hii into the
matrix room and from matrix room you can send Hii into the qaul. To add
more, We have two commands running on matrix-side which are !qaul for
acknowledgement of connection and !users-list for getting list of users
in qaul on matrix.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
This commit makes a logic of seeing the users connected in qaul-room to
make sure that if rooms are public only people we know and want are
joined.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
There was a problem when we run `feed list` and all the messages were
sent to matrix which is not correct. This commit solves it while
checking against the last_index from the configuration file.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
With this commit, The bug of saving the configuration file when it gets
changed is fixed. For this, The MatrixConfiguration::save() method has
been written which takes a configuration and serializes it in YAML and
saves the file.

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Harshil-Jani and others added 7 commits September 3, 2023 16:49
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
@MathJud
Copy link
Member Author

MathJud commented Sep 15, 2023

Function Checks

  • Compiles
    • Linux
    • MacOS
    • Windows
  • Successfully run bridge, following the tutorial
  • Write a documentation comment for each function. (document comments start with ///)
  • Fix all possible panic options
    • Test with wrong CLI input
      • -f wrong input does not panic anymore

@MathJud
Copy link
Member Author

MathJud commented Sep 15, 2023

Running the following command line on Windows:
.\..\..\target\debug\qaul-matrix-bridge.exe -h "https://matrix.42d.org" -a qaul-bot -p MY_PASSWORD_REPLACED -f "!fTgvltwRPSvgK0fqKa"

I got the following error:

PS C:\Users\jud\src\qaul.net\rust\clients\test> .\..\..\target\debug\qaul-matrix-bridge.exe -h "https://matrix.42d.org" -a qaul-bot -p MY_PASSWORD_REPLACED -f "!fTgvltwRPSvgK0fqKa"
running libqaul 2.0.0-beta.16
libqaul data on latest version
Matrix Bot has been initialized as a Qaul User
Connecting to Matrix Bot
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: MissingDelimiter', clients\bridge\src\relay_bot.rs:485:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'storage::get(): called get() before set()', C:\Users\jud\.cargo\registry\src\index.crates.io-6f17d22bba15001f\state-0.5.3\src\storage.rs:162:14

@MathJud
Copy link
Member Author

MathJud commented Sep 15, 2023

The matrix folder seems ot go to a different location then all the other storage folders.
It also seems not to be done in an OS agnostic way.

Please see the following program output on Windows:

Matrix Bot has been initialized as a Qaul User
Connecting to Matrix Bot
"C:\\Users\\jud\\AppData\\Roaming\\qaul/matrix"

@MathJud
Copy link
Member Author

MathJud commented Sep 22, 2023

There needs to be a matrix-bridge initialization function, as the binary crashes, when libqaul is sending messages to the matrix bridge before the matrix bridge has been initialized. It crashes, because the storage was not set and the MATRIX_CONFIG.set() was not called and does therefore not exist.

The initialization process is at the moment in the main running function and needs to be moved to a separate function that can be run before starting the loop.

Panic report:

[1] Time Sent - 2023-09-22T15:44:28.015880182Z
Timestamp Sent - 1695143904178
Time Received - 2023-09-22T15:44:28.015880182Z
Timestamp Received - 1695397467956
Message ID 3qbXq5G4sCcigXRuf6zpXSfHsRv6RoBogjc9ycKYoHBQggup5XPyAVjdKSncdVpNp4ZF92akhwJWjfMSmSi64R5X
From 12D3KooWHRKdxYwvLMzQ3kNpwAHFfa38Lvdaotx9xWpYazmb7YK8
	great

thread 'main' panicked at 'storage::get(): called get() before set()', /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/state-0.5.3/src/storage.rs:162:14
stack backtrace:
 INFO  libp2p_mdns::behaviour        > discovered: 12D3KooWNQrathUZinP5rposzPhToW6Yu2G4ZA9aEZtYcpsGDwKy /ip4/192.168.1.199/tcp/38797
 INFO  libp2p_mdns::behaviour        > discovered: 12D3KooWNQrathUZinP5rposzPhToW6Yu2G4ZA9aEZtYcpsGDwKy /ip4/192.168.1.199/tcp/37665
   0:     0x55b7144ca8b1 - std::backtrace_rs::backtrace::libunwind::trace::he648b5c8dd376705
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55b7144ca8b1 - std::backtrace_rs::backtrace::trace_unsynchronized::h5da3e203eef39e9f
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55b7144ca8b1 - std::sys_common::backtrace::_print_fmt::h8d28d3f20588ae4c
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x55b7144ca8b1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd9a5b0c9c6b058c0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55b7144f925f - core::fmt::rt::Argument::fmt::h0afc04119f252b53
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/rt.rs:138:9
   5:     0x55b7144f925f - core::fmt::write::h50b1b3e73851a6fe
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/mod.rs:1094:21
   6:     0x55b7144c6107 - std::io::Write::write_fmt::h184eaf275e4484f0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/io/mod.rs:1714:15
   7:     0x55b7144ca6c5 - std::sys_common::backtrace::_print::hf58c3a5a25090e71
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x55b7144ca6c5 - std::sys_common::backtrace::print::hb9cf0a7c7f077819
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x55b7144cbe33 - std::panicking::default_hook::{{closure}}::h066adb2e3f3e2c07
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:269:22
  10:     0x55b7144cbbc4 - std::panicking::default_hook::h277fa2776900ff14
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:288:9
  11:     0x55b7144cc3b9 - std::panicking::rust_panic_with_hook::hceaf38da6d9db792
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:705:13
  12:     0x55b7144cc2b7 - std::panicking::begin_panic_handler::{{closure}}::h2bce3ed2516af7df
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:597:13
  13:     0x55b7144cad16 - std::sys_common::backtrace::__rust_end_short_backtrace::h090f3faf8f98a395
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55b7144cc002 - rust_begin_unwind
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
  15:     0x55b711eef853 - core::panicking::panic_fmt::h4ec8274704d163a3
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
  16:     0x55b711eef813 - core::panicking::panic_display::h5ef861b25744765d
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:150:5
  17:     0x55b711eef813 - core::panicking::panic_str::hb2e5b3cf68d2f306
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:134:5
  18:     0x55b711eef813 - core::option::expect_failed::h3de37afca26e8e59
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/option.rs:1952:5
  19:     0x55b7121ebab2 - core::option::Option<T>::expect::h1ab224d9672e2653
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/option.rs:898:21
  20:     0x55b7120a7d85 - state::storage::Storage<T>::get::h85c94d6ed1fd6673
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/state-0.5.3/src/storage.rs:161:9
  21:     0x55b711fd8a87 - qaul_matrix_bridge::feed::Feed::matrix_send::hf62ead07070bc375
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/feed.rs:94:29
  22:     0x55b711fd8458 - qaul_matrix_bridge::feed::Feed::rpc::h1bd08bf2c07d4a9d
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/feed.rs:73:33
  23:     0x55b712286116 - qaul_matrix_bridge::rpc::Rpc::received_message::h87c7758b18bb5c1c
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/rpc.rs:89:25
  24:     0x55b71225ef46 - qaul_matrix_bridge::main::main::{{closure}}::h43db9928d7dc9aa6
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/main.rs:144:25
  25:     0x55b71225f722 - qaul_matrix_bridge::main::{{closure}}::h91017ec214f816a8
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/main.rs:36:1
  26:     0x55b711f7ee22 - <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::{{closure}}::h9f59d185cd387894
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/builder.rs:199:17
  27:     0x55b711f70e13 - async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}::hba9448c416dc2c1e
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/task_locals_wrapper.rs:60:13
  28:     0x55b7123962c9 - std::thread::local::LocalKey<T>::try_with::hf98bc96c7d8bc02c
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:270:16
  29:     0x55b712390fca - std::thread::local::LocalKey<T>::with::h8248eef5a98cf684
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:246:9
  30:     0x55b711f70d48 - async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::hcc024b3cf1594426
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/task_locals_wrapper.rs:55:9
  31:     0x55b711f7edde - <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::h80aee0ccb8ab66d0
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/builder.rs:197:13
  32:     0x55b71232def2 - <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll::haec79fe12d15fc9b
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-1.13.0/src/future.rs:526:33
  33:     0x55b712456d71 - async_executor::Executor::run::{{closure}}::hdc24015104406036
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.5.1/src/lib.rs:243:32
  34:     0x55b7124569b2 - async_executor::LocalExecutor::run::{{closure}}::ha31919ca8b5b9452
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.5.1/src/lib.rs:447:34
  35:     0x55b711fed2ee - async_io::driver::block_on::hc1ae9c21b0932ddc
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-io-1.13.0/src/driver.rs:146:33
  36:     0x55b71248f8e3 - async_global_executor::reactor::block_on::{{closure}}::h4fb008ed31fb74a9
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-global-executor-2.3.1/src/reactor.rs:3:18
  37:     0x55b71248f8b3 - async_global_executor::reactor::block_on::h01f788dc68226800
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-global-executor-2.3.1/src/reactor.rs:12:5
  38:     0x55b7123d8efd - async_global_executor::executor::block_on::{{closure}}::h6ab4f5785a10e40a
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-global-executor-2.3.1/src/executor.rs:26:36
  39:     0x55b7123943a7 - std::thread::local::LocalKey<T>::try_with::h833ca49fe5d61771
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:270:16
  40:     0x55b712390bea - std::thread::local::LocalKey<T>::with::h0745f19fe052a60c
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:246:9
  41:     0x55b7123d8e9a - async_global_executor::executor::block_on::h7d99011809f3da2b
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-global-executor-2.3.1/src/executor.rs:26:5
  42:     0x55b711f7ffe0 - async_std::task::builder::Builder::blocking::{{closure}}::{{closure}}::h77cf0edf29cab10d
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/builder.rs:171:25
  43:     0x55b711f70f51 - async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}::hcafa6e30af8d6f1b
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/task_locals_wrapper.rs:60:13
  44:     0x55b712391835 - std::thread::local::LocalKey<T>::try_with::h1c1755d5bea98195
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:270:16
  45:     0x55b7123911fa - std::thread::local::LocalKey<T>::with::hd2d336b2ac24db36
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:246:9
  46:     0x55b711f70cfa - async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::h5332514c9fa50016
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/task_locals_wrapper.rs:55:9
  47:     0x55b711f7ff28 - async_std::task::builder::Builder::blocking::{{closure}}::h1bbaeb57f540e68e
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/builder.rs:168:17
  48:     0x55b712394a87 - std::thread::local::LocalKey<T>::try_with::h9f11ff5478a44837
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:270:16
  49:     0x55b712390e9a - std::thread::local::LocalKey<T>::with::h5f040a3ba030c64f
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/thread/local.rs:246:9
  50:     0x55b711f7fc50 - async_std::task::builder::Builder::blocking::h36060c6663cc9675
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/builder.rs:161:9
  51:     0x55b7120c8a2c - async_std::task::block_on::block_on::hf1a3b7369e09d531
                               at /home/sojus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-std-1.12.0/src/task/block_on.rs:33:5
  52:     0x55b7120c8c37 - qaul_matrix_bridge::main::h29fb102033432396
                               at /home/sojus/src/qaul/qaul-libp2p/rust/clients/bridge/src/main.rs:36:1
  53:     0x55b711f8435b - core::ops::function::FnOnce::call_once::h5d11379ac06e2de5
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  54:     0x55b7123681ce - std::sys_common::backtrace::__rust_begin_short_backtrace::h167d5b1a96c9b059
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:135:18
  55:     0x55b712458351 - std::rt::lang_start::{{closure}}::h59bd2217cd6d3945
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:166:18
  56:     0x55b7144be55b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h75ba4244a1c7bb54
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:284:13
  57:     0x55b7144be55b - std::panicking::try::do_call::h0a2baa36dea975a1
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
  58:     0x55b7144be55b - std::panicking::try::h0e42aa233d4224d4
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
  59:     0x55b7144be55b - std::panic::catch_unwind::hefdfd8f482606434
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
  60:     0x55b7144be55b - std::rt::lang_start_internal::{{closure}}::h457959f0f91da23b
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:48
  61:     0x55b7144be55b - std::panicking::try::do_call::h112cfd1acb38183b
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
  62:     0x55b7144be55b - std::panicking::try::ha64f15b20cec18ca
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
  63:     0x55b7144be55b - std::panic::catch_unwind::hbacc2b68ee2c119e
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
  64:     0x55b7144be55b - std::rt::lang_start_internal::h5f408694586c2a05
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:20
  65:     0x55b71245832a - std::rt::lang_start::hb8b84b7cd0397f21
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:165:17
  66:     0x55b7120c8c6e - main
  67:     0x7f354ca27cd0 - <unknown>
  68:     0x7f354ca27d8a - __libc_start_main
  69:     0x55b711ef0d55 - _start
  70:                0x0 - <unknown>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants