mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-12-05 14:51:45 +00:00
Compare commits
49
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46e2607aeb | ||
|
|
90758944ca | ||
|
|
e3aa13d2f6 | ||
|
|
5a0e9303ee | ||
|
|
32b018a676 | ||
|
|
8a652cdd2f | ||
|
|
d0e885fb1c | ||
|
|
e95e653379 | ||
|
|
3057a44de4 | ||
|
|
37f26dc430 | ||
|
|
1442cfcb4f | ||
|
|
3f263714c3 | ||
|
|
30684724b5 | ||
|
|
df8bcdd92d | ||
|
|
560c959ee7 | ||
|
|
ee4b2f5b8d | ||
|
|
1a766d52d4 | ||
|
|
0c34700a96 | ||
|
|
9ef401f13e | ||
|
|
bfe45facad | ||
|
|
866742ecc5 | ||
|
|
7a7e3b4697 | ||
|
|
27267eec69 | ||
|
|
6f3985d837 | ||
|
|
d42836dabf | ||
|
|
05dc9d08e1 | ||
|
|
0daf876e9b | ||
|
|
77ae59fde7 | ||
|
|
b865f0d56e | ||
|
|
9e9eb19331 | ||
|
|
4f333ed173 | ||
|
|
1840549332 | ||
|
|
ca50d52469 | ||
|
|
80493f3e36 | ||
|
|
e39c3e3aee | ||
|
|
25144ecceb | ||
|
|
c2c841b8c7 | ||
|
|
9f10657406 | ||
|
|
a8c49a3034 | ||
|
|
35f3b44e46 | ||
|
|
2ffbead621 | ||
|
|
772553ec79 | ||
|
|
732dd623ee | ||
|
|
0974481066 | ||
|
|
5ac3ef7372 | ||
|
|
53a0ca9ae5 | ||
|
|
b5956368bc | ||
|
|
e143da969a | ||
|
|
7631250278 |
No files matched your search
@@ -71,7 +71,7 @@ runs:
|
|||||||
|
|
||||||
- name: Install timelord-cli and git-warp-time
|
- name: Install timelord-cli and git-warp-time
|
||||||
if: steps.check-binaries.outputs.need-install == 'true'
|
if: steps.check-binaries.outputs.need-install == 'true'
|
||||||
uses: https://github.com/taiki-e/install-action@9e1e5806d4a4822de933115878265be9aaa786d9 # v2
|
uses: https://github.com/taiki-e/install-action@15449e3094499af05d8d964a1c884208e4b8b595 # v2
|
||||||
with:
|
with:
|
||||||
tool: git-warp-time,timelord-cli@3.0.1
|
tool: git-warp-time,timelord-cli@3.0.1
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ on:
|
|||||||
- "v*.*.*"
|
- "v*.*.*"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 0 * * 1'
|
- cron: '30 0 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -41,9 +41,20 @@ jobs:
|
|||||||
# else
|
# else
|
||||||
# echo "No workaround needed for llvm-project#153385"
|
# echo "No workaround needed for llvm-project#153385"
|
||||||
# fi
|
# fi
|
||||||
|
- name: Pick compatible clang version
|
||||||
|
id: clang-version
|
||||||
|
run: |
|
||||||
|
# both latest need to use clang-23, but oldstable and previous can just use clang
|
||||||
|
if [[ "${{ matrix.container }}" == "ubuntu-latest" ]]; then
|
||||||
|
echo "Using clang-23 package for ${{ matrix.container }}"
|
||||||
|
echo "version=clang-23" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "Using default clang package for ${{ matrix.container }}"
|
||||||
|
echo "version=clang" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Checkout repository with full history
|
- name: Checkout repository with full history
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: ${{ github.ref_name }}
|
ref: ${{ github.ref_name }}
|
||||||
@@ -82,10 +93,10 @@ jobs:
|
|||||||
# VERSION is the package version, COMPONENT is used in
|
# VERSION is the package version, COMPONENT is used in
|
||||||
# apt's repository config like a git repo branch
|
# apt's repository config like a git repo branch
|
||||||
VERSION=$BASE_VERSION
|
VERSION=$BASE_VERSION
|
||||||
if [[ ${{ forge.ref_name }} =~ ^v+[0-9]+\.+[0-9]+\.+[0-9]+$ ]]; then
|
if [[ ${{ forge.ref_name }} =~ ^v+[0-9]\.+[0-9]\.+[0-9]$ ]]; then
|
||||||
# Use the "stable" component for tagged semver releases
|
# Use the "stable" component for tagged semver releases
|
||||||
COMPONENT="stable"
|
COMPONENT="stable"
|
||||||
elif [[ ${{ forge.ref_name }} =~ ^v+[0-9]+\.+[0-9]+\.+[0-9]+ ]]; then
|
elif [[ ${{ forge.ref_name }} =~ ^v+[0-9]\.+[0-9]\.+[0-9] ]]; then
|
||||||
# Use the "unstable" component for tagged semver pre-releases
|
# Use the "unstable" component for tagged semver pre-releases
|
||||||
COMPONENT="unstable"
|
COMPONENT="unstable"
|
||||||
else
|
else
|
||||||
@@ -119,7 +130,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
# Build dependencies for rocksdb
|
# Build dependencies for rocksdb
|
||||||
apt-get install -y liburing-dev clang
|
apt-get install -y liburing-dev ${{ steps.clang-version.outputs.version }}
|
||||||
|
|
||||||
- name: Run cargo-deb
|
- name: Run cargo-deb
|
||||||
id: cargo-deb
|
id: cargo-deb
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ on:
|
|||||||
# - '.forgejo/workflows/build-fedora.yml'
|
# - '.forgejo/workflows/build-fedora.yml'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 0 * * 2'
|
- cron: '30 0 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -30,7 +30,7 @@ jobs:
|
|||||||
echo "Fedora version: $VERSION"
|
echo "Fedora version: $VERSION"
|
||||||
|
|
||||||
- name: Checkout repository with full history
|
- name: Checkout repository with full history
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: ${{ github.ref_name }}
|
ref: ${{ github.ref_name }}
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
name: Build / Static via Nix
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: "build-nix-${{ forge.ref }}"
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "v*.*.*"
|
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
|
||||||
- cron: '30 0 * * 3'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: "Build ${{ matrix.filename }} Binary"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- package: default-static-x86_64
|
|
||||||
filename: conduwuit-linux-static-amd64
|
|
||||||
- package: default-static-aarch64
|
|
||||||
filename: conduwuit-linux-static-arm64
|
|
||||||
|
|
||||||
- package: max-perf-static-aarch64
|
|
||||||
filename: conduwuit-linux-static-arm64-maxperf
|
|
||||||
- package: max-perf-haswell-static-x86_64
|
|
||||||
filename: conduwuit-haswell-linux-static-amd64-maxperf
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
|
|
||||||
|
|
||||||
- name: Install Lix
|
|
||||||
uses: https://github.com/samueldr/lix-gha-installer-action@a0fee77b2a98bb7c5c0ed7ae6d6ad4903dbdad0d
|
|
||||||
with:
|
|
||||||
extra_nix_config: experimental-features = nix-command flakes flake-self-attrs
|
|
||||||
|
|
||||||
- name: Build static binary
|
|
||||||
run: |
|
|
||||||
nix build .#${{ matrix.package }}
|
|
||||||
install -D result/bin/conduwuit /tmp/binaries/${{ matrix.filename }}
|
|
||||||
|
|
||||||
- name: Upload binary artifact
|
|
||||||
uses: forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.filename }}
|
|
||||||
path: /tmp/binaries/${{ matrix.filename }}
|
|
||||||
|
|
||||||
release-binaries:
|
|
||||||
name: "Release Binaries"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
steps:
|
|
||||||
- name: Download binary artifacts
|
|
||||||
uses: forgejo/download-artifact@v4
|
|
||||||
with:
|
|
||||||
pattern: conduwuit*
|
|
||||||
path: binaries
|
|
||||||
merge-multiple: true
|
|
||||||
- name: Create Release and Upload
|
|
||||||
uses: https://github.com/softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3
|
|
||||||
with:
|
|
||||||
draft: true
|
|
||||||
files: binaries/*
|
|
||||||
@@ -14,19 +14,23 @@ jobs:
|
|||||||
name: Check changelog is added
|
name: Check changelog is added
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
sparse-checkout: .
|
||||||
|
|
||||||
- name: Check for changelog entry
|
- name: Check for changelog entry
|
||||||
id: check_files
|
id: check_files
|
||||||
run: |
|
run: |
|
||||||
AUTH=$(echo -n "x-access-token:${{ secrets.GITHUB_TOKEN }}" | base64 -w 0)
|
git fetch origin ${GITHUB_BASE_REF}
|
||||||
git config --global http.${{ github.server_url }}/.extraheader "Authorization: basic $AUTH"
|
|
||||||
git clone "${{ github.event.repository.clone_url }}" repo.git --bare
|
|
||||||
|
|
||||||
git -C repo.git fetch origin pull/${{ github.event.pull_request.number }}/head
|
|
||||||
|
|
||||||
# Check for Added (A) or Modified (M) files in changelog.d
|
# Check for Added (A) or Modified (M) files in changelog.d
|
||||||
CHANGELOG_CHANGES=$(git -C repo.git diff --name-status ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} -- changelog.d/)
|
CHANGELOG_CHANGES=$(git diff --name-status origin/${GITHUB_BASE_REF}...HEAD -- changelog.d/)
|
||||||
|
|
||||||
SRC_CHANGES=$(git -C repo.git diff --name-status ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} -- src/)
|
SRC_CHANGES=$(git diff --name-status origin/${GITHUB_BASE_REF}...HEAD -- src/)
|
||||||
|
|
||||||
echo "Changes in changelog.d/:"
|
echo "Changes in changelog.d/:"
|
||||||
echo "$CHANGELOG_CHANGES"
|
echo "$CHANGELOG_CHANGES"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Sync repository
|
- name: Sync repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ jobs:
|
|||||||
DOCKER_MIRROR_TOKEN: ${{ secrets.DOCKER_MIRROR_TOKEN }}
|
DOCKER_MIRROR_TOKEN: ${{ secrets.DOCKER_MIRROR_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ jobs:
|
|||||||
# repositories: continuwuity
|
# repositories: continuwuity
|
||||||
|
|
||||||
- name: Install regsync
|
- name: Install regsync
|
||||||
uses: https://github.com/regclient/actions/regsync-installer@4b4db1dcc7dad75ad67a788a380f75a20cc8a040 # main
|
uses: https://github.com/regclient/actions/regsync-installer@14f9d37db17b5dc41fefd1ffdd1af4b9e2490560 # main
|
||||||
|
|
||||||
- name: Check what images need mirroring
|
- name: Check what images need mirroring
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ jobs:
|
|||||||
rust: ${{ steps.filter.outputs.rust }}
|
rust: ${{ steps.filter.outputs.rust }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Prepare Docker build environment
|
- name: Prepare Docker build environment
|
||||||
@@ -100,7 +100,7 @@ jobs:
|
|||||||
needs: build-release
|
needs: build-release
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Create multi-platform manifest
|
- name: Create multi-platform manifest
|
||||||
@@ -133,7 +133,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Prepare max-perf Docker build environment
|
- name: Prepare max-perf Docker build environment
|
||||||
@@ -187,7 +187,7 @@ jobs:
|
|||||||
needs: build-maxperf
|
needs: build-maxperf
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Create max-perf manifest
|
- name: Create max-perf manifest
|
||||||
@@ -216,7 +216,7 @@ jobs:
|
|||||||
path: binaries
|
path: binaries
|
||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
- name: Create Release and Upload
|
- name: Create Release and Upload
|
||||||
uses: https://github.com/softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3
|
uses: https://github.com/softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
|
||||||
with:
|
with:
|
||||||
draft: true
|
draft: true
|
||||||
files: binaries/*
|
files: binaries/*
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ jobs:
|
|||||||
name: Renovate
|
name: Renovate
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/renovatebot/renovate:43.246.1@sha256:5965c08f8ca5baff8dc9bf3a32c44ca71fef843ad94880e9696d46e1d722b0fa
|
image: ghcr.io/renovatebot/renovate:43.222.1@sha256:b9af3f59f3f4d92b2c41e9f4ca3ffe92400503f20158d0bd67d07a3fdbe781d2
|
||||||
options: --tmpfs /tmp:exec
|
options: --tmpfs /tmp:exec
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
show-progress: false
|
show-progress: false
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
update-flake-hashes:
|
update-flake-hashes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||||
with:
|
with:
|
||||||
persist-credentials: true
|
persist-credentials: true
|
||||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
- name: Get new toolchain hash
|
- name: Get new toolchain hash
|
||||||
run: |
|
run: |
|
||||||
# Set the current sha256 to an empty hash to make `nix build` calculate a new one
|
# Set the current sha256 to an empty hash to make `nix build` calculate a new one
|
||||||
awk '/fromToolchainName *\{/{found=1; print; next} found && /sha256 =/{sub(/sha256 = .*/, "sha256 = lib.fakeSha256;"); found=0} 1' nix/rust.nix > temp.nix
|
awk '/fromToolchainFile *\{/{found=1; print; next} found && /sha256 =/{sub(/sha256 = .*/, "sha256 = lib.fakeSha256;"); found=0} 1' nix/rust.nix > temp.nix
|
||||||
mv temp.nix nix/rust.nix
|
mv temp.nix nix/rust.nix
|
||||||
|
|
||||||
# Build continuwuity and filter for the new hash
|
# Build continuwuity and filter for the new hash
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
sed -i "s|lib.fakeSha256|\"$new_hash\"|" nix/rust.nix
|
sed -i "s|lib.fakeSha256|\"$new_hash\"|" nix/rust.nix
|
||||||
|
|
||||||
echo "New hash:"
|
echo "New hash:"
|
||||||
awk -F'"' '/fromToolchainName/{found=1; next} found && /sha256 =/{print $2; found=0}' nix/rust.nix
|
awk -F'"' '/fromToolchainFile/{found=1; next} found && /sha256 =/{print $2; found=0}' nix/rust.nix
|
||||||
echo "Expected new hash:"
|
echo "Expected new hash:"
|
||||||
cat new_toolchain_hash.txt
|
cat new_toolchain_hash.txt
|
||||||
|
|
||||||
|
|||||||
Generated
+59
-91
@@ -130,9 +130,9 @@ checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayvec"
|
name = "arrayvec"
|
||||||
version = "0.7.7"
|
version = "0.7.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f02882884d3e1bc524fb12c79f107f6ad0e1cfd498c536ffb494301740995dfe"
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@@ -560,9 +560,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.12.0"
|
version = "1.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593"
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytesize"
|
name = "bytesize"
|
||||||
@@ -805,7 +805,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit"
|
name = "conduwuit"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-rs",
|
"aws-lc-rs",
|
||||||
"clap",
|
"clap",
|
||||||
@@ -843,7 +843,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_admin"
|
name = "conduwuit_admin"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assign",
|
"assign",
|
||||||
"clap",
|
"clap",
|
||||||
@@ -868,7 +868,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_api"
|
name = "conduwuit_api"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assign",
|
"assign",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -889,7 +889,7 @@ dependencies = [
|
|||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
"ipaddress",
|
"ipaddress",
|
||||||
"itertools 0.15.0",
|
"itertools 0.14.0",
|
||||||
"lettre",
|
"lettre",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.10.1",
|
"rand 0.10.1",
|
||||||
@@ -906,7 +906,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_build_metadata"
|
name = "conduwuit_build_metadata"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"built",
|
"built",
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
@@ -914,7 +914,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_core"
|
name = "conduwuit_core"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
@@ -942,7 +942,7 @@ dependencies = [
|
|||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"ipaddress",
|
"ipaddress",
|
||||||
"itertools 0.15.0",
|
"itertools 0.14.0",
|
||||||
"lettre",
|
"lettre",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading 0.9.0",
|
"libloading 0.9.0",
|
||||||
@@ -980,7 +980,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_database"
|
name = "conduwuit_database"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"conduwuit_core",
|
"conduwuit_core",
|
||||||
@@ -1001,10 +1001,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_macros"
|
name = "conduwuit_macros"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
"itertools 0.15.0",
|
"itertools 0.14.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
@@ -1012,7 +1012,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_router"
|
name = "conduwuit_router"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assign",
|
"assign",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -1044,13 +1044,13 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http 0.7.0",
|
"tower-http",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_service"
|
name = "conduwuit_service"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"assign",
|
"assign",
|
||||||
@@ -1070,7 +1070,7 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"image",
|
"image",
|
||||||
"ipaddress",
|
"ipaddress",
|
||||||
"itertools 0.15.0",
|
"itertools 0.14.0",
|
||||||
"lettre",
|
"lettre",
|
||||||
"log",
|
"log",
|
||||||
"loole",
|
"loole",
|
||||||
@@ -1100,7 +1100,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conduwuit_web"
|
name = "conduwuit_web"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"assign",
|
"assign",
|
||||||
@@ -1125,7 +1125,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tower-http 0.7.0",
|
"tower-http",
|
||||||
"tower-sec-fetch",
|
"tower-sec-fetch",
|
||||||
"tower-sessions",
|
"tower-sessions",
|
||||||
"tower-sessions-core",
|
"tower-sessions-core",
|
||||||
@@ -2051,9 +2051,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "granit-parser"
|
name = "granit-parser"
|
||||||
version = "0.0.6"
|
version = "0.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14668345710c92cb04181d9268407067689327d4b055273e3c4179a0777ee6a1"
|
checksum = "b7e736dfe3881c53a7dce0685eb18202d0d9fe6911782f9870946eb9ee89d778"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arraydeque",
|
"arraydeque",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@@ -2656,15 +2656,6 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
@@ -2918,9 +2909,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.33"
|
version = "0.4.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "loole"
|
name = "loole"
|
||||||
@@ -3969,9 +3960,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.46"
|
version = "1.0.45"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -4136,7 +4127,7 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http 0.6.11",
|
"tower-http",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@@ -4181,7 +4172,7 @@ dependencies = [
|
|||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http 0.6.11",
|
"tower-http",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@@ -4410,7 +4401,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ruminuwuity"
|
name = "ruminuwuity"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assign",
|
"assign",
|
||||||
"ruma",
|
"ruma",
|
||||||
@@ -4482,9 +4473,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.23.41"
|
version = "0.23.40"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f"
|
checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-rs",
|
"aws-lc-rs",
|
||||||
"log",
|
"log",
|
||||||
@@ -4660,9 +4651,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry"
|
name = "sentry"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1975064d9f3d9d87a7c8f0371f7fac10d876906ca3e39faad72e61c263ff9b87"
|
checksum = "931a20b0da02350676e3d6d3c9028d58eaa448cf42a866712eec5845a505421e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"httpdate",
|
"httpdate",
|
||||||
@@ -4680,9 +4671,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-backtrace"
|
name = "sentry-backtrace"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "134f552b6b147f77aeee46ece875d67a8bfc1d56fe3860d78446ed4c25bb5f9f"
|
checksum = "911ee36abf5b7fa335fccd5f54361ba9c16baea5f0c3bb361a687b6c195c21cf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -4691,9 +4682,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-contexts"
|
name = "sentry-contexts"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "98482b938fb1f31ecd23506fb7f08b2ba20d60b9cc72581b1205a9acd31d32fa"
|
checksum = "9b9d7d469e9e22741c17ca23fb8b42d79861590eb7cf330f3da34fc1e4bc1bc6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hostname",
|
"hostname",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -4705,9 +4696,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-core"
|
name = "sentry-core"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7cff96247f4dc36867511d108709e703eb354143e7893319d763d2dd1edb4f48"
|
checksum = "545dc562b6758d646ac19e1407f4ebc26d452111386743e03323464bc48bb2e0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand 0.9.4",
|
"rand 0.9.4",
|
||||||
"sentry-types",
|
"sentry-types",
|
||||||
@@ -4718,9 +4709,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-debug-images"
|
name = "sentry-debug-images"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b603a51b083141062a142d73e36391b14244b4bd0bfe28bcd80e8327bb1d7698"
|
checksum = "660e9def38a573a869a182f7e90f58aaaa460f38b92b31fd1755ec537193bb48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"findshlibs",
|
"findshlibs",
|
||||||
"sentry-core",
|
"sentry-core",
|
||||||
@@ -4728,9 +4719,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-log"
|
name = "sentry-log"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "74df4d09a38fd59da258269ffd7f344bd308470117d68eda5a95b4fbd65683d0"
|
checksum = "2c13b9313bdd6a9db19e65ac0e4754e64dea6f18cdd15444656abb050db4538d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"log",
|
"log",
|
||||||
@@ -4739,9 +4730,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-panic"
|
name = "sentry-panic"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61de3f4a1fc77d4c57e8bacd8ef064c26aaa88ea5b2541a761d37c7c3703b9a9"
|
checksum = "772d9de150c8ca910c835353c85f434457348fdd21208f9b3da3574202b1dc5d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"sentry-backtrace",
|
"sentry-backtrace",
|
||||||
"sentry-core",
|
"sentry-core",
|
||||||
@@ -4749,9 +4740,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-tower"
|
name = "sentry-tower"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2d5cb61301e328cbd42d2fede094aca746674b359fcd9c44691f027820e8fe59"
|
checksum = "2abea154597936d5df2d39fbe8aac16d584de6b3572c70c39558764d9d2efe15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"http",
|
"http",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
@@ -4763,9 +4754,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-tracing"
|
name = "sentry-tracing"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bc59b27dae3bb495e37e6d62d252214840a2e7e1875531ee9fa2953df8985537"
|
checksum = "c51ec9620a4d398dcdf7ee90effbf8d8691cfa24e91978bfa8565cac039d4980"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"sentry-backtrace",
|
"sentry-backtrace",
|
||||||
@@ -4776,9 +4767,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry-types"
|
name = "sentry-types"
|
||||||
version = "0.48.3"
|
version = "0.48.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d7e78132ccfb4a1c777b959fb2944d1f6d5145bffe6be2a98ee6b25d244f72c"
|
checksum = "041359745a44dd2e14fe21b7510fe7ca8b5beffce6636a0b52e5bc7d5f736887"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"debugid",
|
"debugid",
|
||||||
"hex",
|
"hex",
|
||||||
@@ -4803,19 +4794,19 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde-saphyr"
|
name = "serde-saphyr"
|
||||||
version = "0.0.28"
|
version = "0.0.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a15e3bc297370dc9c526bcf0986f29167a9286cfaad404f2f572b3074dabe5ec"
|
checksum = "dcc7fe48e34d02a97bc8e6253b8b91e5a47fe2c47eaacb5149cefbb69922eaf0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"annotate-snippets",
|
"annotate-snippets",
|
||||||
"base64 0.21.7",
|
"base64 0.22.1",
|
||||||
"encoding_rs_io",
|
"encoding_rs_io",
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
"granit-parser",
|
"granit-parser",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"serde_core",
|
"serde",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"zmij",
|
"zmij",
|
||||||
]
|
]
|
||||||
@@ -5168,9 +5159,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.118"
|
version = "2.0.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -5667,31 +5658,8 @@ dependencies = [
|
|||||||
"tower",
|
"tower",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tower-http"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b11f75e912b0c2be01b63d8cf8057b8c3f97cf34abb3d431a3a4c8675498e233"
|
|
||||||
dependencies = [
|
|
||||||
"async-compression",
|
|
||||||
"bitflags",
|
|
||||||
"bytes",
|
|
||||||
"futures-core",
|
|
||||||
"futures-util",
|
|
||||||
"http",
|
|
||||||
"http-body",
|
|
||||||
"http-body-util",
|
|
||||||
"percent-encoding",
|
|
||||||
"pin-project-lite",
|
|
||||||
"tokio",
|
|
||||||
"tokio-util",
|
|
||||||
"tower",
|
|
||||||
"tower-layer",
|
|
||||||
"tower-service",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6582,7 +6550,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
|
|||||||
+4
-4
@@ -12,7 +12,7 @@ license = "Apache-2.0"
|
|||||||
# See also `rust-toolchain.toml`
|
# See also `rust-toolchain.toml`
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
||||||
version = "26.6.0-alpha.1"
|
version = "0.5.9"
|
||||||
|
|
||||||
[workspace.metadata.crane]
|
[workspace.metadata.crane]
|
||||||
name = "conduwuit"
|
name = "conduwuit"
|
||||||
@@ -124,7 +124,7 @@ default-features = false
|
|||||||
features = ["util"]
|
features = ["util"]
|
||||||
|
|
||||||
[workspace.dependencies.tower-http]
|
[workspace.dependencies.tower-http]
|
||||||
version = "0.7.0"
|
version = "0.6.8"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"add-extension",
|
"add-extension",
|
||||||
@@ -164,7 +164,7 @@ features = ["raw_value"]
|
|||||||
|
|
||||||
# Used for appservice registration files
|
# Used for appservice registration files
|
||||||
[workspace.dependencies.serde-saphyr]
|
[workspace.dependencies.serde-saphyr]
|
||||||
version = "0.0.28"
|
version = "0.0.26"
|
||||||
|
|
||||||
# Used to load forbidden room/user regex from config
|
# Used to load forbidden room/user regex from config
|
||||||
[workspace.dependencies.serde_regex]
|
[workspace.dependencies.serde_regex]
|
||||||
@@ -316,7 +316,7 @@ default-features = false
|
|||||||
|
|
||||||
# Used to make working with iterators easier, was already a transitive depdendency
|
# Used to make working with iterators easier, was already a transitive depdendency
|
||||||
[workspace.dependencies.itertools]
|
[workspace.dependencies.itertools]
|
||||||
version = "0.15.0"
|
version = "0.14.0"
|
||||||
|
|
||||||
# to parse user-friendly time durations in admin commands
|
# to parse user-friendly time durations in admin commands
|
||||||
#TODO: overlaps chrono?
|
#TODO: overlaps chrono?
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ We appreciate the efforts of security researchers and the community in identifyi
|
|||||||
1. **Contact members of the team directly** over E2EE private message.
|
1. **Contact members of the team directly** over E2EE private message.
|
||||||
- [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link)
|
- [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link)
|
||||||
- [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk)
|
- [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk)
|
||||||
- [@ginger:gingershaped.computer](https://matrix.to/#/@ginger:gingershaped.computer)
|
|
||||||
2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so don't include sensitive details.
|
2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so don't include sensitive details.
|
||||||
3. **Do not disclose the vulnerability publicly** until it has been addressed
|
3. **Do not disclose the vulnerability publicly** until it has been addressed
|
||||||
4. **Provide detailed information** about the vulnerability, including:
|
4. **Provide detailed information** about the vulnerability, including:
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Added support for Matrix 1.16's `state_after` feature, allowing clients which understand it to sync room state changes more reliably. Contributed by @ginger.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Added static builds using Nix, allowing for Continuwuity on musl. During this, we also introduced a `max-perf-haswell` package, separating it from `max-perf`, so you may want to swap to this if you are on NixOS. Contributed by @Henry-Hiles (QuadRadical).
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Added support for MSC4380 invite blocking, which has become part of the Matrix specification in v1.18. Contributed by @nex.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Added `!admin debug get-state-at` command
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Adjusted legacy sync logic to no longer use the `roomsynctoken_shortstatehash` database column. Once this change has been confirmed to be stable and reliable, a future update will remove it entirely, significantly decreasing database sizes. Contributed by @ginger.
|
|
||||||
+1
-1
@@ -50,7 +50,7 @@ EOF
|
|||||||
|
|
||||||
# Developer tool versions
|
# Developer tool versions
|
||||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||||
ENV BINSTALL_VERSION=1.20.1
|
ENV BINSTALL_VERSION=1.20.0
|
||||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||||
ENV CARGO_SBOM_VERSION=0.9.1
|
ENV CARGO_SBOM_VERSION=0.9.1
|
||||||
# renovate: datasource=crate depName=lddtree
|
# renovate: datasource=crate depName=lddtree
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
|
|||||||
|
|
||||||
# Developer tool versions
|
# Developer tool versions
|
||||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||||
ENV BINSTALL_VERSION=1.20.1
|
ENV BINSTALL_VERSION=1.20.0
|
||||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||||
ENV CARGO_SBOM_VERSION=0.9.1
|
ENV CARGO_SBOM_VERSION=0.9.1
|
||||||
# renovate: datasource=crate depName=lddtree
|
# renovate: datasource=crate depName=lddtree
|
||||||
|
|||||||
@@ -47,15 +47,9 @@ and, for amd64, target the haswell CPU architecture.
|
|||||||
|
|
||||||
### Nix
|
### Nix
|
||||||
|
|
||||||
If you wish to generate a static binary, you can do so using Nix: `nix build git+https://forgejo.ellis.link/continuwuation/continuwuity#packageName`, where `packageName` is one of:
|
Theres a Nix package defined in our flake, available for Linux and MacOS. Add continuwuity as an input to your flake, and use `inputs.continuwuity.packages.${system}.default` to get a working Continuwuity package.
|
||||||
|
|
||||||
- `default-static-x86_64`
|
If you simply wish to generate a binary using Nix, you can run `nix build git+https://forgejo.ellis.link/continuwuation/continuwuity` to generate a binary in `result/bin/conduwuit`.
|
||||||
- `default-static-aarch64`
|
|
||||||
- `max-perf-static-x86_64`
|
|
||||||
- `max-perf-haswell-static-x86_64`
|
|
||||||
- `max-perf-static-aarch64`
|
|
||||||
|
|
||||||
`max-perf` takes longer to build, but has more runtime optimizations. Haswell builds are optimized for modern CPUs.
|
|
||||||
|
|
||||||
### Compiling
|
### Compiling
|
||||||
|
|
||||||
|
|||||||
@@ -47,16 +47,9 @@ The NixOS module provides these configuration options:
|
|||||||
- `extraEnvironment`: Extra environment variables to pass to the Continuwuity server
|
- `extraEnvironment`: Extra environment variables to pass to the Continuwuity server
|
||||||
- `package`: The Continuwuity package to use, defaults to `pkgs.matrix-continuwuity`
|
- `package`: The Continuwuity package to use, defaults to `pkgs.matrix-continuwuity`
|
||||||
- You may want to override this to be from our flake, for faster updates and unstable versions:
|
- You may want to override this to be from our flake, for faster updates and unstable versions:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
package = inputs.continuwuity.packages.${pkgs.stdenv.hostPlatform.system}.packageName;
|
package = inputs.continuwuity.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `packageName` is one of:
|
|
||||||
- `default`
|
|
||||||
- `max-perf`: Takes longer to build, but has more runtime optimizations
|
|
||||||
- `max-perf-haswell`: Optimized for modern CPUs, don't use if your CPU is not Haswell or later.
|
|
||||||
|
|
||||||
- `admin.enable`: Whether to add the `conduwuit` binary to `PATH` for administration (enabled by default)
|
- `admin.enable`: Whether to add the `conduwuit` binary to `PATH` for administration (enabled by default)
|
||||||
- `settings`: The Continuwuity configuration
|
- `settings`: The Continuwuity configuration
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
"message": "Welcome to Continuwuity! Important announcements about the project will appear here."
|
"message": "Welcome to Continuwuity! Important announcements about the project will appear here."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 14,
|
"id": 13,
|
||||||
"mention_room": true,
|
"mention_room": true,
|
||||||
"date": "2026-06-20",
|
"date": "2026-05-08",
|
||||||
"message": "[v0.5.10](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.10) has been released. It is a security release, so we suggest you update as soon as possible. Don't forget to also join [our announcements room](https://matrix.to/#/!jIdNjSM5X-V5JVx2h2kAhUZIIQ08GyzPL55NFZAH1vM/%24K1ISNKIqfNiZzsNVCaTt2E7ZtNeP6Dsy6sbz9l3rO0A?via=ellis.link&via=gingershaped.computer&via=matrix.org)."
|
"message": "[v0.5.9](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.9) has been released, fixing a few low-severity federation-related vulnerabilities. It is recommended you read the changelog and update as soon as possible. There are no new features or other changes in this release, only related bugfixes. Deployments tracking the main branch should also update to the latest commit."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ Please check that your issues are not due to problems with your Docker setup.
|
|||||||
|
|
||||||
### Slow joins to rooms
|
### Slow joins to rooms
|
||||||
|
|
||||||
Some slowness is to be expected if you're the first person on your homeserver to join a room (which will
|
Some slowness is to be expected if you're the first person on your homserver to join a room (which will
|
||||||
always be the case for single-user homeservers). In this situation, your homeserver has to verify the signatures of
|
always be the case for single-user homeservers). In this situation, your homeserver has to verify the signatures of
|
||||||
all of the state events sent by other servers before your join. To make this process as fast as possible, make sure you have
|
all of the state events sent by other servers before your join. To make this process as fast as possible, make sure you have
|
||||||
multiple fast, trusted servers listed in `trusted_servers` in your configuration, and ensure
|
multiple fast, trusted servers listed in `trusted_servers` in your configuration, and ensure
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
self',
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
_module.args.craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
|
||||||
|
pkgs: self'.packages.stable-toolchain
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./rust.nix
|
./rust.nix
|
||||||
|
./crane.nix
|
||||||
./packages
|
./packages
|
||||||
./devshell.nix
|
./devshell.nix
|
||||||
./fmt.nix
|
./fmt.nix
|
||||||
|
|||||||
+3
-4
@@ -1,6 +1,7 @@
|
|||||||
{ inputs, ... }: {
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
|
craneLib,
|
||||||
self',
|
self',
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
@@ -8,9 +9,7 @@
|
|||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
# basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux)
|
# basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux)
|
||||||
devShells.default =
|
devShells.default = craneLib.devShell {
|
||||||
(inputs.crane.mkLib pkgs).overrideToolchain (pkgs: self'.packages.stable-toolchain).devShell
|
|
||||||
{
|
|
||||||
packages = [
|
packages = [
|
||||||
self'.packages.rocksdb
|
self'.packages.rocksdb
|
||||||
pkgs.nodejs
|
pkgs.nodejs
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
lib,
|
lib,
|
||||||
self,
|
self,
|
||||||
stdenv,
|
stdenv,
|
||||||
rocksdb,
|
liburing,
|
||||||
craneLib,
|
craneLib,
|
||||||
pkg-config,
|
pkg-config,
|
||||||
liburing,
|
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
cargoExtraArgs ? "",
|
cargoExtraArgs ? "",
|
||||||
rustflags ? "",
|
rustflags ? "",
|
||||||
target_cpu ? null,
|
target_cpu ? null,
|
||||||
|
rocksdb,
|
||||||
profile ? "release",
|
profile ? "release",
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@@ -28,26 +28,18 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
attrs = {
|
attrs = {
|
||||||
__structuredAttrs = true;
|
|
||||||
strictDeps = true;
|
|
||||||
|
|
||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
pkg-config
|
pkg-config
|
||||||
rustPlatform.bindgenHook
|
rustPlatform.bindgenHook
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ liburing ];
|
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ liburing ];
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
|
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
||||||
|
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
||||||
CARGO_PROFILE = profile;
|
CARGO_PROFILE = profile;
|
||||||
RUSTFLAGS = rustflags;
|
RUSTFLAGS = rustflags;
|
||||||
}
|
}
|
||||||
// (lib.optionalAttrs (rocksdb != null) {
|
|
||||||
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
|
||||||
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
|
||||||
})
|
|
||||||
// (lib.optionalAttrs (target_cpu != null) {
|
// (lib.optionalAttrs (target_cpu != null) {
|
||||||
TARGET_CPU = target_cpu;
|
TARGET_CPU = target_cpu;
|
||||||
});
|
});
|
||||||
@@ -59,7 +51,7 @@ craneLib.buildPackage (
|
|||||||
cargoArtifacts = craneLib.buildDepsOnly attrs;
|
cargoArtifacts = craneLib.buildDepsOnly attrs;
|
||||||
|
|
||||||
# Needed to make continuwuity link to rocksdb
|
# Needed to make continuwuity link to rocksdb
|
||||||
postFixup = lib.optionalString (stdenv.hostPlatform.isLinux && rocksdb != null) ''
|
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||||
old_rpath="$(patchelf --print-rpath $out/bin/conduwuit)"
|
old_rpath="$(patchelf --print-rpath $out/bin/conduwuit)"
|
||||||
extra_rpath="${
|
extra_rpath="${
|
||||||
lib.makeLibraryPath [
|
lib.makeLibraryPath [
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
inputs,
|
|
||||||
self,
|
self,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@@ -7,84 +6,32 @@
|
|||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
self',
|
self',
|
||||||
lib,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
inputs',
|
|
||||||
system,
|
|
||||||
craneLib,
|
craneLib,
|
||||||
mkToolchain,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
packages =
|
packages = {
|
||||||
let
|
rocksdb = pkgs.callPackage ./rocksdb.nix { };
|
||||||
mkPackages =
|
|
||||||
pkgs:
|
|
||||||
let
|
|
||||||
fnx = inputs'.fenix.packages;
|
|
||||||
|
|
||||||
isStatic = pkgs.stdenv.hostPlatform.isMusl;
|
|
||||||
|
|
||||||
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
|
|
||||||
_:
|
|
||||||
if isStatic then
|
|
||||||
fnx.combine [
|
|
||||||
self'.packages.stable-toolchain
|
|
||||||
(mkToolchain fnx.targets.${pkgs.stdenv.hostPlatform.config}).rust-std
|
|
||||||
]
|
|
||||||
else
|
|
||||||
self'.packages.stable-toolchain
|
|
||||||
);
|
|
||||||
|
|
||||||
default = pkgs.callPackage ./continuwuity.nix {
|
default = pkgs.callPackage ./continuwuity.nix {
|
||||||
inherit self craneLib;
|
inherit self craneLib;
|
||||||
|
inherit (self'.packages) rocksdb;
|
||||||
liburing = (if isStatic then pkgs.pkgsStatic else pkgs).liburing;
|
|
||||||
rocksdb = if isStatic then null else self'.packages.rocksdb;
|
|
||||||
|
|
||||||
# extra features via `cargoExtraArgs`
|
# extra features via `cargoExtraArgs`
|
||||||
cargoExtraArgs = "-F http3";
|
cargoExtraArgs = "-F http3";
|
||||||
# extra RUSTFLAGS via `rustflags`
|
# extra RUSTFLAGS via `rustflags`
|
||||||
# the stuff below is required for http3
|
# the stuff below is required for http3
|
||||||
rustflags = "--cfg reqwest_unstable";
|
rustflags = "--cfg reqwest_unstable";
|
||||||
};
|
};
|
||||||
|
|
||||||
# users may also override this with other cargo profiles to build for other feature sets
|
# users may also override this with other cargo profiles to build for other feature sets
|
||||||
# for features configuration see `default` package which enables http3 by default
|
# for features configuration see `default` package which enables http3 by default
|
||||||
|
|
||||||
max-perf = default.override {
|
# example: different compilation profile and different target_cpu
|
||||||
|
max-perf-haswell = self'.packages.default.override {
|
||||||
|
# compiles explicitly for haswell arch cpus
|
||||||
|
target_cpu = "haswell";
|
||||||
# compiles slower but with more thorough optimizations
|
# compiles slower but with more thorough optimizations
|
||||||
profile = "release-max-perf";
|
profile = "release-max-perf";
|
||||||
};
|
};
|
||||||
|
|
||||||
max-perf-haswell = max-perf.override {
|
|
||||||
# compiles explicitly for haswell arch cpus
|
|
||||||
target_cpu = "haswell";
|
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit default max-perf max-perf-haswell;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
rocksdb = pkgs.callPackage ./rocksdb.nix { };
|
|
||||||
}
|
|
||||||
// (mkPackages pkgs)
|
|
||||||
// (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-static-x86_64" value) (
|
|
||||||
mkPackages (
|
|
||||||
import inputs.nixpkgs {
|
|
||||||
localSystem = system;
|
|
||||||
crossSystem = "x86_64-unknown-linux-musl";
|
|
||||||
}
|
|
||||||
)
|
|
||||||
))
|
|
||||||
// (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-static-aarch64" value) (
|
|
||||||
mkPackages (
|
|
||||||
import inputs.nixpkgs {
|
|
||||||
localSystem = system;
|
|
||||||
crossSystem = "aarch64-unknown-linux-musl";
|
|
||||||
}
|
|
||||||
)
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+9
-13
@@ -2,26 +2,22 @@
|
|||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
|
system,
|
||||||
lib,
|
lib,
|
||||||
inputs',
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
mkToolchain =
|
|
||||||
target:
|
|
||||||
target.fromToolchainName {
|
|
||||||
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
|
|
||||||
sha256 = "sha256-mvUGEOHYJpn3ikC5hckneuGixaC+yGrkMM/liDIDgoU=";
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
_module.args = { inherit mkToolchain; };
|
|
||||||
|
|
||||||
packages =
|
packages =
|
||||||
let
|
let
|
||||||
fnx = inputs'.fenix.packages;
|
fnx = inputs.fenix.packages.${system};
|
||||||
stable-toolchain = (mkToolchain fnx).toolchain;
|
|
||||||
|
stable-toolchain = fnx.fromToolchainFile {
|
||||||
|
file = inputs.self + "/rust-toolchain.toml";
|
||||||
|
|
||||||
|
# See also `rust-toolchain.toml`
|
||||||
|
sha256 = "sha256-mvUGEOHYJpn3ikC5hckneuGixaC+yGrkMM/liDIDgoU=";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit stable-toolchain;
|
inherit stable-toolchain;
|
||||||
|
|||||||
Generated
+25
-25
@@ -383,18 +383,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rspress/core": {
|
"node_modules/@rspress/core": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.14",
|
||||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.0.14.tgz",
|
||||||
"integrity": "sha512-epLmUXYscNRw/GtQZx2oknoBE9wKbCrUGEOrQEDI4Qq8X32GdM4d7itzuHsliY7q3IbffKx8rMVbvlmygEocTQ==",
|
"integrity": "sha512-k59i08zwBGgHrjHw8CK1m4CeTrKPvZRmV54bxubQl6AdDdmhJK6WrNg3UthwWmd38scKtqF40ATXDE8RMiNcNA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdx-js/mdx": "^3.1.1",
|
"@mdx-js/mdx": "^3.1.1",
|
||||||
"@mdx-js/react": "^3.1.1",
|
"@mdx-js/react": "^3.1.1",
|
||||||
"@rsbuild/core": "^2.0.15",
|
"@rsbuild/core": "^2.0.9",
|
||||||
"@rsbuild/plugin-react": "~2.0.1",
|
"@rsbuild/plugin-react": "~2.0.1",
|
||||||
"@rspress/shared": "2.0.15",
|
"@rspress/shared": "2.0.14",
|
||||||
"@shikijs/rehype": "^4.2.0",
|
"@shikijs/rehype": "^4.0.2",
|
||||||
"@types/unist": "^3.0.3",
|
"@types/unist": "^3.0.3",
|
||||||
"@unhead/react": "^2.1.15",
|
"@unhead/react": "^2.1.15",
|
||||||
"body-scroll-lock": "4.0.0-beta.0",
|
"body-scroll-lock": "4.0.0-beta.0",
|
||||||
@@ -407,22 +407,22 @@
|
|||||||
"mdast-util-mdxjs-esm": "^2.0.1",
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
||||||
"medium-zoom": "1.1.0",
|
"medium-zoom": "1.1.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"react": "^19.2.7",
|
"react": "^19.2.6",
|
||||||
"react-dom": "^19.2.7",
|
"react-dom": "^19.2.6",
|
||||||
"react-lazy-with-preload": "^2.2.1",
|
"react-lazy-with-preload": "^2.2.1",
|
||||||
"react-reconciler": "0.33.0",
|
"react-reconciler": "0.33.0",
|
||||||
"react-render-to-markdown": "19.1.0",
|
"react-render-to-markdown": "19.1.0",
|
||||||
"react-router-dom": "^7.15.1",
|
"react-router-dom": "^7.15.1",
|
||||||
"rehype-external-links": "^3.0.0",
|
"rehype-external-links": "^3.0.0",
|
||||||
"rehype-raw": "^7.0.0",
|
"rehype-raw": "^7.0.0",
|
||||||
"remark-cjk-friendly": "^2.3.1",
|
"remark-cjk-friendly": "^2.0.1",
|
||||||
"remark-cjk-friendly-gfm-strikethrough": "^2.1.0",
|
"remark-cjk-friendly-gfm-strikethrough": "^2.0.1",
|
||||||
"remark-gfm": "^4.0.1",
|
"remark-gfm": "^4.0.1",
|
||||||
"remark-mdx": "^3.1.1",
|
"remark-mdx": "^3.1.1",
|
||||||
"remark-parse": "^11.0.0",
|
"remark-parse": "^11.0.0",
|
||||||
"remark-stringify": "^11.0.0",
|
"remark-stringify": "^11.0.0",
|
||||||
"scroll-into-view-if-needed": "^3.1.0",
|
"scroll-into-view-if-needed": "^3.1.0",
|
||||||
"shiki": "^4.2.0",
|
"shiki": "^4.0.2",
|
||||||
"unified": "^11.0.5",
|
"unified": "^11.0.5",
|
||||||
"unist-util-remove": "^4.0.0",
|
"unist-util-remove": "^4.0.0",
|
||||||
"unist-util-visit": "^5.1.0",
|
"unist-util-visit": "^5.1.0",
|
||||||
@@ -436,9 +436,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rspress/plugin-client-redirects": {
|
"node_modules/@rspress/plugin-client-redirects": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.14",
|
||||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.0.14.tgz",
|
||||||
"integrity": "sha512-bPf/KIHH7Y6huLTtK6JXwRfxM7zKjksoxm46+IBsF1wisw0doKkEKR9HwJydxWnykyKBbA2cuZOaoT4h174Z1w==",
|
"integrity": "sha512-/WpbWUiepQglpPeplxCnELe2c7VdBUxPiICPAVnS1ZxAFdYkIpW0C+Vbk1t08kZqx8EAZGu+s6Zy43zyQpjdxg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -449,9 +449,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rspress/plugin-sitemap": {
|
"node_modules/@rspress/plugin-sitemap": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.14",
|
||||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.0.14.tgz",
|
||||||
"integrity": "sha512-z1hbyGP79ZXdSGJxiWw7ZjmX8qW0q9nXMDxr14cVEg/wdj7ToVzGtZHw0wvTPE0YiKG3BMiGkVNfE1rdOaPXiQ==",
|
"integrity": "sha512-Gpone22PvXGfGRSyi/WM8IXgsvKhNspXqHjtPD3g62jX8SJL3kpj2YZ2V28WEkg672fICauUYXrpre74Rddcsw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -462,14 +462,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rspress/shared": {
|
"node_modules/@rspress/shared": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.14",
|
||||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.0.14.tgz",
|
||||||
"integrity": "sha512-o8aYwEzNuTmWnmKe91ntPv+34u3RbtAe+rcK9XC5MANOlgncwOaCs3bUa8/B1/llwyLoNgrpi+VB9bEiU11ZRQ==",
|
"integrity": "sha512-sCe9tAo+s9tR4DmFSjMyHOxQvhzTSYXkkMUfVEo5w+uMCNXXGAIC6D0xAVDMHq1jIFF9ix47VxzlCo+CYNS14g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rsbuild/core": "^2.0.15",
|
"@rsbuild/core": "^2.0.9",
|
||||||
"@shikijs/rehype": "^4.2.0",
|
"@shikijs/rehype": "^4.0.2",
|
||||||
"unified": "^11.0.5"
|
"unified": "^11.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3058,9 +3058,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/remark-cjk-friendly": {
|
"node_modules/remark-cjk-friendly": {
|
||||||
"version": "2.3.1",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/remark-cjk-friendly/-/remark-cjk-friendly-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/remark-cjk-friendly/-/remark-cjk-friendly-2.1.0.tgz",
|
||||||
"integrity": "sha512-f+pKZRxCRwNEGFBKNRAZAqU91GIK1SAo3ZyFHWRUgC9zcxRR0BXKd6YwqgSsxtW0rNpUDtONj7H5nje2WL3fcA==",
|
"integrity": "sha512-ZWGDfTJNLEZ1gap+pd33K13ZhRAWgVDqxKA7JIlBs5IDu+qvbiWl/pEbeuxzRrWyrrkeFFoTnvNw00iW9mBcow==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use conduwuit::{Err, Result, checked};
|
use conduwuit::{Err, Result, checked};
|
||||||
use futures::{FutureExt, StreamExt, TryFutureExt};
|
use futures::{FutureExt, StreamExt, TryFutureExt};
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
use crate::admin_command;
|
||||||
pub(super) async fn register(&self) -> Result {
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn register(&self) -> Result {
|
||||||
let body = &self.body;
|
let body = &self.body;
|
||||||
let body_len = self.body.len();
|
let body_len = self.body.len();
|
||||||
if body_len < 2
|
if body_len < 2
|
||||||
@@ -29,9 +31,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn unregister(&self, appservice_identifier: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn unregister(&self, appservice_identifier: String) -> Result {
|
||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.appservice
|
.appservice
|
||||||
@@ -42,9 +45,10 @@ impl crate::Context<'_> {
|
|||||||
| Ok(()) => write!(self, "Appservice unregistered."),
|
| Ok(()) => write!(self, "Appservice unregistered."),
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn show_appservice_config(&self, appservice_identifier: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn show_appservice_config(&self, appservice_identifier: String) -> Result {
|
||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.appservice
|
.appservice
|
||||||
@@ -58,9 +62,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_registered(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_registered(&self) -> Result {
|
||||||
self.services
|
self.services
|
||||||
.appservice
|
.appservice
|
||||||
.iter_ids()
|
.iter_ids()
|
||||||
@@ -72,5 +77,4 @@ impl crate::Context<'_> {
|
|||||||
write!(self, "Appservices ({len}): {list}")
|
write!(self, "Appservices ({len}): {list}")
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
use conduwuit::Result;
|
use conduwuit::Result;
|
||||||
|
use conduwuit_macros::implement;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
impl Context<'_> {
|
#[implement(Context, params = "<'_>")]
|
||||||
pub(super) async fn check_all_users(&self) -> Result {
|
pub(super) async fn check_all_users(&self) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let users = self.services.users.stream().collect::<Vec<_>>().await;
|
let users = self.services.users.stream().collect::<Vec<_>>().await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -19,5 +20,4 @@ impl Context<'_> {
|
|||||||
{ok_count:?}\n```"
|
{ok_count:?}\n```"
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+152
-181
@@ -6,7 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, at, debug_error, err, info,
|
Err, Result, debug_error, err, info,
|
||||||
matrix::{
|
matrix::{
|
||||||
Event,
|
Event,
|
||||||
pdu::{PduEvent, PduId, RawPduId},
|
pdu::{PduEvent, PduId, RawPduId},
|
||||||
@@ -31,6 +31,44 @@ use service::rooms::{
|
|||||||
};
|
};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use crate::admin_command;
|
||||||
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn echo(&self, message: Vec<String>) -> Result {
|
||||||
|
let message = message.join(" ");
|
||||||
|
self.write_str(&message).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn get_auth_chain(&self, event_id: OwnedEventId) -> Result {
|
||||||
|
let Ok(event) = self.services.rooms.timeline.get_pdu_json(&event_id).await else {
|
||||||
|
return Err!("Event not found.");
|
||||||
|
};
|
||||||
|
|
||||||
|
let room_id_str = event
|
||||||
|
.get("room_id")
|
||||||
|
.and_then(CanonicalJsonValue::as_str)
|
||||||
|
.ok_or_else(|| err!(Database("Invalid event in database")))?;
|
||||||
|
|
||||||
|
let room_id = <&RoomId>::try_from(room_id_str)
|
||||||
|
.map_err(|_| err!(Database("Invalid room id field in event in database")))?;
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
let count = self
|
||||||
|
.services
|
||||||
|
.rooms
|
||||||
|
.auth_chain
|
||||||
|
.event_ids_iter(room_id, once(event_id.as_ref()))
|
||||||
|
.ready_filter_map(Result::ok)
|
||||||
|
.count()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let out = format!("Loaded auth chain with length {count} in {elapsed:?}");
|
||||||
|
|
||||||
|
self.write_str(&out).await
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
enum NodeStatus {
|
enum NodeStatus {
|
||||||
Normal(bool),
|
Normal(bool),
|
||||||
@@ -77,42 +115,8 @@ fn render_node(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn echo(&self, message: Vec<String>) -> Result {
|
pub(super) async fn show_auth_chain(&self, event_id: OwnedEventId) -> Result {
|
||||||
let message = message.join(" ");
|
|
||||||
self.write_str(&message).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) async fn get_auth_chain(&self, event_id: OwnedEventId) -> Result {
|
|
||||||
let Ok(event) = self.services.rooms.timeline.get_pdu_json(&event_id).await else {
|
|
||||||
return Err!("Event not found.");
|
|
||||||
};
|
|
||||||
|
|
||||||
let room_id_str = event
|
|
||||||
.get("room_id")
|
|
||||||
.and_then(CanonicalJsonValue::as_str)
|
|
||||||
.ok_or_else(|| err!(Database("Invalid event in database")))?;
|
|
||||||
|
|
||||||
let room_id = <&RoomId>::try_from(room_id_str)
|
|
||||||
.map_err(|_| err!(Database("Invalid room id field in event in database")))?;
|
|
||||||
|
|
||||||
let start = Instant::now();
|
|
||||||
let count = self
|
|
||||||
.services
|
|
||||||
.rooms
|
|
||||||
.auth_chain
|
|
||||||
.event_ids_iter(room_id, once(event_id.as_ref()))
|
|
||||||
.ready_filter_map(Result::ok)
|
|
||||||
.count()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let elapsed = start.elapsed();
|
|
||||||
let out = format!("Loaded auth chain with length {count} in {elapsed:?}");
|
|
||||||
|
|
||||||
self.write_str(&out).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) async fn show_auth_chain(&self, event_id: OwnedEventId) -> Result {
|
|
||||||
let node_status = async |event_id: &EventId, missing: bool| -> NodeStatus {
|
let node_status = async |event_id: &EventId, missing: bool| -> NodeStatus {
|
||||||
if self
|
if self
|
||||||
.services
|
.services
|
||||||
@@ -180,8 +184,7 @@ impl crate::Context<'_> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_node_id =
|
let current_node_id = node_id_for(¤t_event_id, &mut node_ids, &mut next_node_id);
|
||||||
node_id_for(¤t_event_id, &mut node_ids, &mut next_node_id);
|
|
||||||
let current_status = node_status(¤t_event_id, false).await;
|
let current_status = node_status(¤t_event_id, false).await;
|
||||||
|
|
||||||
render_node(
|
render_node(
|
||||||
@@ -263,9 +266,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
graph.push_str("```\n");
|
graph.push_str("```\n");
|
||||||
self.write_str(&graph).await
|
self.write_str(&graph).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn parse_pdu(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn parse_pdu(&self) -> Result {
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
|| !self.body[0].trim().starts_with("```")
|
|| !self.body[0].trim().starts_with("```")
|
||||||
|| self.body.last().unwrap_or(&EMPTY).trim() != "```"
|
|| self.body.last().unwrap_or(&EMPTY).trim() != "```"
|
||||||
@@ -283,17 +287,17 @@ impl crate::Context<'_> {
|
|||||||
| Ok(hash) => {
|
| Ok(hash) => {
|
||||||
let event_id = EventId::parse(format!("${hash}"));
|
let event_id = EventId::parse(format!("${hash}"));
|
||||||
match serde_json::from_value::<PduEvent>(serde_json::to_value(value)?) {
|
match serde_json::from_value::<PduEvent>(serde_json::to_value(value)?) {
|
||||||
| Err(e) =>
|
| Err(e) => return Err!("EventId: {event_id:?}\nCould not parse event: {e}"),
|
||||||
return Err!("EventId: {event_id:?}\nCould not parse event: {e}"),
|
|
||||||
| Ok(pdu) => write!(self, "EventId: {event_id:?}\n{pdu:#?}"),
|
| Ok(pdu) => write!(self, "EventId: {event_id:?}\n{pdu:#?}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
|
||||||
let mut outlier = false;
|
let mut outlier = false;
|
||||||
let mut pdu_json = self
|
let mut pdu_json = self
|
||||||
.services
|
.services
|
||||||
@@ -336,13 +340,14 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_short_pdu(
|
#[admin_command]
|
||||||
|
pub(super) async fn get_short_pdu(
|
||||||
&self,
|
&self,
|
||||||
shortroomid: ShortRoomId,
|
shortroomid: ShortRoomId,
|
||||||
shorteventid: ShortEventId,
|
shorteventid: ShortEventId,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let pdu_id: RawPduId = PduId {
|
let pdu_id: RawPduId = PduId {
|
||||||
shortroomid,
|
shortroomid,
|
||||||
shorteventid: shorteventid.into(),
|
shorteventid: shorteventid.into(),
|
||||||
@@ -364,13 +369,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_remote_pdu_list(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: bool) -> Result {
|
||||||
server: OwnedServerName,
|
|
||||||
force: bool,
|
|
||||||
) -> Result {
|
|
||||||
if !self.services.server.config.allow_federation {
|
if !self.services.server.config.allow_federation {
|
||||||
return Err!("Federation is disabled on this homeserver.",);
|
return Err!("Federation is disabled on this homeserver.",);
|
||||||
}
|
}
|
||||||
@@ -423,18 +425,18 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let out = format!(
|
let out =
|
||||||
"Fetched {success_count} remote PDUs successfully with {failed_count} failures"
|
format!("Fetched {success_count} remote PDUs successfully with {failed_count} failures");
|
||||||
);
|
|
||||||
|
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_remote_pdu(
|
#[admin_command]
|
||||||
|
pub(super) async fn get_remote_pdu(
|
||||||
&self,
|
&self,
|
||||||
event_id: OwnedEventId,
|
event_id: OwnedEventId,
|
||||||
server: OwnedServerName,
|
server: OwnedServerName,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if !self.services.server.config.allow_federation {
|
if !self.services.server.config.allow_federation {
|
||||||
return Err!("Federation is disabled on this homeserver.");
|
return Err!("Federation is disabled on this homeserver.");
|
||||||
}
|
}
|
||||||
@@ -457,17 +459,15 @@ impl crate::Context<'_> {
|
|||||||
{
|
{
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Remote server did not have PDU or failed sending request to remote server: \
|
"Remote server did not have PDU or failed sending request to remote server: {e}"
|
||||||
{e}"
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
| Ok(response) => {
|
| Ok(response) => {
|
||||||
let json: CanonicalJsonObject = serde_json::from_str(response.pdu.get())
|
let json: CanonicalJsonObject =
|
||||||
.map_err(|e| {
|
serde_json::from_str(response.pdu.get()).map_err(|e| {
|
||||||
warn!(
|
warn!(
|
||||||
"Requested event ID {event_id} from server but failed to convert \
|
"Requested event ID {event_id} from server but failed to convert from \
|
||||||
from RawValue to CanonicalJsonObject (malformed event/response?): \
|
RawValue to CanonicalJsonObject (malformed event/response?): {e}"
|
||||||
{e}"
|
|
||||||
);
|
);
|
||||||
err!(Request(Unknown(
|
err!(Request(Unknown(
|
||||||
"Received response from server but failed to parse PDU"
|
"Received response from server but failed to parse PDU"
|
||||||
@@ -489,9 +489,7 @@ impl crate::Context<'_> {
|
|||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!("Failed to parse PDU: {e}");
|
warn!("Failed to parse PDU: {e}");
|
||||||
info!("Full PDU: {:?}", &response.pdu);
|
info!("Full PDU: {:?}", &response.pdu);
|
||||||
return Err!(
|
return Err!("Failed to parse PDU remote server {server} sent us: {e}");
|
||||||
"Failed to parse PDU remote server {server} sent us: {e}"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -504,46 +502,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_state_at(&self, event_id: OwnedEventId) -> Result {
|
#[admin_command]
|
||||||
self.bail_restricted()?;
|
pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||||
|
|
||||||
let shortstatehash = self
|
|
||||||
.services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.pdu_shortstatehash(&event_id)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let state_ids: Vec<OwnedEventId> = self
|
|
||||||
.services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.state_full_ids(shortstatehash)
|
|
||||||
.map(at!(1))
|
|
||||||
.collect()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let pdus: Vec<CanonicalJsonObject> = state_ids
|
|
||||||
.iter()
|
|
||||||
.try_stream()
|
|
||||||
.and_then(|id| self.services.rooms.timeline.get_pdu_json(id))
|
|
||||||
.try_collect()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let json = serde_json::to_string_pretty(&pdus).map_err(|e| {
|
|
||||||
err!(Database(
|
|
||||||
"Failed to convert room state events to pretty JSON, possible invalid room \
|
|
||||||
state events in our database {e}",
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let out = format!("```json\n{json}\n```");
|
|
||||||
self.write_str(&out).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result {
|
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
||||||
@@ -562,16 +524,17 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let json = serde_json::to_string_pretty(&room_state).map_err(|e| {
|
let json = serde_json::to_string_pretty(&room_state).map_err(|e| {
|
||||||
err!(Database(
|
err!(Database(
|
||||||
"Failed to convert room state events to pretty JSON, possible invalid room \
|
"Failed to convert room state events to pretty JSON, possible invalid room state \
|
||||||
state events in our database {e}",
|
events in our database {e}",
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let out = format!("```json\n{json}\n```");
|
let out = format!("```json\n{json}\n```");
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn ping(&self, server: OwnedServerName) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn ping(&self, server: OwnedServerName) -> Result {
|
||||||
if server == self.services.globals.server_name() {
|
if server == self.services.globals.server_name() {
|
||||||
return Err!("Not allowed to send federation requests to ourselves.");
|
return Err!("Not allowed to send federation requests to ourselves.");
|
||||||
}
|
}
|
||||||
@@ -604,9 +567,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_device_list_updates(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn force_device_list_updates(&self) -> Result {
|
||||||
// Force E2EE device list updates for all users
|
// Force E2EE device list updates for all users
|
||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
@@ -615,9 +579,10 @@ impl crate::Context<'_> {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
write!(self, "Marked all devices for all users as having new keys to update").await
|
write!(self, "Marked all devices for all users as having new keys to update").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn change_log_level(&self, filter: Option<String>, reset: bool) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn change_log_level(&self, filter: Option<String>, reset: bool) -> Result {
|
||||||
let handles = &["console"];
|
let handles = &["console"];
|
||||||
|
|
||||||
if reset {
|
if reset {
|
||||||
@@ -638,8 +603,7 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
| Ok(()) => {
|
| Ok(()) => {
|
||||||
let value = &self.services.server.config.log;
|
let value = &self.services.server.config.log;
|
||||||
let out =
|
let out = format!("Successfully changed log level back to config value {value}");
|
||||||
format!("Successfully changed log level back to config value {value}");
|
|
||||||
return self.write_str(&out).await;
|
return self.write_str(&out).await;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -668,9 +632,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Err!("No log level was specified.")
|
Err!("No log level was specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn verify_json(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn verify_json(&self) -> Result {
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
|| !self.body[0].trim().starts_with("```")
|
|| !self.body[0].trim().starts_with("```")
|
||||||
|| self.body.last().unwrap_or(&"").trim() != "```"
|
|| self.body.last().unwrap_or(&"").trim() != "```"
|
||||||
@@ -694,9 +659,10 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result {
|
||||||
use ruma::signatures::Verified;
|
use ruma::signatures::Verified;
|
||||||
|
|
||||||
let mut event = self.services.rooms.timeline.get_pdu_json(&event_id).await?;
|
let mut event = self.services.rooms.timeline.get_pdu_json(&event_id).await?;
|
||||||
@@ -715,10 +681,11 @@ impl crate::Context<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.write_str(msg).await
|
self.write_str(msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "info")]
|
#[admin_command]
|
||||||
pub(super) async fn first_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
|
#[tracing::instrument(skip(self), level = "info")]
|
||||||
|
pub(super) async fn first_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if !self
|
if !self
|
||||||
@@ -728,9 +695,7 @@ impl crate::Context<'_> {
|
|||||||
.server_in_room(&self.services.server.name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!(
|
return Err!("We are not participating in the room / we don't know about the room ID.",);
|
||||||
"We are not participating in the room / we don't know about the room ID.",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let first_pdu = self
|
let first_pdu = self
|
||||||
@@ -743,10 +708,11 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let out = format!("{first_pdu:?}");
|
let out = format!("{first_pdu:?}");
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "info")]
|
#[admin_command]
|
||||||
pub(super) async fn latest_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
|
#[tracing::instrument(skip(self), level = "info")]
|
||||||
|
pub(super) async fn latest_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if !self
|
if !self
|
||||||
@@ -756,9 +722,7 @@ impl crate::Context<'_> {
|
|||||||
.server_in_room(&self.services.server.name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!(
|
return Err!("We are not participating in the room / we don't know about the room ID.");
|
||||||
"We are not participating in the room / we don't know about the room ID."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let latest_pdu = self
|
let latest_pdu = self
|
||||||
@@ -771,15 +735,16 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let out = format!("{latest_pdu:?}");
|
let out = format!("{latest_pdu:?}");
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "info")]
|
#[admin_command]
|
||||||
pub(super) async fn force_set_room_state_from_server(
|
#[tracing::instrument(skip(self), level = "info")]
|
||||||
|
pub(super) async fn force_set_room_state_from_server(
|
||||||
&self,
|
&self,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
server_name: OwnedServerName,
|
server_name: OwnedServerName,
|
||||||
at_event: Option<OwnedEventId>,
|
at_event: Option<OwnedEventId>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if !self
|
if !self
|
||||||
@@ -789,9 +754,7 @@ impl crate::Context<'_> {
|
|||||||
.server_in_room(&self.services.server.name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!(
|
return Err!("We are not participating in the room / we don't know about the room ID.");
|
||||||
"We are not participating in the room / we don't know about the room ID."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let at_event_id = match at_event {
|
let at_event_id = match at_event {
|
||||||
@@ -848,9 +811,7 @@ impl crate::Context<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let pdu = PduEvent::from_id_val(&event_id, value.clone()).map_err(|e| {
|
let pdu = PduEvent::from_id_val(&event_id, value.clone()).map_err(|e| {
|
||||||
debug_error!(
|
debug_error!("Invalid PDU in fetching remote room state PDUs response: {value:#?}");
|
||||||
"Invalid PDU in fetching remote room state PDUs response: {value:#?}"
|
|
||||||
);
|
|
||||||
err!(BadServerResponse(debug_error!("Invalid PDU in send_join response: {e:?}")))
|
err!(BadServerResponse(debug_error!("Invalid PDU in send_join response: {e:?}")))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@@ -933,14 +894,15 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str("Successfully forced the room state from the requested remote server.")
|
self.write_str("Successfully forced the room state from the requested remote server.")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_signing_keys(
|
#[admin_command]
|
||||||
|
pub(super) async fn get_signing_keys(
|
||||||
&self,
|
&self,
|
||||||
server_name: Option<OwnedServerName>,
|
server_name: Option<OwnedServerName>,
|
||||||
notary: Option<OwnedServerName>,
|
notary: Option<OwnedServerName>,
|
||||||
query: bool,
|
query: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let server_name = server_name.unwrap_or_else(|| self.services.server.name.clone());
|
let server_name = server_name.unwrap_or_else(|| self.services.server.name.clone());
|
||||||
|
|
||||||
if let Some(notary) = notary {
|
if let Some(notary) = notary {
|
||||||
@@ -968,9 +930,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let out = format!("```rs\n{signing_keys:#?}\n```");
|
let out = format!("```rs\n{signing_keys:#?}\n```");
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_verify_keys(&self, server_name: Option<OwnedServerName>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_verify_keys(&self, server_name: Option<OwnedServerName>) -> Result {
|
||||||
let server_name = server_name.unwrap_or_else(|| self.services.server.name.clone());
|
let server_name = server_name.unwrap_or_else(|| self.services.server.name.clone());
|
||||||
|
|
||||||
let keys = self
|
let keys = self
|
||||||
@@ -987,13 +950,14 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn resolve_true_destination(
|
#[admin_command]
|
||||||
|
pub(super) async fn resolve_true_destination(
|
||||||
&self,
|
&self,
|
||||||
server_name: OwnedServerName,
|
server_name: OwnedServerName,
|
||||||
no_cache: bool,
|
no_cache: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if !self.services.server.config.allow_federation {
|
if !self.services.server.config.allow_federation {
|
||||||
return Err!("Federation is disabled on this homeserver.",);
|
return Err!("Federation is disabled on this homeserver.",);
|
||||||
}
|
}
|
||||||
@@ -1013,9 +977,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let msg = format!("Destination: {}\nHostname URI: {}", actual.dest, actual.host);
|
let msg = format!("Destination: {}\nHostname URI: {}", actual.dest, actual.host);
|
||||||
self.write_str(&msg).await
|
self.write_str(&msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn memory_stats(&self, opts: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn memory_stats(&self, opts: Option<String>) -> Result {
|
||||||
const OPTS: &str = "abcdefghijklmnopqrstuvwxyz";
|
const OPTS: &str = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
let opts: String = OPTS
|
let opts: String = OPTS
|
||||||
@@ -1035,11 +1000,11 @@ impl crate::Context<'_> {
|
|||||||
self.write_str(&stats).await?;
|
self.write_str(&stats).await?;
|
||||||
self.write_str("\n```").await?;
|
self.write_str("\n```").await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(tokio_unstable)]
|
#[cfg(tokio_unstable)]
|
||||||
|
#[admin_command]
|
||||||
pub(super) async fn runtime_metrics(&self) -> Result {
|
pub(super) async fn runtime_metrics(&self) -> Result {
|
||||||
let out = self.services.server.metrics.runtime_metrics().map_or_else(
|
let out = self.services.server.metrics.runtime_metrics().map_or_else(
|
||||||
|| "Runtime metrics are not available.".to_owned(),
|
|| "Runtime metrics are not available.".to_owned(),
|
||||||
|metrics| {
|
|metrics| {
|
||||||
@@ -1053,43 +1018,47 @@ impl crate::Context<'_> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tokio_unstable))]
|
#[cfg(not(tokio_unstable))]
|
||||||
pub(super) async fn runtime_metrics(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn runtime_metrics(&self) -> Result {
|
||||||
self.write_str("Runtime metrics require building with `tokio_unstable`.")
|
self.write_str("Runtime metrics require building with `tokio_unstable`.")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(tokio_unstable)]
|
#[cfg(tokio_unstable)]
|
||||||
|
#[admin_command]
|
||||||
pub(super) async fn runtime_interval(&self) -> Result {
|
pub(super) async fn runtime_interval(&self) -> Result {
|
||||||
let out = self.services.server.metrics.runtime_interval().map_or_else(
|
let out = self.services.server.metrics.runtime_interval().map_or_else(
|
||||||
|| "Runtime metrics are not available.".to_owned(),
|
|| "Runtime metrics are not available.".to_owned(),
|
||||||
|metrics| format!("```rs\n{metrics:#?}\n```"),
|
|metrics| format!("```rs\n{metrics:#?}\n```"),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.write_str(&out).await
|
self.write_str(&out).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tokio_unstable))]
|
#[cfg(not(tokio_unstable))]
|
||||||
pub(super) async fn runtime_interval(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn runtime_interval(&self) -> Result {
|
||||||
self.write_str("Runtime metrics require building with `tokio_unstable`.")
|
self.write_str("Runtime metrics require building with `tokio_unstable`.")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn time(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn time(&self) -> Result {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let now = utils::time::format(now, "%+");
|
let now = utils::time::format(now, "%+");
|
||||||
|
|
||||||
self.write_str(&now).await
|
self.write_str(&now).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn database_stats(
|
#[admin_command]
|
||||||
|
pub(super) async fn database_stats(
|
||||||
&self,
|
&self,
|
||||||
property: Option<String>,
|
property: Option<String>,
|
||||||
map: Option<String>,
|
map: Option<String>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let map_name = map.as_ref().map_or(EMPTY, String::as_str);
|
let map_name = map.as_ref().map_or(EMPTY, String::as_str);
|
||||||
let property = property.unwrap_or_else(|| "rocksdb.stats".to_owned());
|
let property = property.unwrap_or_else(|| "rocksdb.stats".to_owned());
|
||||||
self.services
|
self.services
|
||||||
@@ -1102,9 +1071,10 @@ impl crate::Context<'_> {
|
|||||||
writeln!(self, "##### {name}:\n```\n{}\n```", res.trim())
|
writeln!(self, "##### {name}:\n```\n{}\n```", res.trim())
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn database_files(&self, map: Option<String>, level: Option<i32>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn database_files(&self, map: Option<String>, level: Option<i32>) -> Result {
|
||||||
let mut files: Vec<_> = self.services.db.db.file_list().collect::<Result<_>>()?;
|
let mut files: Vec<_> = self.services.db.db.file_list().collect::<Result<_>>()?;
|
||||||
|
|
||||||
files.sort_by_key(|f| f.name.clone());
|
files.sort_by_key(|f| f.name.clone());
|
||||||
@@ -1132,15 +1102,17 @@ impl crate::Context<'_> {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn trim_memory(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn trim_memory(&self) -> Result {
|
||||||
conduwuit::alloc::trim(None)?;
|
conduwuit::alloc::trim(None)?;
|
||||||
|
|
||||||
writeln!(self, "done").await
|
writeln!(self, "done").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn send_test_email(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn send_test_email(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
let mailer = self.services.mailer.expect_mailer()?;
|
let mailer = self.services.mailer.expect_mailer()?;
|
||||||
@@ -1165,5 +1137,4 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -95,14 +95,6 @@ pub enum DebugCommand {
|
|||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Gets all the room state events at the specified event.
|
|
||||||
///
|
|
||||||
/// State at event might not be available for some PDUs, such as rejected
|
|
||||||
/// ones.
|
|
||||||
GetStateAt {
|
|
||||||
event_id: OwnedEventId,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// Get and display signing keys from local cache or remote server.
|
/// Get and display signing keys from local cache or remote server.
|
||||||
GetSigningKeys {
|
GetSigningKeys {
|
||||||
server_name: Option<OwnedServerName>,
|
server_name: Option<OwnedServerName>,
|
||||||
|
|||||||
+21
-16
@@ -1,6 +1,6 @@
|
|||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, clap::Subcommand)]
|
#[derive(Debug, clap::Subcommand)]
|
||||||
@@ -11,32 +11,37 @@ pub enum TesterCommand {
|
|||||||
Timer,
|
Timer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[rustfmt::skip]
|
||||||
#[rustfmt::skip]
|
#[admin_command]
|
||||||
async fn panic(&self) -> Result {
|
async fn panic(&self) -> Result {
|
||||||
|
|
||||||
panic!("panicked")
|
panic!("panicked")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
#[admin_command]
|
||||||
|
async fn failure(&self) -> Result {
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
async fn failure(&self) -> Result {
|
|
||||||
Err!("failed")
|
Err!("failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
#[admin_command]
|
||||||
|
async fn tester(&self) -> Result {
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
#[rustfmt::skip]
|
|
||||||
async fn tester(&self) -> Result {
|
|
||||||
self.write_str("Ok").await
|
self.write_str("Ok").await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
async fn timer(&self) -> Result {
|
#[admin_command]
|
||||||
|
async fn timer(&self) -> Result {
|
||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
timed(self.body);
|
timed(self.body);
|
||||||
|
|
||||||
let elapsed = started.elapsed();
|
let elapsed = started.elapsed();
|
||||||
self.write_str(&format!("completed in {elapsed:#?}")).await
|
self.write_str(&format!("completed in {elapsed:#?}")).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
|||||||
@@ -4,22 +4,24 @@ use conduwuit::{Err, Result, utils::response::LimitReadExt};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{OwnedRoomId, OwnedServerName, OwnedUserId};
|
use ruma::{OwnedRoomId, OwnedServerName, OwnedUserId};
|
||||||
|
|
||||||
use crate::get_room_info;
|
use crate::{admin_command, get_room_info};
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn disable_room(&self, room_id: OwnedRoomId) -> Result {
|
pub(super) async fn disable_room(&self, room_id: OwnedRoomId) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
self.services.rooms.metadata.disable_room(&room_id, true);
|
self.services.rooms.metadata.disable_room(&room_id, true);
|
||||||
self.write_str("Room disabled.").await
|
self.write_str("Room disabled.").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn enable_room(&self, room_id: OwnedRoomId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn enable_room(&self, room_id: OwnedRoomId) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
self.services.rooms.metadata.disable_room(&room_id, false);
|
self.services.rooms.metadata.disable_room(&room_id, false);
|
||||||
self.write_str("Room enabled.").await
|
self.write_str("Room enabled.").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn incoming_federation(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn incoming_federation(&self) -> Result {
|
||||||
let msg = {
|
let msg = {
|
||||||
let map = self
|
let map = self
|
||||||
.services
|
.services
|
||||||
@@ -35,22 +37,16 @@ impl crate::Context<'_> {
|
|||||||
);
|
);
|
||||||
for (r, (e, i)) in map.iter() {
|
for (r, (e, i)) in map.iter() {
|
||||||
let elapsed = i.elapsed();
|
let elapsed = i.elapsed();
|
||||||
writeln!(
|
writeln!(msg, "{} {}: {}m{}s", r, e, elapsed.as_secs() / 60, elapsed.as_secs() % 60)?;
|
||||||
msg,
|
|
||||||
"{} {}: {}m{}s",
|
|
||||||
r,
|
|
||||||
e,
|
|
||||||
elapsed.as_secs() / 60,
|
|
||||||
elapsed.as_secs() % 60
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
msg
|
msg
|
||||||
};
|
};
|
||||||
|
|
||||||
self.write_str(&msg).await
|
self.write_str(&msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn fetch_support_well_known(&self, server_name: OwnedServerName) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn fetch_support_well_known(&self, server_name: OwnedServerName) -> Result {
|
||||||
let response = self
|
let response = self
|
||||||
.services
|
.services
|
||||||
.client
|
.client
|
||||||
@@ -95,9 +91,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Got JSON response:\n\n```json\n{pretty_json}\n```"))
|
self.write_str(&format!("Got JSON response:\n\n```json\n{pretty_json}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result {
|
||||||
if user_id.server_name() == self.services.server.name {
|
if user_id.server_name() == self.services.server.name {
|
||||||
return Err!(
|
return Err!(
|
||||||
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
||||||
@@ -130,5 +127,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
|
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+52
-54
@@ -9,14 +9,14 @@ use conduwuit_service::media::Dim;
|
|||||||
use ruma::{OwnedEventId, OwnedMxcUri, OwnedServerName};
|
use ruma::{OwnedEventId, OwnedMxcUri, OwnedServerName};
|
||||||
use service::media::mxc::Mxc;
|
use service::media::mxc::Mxc;
|
||||||
|
|
||||||
use crate::utils::parse_local_user_id;
|
use crate::{admin_command, utils::parse_local_user_id};
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn delete(
|
pub(super) async fn delete(
|
||||||
&self,
|
&self,
|
||||||
mxc: Option<OwnedMxcUri>,
|
mxc: Option<OwnedMxcUri>,
|
||||||
event_id: Option<OwnedEventId>,
|
event_id: Option<OwnedEventId>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if event_id.is_some() && mxc.is_some() {
|
if event_id.is_some() && mxc.is_some() {
|
||||||
@@ -59,8 +59,8 @@ impl crate::Context<'_> {
|
|||||||
mxc_urls.push(final_url);
|
mxc_urls.push(final_url);
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"Found a URL in the event ID {event_id} but did not \
|
"Found a URL in the event ID {event_id} but did not start \
|
||||||
start with mxc://, ignoring"
|
with mxc://, ignoring"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,29 +73,26 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
if let Some(info) = info_obj {
|
if let Some(info) = info_obj {
|
||||||
if let Some(thumbnail_url) = info.get("thumbnail_url") {
|
if let Some(thumbnail_url) = info.get("thumbnail_url") {
|
||||||
debug!(
|
debug!("Found a thumbnail_url in info key: {thumbnail_url}");
|
||||||
"Found a thumbnail_url in info key: {thumbnail_url}"
|
|
||||||
);
|
|
||||||
|
|
||||||
if thumbnail_url.to_string().starts_with("\"mxc://") {
|
if thumbnail_url.to_string().starts_with("\"mxc://") {
|
||||||
debug!(
|
debug!(
|
||||||
"Pushing thumbnail URL {thumbnail_url} to list \
|
"Pushing thumbnail URL {thumbnail_url} to list of \
|
||||||
of MXCs to delete"
|
MXCs to delete"
|
||||||
);
|
);
|
||||||
let final_thumbnail_url =
|
let final_thumbnail_url =
|
||||||
thumbnail_url.to_string().replace('"', "");
|
thumbnail_url.to_string().replace('"', "");
|
||||||
mxc_urls.push(final_thumbnail_url);
|
mxc_urls.push(final_thumbnail_url);
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"Found a thumbnail URL in the event ID \
|
"Found a thumbnail URL in the event ID {event_id} \
|
||||||
{event_id} but did not start with mxc://, \
|
but did not start with mxc://, ignoring"
|
||||||
ignoring"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"No \"thumbnail_url\" key in \"info\" key, assuming \
|
"No \"thumbnail_url\" key in \"info\" key, assuming no \
|
||||||
no thumbnails."
|
thumbnails."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,8 +114,8 @@ impl crate::Context<'_> {
|
|||||||
mxc_urls.push(final_url);
|
mxc_urls.push(final_url);
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
"Found a URL in the event ID {event_id} but did \
|
"Found a URL in the event ID {event_id} but did not \
|
||||||
not start with mxc://, ignoring"
|
start with mxc://, ignoring"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -134,8 +131,8 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Event ID does not have a \"content\" key, this is not a message or \
|
"Event ID does not have a \"content\" key, this is not a message or an \
|
||||||
an event type that contains media.",
|
event type that contains media.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -158,15 +155,11 @@ impl crate::Context<'_> {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Ok(()) => {
|
| Ok(()) => {
|
||||||
debug_info!(
|
debug_info!("Successfully deleted {mxc_url} from filesystem and database");
|
||||||
"Successfully deleted {mxc_url} from filesystem and database"
|
|
||||||
);
|
|
||||||
mxc_deletion_count = mxc_deletion_count.saturating_add(1);
|
mxc_deletion_count = mxc_deletion_count.saturating_add(1);
|
||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
debug_warn!(
|
debug_warn!("Failed to delete {mxc_url}, ignoring error and skipping: {e}");
|
||||||
"Failed to delete {mxc_url}, ignoring error and skipping: {e}"
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -174,8 +167,8 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
.write_str(&format!(
|
.write_str(&format!(
|
||||||
"Deleted {mxc_deletion_count} total MXCs from our database and the \
|
"Deleted {mxc_deletion_count} total MXCs from our database and the filesystem \
|
||||||
filesystem from event ID {event_id}."
|
from event ID {event_id}."
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -184,9 +177,10 @@ impl crate::Context<'_> {
|
|||||||
"Please specify either an MXC using --mxc or an event ID using --event-id of the \
|
"Please specify either an MXC using --mxc or an event ID using --event-id of the \
|
||||||
message containing an image. See --help for details."
|
message containing an image. See --help for details."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_list(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_list(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
@@ -230,20 +224,20 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"Finished bulk MXC deletion, deleted {mxc_deletion_count} total MXCs from our \
|
"Finished bulk MXC deletion, deleted {mxc_deletion_count} total MXCs from our database \
|
||||||
database and the filesystem. {failed_parsed_mxcs} MXCs failed to be parsed from \
|
and the filesystem. {failed_parsed_mxcs} MXCs failed to be parsed from the database.",
|
||||||
the database.",
|
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_past_remote_media(
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_past_remote_media(
|
||||||
&self,
|
&self,
|
||||||
duration: String,
|
duration: String,
|
||||||
before: bool,
|
before: bool,
|
||||||
after: bool,
|
after: bool,
|
||||||
yes_i_want_to_delete_local_media: bool,
|
yes_i_want_to_delete_local_media: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if before && after {
|
if before && after {
|
||||||
@@ -270,26 +264,27 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files."))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_all_from_user(&self, username: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_all_from_user(&self, username: String) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &username)?;
|
let user_id = parse_local_user_id(self.services, &username)?;
|
||||||
|
|
||||||
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files."))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_all_from_server(
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_all_from_server(
|
||||||
&self,
|
&self,
|
||||||
server_name: OwnedServerName,
|
server_name: OwnedServerName,
|
||||||
yes_i_want_to_delete_local_media: bool,
|
yes_i_want_to_delete_local_media: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
if server_name == self.services.globals.server_name() && !yes_i_want_to_delete_local_media
|
if server_name == self.services.globals.server_name() && !yes_i_want_to_delete_local_media {
|
||||||
{
|
|
||||||
return Err!("This command only works for remote media by default.",);
|
return Err!("This command only works for remote media by default.",);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,21 +333,23 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files."))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_file_info(&self, mxc: OwnedMxcUri) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_file_info(&self, mxc: OwnedMxcUri) -> Result {
|
||||||
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
||||||
let metadata = self.services.media.get_metadata(&mxc).await;
|
let metadata = self.services.media.get_metadata(&mxc).await;
|
||||||
|
|
||||||
self.write_str(&format!("```\n{metadata:#?}\n```")).await
|
self.write_str(&format!("```\n{metadata:#?}\n```")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_remote_file(
|
#[admin_command]
|
||||||
|
pub(super) async fn get_remote_file(
|
||||||
&self,
|
&self,
|
||||||
mxc: OwnedMxcUri,
|
mxc: OwnedMxcUri,
|
||||||
server: Option<OwnedServerName>,
|
server: Option<OwnedServerName>,
|
||||||
timeout: u32,
|
timeout: u32,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
||||||
let timeout = Duration::from_millis(timeout.into());
|
let timeout = Duration::from_millis(timeout.into());
|
||||||
let mut result = self
|
let mut result = self
|
||||||
@@ -367,16 +364,17 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("```\n{result:#?}\nreceived {len} bytes for file content.\n```"))
|
self.write_str(&format!("```\n{result:#?}\nreceived {len} bytes for file content.\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_remote_thumbnail(
|
#[admin_command]
|
||||||
|
pub(super) async fn get_remote_thumbnail(
|
||||||
&self,
|
&self,
|
||||||
mxc: OwnedMxcUri,
|
mxc: OwnedMxcUri,
|
||||||
server: Option<OwnedServerName>,
|
server: Option<OwnedServerName>,
|
||||||
timeout: u32,
|
timeout: u32,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
let mxc: Mxc<'_> = mxc.as_str().try_into()?;
|
||||||
let timeout = Duration::from_millis(timeout.into());
|
let timeout = Duration::from_millis(timeout.into());
|
||||||
let dim = Dim::new(width, height, None);
|
let dim = Dim::new(width, height, None);
|
||||||
@@ -392,9 +390,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("```\n{result:#?}\nreceived {len} bytes for file content.\n```"))
|
self.write_str(&format!("```\n{result:#?}\nreceived {len} bytes for file content.\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_url_preview(&self, url: Option<String>, all: bool) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_url_preview(&self, url: Option<String>, all: bool) -> Result {
|
||||||
if all {
|
if all {
|
||||||
self.services.media.clear_url_previews().await;
|
self.services.media.clear_url_previews().await;
|
||||||
|
|
||||||
@@ -407,5 +406,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Deleted cached URL preview for: {url}"))
|
self.write_str(&format!("Deleted cached URL preview for: {url}"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -26,7 +26,7 @@ extern crate conduwuit_api as api;
|
|||||||
extern crate conduwuit_core as conduwuit;
|
extern crate conduwuit_core as conduwuit;
|
||||||
extern crate conduwuit_service as service;
|
extern crate conduwuit_service as service;
|
||||||
|
|
||||||
pub(crate) use conduwuit_macros::admin_command_dispatch;
|
pub(crate) use conduwuit_macros::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
pub(crate) use crate::{context::Context, utils::get_room_info};
|
pub(crate) use crate::{context::Context, utils::get_room_info};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use conduwuit_database::Deserialized as _;
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{OwnedRoomId, OwnedUserId, exports::serde::Serialize};
|
use ruma::{OwnedRoomId, OwnedUserId, exports::serde::Serialize};
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -31,13 +31,13 @@ pub enum AccountDataCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
async fn changes_since(
|
async fn changes_since(
|
||||||
&self,
|
&self,
|
||||||
user_id: OwnedUserId,
|
user_id: OwnedUserId,
|
||||||
since: u64,
|
since: u64,
|
||||||
room_id: Option<OwnedRoomId>,
|
room_id: Option<OwnedRoomId>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let results: Vec<_> = self
|
let results: Vec<_> = self
|
||||||
.services
|
.services
|
||||||
@@ -49,14 +49,15 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn account_data_get(
|
#[admin_command]
|
||||||
|
async fn account_data_get(
|
||||||
&self,
|
&self,
|
||||||
user_id: OwnedUserId,
|
user_id: OwnedUserId,
|
||||||
kind: String,
|
kind: String,
|
||||||
room_id: Option<OwnedRoomId>,
|
room_id: Option<OwnedRoomId>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -76,5 +77,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{json}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{json}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+43
-51
@@ -13,7 +13,7 @@ use conduwuit_service::Services;
|
|||||||
use futures::{FutureExt, Stream, StreamExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryStreamExt};
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -159,8 +159,8 @@ pub enum RawCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn compact(
|
pub(super) async fn compact(
|
||||||
&self,
|
&self,
|
||||||
map: Option<Vec<String>>,
|
map: Option<Vec<String>>,
|
||||||
start: Option<String>,
|
start: Option<String>,
|
||||||
@@ -169,7 +169,7 @@ impl crate::Context<'_> {
|
|||||||
into: Option<usize>,
|
into: Option<usize>,
|
||||||
parallelism: Option<usize>,
|
parallelism: Option<usize>,
|
||||||
exhaustive: bool,
|
exhaustive: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
use conduwuit_database::compact::Options;
|
use conduwuit_database::compact::Options;
|
||||||
|
|
||||||
let default_all_maps: Option<_> = map.is_none().then(|| {
|
let default_all_maps: Option<_> = map.is_none().then(|| {
|
||||||
@@ -221,9 +221,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("Jobs completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
|
self.write_str(&format!("Jobs completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_count(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_count(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
||||||
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
||||||
|
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
@@ -235,9 +236,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{count:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{count:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_keys(&self, map: String, prefix: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_keys(&self, map: String, prefix: Option<String>) -> Result {
|
||||||
writeln!(self, "```").boxed().await?;
|
writeln!(self, "```").boxed().await?;
|
||||||
|
|
||||||
let map = self.services.db.get(map.as_str())?;
|
let map = self.services.db.get(map.as_str())?;
|
||||||
@@ -253,13 +255,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_keys_sizes(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn raw_keys_sizes(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
||||||
map: Option<String>,
|
|
||||||
prefix: Option<String>,
|
|
||||||
) -> Result {
|
|
||||||
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
||||||
|
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
@@ -278,13 +277,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("```\n{result:#?}\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("```\n{result:#?}\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_keys_total(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn raw_keys_total(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
||||||
map: Option<String>,
|
|
||||||
prefix: Option<String>,
|
|
||||||
) -> Result {
|
|
||||||
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
||||||
|
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
@@ -299,13 +295,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("```\n{result:#?}\n\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("```\n{result:#?}\n\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_vals_sizes(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn raw_vals_sizes(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
||||||
map: Option<String>,
|
|
||||||
prefix: Option<String>,
|
|
||||||
) -> Result {
|
|
||||||
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
||||||
|
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
@@ -325,13 +318,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("```\n{result:#?}\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("```\n{result:#?}\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_vals_total(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn raw_vals_total(&self, map: Option<String>, prefix: Option<String>) -> Result {
|
||||||
map: Option<String>,
|
|
||||||
prefix: Option<String>,
|
|
||||||
) -> Result {
|
|
||||||
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
let prefix = prefix.as_deref().unwrap_or(EMPTY);
|
||||||
|
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
@@ -347,19 +337,17 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("```\n{result:#?}\n\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("```\n{result:#?}\n\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_iter(&self, map: String, prefix: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_iter(&self, map: String, prefix: Option<String>) -> Result {
|
||||||
writeln!(self, "```").await?;
|
writeln!(self, "```").await?;
|
||||||
|
|
||||||
let map = self.services.db.get(&map)?;
|
let map = self.services.db.get(&map)?;
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
prefix
|
prefix
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map_or_else(
|
.map_or_else(|| map.raw_stream().boxed(), |prefix| map.raw_stream_prefix(prefix).boxed())
|
||||||
|| map.raw_stream().boxed(),
|
|
||||||
|prefix| map.raw_stream_prefix(prefix).boxed(),
|
|
||||||
)
|
|
||||||
.map_ok(apply!(2, String::from_utf8_lossy))
|
.map_ok(apply!(2, String::from_utf8_lossy))
|
||||||
.map_ok(apply!(2, Cow::into_owned))
|
.map_ok(apply!(2, Cow::into_owned))
|
||||||
.try_for_each(|keyval| writeln!(self, "{keyval:?}"))
|
.try_for_each(|keyval| writeln!(self, "{keyval:?}"))
|
||||||
@@ -369,14 +357,15 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_keys_from(
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_keys_from(
|
||||||
&self,
|
&self,
|
||||||
map: String,
|
map: String,
|
||||||
start: String,
|
start: String,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
writeln!(self, "```").await?;
|
writeln!(self, "```").await?;
|
||||||
|
|
||||||
let map = self.services.db.get(&map)?;
|
let map = self.services.db.get(&map)?;
|
||||||
@@ -391,14 +380,15 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
self.write_str(&format!("\n```\n\nQuery completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_iter_from(
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_iter_from(
|
||||||
&self,
|
&self,
|
||||||
map: String,
|
map: String,
|
||||||
start: String,
|
start: String,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let map = self.services.db.get(&map)?;
|
let map = self.services.db.get(&map)?;
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
let result = map
|
let result = map
|
||||||
@@ -412,9 +402,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_del(&self, map: String, key: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_del(&self, map: String, key: String) -> Result {
|
||||||
let map = self.services.db.get(&map)?;
|
let map = self.services.db.get(&map)?;
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
map.remove(&key);
|
map.remove(&key);
|
||||||
@@ -422,9 +413,10 @@ impl crate::Context<'_> {
|
|||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
self.write_str(&format!("Operation completed in {query_time:?}"))
|
self.write_str(&format!("Operation completed in {query_time:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_get(&self, map: String, key: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_get(&self, map: String, key: String) -> Result {
|
||||||
let map = self.services.db.get(&map)?;
|
let map = self.services.db.get(&map)?;
|
||||||
let timer = Instant::now();
|
let timer = Instant::now();
|
||||||
let handle = map.get(&key).await?;
|
let handle = map.get(&key).await?;
|
||||||
@@ -433,13 +425,13 @@ impl crate::Context<'_> {
|
|||||||
let result = String::from_utf8_lossy(&handle);
|
let result = String::from_utf8_lossy(&handle);
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn raw_maps(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn raw_maps(&self) -> Result {
|
||||||
let list: Vec<_> = self.services.db.iter().map(at!(0)).copied().collect();
|
let list: Vec<_> = self.services.db.iter().map(at!(0)).copied().collect();
|
||||||
|
|
||||||
self.write_str(&format!("{list:#?}")).await
|
self.write_str(&format!("{list:#?}")).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_maps_or<'a>(
|
fn with_maps_or<'a>(
|
||||||
|
|||||||
+10
-11
@@ -3,7 +3,7 @@ use conduwuit::{Err, Result, utils::time};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::OwnedServerName;
|
use ruma::OwnedServerName;
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -39,8 +39,8 @@ pub enum ResolverCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
async fn destinations_cache(&self, server_name: Option<OwnedServerName>) -> Result {
|
async fn destinations_cache(&self, server_name: Option<OwnedServerName>) -> Result {
|
||||||
use service::resolver::cache::CachedDest;
|
use service::resolver::cache::CachedDest;
|
||||||
|
|
||||||
writeln!(self, "| Server Name | Destination | Hostname | Expires |").await?;
|
writeln!(self, "| Server Name | Destination | Hostname | Expires |").await?;
|
||||||
@@ -61,9 +61,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn overrides_cache(&self, server_name: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
async fn overrides_cache(&self, server_name: Option<String>) -> Result {
|
||||||
use service::resolver::cache::CachedOverride;
|
use service::resolver::cache::CachedOverride;
|
||||||
|
|
||||||
writeln!(self, "| Server Name | IP | Port | Expires | Overriding |").await?;
|
writeln!(self, "| Server Name | IP | Port | Expires | Overriding |").await?;
|
||||||
@@ -81,16 +82,15 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let expire = time::format(expire, "%+");
|
let expire = time::format(expire, "%+");
|
||||||
self.write_str(&format!(
|
self.write_str(&format!("| {name} | {ips:?} | {port} | {expire} | {overriding:?} |\n"))
|
||||||
"| {name} | {ips:?} | {port} | {expire} | {overriding:?} |\n"
|
|
||||||
))
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn flush_cache(&self, name: Option<OwnedServerName>, all: bool) -> Result {
|
#[admin_command]
|
||||||
|
async fn flush_cache(&self, name: Option<OwnedServerName>, all: bool) -> Result {
|
||||||
if all {
|
if all {
|
||||||
self.services.resolver.cache.clear().await;
|
self.services.resolver.cache.clear().await;
|
||||||
writeln!(self, "Resolver caches cleared!").await
|
writeln!(self, "Resolver caches cleared!").await
|
||||||
@@ -102,5 +102,4 @@ impl crate::Context<'_> {
|
|||||||
} else {
|
} else {
|
||||||
Err!("Missing name. Supply a name or use --all to flush the whole cache.")
|
Err!("Missing name. Supply a name or use --all to flush the whole cache.")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ use conduwuit::{PduCount, Result, utils::stream::TryTools};
|
|||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use ruma::OwnedRoomOrAliasId;
|
use ruma::OwnedRoomOrAliasId;
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -23,8 +23,8 @@ pub enum RoomTimelineCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn last(&self, room_id: OwnedRoomOrAliasId) -> Result {
|
pub(super) async fn last(&self, room_id: OwnedRoomOrAliasId) -> Result {
|
||||||
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
||||||
|
|
||||||
let result = self
|
let result = self
|
||||||
@@ -35,14 +35,15 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{result:#?}")).await
|
self.write_str(&format!("{result:#?}")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn pdus(
|
#[admin_command]
|
||||||
|
pub(super) async fn pdus(
|
||||||
&self,
|
&self,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
from: Option<String>,
|
from: Option<String>,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
||||||
|
|
||||||
let from: Option<PduCount> = from.as_deref().map(str::parse).transpose()?;
|
let from: Option<PduCount> = from.as_deref().map(str::parse).transpose()?;
|
||||||
@@ -57,5 +58,4 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("```\n{result:#?}\n```")).await
|
self.write_str(&format!("```\n{result:#?}\n```")).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ use clap::Subcommand;
|
|||||||
use conduwuit::Result;
|
use conduwuit::Result;
|
||||||
use ruma::{OwnedEventId, OwnedRoomOrAliasId};
|
use ruma::{OwnedEventId, OwnedRoomOrAliasId};
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -17,8 +17,8 @@ pub enum ShortCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn short_event_id(&self, event_id: OwnedEventId) -> Result {
|
pub(super) async fn short_event_id(&self, event_id: OwnedEventId) -> Result {
|
||||||
let shortid = self
|
let shortid = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -27,13 +27,13 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{shortid:#?}")).await
|
self.write_str(&format!("{shortid:#?}")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn short_room_id(&self, room_id: OwnedRoomOrAliasId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn short_room_id(&self, room_id: OwnedRoomOrAliasId) -> Result {
|
||||||
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
||||||
|
|
||||||
let shortid = self.services.rooms.short.get_shortroomid(&room_id).await?;
|
let shortid = self.services.rooms.short.get_shortroomid(&room_id).await?;
|
||||||
|
|
||||||
self.write_str(&format!("{shortid:#?}")).await
|
self.write_str(&format!("{shortid:#?}")).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+60
-56
@@ -3,7 +3,7 @@ use conduwuit::Result;
|
|||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use ruma::{OwnedDeviceId, OwnedRoomId, OwnedUserId};
|
use ruma::{OwnedDeviceId, OwnedRoomId, OwnedUserId};
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -92,8 +92,8 @@ pub enum UsersCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
async fn get_shared_rooms(&self, user_a: OwnedUserId, user_b: OwnedUserId) -> Result {
|
async fn get_shared_rooms(&self, user_a: OwnedUserId, user_b: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result: Vec<_> = self
|
let result: Vec<_> = self
|
||||||
.services
|
.services
|
||||||
@@ -106,15 +106,16 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_backup_session(
|
#[admin_command]
|
||||||
|
async fn get_backup_session(
|
||||||
&self,
|
&self,
|
||||||
user_id: OwnedUserId,
|
user_id: OwnedUserId,
|
||||||
version: String,
|
version: String,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
session_id: String,
|
session_id: String,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -125,14 +126,15 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_room_backups(
|
#[admin_command]
|
||||||
|
async fn get_room_backups(
|
||||||
&self,
|
&self,
|
||||||
user_id: OwnedUserId,
|
user_id: OwnedUserId,
|
||||||
version: String,
|
version: String,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -143,18 +145,20 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_all_backups(&self, user_id: OwnedUserId, version: String) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_all_backups(&self, user_id: OwnedUserId, version: String) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self.services.key_backups.get_all(&user_id, &version).await;
|
let result = self.services.key_backups.get_all(&user_id, &version).await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_backup_algorithm(&self, user_id: OwnedUserId, version: String) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_backup_algorithm(&self, user_id: OwnedUserId, version: String) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -165,9 +169,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_latest_backup_version(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_latest_backup_version(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -178,29 +183,31 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_latest_backup(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_latest_backup(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self.services.key_backups.get_latest_backup(&user_id).await;
|
let result = self.services.key_backups.get_latest_backup(&user_id).await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn iter_users(&self) -> Result {
|
#[admin_command]
|
||||||
|
async fn iter_users(&self) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result: Vec<OwnedUserId> =
|
let result: Vec<OwnedUserId> = self.services.users.stream().map(Into::into).collect().await;
|
||||||
self.services.users.stream().map(Into::into).collect().await;
|
|
||||||
|
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn iter_users2(&self) -> Result {
|
#[admin_command]
|
||||||
|
async fn iter_users2(&self) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result: Vec<_> = self.services.users.stream().collect().await;
|
let result: Vec<_> = self.services.users.stream().collect().await;
|
||||||
let result: Vec<_> = result
|
let result: Vec<_> = result
|
||||||
@@ -212,18 +219,20 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn count_users(&self) -> Result {
|
#[admin_command]
|
||||||
|
async fn count_users(&self) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self.services.users.count().await;
|
let result = self.services.users.count().await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_devices(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn list_devices(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let devices = self
|
let devices = self
|
||||||
.services
|
.services
|
||||||
@@ -236,9 +245,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{devices:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{devices:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_devices_metadata(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn list_devices_metadata(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let devices = self
|
let devices = self
|
||||||
.services
|
.services
|
||||||
@@ -250,13 +260,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{devices:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{devices:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_device_metadata(
|
#[admin_command]
|
||||||
&self,
|
async fn get_device_metadata(&self, user_id: OwnedUserId, device_id: OwnedDeviceId) -> Result {
|
||||||
user_id: OwnedUserId,
|
|
||||||
device_id: OwnedDeviceId,
|
|
||||||
) -> Result {
|
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let device = self
|
let device = self
|
||||||
.services
|
.services
|
||||||
@@ -267,22 +274,20 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{device:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{device:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_devices_version(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_devices_version(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let device = self.services.users.get_devicelist_version(&user_id).await;
|
let device = self.services.users.get_devicelist_version(&user_id).await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{device:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{device:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn count_one_time_keys(
|
#[admin_command]
|
||||||
&self,
|
async fn count_one_time_keys(&self, user_id: OwnedUserId, device_id: OwnedDeviceId) -> Result {
|
||||||
user_id: OwnedUserId,
|
|
||||||
device_id: OwnedDeviceId,
|
|
||||||
) -> Result {
|
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -293,9 +298,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_device_keys(&self, user_id: OwnedUserId, device_id: OwnedDeviceId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_device_keys(&self, user_id: OwnedUserId, device_id: OwnedDeviceId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -306,18 +312,20 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_signing_key(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_user_signing_key(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self.services.users.get_user_signing_key(&user_id).await;
|
let result = self.services.users.get_user_signing_key(&user_id).await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_master_key(&self, user_id: OwnedUserId) -> Result {
|
#[admin_command]
|
||||||
|
async fn get_master_key(&self, user_id: OwnedUserId) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -328,13 +336,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_to_device_events(
|
#[admin_command]
|
||||||
&self,
|
async fn get_to_device_events(&self, user_id: OwnedUserId, device_id: OwnedDeviceId) -> Result {
|
||||||
user_id: OwnedUserId,
|
|
||||||
device_id: OwnedDeviceId,
|
|
||||||
) -> Result {
|
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let result = self
|
let result = self
|
||||||
.services
|
.services
|
||||||
@@ -346,5 +351,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{result:#?}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,18 @@ use conduwuit::{Err, Result};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::OwnedRoomId;
|
use ruma::OwnedRoomId;
|
||||||
|
|
||||||
use crate::{PAGE_SIZE, get_room_info};
|
use crate::{PAGE_SIZE, admin_command, get_room_info};
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[allow(clippy::fn_params_excessive_bools)]
|
||||||
#[allow(clippy::fn_params_excessive_bools)]
|
#[admin_command]
|
||||||
pub(super) async fn list_rooms(
|
pub(super) async fn list_rooms(
|
||||||
&self,
|
&self,
|
||||||
page: Option<usize>,
|
page: Option<usize>,
|
||||||
exclude_disabled: bool,
|
exclude_disabled: bool,
|
||||||
exclude_banned: bool,
|
exclude_banned: bool,
|
||||||
include_empty: bool,
|
include_empty: bool,
|
||||||
no_details: bool,
|
no_details: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
// TODO: i know there's a way to do this with clap, but i can't seem to find it
|
// TODO: i know there's a way to do this with clap, but i can't seem to find it
|
||||||
let page = page.unwrap_or(1);
|
let page = page.unwrap_or(1);
|
||||||
let mut rooms = self
|
let mut rooms = self
|
||||||
@@ -74,11 +74,11 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len()))
|
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn exists(&self, room_id: OwnedRoomId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn exists(&self, room_id: OwnedRoomId) -> Result {
|
||||||
let result = self.services.rooms.metadata.exists(&room_id).await;
|
let result = self.services.rooms.metadata.exists(&room_id).await;
|
||||||
|
|
||||||
self.write_str(&format!("{result}")).await
|
self.write_str(&format!("{result}")).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ use conduwuit::{Err, Result, utils::ReadyExt};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::OwnedRoomId;
|
use ruma::OwnedRoomId;
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::{admin_command, admin_command_dispatch};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -26,8 +26,8 @@ pub enum RoomInfoCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> Result {
|
async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> Result {
|
||||||
let room_name = self
|
let room_name = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -68,9 +68,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```"))
|
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn view_room_topic(&self, room_id: OwnedRoomId) -> Result {
|
#[admin_command]
|
||||||
|
async fn view_room_topic(&self, room_id: OwnedRoomId) -> Result {
|
||||||
let Ok(room_topic) = self
|
let Ok(room_topic) = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -83,5 +84,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Room topic:\n```\n{room_topic}\n```"))
|
self.write_str(&format!("Room topic:\n```\n{room_topic}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ use conduwuit::{
|
|||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use ruma::{OwnedRoomId, OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId};
|
use ruma::{OwnedRoomId, OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId};
|
||||||
|
|
||||||
use crate::{admin_command_dispatch, get_room_info};
|
use crate::{admin_command, admin_command_dispatch, get_room_info};
|
||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
@@ -45,8 +45,8 @@ pub enum RoomModerationCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||||
debug!("Got room alias or ID: {}", room);
|
debug!("Got room alias or ID: {}", room);
|
||||||
|
|
||||||
let admin_room_alias = &self.services.globals.admin_alias;
|
let admin_room_alias = &self.services.globals.admin_alias;
|
||||||
@@ -62,8 +62,8 @@ impl crate::Context<'_> {
|
|||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Failed to parse room ID {room}. Please note that this requires a full \
|
"Failed to parse room ID {room}. Please note that this requires a full room \
|
||||||
room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`): {e}"
|
(`#roomalias:example.com`): {e}"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -77,8 +77,8 @@ impl crate::Context<'_> {
|
|||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Failed to parse room ID {room}. Please note that this requires a full \
|
"Failed to parse room ID {room}. Please note that this requires a full room \
|
||||||
room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`): {e}"
|
(`#roomalias:example.com`): {e}"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -104,8 +104,8 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Room specified is not a room ID or room alias. Please note that this requires \
|
"Room specified is not a room ID or room alias. Please note that this requires a \
|
||||||
a full room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
full room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`)",
|
(`#roomalias:example.com`)",
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -154,13 +154,13 @@ impl crate::Context<'_> {
|
|||||||
self.services.rooms.metadata.disable_room(&room_id, true); // disable federation
|
self.services.rooms.metadata.disable_room(&room_id, true); // disable federation
|
||||||
|
|
||||||
self.write_str(
|
self.write_str(
|
||||||
"Room banned, removed all our local users, and disabled incoming federation with \
|
"Room banned, removed all our local users, and disabled incoming federation with room.",
|
||||||
room.",
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ban_list_of_rooms(&self) -> Result {
|
#[admin_command]
|
||||||
|
async fn ban_list_of_rooms(&self) -> Result {
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
|| !self.body[0].trim().starts_with("```")
|
|| !self.body[0].trim().starts_with("```")
|
||||||
|| self.body.last().unwrap_or(&"").trim() != "```"
|
|| self.body.last().unwrap_or(&"").trim() != "```"
|
||||||
@@ -183,8 +183,7 @@ impl crate::Context<'_> {
|
|||||||
match <&RoomOrAliasId>::try_from(room) {
|
match <&RoomOrAliasId>::try_from(room) {
|
||||||
| Ok(room_alias_or_id) => {
|
| Ok(room_alias_or_id) => {
|
||||||
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await {
|
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await {
|
||||||
if room.to_owned().eq(&admin_room_id)
|
if room.to_owned().eq(&admin_room_id) || room.to_owned().eq(admin_room_alias)
|
||||||
|| room.to_owned().eq(admin_room_alias)
|
|
||||||
{
|
{
|
||||||
warn!("User specified admin room in bulk ban list, ignoring");
|
warn!("User specified admin room in bulk ban list, ignoring");
|
||||||
continue;
|
continue;
|
||||||
@@ -220,9 +219,8 @@ impl crate::Context<'_> {
|
|||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
| _ => {
|
| _ => {
|
||||||
debug!(
|
debug!(
|
||||||
"We don't have this room alias to a room ID \
|
"We don't have this room alias to a room ID locally, \
|
||||||
locally, attempting to fetch room ID over \
|
attempting to fetch room ID over federation"
|
||||||
federation"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
match self
|
match self
|
||||||
@@ -243,8 +241,8 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!(
|
warn!(
|
||||||
"Failed to resolve room alias {room} to a \
|
"Failed to resolve room alias {room} to a room \
|
||||||
room ID: {e}"
|
ID: {e}"
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
@@ -266,8 +264,8 @@ impl crate::Context<'_> {
|
|||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!(
|
warn!(
|
||||||
"Error parsing room \"{room}\" during bulk room banning, ignoring error \
|
"Error parsing room \"{room}\" during bulk room banning, ignoring error and \
|
||||||
and logging here: {e}"
|
logging here: {e}"
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
@@ -289,8 +287,8 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
while let Some(ref user_id) = users.next().await {
|
while let Some(ref user_id) = users.next().await {
|
||||||
debug!(
|
debug!(
|
||||||
"Attempting leave for user {user_id} in room {room_id} (ignoring all \
|
"Attempting leave for user {user_id} in room {room_id} (ignoring all errors, \
|
||||||
errors, evicting admins too)",
|
evicting admins too)",
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = leave_room(self.services, user_id, &room_id, None)
|
if let Err(e) = leave_room(self.services, user_id, &room_id, None)
|
||||||
@@ -325,20 +323,21 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"Finished bulk room ban, banned {room_ban_count} total rooms, evicted all users, \
|
"Finished bulk room ban, banned {room_ban_count} total rooms, evicted all users, and \
|
||||||
and disabled incoming federation with the room."
|
disabled incoming federation with the room."
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
#[admin_command]
|
||||||
|
async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||||
let room_id = if room.is_room_id() {
|
let room_id = if room.is_room_id() {
|
||||||
let room_id = match RoomId::parse(&room) {
|
let room_id = match RoomId::parse(&room) {
|
||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Failed to parse room ID {room}. Please note that this requires a full \
|
"Failed to parse room ID {room}. Please note that this requires a full room \
|
||||||
room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`): {e}"
|
(`#roomalias:example.com`): {e}"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -353,8 +352,8 @@ impl crate::Context<'_> {
|
|||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Failed to parse room ID {room}. Please note that this requires a full \
|
"Failed to parse room ID {room}. Please note that this requires a full room \
|
||||||
room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`): {e}"
|
(`#roomalias:example.com`): {e}"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -375,8 +374,8 @@ impl crate::Context<'_> {
|
|||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
| _ => {
|
| _ => {
|
||||||
debug!(
|
debug!(
|
||||||
"We don't have this room alias to a room ID locally, attempting to \
|
"We don't have this room alias to a room ID locally, attempting to fetch \
|
||||||
fetch room ID over federation"
|
room ID over federation"
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.services.rooms.alias.resolve_alias(&room_alias).await {
|
match self.services.rooms.alias.resolve_alias(&room_alias).await {
|
||||||
@@ -400,8 +399,8 @@ impl crate::Context<'_> {
|
|||||||
room_id
|
room_id
|
||||||
} else {
|
} else {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Room specified is not a room ID or room alias. Please note that this requires \
|
"Room specified is not a room ID or room alias. Please note that this requires a \
|
||||||
a full room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
full room ID (`!awIh6gGInaS5wLQJwa:example.com`) or a room alias \
|
||||||
(`#roomalias:example.com`)",
|
(`#roomalias:example.com`)",
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -409,9 +408,10 @@ impl crate::Context<'_> {
|
|||||||
self.services.rooms.metadata.disable_room(&room_id, false);
|
self.services.rooms.metadata.disable_room(&room_id, false);
|
||||||
self.write_str("Room unbanned and federation re-enabled.")
|
self.write_str("Room unbanned and federation re-enabled.")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_banned_rooms(&self, no_details: bool) -> Result {
|
#[admin_command]
|
||||||
|
async fn list_banned_rooms(&self, no_details: bool) -> Result {
|
||||||
let room_ids: Vec<OwnedRoomId> = self
|
let room_ids: Vec<OwnedRoomId> = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -451,5 +451,4 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```"))
|
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,10 @@ use conduwuit::{
|
|||||||
};
|
};
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
use crate::admin_command;
|
||||||
pub(super) async fn uptime(&self) -> Result {
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn uptime(&self) -> Result {
|
||||||
let elapsed = self
|
let elapsed = self
|
||||||
.services
|
.services
|
||||||
.server
|
.server
|
||||||
@@ -18,16 +20,18 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
let result = time::pretty(elapsed);
|
let result = time::pretty(elapsed);
|
||||||
self.write_str(&format!("{result}.")).await
|
self.write_str(&format!("{result}.")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn show_config(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn show_config(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
self.write_str(&format!("{}", *self.services.server.config))
|
self.write_str(&format!("{}", *self.services.server.config))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn reload_config(&self, path: Option<PathBuf>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn reload_config(&self, path: Option<PathBuf>) -> Result {
|
||||||
// The path argument is only what's optionally passed via the admin command,
|
// The path argument is only what's optionally passed via the admin command,
|
||||||
// so we need to merge it with the existing paths if any were given at startup.
|
// so we need to merge it with the existing paths if any were given at startup.
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
@@ -53,27 +57,30 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Successfully reconfigured from paths: {paths:?}"))
|
self.write_str(&format!("Successfully reconfigured from paths: {paths:?}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn memory_usage(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn memory_usage(&self) -> Result {
|
||||||
let services_usage = self.services.memory_usage().await?;
|
let services_usage = self.services.memory_usage().await?;
|
||||||
let database_usage = self.services.db.db.memory_usage()?;
|
let database_usage = self.services.db.db.memory_usage()?;
|
||||||
let allocator_usage = conduwuit::alloc::memory_usage()
|
let allocator_usage =
|
||||||
.map_or(String::new(), |s| format!("\nAllocator:\n{s}"));
|
conduwuit::alloc::memory_usage().map_or(String::new(), |s| format!("\nAllocator:\n{s}"));
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"Services:\n{services_usage}\nDatabase:\n{database_usage}{allocator_usage}",
|
"Services:\n{services_usage}\nDatabase:\n{database_usage}{allocator_usage}",
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn clear_caches(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn clear_caches(&self) -> Result {
|
||||||
self.services.clear_cache().await;
|
self.services.clear_cache().await;
|
||||||
|
|
||||||
self.write_str("Done.").await
|
self.write_str("Done.").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_backups(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_backups(&self) -> Result {
|
||||||
self.services
|
self.services
|
||||||
.db
|
.db
|
||||||
.db
|
.db
|
||||||
@@ -81,9 +88,10 @@ impl crate::Context<'_> {
|
|||||||
.try_stream()
|
.try_stream()
|
||||||
.try_for_each(|result| writeln!(self, "{result}"))
|
.try_for_each(|result| writeln!(self, "{result}"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn backup_database(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn backup_database(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
let db = Arc::clone(&self.services.db);
|
let db = Arc::clone(&self.services.db);
|
||||||
@@ -100,49 +108,54 @@ impl crate::Context<'_> {
|
|||||||
let count = self.services.db.db.backup_count()?;
|
let count = self.services.db.db.backup_count()?;
|
||||||
self.write_str(&format!("{result}. Currently have {count} backups."))
|
self.write_str(&format!("{result}. Currently have {count} backups."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn admin_notice(&self, message: Vec<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn admin_notice(&self, message: Vec<String>) -> Result {
|
||||||
let message = message.join(" ");
|
let message = message.join(" ");
|
||||||
self.services.admin.send_text(&message).await;
|
self.services.admin.send_text(&message).await;
|
||||||
|
|
||||||
self.write_str("Notice was sent to #admins").await
|
self.write_str("Notice was sent to #admins").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn reload_mods(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn reload_mods(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
self.services.server.reload()?;
|
self.services.server.reload()?;
|
||||||
|
|
||||||
self.write_str("Reloading server...").await
|
self.write_str("Reloading server...").await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[admin_command]
|
||||||
pub(super) async fn restart(&self, force: bool) -> Result {
|
#[cfg(unix)]
|
||||||
|
pub(super) async fn restart(&self, force: bool) -> Result {
|
||||||
use conduwuit::utils::sys::current_exe_deleted;
|
use conduwuit::utils::sys::current_exe_deleted;
|
||||||
|
|
||||||
if !force && current_exe_deleted() {
|
if !force && current_exe_deleted() {
|
||||||
return Err!(
|
return Err!(
|
||||||
"The server cannot be restarted because the executable changed. If this is \
|
"The server cannot be restarted because the executable changed. If this is expected \
|
||||||
expected use --force to override."
|
use --force to override."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.services.server.restart()?;
|
self.services.server.restart()?;
|
||||||
|
|
||||||
self.write_str("Restarting server...").await
|
self.write_str("Restarting server...").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn shutdown(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn shutdown(&self) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
warn!("shutdown command");
|
warn!("shutdown command");
|
||||||
self.services.server.shutdown()?;
|
self.services.server.shutdown()?;
|
||||||
|
|
||||||
self.write_str("Shutting down server...").await
|
self.write_str("Shutting down server...").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_features(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_features(&self) -> Result {
|
||||||
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
@@ -171,9 +184,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&features).await
|
self.write_str(&features).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn build_info(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn build_info(&self) -> Result {
|
||||||
use conduwuit::build_metadata::built;
|
use conduwuit::build_metadata::built;
|
||||||
|
|
||||||
let mut info = String::new();
|
let mut info = String::new();
|
||||||
@@ -232,5 +246,4 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&info).await
|
self.write_str(&info).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+10
-10
@@ -1,9 +1,10 @@
|
|||||||
use conduwuit::{Err, Result, utils};
|
use conduwuit::{Err, Result, utils};
|
||||||
|
use conduwuit_macros::admin_command;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use service::registration_tokens::TokenExpires;
|
use service::registration_tokens::TokenExpires;
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn issue_token(&self, expires: super::TokenExpires) -> Result {
|
pub(super) async fn issue_token(&self, expires: super::TokenExpires) -> Result {
|
||||||
let expires = {
|
let expires = {
|
||||||
if expires.immortal {
|
if expires.immortal {
|
||||||
None
|
None
|
||||||
@@ -14,9 +15,7 @@ impl crate::Context<'_> {
|
|||||||
} else if let Some(max_age) = expires
|
} else if let Some(max_age) = expires
|
||||||
.max_age
|
.max_age
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|max_age| {
|
.map(|max_age| utils::time::timepoint_from_now(utils::time::parse_duration(max_age)?))
|
||||||
utils::time::timepoint_from_now(utils::time::parse_duration(max_age)?)
|
|
||||||
})
|
|
||||||
.transpose()?
|
.transpose()?
|
||||||
{
|
{
|
||||||
Some(TokenExpires::AfterTime(max_age))
|
Some(TokenExpires::AfterTime(max_age))
|
||||||
@@ -62,9 +61,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn revoke_token(&self, token: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn revoke_token(&self, token: String) -> Result {
|
||||||
let Some(token) = self
|
let Some(token) = self
|
||||||
.services
|
.services
|
||||||
.registration_tokens
|
.registration_tokens
|
||||||
@@ -77,9 +77,10 @@ impl crate::Context<'_> {
|
|||||||
self.services.registration_tokens.revoke_token(token)?;
|
self.services.registration_tokens.revoke_token(token)?;
|
||||||
|
|
||||||
self.write_str("Token revoked successfully.").await
|
self.write_str("Token revoked successfully.").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_tokens(&self) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_tokens(&self) -> Result {
|
||||||
let tokens: Vec<_> = self
|
let tokens: Vec<_> = self
|
||||||
.services
|
.services
|
||||||
.registration_tokens
|
.registration_tokens
|
||||||
@@ -95,5 +96,4 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+120
-113
@@ -23,15 +23,15 @@ use ruma::{
|
|||||||
use service::users::HashedPassword;
|
use service::users::HashedPassword;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_room_info,
|
admin_command, get_room_info,
|
||||||
utils::{parse_active_local_user_id, parse_local_user_id},
|
utils::{parse_active_local_user_id, parse_local_user_id},
|
||||||
};
|
};
|
||||||
|
|
||||||
const AUTO_GEN_PASSWORD_LENGTH: usize = 25;
|
const AUTO_GEN_PASSWORD_LENGTH: usize = 25;
|
||||||
const BULK_JOIN_REASON: &str = "Bulk force joining this room as initiated by the server admin.";
|
const BULK_JOIN_REASON: &str = "Bulk force joining this room as initiated by the server admin.";
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
#[admin_command]
|
||||||
pub(super) async fn list_users(&self) -> Result {
|
pub(super) async fn list_users(&self) -> Result {
|
||||||
let users: Vec<_> = self
|
let users: Vec<_> = self
|
||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
@@ -45,9 +45,11 @@ impl crate::Context<'_> {
|
|||||||
plain_msg += "\n```";
|
plain_msg += "\n```";
|
||||||
|
|
||||||
self.write_str(&plain_msg).await
|
self.write_str(&plain_msg).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn create_user(&self, username: String, password: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn create_user(&self, username: String, password: Option<String>) -> Result {
|
||||||
|
// Validate user id
|
||||||
let user_id = self
|
let user_id = self
|
||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
@@ -64,9 +66,10 @@ impl crate::Context<'_> {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.write_str(&format!("Created user {user_id}")).await
|
self.write_str(&format!("Created user {user_id}")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn deactivate(&self, no_leave_rooms: bool, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn deactivate(&self, no_leave_rooms: bool, user_id: String) -> Result {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -99,9 +102,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("User {user_id} has been deactivated"))
|
self.write_str(&format!("User {user_id} has been deactivated"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn suspend(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn suspend(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -123,9 +127,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("User {user_id} has been suspended."))
|
self.write_str(&format!("User {user_id} has been suspended."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn unsuspend(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn unsuspend(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -140,25 +145,25 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("User {user_id} has been unsuspended."))
|
self.write_str(&format!("User {user_id} has been unsuspended."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn reset_password(
|
#[admin_command]
|
||||||
|
pub(super) async fn reset_password(
|
||||||
&self,
|
&self,
|
||||||
logout: bool,
|
logout: bool,
|
||||||
username: String,
|
username: String,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &username)?;
|
let user_id = parse_local_user_id(self.services, &username)?;
|
||||||
|
|
||||||
if user_id == self.services.globals.server_user {
|
if user_id == self.services.globals.server_user {
|
||||||
return Err!(
|
return Err!(
|
||||||
"Not allowed to set the password for the server account. Please use the \
|
"Not allowed to set the password for the server account. Please use the emergency \
|
||||||
emergency password config option.",
|
password config option.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_password =
|
let new_password = password.unwrap_or_else(|| utils::random_string(AUTO_GEN_PASSWORD_LENGTH));
|
||||||
password.unwrap_or_else(|| utils::random_string(AUTO_GEN_PASSWORD_LENGTH));
|
|
||||||
|
|
||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
@@ -184,9 +189,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn deactivate_all(&self, no_leave_rooms: bool, force: bool) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn deactivate_all(&self, no_leave_rooms: bool, force: bool) -> Result {
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
|| !self.body[0].trim().starts_with("```")
|
|| !self.body[0].trim().starts_with("```")
|
||||||
|| self.body.last().unwrap_or(&"").trim() != "```"
|
|| self.body.last().unwrap_or(&"").trim() != "```"
|
||||||
@@ -208,9 +214,7 @@ impl crate::Context<'_> {
|
|||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
self.services
|
self.services
|
||||||
.admin
|
.admin
|
||||||
.send_text(&format!(
|
.send_text(&format!("{username} is not a valid username, skipping over: {e}"))
|
||||||
"{username} is not a valid username, skipping over: {e}"
|
|
||||||
))
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -258,9 +262,7 @@ impl crate::Context<'_> {
|
|||||||
| Ok(()) => {
|
| Ok(()) => {
|
||||||
deactivation_count = deactivation_count.saturating_add(1);
|
deactivation_count = deactivation_count.saturating_add(1);
|
||||||
if !no_leave_rooms {
|
if !no_leave_rooms {
|
||||||
info!(
|
info!("Forcing user {user_id} to leave all rooms apart of deactivate-all");
|
||||||
"Forcing user {user_id} to leave all rooms apart of deactivate-all"
|
|
||||||
);
|
|
||||||
let all_joined_rooms: Vec<OwnedRoomId> = self
|
let all_joined_rooms: Vec<OwnedRoomId> = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -289,9 +291,10 @@ impl crate::Context<'_> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_invited_rooms(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_invited_rooms(&self, user_id: String) -> Result {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -329,14 +332,12 @@ impl crate::Context<'_> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!("Rooms {user_id} is Invited to ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
"Rooms {user_id} is Invited to ({}):\n```\n{body}\n```",
|
|
||||||
rooms.len()
|
|
||||||
))
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn reject_all_invites(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn reject_all_invites(&self, user_id: String) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
@@ -366,9 +367,10 @@ impl crate::Context<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.write_str("Successfully rejected all invites.").await
|
self.write_str("Successfully rejected all invites.").await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -396,13 +398,14 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len()))
|
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_join_list_of_local_users(
|
#[admin_command]
|
||||||
|
pub(super) async fn force_join_list_of_local_users(
|
||||||
&self,
|
&self,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
yes_i_want_to_do_this: bool,
|
yes_i_want_to_do_this: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if self.body.len() < 2
|
if self.body.len() < 2
|
||||||
|| !self.body[0].trim().starts_with("```")
|
|| !self.body[0].trim().starts_with("```")
|
||||||
|| self.body.last().unwrap_or(&"").trim() != "```"
|
|| self.body.last().unwrap_or(&"").trim() != "```"
|
||||||
@@ -412,8 +415,8 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
if !yes_i_want_to_do_this {
|
if !yes_i_want_to_do_this {
|
||||||
return Err!(
|
return Err!(
|
||||||
"You must pass the --yes-i-want-to-do-this-flag to ensure you really want to \
|
"You must pass the --yes-i-want-to-do-this-flag to ensure you really want to force \
|
||||||
force bulk join all specified local users.",
|
bulk join all specified local users.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,9 +482,7 @@ impl crate::Context<'_> {
|
|||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
self.services
|
self.services
|
||||||
.admin
|
.admin
|
||||||
.send_text(&format!(
|
.send_text(&format!("{username} is not a valid username, skipping over: {e}"))
|
||||||
"{username} is not a valid username, skipping over: {e}"
|
|
||||||
))
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -504,9 +505,7 @@ impl crate::Context<'_> {
|
|||||||
successful_joins = successful_joins.saturating_add(1);
|
successful_joins = successful_joins.saturating_add(1);
|
||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
debug_warn!(
|
debug_warn!("Failed force joining {user_id} to {room_id} during bulk join: {e}");
|
||||||
"Failed force joining {user_id} to {room_id} during bulk join: {e}"
|
|
||||||
);
|
|
||||||
failed_joins = failed_joins.saturating_add(1);
|
failed_joins = failed_joins.saturating_add(1);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -517,17 +516,18 @@ impl crate::Context<'_> {
|
|||||||
failed.",
|
failed.",
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_join_all_local_users(
|
#[admin_command]
|
||||||
|
pub(super) async fn force_join_all_local_users(
|
||||||
&self,
|
&self,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
yes_i_want_to_do_this: bool,
|
yes_i_want_to_do_this: bool,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if !yes_i_want_to_do_this {
|
if !yes_i_want_to_do_this {
|
||||||
return Err!(
|
return Err!(
|
||||||
"You must pass the --yes-i-want-to-do-this-flag to ensure you really want to \
|
"You must pass the --yes-i-want-to-do-this-flag to ensure you really want to force \
|
||||||
force bulk join all local users.",
|
bulk join all local users.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,9 +586,7 @@ impl crate::Context<'_> {
|
|||||||
successful_joins = successful_joins.saturating_add(1);
|
successful_joins = successful_joins.saturating_add(1);
|
||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
debug_warn!(
|
debug_warn!("Failed force joining {user_id} to {room_id} during bulk join: {e}");
|
||||||
"Failed force joining {user_id} to {room_id} during bulk join: {e}"
|
|
||||||
);
|
|
||||||
failed_joins = failed_joins.saturating_add(1);
|
failed_joins = failed_joins.saturating_add(1);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -599,14 +597,15 @@ impl crate::Context<'_> {
|
|||||||
failed.",
|
failed.",
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_join_room(
|
#[admin_command]
|
||||||
|
pub(super) async fn force_join_room(
|
||||||
&self,
|
&self,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
via: Option<String>,
|
via: Option<String>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
let (room_id, mut servers) = self
|
let (room_id, mut servers) = self
|
||||||
.services
|
.services
|
||||||
@@ -631,13 +630,14 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("{user_id} has been joined to {room_id}."))
|
self.write_str(&format!("{user_id} has been joined to {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_leave_room(
|
#[admin_command]
|
||||||
|
pub(super) async fn force_leave_room(
|
||||||
&self,
|
&self,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
||||||
|
|
||||||
@@ -662,13 +662,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("{user_id} has left {room_id}."))
|
self.write_str(&format!("{user_id} has left {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_demote(
|
#[admin_command]
|
||||||
&self,
|
pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAliasId) -> Result {
|
||||||
user_id: String,
|
|
||||||
room_id: OwnedRoomOrAliasId,
|
|
||||||
) -> Result {
|
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
let room_id = self.services.rooms.alias.resolve(&room_id).await?;
|
||||||
|
|
||||||
@@ -716,9 +713,10 @@ impl crate::Context<'_> {
|
|||||||
{event_id}"
|
{event_id}"
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
self.services.globals.user_is_local(&user_id),
|
self.services.globals.user_is_local(&user_id),
|
||||||
@@ -733,14 +731,15 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("{user_id} has been granted admin privileges."))
|
self.write_str(&format!("{user_id} has been granted admin privileges."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn put_room_tag(
|
#[admin_command]
|
||||||
|
pub(super) async fn put_room_tag(
|
||||||
&self,
|
&self,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
tag: String,
|
tag: String,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
||||||
|
|
||||||
let mut tags_event = self
|
let mut tags_event = self
|
||||||
@@ -766,18 +765,18 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"Successfully updated room account data for {user_id} and room {room_id} with tag \
|
"Successfully updated room account data for {user_id} and room {room_id} with tag {tag}"
|
||||||
{tag}"
|
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn delete_room_tag(
|
#[admin_command]
|
||||||
|
pub(super) async fn delete_room_tag(
|
||||||
&self,
|
&self,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
tag: String,
|
tag: String,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
||||||
|
|
||||||
let mut tags_event = self
|
let mut tags_event = self
|
||||||
@@ -800,13 +799,14 @@ impl crate::Context<'_> {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"Successfully updated room account data for {user_id} and room {room_id}, deleting \
|
"Successfully updated room account data for {user_id} and room {room_id}, deleting room \
|
||||||
room tag {tag}"
|
tag {tag}"
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId) -> Result {
|
||||||
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
|
||||||
|
|
||||||
let tags_event = self
|
let tags_event = self
|
||||||
@@ -818,9 +818,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
||||||
let Ok(event) = self
|
let Ok(event) = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -875,14 +876,15 @@ impl crate::Context<'_> {
|
|||||||
"Successfully redacted event. Redaction event ID: {redaction_event_id}"
|
"Successfully redacted event. Redaction event ID: {redaction_event_id}"
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn force_leave_remote_room(
|
#[admin_command]
|
||||||
|
pub(super) async fn force_leave_remote_room(
|
||||||
&self,
|
&self,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
room_id: OwnedRoomOrAliasId,
|
room_id: OwnedRoomOrAliasId,
|
||||||
via: Option<String>,
|
via: Option<String>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
let (room_id, vias_raw) = self
|
let (room_id, vias_raw) = self
|
||||||
.services
|
.services
|
||||||
@@ -915,9 +917,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("{user_id} successfully left {room_id} via remote server."))
|
self.write_str(&format!("{user_id} successfully left {room_id} via remote server."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn lock(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn lock(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -941,9 +944,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("User {user_id} has been locked."))
|
self.write_str(&format!("User {user_id} has been locked."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn unlock(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn unlock(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -954,9 +958,10 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
self.write_str(&format!("User {user_id} has been unlocked."))
|
self.write_str(&format!("User {user_id} has been unlocked."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn logout(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn logout(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -985,9 +990,10 @@ impl crate::Context<'_> {
|
|||||||
.await;
|
.await;
|
||||||
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn disable_login(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn disable_login(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1010,9 +1016,10 @@ impl crate::Context<'_> {
|
|||||||
"{user_id} can no longer log in. Their existing sessions remain unaffected."
|
"{user_id} can no longer log in. Their existing sessions remain unaffected."
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn enable_login(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn enable_login(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1025,9 +1032,10 @@ impl crate::Context<'_> {
|
|||||||
self.services.users.enable_login(&user_id);
|
self.services.users.enable_login(&user_id);
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} can now log in.")).await
|
self.write_str(&format!("{user_id} can now log in.")).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_email(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_email(&self, user_id: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
|
|
||||||
@@ -1044,9 +1052,10 @@ impl crate::Context<'_> {
|
|||||||
self.write_str(&format!("{user_id} has no associated email address."))
|
self.write_str(&format!("{user_id} has no associated email address."))
|
||||||
.await,
|
.await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn get_user_by_email(&self, email: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn get_user_by_email(&self, email: String) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
let Ok(email) = Address::try_from(email) else {
|
let Ok(email) = Address::try_from(email) else {
|
||||||
@@ -1055,10 +1064,8 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
match self.services.threepid.get_localpart_for_email(&email).await {
|
match self.services.threepid.get_localpart_for_email(&email).await {
|
||||||
| Some(localpart) => {
|
| Some(localpart) => {
|
||||||
let user_id = UserId::parse(format!(
|
let user_id =
|
||||||
"@{localpart}:{}",
|
UserId::parse(format!("@{localpart}:{}", self.services.globals.server_name()))
|
||||||
self.services.globals.server_name()
|
|
||||||
))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
self.write_str(&format!("{email} belongs to {user_id}."))
|
self.write_str(&format!("{email} belongs to {user_id}."))
|
||||||
@@ -1068,9 +1075,10 @@ impl crate::Context<'_> {
|
|||||||
self.write_str(&format!("No user has {email} as their email address."))
|
self.write_str(&format!("No user has {email} as their email address."))
|
||||||
.await,
|
.await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn change_email(&self, user_id: String, email: Option<String>) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn change_email(&self, user_id: String, email: Option<String>) -> Result {
|
||||||
self.bail_restricted()?;
|
self.bail_restricted()?;
|
||||||
|
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
@@ -1102,8 +1110,8 @@ impl crate::Context<'_> {
|
|||||||
|
|
||||||
if let Some(current_email) = current_email {
|
if let Some(current_email) = current_email {
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"The associated email of {user_id} has been changed from \
|
"The associated email of {user_id} has been changed from {current_email} to \
|
||||||
{current_email} to {new_email}."
|
{new_email}."
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
@@ -1120,15 +1128,15 @@ impl crate::Context<'_> {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.write_str(&format!(
|
self.write_str(&format!(
|
||||||
"The associated email of {user_id} has been removed (it was \
|
"The associated email of {user_id} has been removed (it was {current_email})."
|
||||||
{current_email})."
|
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn reset_push_rules(&self, user_id: String) -> Result {
|
#[admin_command]
|
||||||
|
pub(super) async fn reset_push_rules(&self, user_id: String) -> Result {
|
||||||
let user_id = parse_local_user_id(self.services, &user_id)?;
|
let user_id = parse_local_user_id(self.services, &user_id)?;
|
||||||
if !self.services.users.is_active(&user_id).await {
|
if !self.services.users.is_active(&user_id).await {
|
||||||
return Err!("User is not active.");
|
return Err!("User is not active.");
|
||||||
@@ -1136,5 +1144,4 @@ impl crate::Context<'_> {
|
|||||||
recreate_push_rules_and_return(self.services, &user_id).await?;
|
recreate_push_rules_and_return(self.services, &user_id).await?;
|
||||||
self.write_str("Reset user's push rules to the server default.")
|
self.write_str("Reset user's push rules to the server default.")
|
||||||
.await
|
.await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ pub(crate) async fn deactivate_route(
|
|||||||
let sender_user = identity.expect_sender_user()?;
|
let sender_user = identity.expect_sender_user()?;
|
||||||
|
|
||||||
if !services.config.allow_deactivation {
|
if !services.config.allow_deactivation {
|
||||||
return Err!(Request(Forbidden(
|
return Err!(Request(Unauthorized(
|
||||||
"You may not deactivate your own account. Contact your server's administrator for \
|
"You may not deactivate your own account. Contact your server's administrator for \
|
||||||
assistance."
|
assistance."
|
||||||
)));
|
)));
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ pub(crate) async fn register_route(
|
|||||||
.determine_registration_user_id(body.username.clone(), None, Some(appservice_info))
|
.determine_registration_user_id(body.username.clone(), None, Some(appservice_info))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
services.users.create(&user_id, None)?;
|
services.users.create(&user_id, None).await?;
|
||||||
|
|
||||||
user_id
|
user_id
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -92,14 +92,6 @@ pub async fn handle_login(
|
|||||||
return Err!(Request(InvalidParam("User ID does not belong to this homeserver")));
|
return Err!(Request(InvalidParam("User ID does not belong to this homeserver")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if services.users.is_deactivated(&user_id).await? {
|
|
||||||
return Err!(Request(UserDeactivated("This account has been deactivated.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if services.users.is_locked(&user_id).await? {
|
|
||||||
return Err!(Request(UserLocked("This account has been locked.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if services.users.is_login_disabled(&user_id).await {
|
if services.users.is_login_disabled(&user_id).await {
|
||||||
warn!(%user_id, "user attempted to log in with a login-disabled account");
|
warn!(%user_id, "user attempted to log in with a login-disabled account");
|
||||||
return Err!(Request(Forbidden("This account is not permitted to log in.")));
|
return Err!(Request(Forbidden("This account is not permitted to log in.")));
|
||||||
|
|||||||
@@ -48,13 +48,6 @@ async fn load_timeline(
|
|||||||
ending_count: Option<PduCount>,
|
ending_count: Option<PduCount>,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
) -> Result<TimelinePdus> {
|
) -> Result<TimelinePdus> {
|
||||||
if let (Some(starting_count), Some(ending_count)) = (starting_count, ending_count) {
|
|
||||||
debug_assert!(
|
|
||||||
starting_count <= ending_count,
|
|
||||||
"starting count {starting_count} > ending count {ending_count}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pdu_stream = match starting_count {
|
let mut pdu_stream = match starting_count {
|
||||||
| Some(starting_count) => {
|
| Some(starting_count) => {
|
||||||
let last_timeline_count = services
|
let last_timeline_count = services
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ use ruma::{
|
|||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
use service::{account_data::AnyRawAccountDataEvent, rooms::short::ShortStateHash};
|
use service::{account_data::AnyRawAccountDataEvent, rooms::short::ShortStateHash};
|
||||||
use tokio::pin;
|
|
||||||
|
|
||||||
use super::{load_timeline, share_encrypted_room};
|
use super::{load_timeline, share_encrypted_room};
|
||||||
use crate::client::{
|
use crate::client::{
|
||||||
@@ -97,19 +96,12 @@ pub(super) async fn load_joined_room(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let state_events =
|
|
||||||
StateEvents::with_events(state_events.into_iter().map(Event::into_format).collect());
|
|
||||||
|
|
||||||
let joined_room = assign!(JoinedRoom::new(), {
|
let joined_room = assign!(JoinedRoom::new(), {
|
||||||
account_data,
|
account_data,
|
||||||
summary: summary.unwrap_or_default(),
|
summary: summary.unwrap_or_default(),
|
||||||
unread_notifications: notification_counts.unwrap_or_default(),
|
unread_notifications: notification_counts.unwrap_or_default(),
|
||||||
timeline,
|
timeline,
|
||||||
state: if sync_context.use_state_after {
|
state: RoomState::Before(StateEvents::with_events(state_events.into_iter().map(Event::into_format).collect())),
|
||||||
RoomState::After(state_events)
|
|
||||||
} else {
|
|
||||||
RoomState::Before(state_events)
|
|
||||||
},
|
|
||||||
ephemeral,
|
ephemeral,
|
||||||
unread_thread_notifications: BTreeMap::new(),
|
unread_thread_notifications: BTreeMap::new(),
|
||||||
});
|
});
|
||||||
@@ -352,7 +344,7 @@ struct ShortStateHashes {
|
|||||||
#[tracing::instrument(level = "debug", skip_all)]
|
#[tracing::instrument(level = "debug", skip_all)]
|
||||||
async fn fetch_shortstatehashes(
|
async fn fetch_shortstatehashes(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
SyncContext { last_sync_end_count, .. }: SyncContext<'_>,
|
SyncContext { last_sync_end_count, current_count, .. }: SyncContext<'_>,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> Result<ShortStateHashes> {
|
) -> Result<ShortStateHashes> {
|
||||||
// the room state currently.
|
// the room state currently.
|
||||||
@@ -362,45 +354,46 @@ async fn fetch_shortstatehashes(
|
|||||||
.rooms
|
.rooms
|
||||||
.state
|
.state
|
||||||
.get_room_shortstatehash(room_id)
|
.get_room_shortstatehash(room_id)
|
||||||
.map_err(|_| err!(Database(error!("Room {room_id} has no state"))))
|
.map_err(|_| err!(Database(error!("Room {room_id} has no state"))));
|
||||||
.await?;
|
|
||||||
|
|
||||||
// The room state as of the end of the last sync.
|
// the room state as of the end of the last sync.
|
||||||
// This will be None if we are doing an initial sync.
|
// this will be None if we are doing an initial sync or if we just joined this
|
||||||
|
// room.
|
||||||
let last_sync_end_shortstatehash =
|
let last_sync_end_shortstatehash =
|
||||||
OptionFuture::from(last_sync_end_count.map(async |last_sync_end_count| {
|
OptionFuture::from(last_sync_end_count.map(|last_sync_end_count| {
|
||||||
pin! {
|
// look up the shortstatehash saved by the last sync's call to
|
||||||
let pdus = services
|
// `associate_token_shortstatehash`
|
||||||
.rooms
|
|
||||||
.timeline
|
|
||||||
.pdus(room_id, Some(PduCount::Normal(last_sync_end_count)))
|
|
||||||
.ignore_err();
|
|
||||||
}
|
|
||||||
|
|
||||||
match pdus.next().await {
|
|
||||||
| Some((_, pdu_after_last_sync_end)) => {
|
|
||||||
trace!(?pdu_after_last_sync_end.event_id, "pdu at last sync end");
|
|
||||||
|
|
||||||
Some(
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.user
|
||||||
.pdu_shortstatehash(&pdu_after_last_sync_end.event_id)
|
.get_token_shortstatehash(room_id, last_sync_end_count)
|
||||||
.await
|
.inspect_err(move |_| {
|
||||||
.map_err(|err| {
|
debug_warn!(
|
||||||
err!("Last sync end PDU has no shortstatehash: {err}")
|
token = last_sync_end_count,
|
||||||
}),
|
"Room has no shortstatehash for this token"
|
||||||
)
|
);
|
||||||
},
|
})
|
||||||
| None => {
|
.ok()
|
||||||
// No events have been sent since the last sync, or we just joined this room
|
|
||||||
None
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
.await
|
.map(Option::flatten)
|
||||||
.flatten()
|
.map(Ok);
|
||||||
.transpose()?;
|
|
||||||
|
let (current_shortstatehash, last_sync_end_shortstatehash) =
|
||||||
|
try_join(current_shortstatehash, last_sync_end_shortstatehash).await?;
|
||||||
|
|
||||||
|
/*
|
||||||
|
associate the `current_count` with the `current_shortstatehash`, so we can
|
||||||
|
use it on the next sync as the `last_sync_end_shortstatehash`.
|
||||||
|
|
||||||
|
TODO: the table written to by this call grows extremely fast, gaining one new entry for each
|
||||||
|
joined room on _every single sync request_. we need to find a better way to remember the shortstatehash
|
||||||
|
between syncs.
|
||||||
|
*/
|
||||||
|
services
|
||||||
|
.rooms
|
||||||
|
.user
|
||||||
|
.associate_token_shortstatehash(room_id, current_count, current_shortstatehash)
|
||||||
|
.await;
|
||||||
|
|
||||||
Ok(ShortStateHashes {
|
Ok(ShortStateHashes {
|
||||||
current_shortstatehash,
|
current_shortstatehash,
|
||||||
@@ -459,7 +452,6 @@ async fn build_state_events(
|
|||||||
syncing_user,
|
syncing_user,
|
||||||
last_sync_end_count,
|
last_sync_end_count,
|
||||||
full_state,
|
full_state,
|
||||||
use_state_after,
|
|
||||||
..
|
..
|
||||||
} = sync_context;
|
} = sync_context;
|
||||||
|
|
||||||
@@ -468,15 +460,32 @@ async fn build_state_events(
|
|||||||
last_sync_end_shortstatehash,
|
last_sync_end_shortstatehash,
|
||||||
} = shortstatehashes;
|
} = shortstatehashes;
|
||||||
|
|
||||||
if timeline.pdus.is_empty() {
|
// the spec states that the `state` property only includes state events up to
|
||||||
// If the timeline is empty there can't possibly be any changes to the state
|
// the beginning of the timeline, so we determine the state of the syncing room
|
||||||
return Ok(vec![]);
|
// as of the first timeline event. NOTE: this explanation is not entirely
|
||||||
|
// accurate; see the implementation of `build_state_incremental`.
|
||||||
|
let timeline_start_shortstatehash = async {
|
||||||
|
if let Some((_, pdu)) = timeline.pdus.front() {
|
||||||
|
if let Ok(shortstatehash) = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.pdu_shortstatehash(&pdu.event_id)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
return shortstatehash;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_shortstatehash
|
||||||
|
};
|
||||||
|
|
||||||
// the user IDs of members whose membership needs to be sent to the client, if
|
// the user IDs of members whose membership needs to be sent to the client, if
|
||||||
// lazy-loading is enabled.
|
// lazy-loading is enabled.
|
||||||
let lazily_loaded_members =
|
let lazily_loaded_members =
|
||||||
prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders()).await;
|
prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders());
|
||||||
|
|
||||||
|
let (timeline_start_shortstatehash, lazily_loaded_members) =
|
||||||
|
join(timeline_start_shortstatehash, lazily_loaded_members).await;
|
||||||
|
|
||||||
// compute the state delta between the previous sync and this sync.
|
// compute the state delta between the previous sync and this sync.
|
||||||
match (last_sync_end_count, last_sync_end_shortstatehash) {
|
match (last_sync_end_count, last_sync_end_shortstatehash) {
|
||||||
@@ -485,14 +494,16 @@ async fn build_state_events(
|
|||||||
is Some (meaning the syncing user didn't just join this room for the first time ever), and `full_state` is false,
|
is Some (meaning the syncing user didn't just join this room for the first time ever), and `full_state` is false,
|
||||||
then use `build_state_incremental`.
|
then use `build_state_incremental`.
|
||||||
*/
|
*/
|
||||||
| (Some(_), Some(last_sync_end_shortstatehash)) if !full_state =>
|
| (Some(last_sync_end_count), Some(last_sync_end_shortstatehash)) if !full_state =>
|
||||||
build_state_incremental(
|
build_state_incremental(
|
||||||
services,
|
services,
|
||||||
syncing_user,
|
syncing_user,
|
||||||
|
room_id,
|
||||||
|
PduCount::Normal(last_sync_end_count),
|
||||||
last_sync_end_shortstatehash,
|
last_sync_end_shortstatehash,
|
||||||
|
timeline_start_shortstatehash,
|
||||||
current_shortstatehash,
|
current_shortstatehash,
|
||||||
timeline,
|
timeline,
|
||||||
use_state_after,
|
|
||||||
lazily_loaded_members.as_ref(),
|
lazily_loaded_members.as_ref(),
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -506,9 +517,7 @@ async fn build_state_events(
|
|||||||
build_state_initial(
|
build_state_initial(
|
||||||
services,
|
services,
|
||||||
syncing_user,
|
syncing_user,
|
||||||
current_shortstatehash,
|
timeline_start_shortstatehash,
|
||||||
timeline,
|
|
||||||
use_state_after,
|
|
||||||
lazily_loaded_members.as_ref(),
|
lazily_loaded_members.as_ref(),
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -589,14 +598,10 @@ async fn check_joined_since_last_sync(
|
|||||||
ShortStateHashes { last_sync_end_shortstatehash, .. }: ShortStateHashes,
|
ShortStateHashes { last_sync_end_shortstatehash, .. }: ShortStateHashes,
|
||||||
SyncContext { syncing_user, .. }: SyncContext<'_>,
|
SyncContext { syncing_user, .. }: SyncContext<'_>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let Some(last_sync_end_shortstatehash) = last_sync_end_shortstatehash else {
|
// fetch the syncing user's membership event during the last sync.
|
||||||
// For initial syncs always return false, since there's no "last sync" for the
|
// this will be None if `previous_sync_end_shortstatehash` is None.
|
||||||
// user to have joined since.
|
let membership_during_previous_sync = match last_sync_end_shortstatehash {
|
||||||
return Ok(false);
|
| Some(last_sync_end_shortstatehash) => services
|
||||||
};
|
|
||||||
|
|
||||||
// Fetch the syncing user's membership event during the last sync.
|
|
||||||
let membership_during_previous_sync = services
|
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.state_get_content(
|
.state_get_content(
|
||||||
@@ -606,7 +611,9 @@ async fn check_joined_since_last_sync(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.inspect_err(|_| debug_warn!("User has no previous membership"))
|
.inspect_err(|_| debug_warn!("User has no previous membership"))
|
||||||
.ok();
|
.ok(),
|
||||||
|
| None => None,
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: If the requesting user got state-reset out of the room, this
|
// TODO: If the requesting user got state-reset out of the room, this
|
||||||
// will be `true` when it shouldn't be. this function should never be called
|
// will be `true` when it shouldn't be. this function should never be called
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use conduwuit::{
|
|||||||
trace,
|
trace,
|
||||||
utils::{self, IterStream, future::ReadyEqExt, stream::WidebandExt as _},
|
utils::{self, IterStream, future::ReadyEqExt, stream::WidebandExt as _},
|
||||||
};
|
};
|
||||||
use futures::StreamExt;
|
use futures::{StreamExt, future::join};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
EventId, OwnedRoomId, RoomId,
|
EventId, OwnedRoomId, RoomId,
|
||||||
api::client::sync::sync_events::v3::{
|
api::client::sync::sync_events::v3::{
|
||||||
@@ -181,9 +181,6 @@ pub(super) async fn load_left_room(
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let state_events =
|
|
||||||
StateEvents::with_events(state_events.into_iter().map(Event::into_format).collect());
|
|
||||||
|
|
||||||
Ok(Some(assign!(LeftRoom::new(), {
|
Ok(Some(assign!(LeftRoom::new(), {
|
||||||
account_data: RoomAccountData::new(),
|
account_data: RoomAccountData::new(),
|
||||||
timeline: assign!(Timeline::new(), {
|
timeline: assign!(Timeline::new(), {
|
||||||
@@ -191,11 +188,7 @@ pub(super) async fn load_left_room(
|
|||||||
prev_batch: Some(current_count.to_string()),
|
prev_batch: Some(current_count.to_string()),
|
||||||
events: raw_timeline_pdus,
|
events: raw_timeline_pdus,
|
||||||
}),
|
}),
|
||||||
state: if sync_context.use_state_after {
|
state: State::Before(StateEvents::with_events(state_events.into_iter().map(Event::into_format).collect())),
|
||||||
State::After(state_events)
|
|
||||||
} else {
|
|
||||||
State::Before(state_events)
|
|
||||||
},
|
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,8 +233,29 @@ async fn build_left_state_and_timeline(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let timeline_start_shortstatehash = async {
|
||||||
|
if let Some((_, pdu)) = timeline.pdus.front() {
|
||||||
|
if let Ok(shortstatehash) = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.pdu_shortstatehash(&pdu.event_id)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
return shortstatehash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the timeline generally should not be empty (see the TODO further down),
|
||||||
|
// but in case it is we use `leave_shortstatehash` as the state to
|
||||||
|
// send
|
||||||
|
leave_shortstatehash
|
||||||
|
};
|
||||||
|
|
||||||
let lazily_loaded_members =
|
let lazily_loaded_members =
|
||||||
prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders()).await;
|
prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders());
|
||||||
|
|
||||||
|
let (timeline_start_shortstatehash, lazily_loaded_members) =
|
||||||
|
join(timeline_start_shortstatehash, lazily_loaded_members).await;
|
||||||
|
|
||||||
// TODO: calculate incremental state for incremental syncs.
|
// TODO: calculate incremental state for incremental syncs.
|
||||||
// always calculating initial state _works_ but returns more data and does
|
// always calculating initial state _works_ but returns more data and does
|
||||||
@@ -249,9 +263,7 @@ async fn build_left_state_and_timeline(
|
|||||||
let mut state = build_state_initial(
|
let mut state = build_state_initial(
|
||||||
services,
|
services,
|
||||||
syncing_user,
|
syncing_user,
|
||||||
leave_shortstatehash,
|
timeline_start_shortstatehash,
|
||||||
&timeline,
|
|
||||||
sync_context.use_state_after,
|
|
||||||
lazily_loaded_members.as_ref(),
|
lazily_loaded_members.as_ref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ use std::{
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::ClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, at, error, extract_variant,
|
Err, Result, at, extract_variant,
|
||||||
utils::{
|
utils::{
|
||||||
ReadyExt, TryFutureExtExt,
|
ReadyExt, TryFutureExtExt,
|
||||||
stream::{BroadbandExt, Tools, WidebandExt},
|
stream::{BroadbandExt, Tools, WidebandExt},
|
||||||
},
|
},
|
||||||
|
warn,
|
||||||
};
|
};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{FutureExt, StreamExt, TryFutureExt, future::OptionFuture};
|
use futures::{FutureExt, StreamExt, TryFutureExt, future::OptionFuture};
|
||||||
@@ -110,9 +111,6 @@ struct SyncContext<'a> {
|
|||||||
/// The sync filter, which the client uses to specify what data should be
|
/// The sync filter, which the client uses to specify what data should be
|
||||||
/// included in the sync response.
|
/// included in the sync response.
|
||||||
filter: &'a FilterDefinition,
|
filter: &'a FilterDefinition,
|
||||||
/// Whether the state at the end of the timeline should be used when
|
|
||||||
/// calculating state diffs for sync.
|
|
||||||
use_state_after: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SyncContext<'a> {
|
impl<'a> SyncContext<'a> {
|
||||||
@@ -266,7 +264,6 @@ pub(crate) async fn build_sync_events(
|
|||||||
current_count,
|
current_count,
|
||||||
full_state,
|
full_state,
|
||||||
filter: &filter,
|
filter: &filter,
|
||||||
use_state_after: body.use_state_after,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let joined_rooms = services
|
let joined_rooms = services
|
||||||
@@ -279,7 +276,7 @@ pub(crate) async fn build_sync_events(
|
|||||||
match joined_room {
|
match joined_room {
|
||||||
| Ok((room, updates)) => Some((room_id, room, updates)),
|
| Ok((room, updates)) => Some((room_id, room, updates)),
|
||||||
| Err(err) => {
|
| Err(err) => {
|
||||||
error!(?err, %room_id, "error loading joined room");
|
warn!(?err, %room_id, "error loading joined room");
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -308,7 +305,7 @@ pub(crate) async fn build_sync_events(
|
|||||||
| Ok(Some(left_room)) => Some((room_id, left_room)),
|
| Ok(Some(left_room)) => Some((room_id, left_room)),
|
||||||
| Ok(None) => None,
|
| Ok(None) => None,
|
||||||
| Err(err) => {
|
| Err(err) => {
|
||||||
error!(?err, %room_id, "error loading joined room");
|
warn!(?err, %room_id, "error loading joined room");
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+143
-60
@@ -1,8 +1,11 @@
|
|||||||
use std::collections::HashSet;
|
use std::{collections::BTreeSet, ops::ControlFlow};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result, at,
|
Result, at, is_equal_to,
|
||||||
matrix::{Event, pdu::PduEvent},
|
matrix::{
|
||||||
|
Event,
|
||||||
|
pdu::{PduCount, PduEvent},
|
||||||
|
},
|
||||||
utils::{
|
utils::{
|
||||||
BoolExt, IterStream, ReadyExt, TryFutureExtExt,
|
BoolExt, IterStream, ReadyExt, TryFutureExtExt,
|
||||||
stream::{BroadbandExt, TryIgnore},
|
stream::{BroadbandExt, TryIgnore},
|
||||||
@@ -13,7 +16,9 @@ use conduwuit_service::{
|
|||||||
rooms::{lazy_loading::MemberSet, short::ShortStateHash},
|
rooms::{lazy_loading::MemberSet, short::ShortStateHash},
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use ruma::{OwnedEventId, UserId, events::StateEventType};
|
use itertools::Itertools;
|
||||||
|
use ruma::{OwnedEventId, RoomId, UserId, events::StateEventType};
|
||||||
|
use service::rooms::short::ShortEventId;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use crate::client::TimelinePdus;
|
use crate::client::TimelinePdus;
|
||||||
@@ -33,22 +38,14 @@ use crate::client::TimelinePdus;
|
|||||||
pub(super) async fn build_state_initial(
|
pub(super) async fn build_state_initial(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
timeline_end_shortstatehash: ShortStateHash,
|
timeline_start_shortstatehash: ShortStateHash,
|
||||||
timeline: &TimelinePdus,
|
|
||||||
use_state_after: bool,
|
|
||||||
lazily_loaded_members: Option<&MemberSet>,
|
lazily_loaded_members: Option<&MemberSet>,
|
||||||
) -> Result<Vec<PduEvent>> {
|
) -> Result<Vec<PduEvent>> {
|
||||||
let event_ids_in_timeline: HashSet<_> =
|
|
||||||
timeline.pdus.iter().map(|pdu| &pdu.1.event_id).collect();
|
|
||||||
|
|
||||||
// load the keys and event IDs of the state events at the start of the timeline
|
// load the keys and event IDs of the state events at the start of the timeline
|
||||||
let (shortstatekeys, event_ids): (Vec<_>, Vec<_>) = services
|
let (shortstatekeys, event_ids): (Vec<_>, Vec<_>) = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.state_full_ids(timeline_end_shortstatehash)
|
.state_full_ids(timeline_start_shortstatehash)
|
||||||
.ready_filter(|(_, event_id)| {
|
|
||||||
use_state_after || !event_ids_in_timeline.contains(event_id)
|
|
||||||
})
|
|
||||||
.unzip()
|
.unzip()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -95,32 +92,82 @@ pub(super) async fn build_state_initial(
|
|||||||
pub(super) async fn build_state_incremental<'a>(
|
pub(super) async fn build_state_incremental<'a>(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &'a UserId,
|
sender_user: &'a UserId,
|
||||||
|
room_id: &RoomId,
|
||||||
|
last_sync_end_count: PduCount,
|
||||||
last_sync_end_shortstatehash: ShortStateHash,
|
last_sync_end_shortstatehash: ShortStateHash,
|
||||||
|
timeline_start_shortstatehash: ShortStateHash,
|
||||||
timeline_end_shortstatehash: ShortStateHash,
|
timeline_end_shortstatehash: ShortStateHash,
|
||||||
timeline: &TimelinePdus,
|
timeline: &TimelinePdus,
|
||||||
use_state_after: bool,
|
|
||||||
lazily_loaded_members: Option<&'a MemberSet>,
|
lazily_loaded_members: Option<&'a MemberSet>,
|
||||||
) -> Result<Vec<PduEvent>> {
|
) -> Result<Vec<PduEvent>> {
|
||||||
let mut state_event_ids: HashSet<OwnedEventId> = HashSet::new();
|
/*
|
||||||
|
NB: a limited sync is one where `timeline.limited == true`. Synapse calls this a "gappy" sync internally.
|
||||||
|
|
||||||
|
The algorithm implemented in this function is, currently, quite different from the algorithm vaguely described
|
||||||
|
by the Matrix specification. This is because the specification's description of the `state` property does not accurately
|
||||||
|
reflect how Synapse behaves, and therefore how client SDKs behave. Notable differences include:
|
||||||
|
1. We do not compute the delta using the naive approach of "every state event from the end of the last sync
|
||||||
|
up to the start of this sync's timeline". see below for details.
|
||||||
|
2. If lazy-loading is enabled, we include lazily-loaded membership events. The specific users to include are determined
|
||||||
|
elsewhere and supplied to this function in the `lazily_loaded_members` parameter.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
the `state` property of an incremental sync which isn't limited are _usually_ empty.
|
||||||
|
(note: the specification says that the `state` property is _always_ empty for limited syncs, which is incorrect.)
|
||||||
|
however, if an event in the timeline (`timeline.pdus`) merges a split in the room's DAG (i.e. has multiple `prev_events`),
|
||||||
|
the state at the _end_ of the timeline may include state events which were merged in and don't exist in the state
|
||||||
|
at the _start_ of the timeline. because this is uncommon, we check here to see if any events in the timeline
|
||||||
|
merged a split in the DAG.
|
||||||
|
|
||||||
|
see: https://github.com/element-hq/synapse/issues/16941
|
||||||
|
*/
|
||||||
|
|
||||||
|
let timeline_is_linear = timeline.pdus.is_empty() || {
|
||||||
|
let last_pdu_of_last_sync = services
|
||||||
|
.rooms
|
||||||
|
.timeline
|
||||||
|
.pdus_rev(room_id, Some(last_sync_end_count.saturating_add(1)))
|
||||||
|
.boxed()
|
||||||
|
.next()
|
||||||
|
.await
|
||||||
|
.transpose()
|
||||||
|
.expect("last sync should have had some PDUs")
|
||||||
|
.map(at!(1));
|
||||||
|
|
||||||
|
// make sure the prev_events of each pdu in the timeline refer only to the
|
||||||
|
// previous pdu
|
||||||
|
timeline
|
||||||
|
.pdus
|
||||||
|
.iter()
|
||||||
|
.try_fold(last_pdu_of_last_sync.map(|pdu| pdu.event_id), |prev_event_id, (_, pdu)| {
|
||||||
|
if let Ok(pdu_prev_event_id) = pdu.prev_events.iter().exactly_one() {
|
||||||
|
if prev_event_id
|
||||||
|
.as_ref()
|
||||||
|
.is_none_or(is_equal_to!(pdu_prev_event_id))
|
||||||
|
{
|
||||||
|
return ControlFlow::Continue(Some(pdu_prev_event_id.to_owned()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
%use_state_after,
|
"pdu {:?} has split prev_events (expected {:?}): {:?}",
|
||||||
%last_sync_end_shortstatehash,
|
pdu.event_id, prev_event_id, pdu.prev_events
|
||||||
%timeline_end_shortstatehash,
|
|
||||||
"computing state for incremental sync"
|
|
||||||
);
|
);
|
||||||
|
ControlFlow::Break(())
|
||||||
|
})
|
||||||
|
.is_continue()
|
||||||
|
};
|
||||||
|
|
||||||
// Fetch lazy-loaded membership events if lazy-loading is enabled
|
if timeline_is_linear && !timeline.limited {
|
||||||
if let Some(lazily_loaded_members) = lazily_loaded_members
|
// if there are no splits in the DAG and the timeline isn't limited, then
|
||||||
&& !lazily_loaded_members.is_empty()
|
// `state` will always be empty unless lazy loading is enabled.
|
||||||
{
|
|
||||||
trace!("including lazy membership events for members: {:?}", lazily_loaded_members);
|
|
||||||
|
|
||||||
services
|
if let Some(lazily_loaded_members) = lazily_loaded_members {
|
||||||
.rooms
|
if !timeline.pdus.is_empty() {
|
||||||
.short
|
// lazy loading is enabled, so we return the membership events which were
|
||||||
.multi_get_eventid_from_short::<'_, OwnedEventId, _>(
|
// requested by the caller.
|
||||||
lazily_loaded_members
|
let lazy_membership_events: Vec<_> = lazily_loaded_members
|
||||||
.iter()
|
.iter()
|
||||||
.stream()
|
.stream()
|
||||||
.broad_filter_map(|user_id| async move {
|
.broad_filter_map(|user_id| async move {
|
||||||
@@ -131,24 +178,71 @@ pub(super) async fn build_state_incremental<'a>(
|
|||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.state_get_shortid(
|
.state_get(
|
||||||
timeline_end_shortstatehash,
|
timeline_start_shortstatehash,
|
||||||
&StateEventType::RoomMember,
|
&StateEventType::RoomMember,
|
||||||
user_id.as_str(),
|
user_id.as_str(),
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
.await
|
.await
|
||||||
}),
|
|
||||||
)
|
|
||||||
.ignore_err()
|
|
||||||
.ready_for_each(|event_id| {
|
|
||||||
state_event_ids.insert(event_id);
|
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
if !lazy_membership_events.is_empty() {
|
||||||
|
trace!(
|
||||||
|
"syncing lazy membership events for members: {:?}",
|
||||||
|
lazy_membership_events
|
||||||
|
.iter()
|
||||||
|
.map(|pdu| pdu.state_key().unwrap())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Ok(lazy_membership_events);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the state events added since the last sync.
|
// lazy loading is disabled, `state` is empty.
|
||||||
services
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
at this point, either the timeline is `limited` or the DAG has a split in it. this necessitates
|
||||||
|
computing the incremental state (which may be empty).
|
||||||
|
|
||||||
|
NOTE: this code path does not use the `lazy_membership_events` parameter. any changes to membership will be included
|
||||||
|
in the incremental state. therefore, the incremental state may include "redundant" membership events,
|
||||||
|
which we do not filter out because A. the spec forbids lazy-load filtering if the timeline is `limited`,
|
||||||
|
and B. DAG splits which require sending extra membership state events are (probably) uncommon enough that
|
||||||
|
the performance penalty is acceptable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
trace!(%timeline_is_linear, %timeline.limited, "computing state for incremental sync");
|
||||||
|
|
||||||
|
// fetch the shorteventids of state events in the timeline
|
||||||
|
let state_events_in_timeline: BTreeSet<ShortEventId> = services
|
||||||
|
.rooms
|
||||||
|
.short
|
||||||
|
.multi_get_or_create_shorteventid(timeline.pdus.iter().filter_map(|(_, pdu)| {
|
||||||
|
if pdu.state_key().is_some() {
|
||||||
|
Some(pdu.event_id.as_ref())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.collect()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
trace!("{} state events in timeline", state_events_in_timeline.len());
|
||||||
|
|
||||||
|
/*
|
||||||
|
fetch the state events which were added since the last sync.
|
||||||
|
|
||||||
|
specifically we fetch the difference between the state at the last sync and the state at the _end_
|
||||||
|
of the timeline, and then we filter out state events in the timeline itself using the shorteventids we fetched.
|
||||||
|
this is necessary to account for splits in the DAG, as explained above.
|
||||||
|
*/
|
||||||
|
let state_diff = services
|
||||||
.rooms
|
.rooms
|
||||||
.short
|
.short
|
||||||
.multi_get_eventid_from_short::<'_, OwnedEventId, _>(
|
.multi_get_eventid_from_short::<'_, OwnedEventId, _>(
|
||||||
@@ -158,29 +252,18 @@ pub(super) async fn build_state_incremental<'a>(
|
|||||||
.state_added((last_sync_end_shortstatehash, timeline_end_shortstatehash))
|
.state_added((last_sync_end_shortstatehash, timeline_end_shortstatehash))
|
||||||
.await?
|
.await?
|
||||||
.stream()
|
.stream()
|
||||||
.map(at!(1)),
|
.ready_filter_map(|(_, shorteventid)| {
|
||||||
|
if state_events_in_timeline.contains(&shorteventid) {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(shorteventid)
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.ignore_err()
|
.ignore_err();
|
||||||
.ready_for_each(|event_id| {
|
|
||||||
state_event_ids.insert(event_id);
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if !use_state_after {
|
// finally, fetch the PDU contents and collect them into a vec
|
||||||
// If state_after isn't enabled, filter out state events which also exist
|
let state_diff_pdus = state_diff
|
||||||
// in the timeline. If splits exist in the DAG, this may not be exactly the same
|
|
||||||
// thing as the state diff ending at the start of the timeline, but Synapse
|
|
||||||
// also does this and it's technically more useful behavior anyway.
|
|
||||||
// See: https://github.com/element-hq/synapse/issues/16941
|
|
||||||
|
|
||||||
for (_, pdu) in &timeline.pdus {
|
|
||||||
state_event_ids.remove(pdu.event_id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, fetch the PDU contents and collect them into a vec
|
|
||||||
let state_diff_pdus = state_event_ids
|
|
||||||
.stream()
|
|
||||||
.broad_filter_map(|event_id| async move {
|
.broad_filter_map(|event_id| async move {
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use conduwuit::{
|
|||||||
BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt,
|
BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt,
|
||||||
future::ReadyEqExt,
|
future::ReadyEqExt,
|
||||||
math::{ruma_from_usize, usize_from_ruma},
|
math::{ruma_from_usize, usize_from_ruma},
|
||||||
stream::{TryIgnore, WidebandExt},
|
stream::WidebandExt,
|
||||||
},
|
},
|
||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
@@ -41,7 +41,6 @@ use ruma::{
|
|||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
use service::account_data::AnyRawAccountDataEvent;
|
use service::account_data::AnyRawAccountDataEvent;
|
||||||
use tokio::pin;
|
|
||||||
|
|
||||||
use super::share_encrypted_room;
|
use super::share_encrypted_room;
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -858,31 +857,12 @@ where
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let since_shortstatehash = async {
|
let since_shortstatehash = services
|
||||||
pin! {
|
|
||||||
let pdus_rev = services
|
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.user
|
||||||
.pdus_rev(room_id, Some(PduCount::Normal(globalsince.saturating_sub(1))))
|
.get_token_shortstatehash(room_id, globalsince)
|
||||||
.ignore_err();
|
|
||||||
}
|
|
||||||
|
|
||||||
let (count, pdu_at_last_sync_end) = pdus_rev.next().await?;
|
|
||||||
|
|
||||||
if matches!(count, PduCount::Backfilled(_)) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(
|
|
||||||
services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.pdu_shortstatehash(&pdu_at_last_sync_end.event_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("pdu should have a shortstatehash"),
|
.ok();
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let encrypted_room = services
|
let encrypted_room = services
|
||||||
.rooms
|
.rooms
|
||||||
|
|||||||
@@ -166,9 +166,6 @@ impl CheckAuth for AccessToken {
|
|||||||
query: AuthQueryParams,
|
query: AuthQueryParams,
|
||||||
route: TypeId,
|
route: TypeId,
|
||||||
) -> Result<Self::Identity> {
|
) -> Result<Self::Identity> {
|
||||||
if output.is_empty() {
|
|
||||||
return Err!(Request(Unauthorized("Missing access token.")));
|
|
||||||
}
|
|
||||||
if let Some((sender_user, sender_device, status)) =
|
if let Some((sender_user, sender_device, status)) =
|
||||||
services.users.find_from_token(&output).await
|
services.users.find_from_token(&output).await
|
||||||
{
|
{
|
||||||
@@ -283,9 +280,6 @@ impl CheckAuth for AppserviceToken {
|
|||||||
_query: AuthQueryParams,
|
_query: AuthQueryParams,
|
||||||
_route: TypeId,
|
_route: TypeId,
|
||||||
) -> Result<Self::Identity> {
|
) -> Result<Self::Identity> {
|
||||||
if output.is_empty() {
|
|
||||||
return Err!(Request(Unauthorized("Missing access token.")));
|
|
||||||
}
|
|
||||||
let Ok(appservice_info) = services.appservice.find_from_token(&output).await else {
|
let Ok(appservice_info) = services.appservice.find_from_token(&output).await else {
|
||||||
return Err!(Request(Unauthorized("Invalid appservice token.")));
|
return Err!(Request(Unauthorized("Invalid appservice token.")));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ pub(crate) async fn get_backfill_route(
|
|||||||
room_id: &body.room_id,
|
room_id: &body.room_id,
|
||||||
event_id: None,
|
event_id: None,
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
if !services
|
if !services
|
||||||
.rooms
|
.rooms
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub(crate) async fn get_event_route(
|
|||||||
room_id,
|
room_id,
|
||||||
event_id: Some(&body.event_id),
|
event_id: Some(&body.event_id),
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !services
|
if !services
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub(crate) async fn get_event_authorization_route(
|
|||||||
room_id: &body.room_id,
|
room_id: &body.room_id,
|
||||||
event_id: None,
|
event_id: None,
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if services
|
if services
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub(crate) async fn get_missing_events_route(
|
|||||||
room_id: &body.room_id,
|
room_id: &body.room_id,
|
||||||
event_id: None,
|
event_id: None,
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !services
|
if !services
|
||||||
|
|||||||
@@ -676,13 +676,6 @@ async fn handle_edu_direct_to_device(
|
|||||||
messages
|
messages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.stream()
|
.stream()
|
||||||
.broad_filter_map(|(target_user_id, map)| async move {
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.is_active_local(&target_user_id)
|
|
||||||
.await
|
|
||||||
.then_some((target_user_id, map))
|
|
||||||
})
|
|
||||||
.for_each_concurrent(automatic_width(), |(target_user_id, map)| {
|
.for_each_concurrent(automatic_width(), |(target_user_id, map)| {
|
||||||
handle_edu_direct_to_device_user(services, target_user_id, sender, &ev_type, map)
|
handle_edu_direct_to_device_user(services, target_user_id, sender, &ev_type, map)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub(crate) async fn get_room_state_route(
|
|||||||
room_id: &body.room_id,
|
room_id: &body.room_id,
|
||||||
event_id: None,
|
event_id: None,
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if services
|
if services
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub(crate) async fn get_room_state_ids_route(
|
|||||||
room_id: &body.room_id,
|
room_id: &body.room_id,
|
||||||
event_id: None,
|
event_id: None,
|
||||||
}
|
}
|
||||||
.assert()
|
.check()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if services
|
if services
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use conduwuit::{Err, Result, is_false};
|
use conduwuit::{Err, Result, implement, is_false};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{FutureExt, future::OptionFuture, join};
|
use futures::{FutureExt, future::OptionFuture, join};
|
||||||
use ruma::{EventId, RoomId, ServerName};
|
use ruma::{EventId, RoomId, ServerName};
|
||||||
@@ -10,11 +10,8 @@ pub(super) struct AccessCheck<'a> {
|
|||||||
pub(super) event_id: Option<&'a EventId>,
|
pub(super) event_id: Option<&'a EventId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccessCheck<'_> {
|
#[implement(AccessCheck, params = "<'_>")]
|
||||||
/// Asserts that the server has access to the room and event (if any).
|
pub(super) async fn check(&self) -> Result {
|
||||||
/// If the server is permitted, `Ok(())` is returned. Otherwise, a Forbidden
|
|
||||||
/// error is returned.
|
|
||||||
pub(super) async fn assert(&self) -> Result {
|
|
||||||
let acl_check = self
|
let acl_check = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -61,5 +58,4 @@ impl AccessCheck<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+25
-23
@@ -10,7 +10,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::Config;
|
use super::Config;
|
||||||
use crate::Result;
|
use crate::{Result, implement};
|
||||||
|
|
||||||
/// The configuration manager is an indirection to reload the configuration for
|
/// The configuration manager is an indirection to reload the configuration for
|
||||||
/// the server while it is running. In order to not burden or clutter the many
|
/// the server while it is running. In order to not burden or clutter the many
|
||||||
@@ -39,10 +39,28 @@ impl Manager {
|
|||||||
active: AtomicPtr::new(Arc::into_raw(config).cast_mut()),
|
active: AtomicPtr::new(Arc::into_raw(config).cast_mut()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the active configuration, returning prior configuration.
|
impl Drop for Manager {
|
||||||
#[tracing::instrument(skip_all, level = "info")]
|
fn drop(&mut self) {
|
||||||
pub fn update(&self, config: Config) -> Result<Arc<Config>> {
|
let config = self.active.swap(null_mut(), Ordering::AcqRel);
|
||||||
|
|
||||||
|
// SAFETY: The active pointer was set using an Arc::into_raw(). We're obliged to
|
||||||
|
// reconstitute that into Arc otherwise it will leak.
|
||||||
|
unsafe { Arc::from_raw(config) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for Manager {
|
||||||
|
type Target = Arc<Config>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target { HANDLE.with_borrow_mut(|handle| self.load(handle)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the active configuration, returning prior configuration.
|
||||||
|
#[implement(Manager)]
|
||||||
|
#[tracing::instrument(skip_all, level = "info")]
|
||||||
|
pub fn update(&self, config: Config) -> Result<Arc<Config>> {
|
||||||
let config = Arc::new(config);
|
let config = Arc::new(config);
|
||||||
let new = Arc::into_raw(config);
|
let new = Arc::into_raw(config);
|
||||||
let old = self.active.swap(new.cast_mut(), Ordering::AcqRel);
|
let old = self.active.swap(new.cast_mut(), Ordering::AcqRel);
|
||||||
@@ -50,9 +68,10 @@ impl Manager {
|
|||||||
// SAFETY: The old active pointer was set using an Arc::into_raw(). We're
|
// SAFETY: The old active pointer was set using an Arc::into_raw(). We're
|
||||||
// obliged to reconstitute that into Arc otherwise it will leak.
|
// obliged to reconstitute that into Arc otherwise it will leak.
|
||||||
Ok(unsafe { Arc::from_raw(old) })
|
Ok(unsafe { Arc::from_raw(old) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(&self, handle: &mut [Option<Arc<Config>>]) -> &'static Arc<Config> {
|
#[implement(Manager)]
|
||||||
|
fn load(&self, handle: &mut [Option<Arc<Config>>]) -> &'static Arc<Config> {
|
||||||
let config = self.active.load(Ordering::Acquire);
|
let config = self.active.load(Ordering::Acquire);
|
||||||
|
|
||||||
// Branch taken after config reload or first access by this thread.
|
// Branch taken after config reload or first access by this thread.
|
||||||
@@ -80,23 +99,6 @@ impl Manager {
|
|||||||
// of old configs rather than discarding at the earliest opportunity; the odds
|
// of old configs rather than discarding at the earliest opportunity; the odds
|
||||||
// of this scenario are thus astronomical.
|
// of this scenario are thus astronomical.
|
||||||
unsafe { std::mem::transmute(config) }
|
unsafe { std::mem::transmute(config) }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Manager {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let config = self.active.swap(null_mut(), Ordering::AcqRel);
|
|
||||||
|
|
||||||
// SAFETY: The active pointer was set using an Arc::into_raw(). We're obliged to
|
|
||||||
// reconstitute that into Arc otherwise it will leak.
|
|
||||||
unsafe { Arc::from_raw(config) };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Manager {
|
|
||||||
type Target = Arc<Config>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target { HANDLE.with_borrow_mut(|handle| self.load(handle)) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
use ruma::{RoomVersionId, canonical_json::redact_content_in_place};
|
use ruma::{RoomVersionId, canonical_json::redact_content_in_place};
|
||||||
use serde_json::{Value as JsonValue, json, value::to_raw_value};
|
use serde_json::{Value as JsonValue, json, value::to_raw_value};
|
||||||
|
|
||||||
use crate::{Err, Result, err};
|
use crate::{Err, Result, err, implement};
|
||||||
|
|
||||||
impl super::Pdu {
|
#[implement(super::Pdu)]
|
||||||
pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: JsonValue) -> Result {
|
pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: JsonValue) -> Result {
|
||||||
let Some(rules) = room_version_id.rules() else {
|
let Some(rules) = room_version_id.rules() else {
|
||||||
return Err!("Cannot redact event for unknown room version {room_version_id}");
|
return Err!("Cannot redact event for unknown room version {room_version_id}");
|
||||||
};
|
};
|
||||||
|
|
||||||
self.unsigned = None;
|
self.unsigned = None;
|
||||||
|
|
||||||
let mut content = serde_json::from_str(self.content.get()).map_err(|e| {
|
let mut content = serde_json::from_str(self.content.get())
|
||||||
err!(Request(BadJson("Failed to deserialize content into type: {e}")))
|
.map_err(|e| err!(Request(BadJson("Failed to deserialize content into type: {e}"))))?;
|
||||||
})?;
|
|
||||||
|
|
||||||
redact_content_in_place(&mut content, &rules.redaction, self.kind.to_string());
|
redact_content_in_place(&mut content, &rules.redaction, self.kind.to_string());
|
||||||
|
|
||||||
@@ -30,5 +29,4 @@ impl super::Pdu {
|
|||||||
self.content = to_raw_value(&content).expect("Failed to serialize content");
|
self.content = to_raw_value(&content).expect("Failed to serialize content");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,22 +4,23 @@ use ruma::MilliSecondsSinceUnixEpoch;
|
|||||||
use serde_json::value::{RawValue as RawJsonValue, Value as JsonValue, to_raw_value};
|
use serde_json::value::{RawValue as RawJsonValue, Value as JsonValue, to_raw_value};
|
||||||
|
|
||||||
use super::Pdu;
|
use super::Pdu;
|
||||||
use crate::{Result, err, result::LogErr};
|
use crate::{Result, err, implement, result::LogErr};
|
||||||
|
|
||||||
impl Pdu {
|
/// Set the `unsigned` field of the PDU using only information in the PDU.
|
||||||
/// Set the `unsigned` field of the PDU using only information in the PDU.
|
/// Some unsigned data is already set within the database (eg. prev events,
|
||||||
/// Some unsigned data is already set within the database (eg. prev events,
|
/// threads). Once this is done, other data must be calculated from the database
|
||||||
/// threads). Once this is done, other data must be calculated from the
|
/// (eg. relations) This is for server-to-client events.
|
||||||
/// database (eg. relations) This is for server-to-client events.
|
/// Backfill handles this itself.
|
||||||
/// Backfill handles this itself.
|
#[implement(Pdu)]
|
||||||
pub fn set_unsigned(&mut self, user_id: Option<&ruma::UserId>) {
|
pub fn set_unsigned(&mut self, user_id: Option<&ruma::UserId>) {
|
||||||
if Some(self.sender.borrow()) != user_id {
|
if Some(self.sender.borrow()) != user_id {
|
||||||
self.remove_transaction_id().log_err().ok();
|
self.remove_transaction_id().log_err().ok();
|
||||||
}
|
}
|
||||||
self.add_age().log_err().ok();
|
self.add_age().log_err().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_transaction_id(&mut self) -> Result {
|
#[implement(Pdu)]
|
||||||
|
pub fn remove_transaction_id(&mut self) -> Result {
|
||||||
use BTreeMap as Map;
|
use BTreeMap as Map;
|
||||||
|
|
||||||
let Some(unsigned) = &self.unsigned else {
|
let Some(unsigned) = &self.unsigned else {
|
||||||
@@ -35,9 +36,10 @@ impl Pdu {
|
|||||||
.expect("unsigned is valid");
|
.expect("unsigned is valid");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_age(&mut self) -> Result {
|
#[implement(Pdu)]
|
||||||
|
pub fn add_age(&mut self) -> Result {
|
||||||
use BTreeMap as Map;
|
use BTreeMap as Map;
|
||||||
|
|
||||||
let mut unsigned: Map<&str, Box<RawJsonValue>> = self
|
let mut unsigned: Map<&str, Box<RawJsonValue>> = self
|
||||||
@@ -56,9 +58,10 @@ impl Pdu {
|
|||||||
self.unsigned = Some(to_raw_value(&unsigned)?);
|
self.unsigned = Some(to_raw_value(&unsigned)?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_relation(&mut self, name: &str, pdu: Option<&Self>) -> Result {
|
#[implement(Pdu)]
|
||||||
|
pub fn add_relation(&mut self, name: &str, pdu: Option<&Pdu>) -> Result {
|
||||||
use serde_json::Map;
|
use serde_json::Map;
|
||||||
|
|
||||||
let mut unsigned: Map<String, JsonValue> = self
|
let mut unsigned: Map<String, JsonValue> = self
|
||||||
@@ -82,5 +85,4 @@ impl Pdu {
|
|||||||
self.unsigned = Some(to_raw_value(&unsigned)?);
|
self.unsigned = Some(to_raw_value(&unsigned)?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@ pub fn versions() -> Vec<String> {
|
|||||||
"v1.13".to_owned(),
|
"v1.13".to_owned(),
|
||||||
"v1.14".to_owned(),
|
"v1.14".to_owned(),
|
||||||
"v1.15".to_owned(),
|
"v1.15".to_owned(),
|
||||||
"v1.16".to_owned(),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +44,5 @@ pub fn unstable_features() -> BTreeMap<String, bool> {
|
|||||||
("uk.timedout.msc4323".to_owned(), true), /* agnostic suspend (https://github.com/matrix-org/matrix-spec-proposals/pull/4323) */
|
("uk.timedout.msc4323".to_owned(), true), /* agnostic suspend (https://github.com/matrix-org/matrix-spec-proposals/pull/4323) */
|
||||||
("org.matrix.msc4155".to_owned(), true), /* invite filtering (https://github.com/matrix-org/matrix-spec-proposals/pull/4155) */
|
("org.matrix.msc4155".to_owned(), true), /* invite filtering (https://github.com/matrix-org/matrix-spec-proposals/pull/4155) */
|
||||||
("computer.gingershaped.msc4466".to_owned(), true), /* profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466) */
|
("computer.gingershaped.msc4466".to_owned(), true), /* profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466) */
|
||||||
("org.matrix.msc4380.stable".to_owned(), true),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
+1
-1
@@ -38,7 +38,7 @@ pub use info::version::*;
|
|||||||
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
|
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
|
||||||
pub use parking_lot::{Mutex as SyncMutex, RwLock as SyncRwLock};
|
pub use parking_lot::{Mutex as SyncMutex, RwLock as SyncRwLock};
|
||||||
pub use server::Server;
|
pub use server::Server;
|
||||||
pub use utils::{result, result::Result};
|
pub use utils::{implement, result, result::Result};
|
||||||
|
|
||||||
pub use crate as conduwuit_core;
|
pub use crate as conduwuit_core;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ mod tests;
|
|||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod with_lock;
|
pub mod with_lock;
|
||||||
|
|
||||||
|
pub use ::conduwuit_macros::implement;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
arrayvec::ArrayVecExt,
|
arrayvec::ArrayVecExt,
|
||||||
bool::BoolExt,
|
bool::BoolExt,
|
||||||
|
|||||||
@@ -27,12 +27,3 @@ pub fn continue_exponential_backoff(
|
|||||||
let min = cmp::min(min, max);
|
let min = cmp::min(min, max);
|
||||||
elapsed < min
|
elapsed < min
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the minimum number of backoff seconds
|
|
||||||
#[must_use]
|
|
||||||
pub fn min_exp_backoff_duration(min: u64, max: u64, retries: u32) -> Duration {
|
|
||||||
let min = Duration::from_secs(min)
|
|
||||||
.saturating_mul(retries)
|
|
||||||
.saturating_mul(retries);
|
|
||||||
Duration::from_secs(max).min(min)
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
use std::{ffi::OsString, path::PathBuf};
|
use std::{ffi::OsString, path::PathBuf};
|
||||||
|
|
||||||
use conduwuit::{Err, Result, error, info, utils::time::rfc2822_from_seconds, warn};
|
use conduwuit::{Err, Result, error, implement, info, utils::time::rfc2822_from_seconds, warn};
|
||||||
use rocksdb::backup::{BackupEngine, BackupEngineOptions};
|
use rocksdb::backup::{BackupEngine, BackupEngineOptions};
|
||||||
|
|
||||||
|
use super::Engine;
|
||||||
use crate::util::map_err;
|
use crate::util::map_err;
|
||||||
|
|
||||||
impl super::Engine {
|
#[implement(Engine)]
|
||||||
#[tracing::instrument(skip(self), level = "info")]
|
#[tracing::instrument(skip(self), level = "info")]
|
||||||
pub fn backup(&self) -> Result {
|
pub fn backup(&self) -> Result {
|
||||||
let mut engine = self.backup_engine()?;
|
let mut engine = self.backup_engine()?;
|
||||||
let config = &self.ctx.server.config;
|
let config = &self.ctx.server.config;
|
||||||
if config.database_backups_to_keep > 0 {
|
if config.database_backups_to_keep > 0 {
|
||||||
@@ -35,9 +36,10 @@ impl super::Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backup_list(&self) -> Result<impl Iterator<Item = String> + Send> {
|
#[implement(Engine)]
|
||||||
|
pub fn backup_list(&self) -> Result<impl Iterator<Item = String> + Send> {
|
||||||
let info = self.backup_engine()?.get_backup_info();
|
let info = self.backup_engine()?.get_backup_info();
|
||||||
|
|
||||||
if info.is_empty() {
|
if info.is_empty() {
|
||||||
@@ -55,21 +57,24 @@ impl super::Engine {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backup_count(&self) -> Result<usize> {
|
#[implement(Engine)]
|
||||||
|
pub fn backup_count(&self) -> Result<usize> {
|
||||||
let info = self.backup_engine()?.get_backup_info();
|
let info = self.backup_engine()?.get_backup_info();
|
||||||
|
|
||||||
Ok(info.len())
|
Ok(info.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup_engine(&self) -> Result<BackupEngine> {
|
#[implement(Engine)]
|
||||||
|
fn backup_engine(&self) -> Result<BackupEngine> {
|
||||||
let path = self.backup_path()?;
|
let path = self.backup_path()?;
|
||||||
let options = BackupEngineOptions::new(path).map_err(map_err)?;
|
let options = BackupEngineOptions::new(path).map_err(map_err)?;
|
||||||
BackupEngine::open(&options, &self.ctx.env.lock()).map_err(map_err)
|
BackupEngine::open(&options, &self.ctx.env.lock()).map_err(map_err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup_path(&self) -> Result<OsString> {
|
#[implement(Engine)]
|
||||||
|
fn backup_path(&self) -> Result<OsString> {
|
||||||
let path = self
|
let path = self
|
||||||
.ctx
|
.ctx
|
||||||
.server
|
.server
|
||||||
@@ -84,5 +89,4 @@ impl super::Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use rocksdb::LiveFile as SstFile;
|
use rocksdb::LiveFile as SstFile;
|
||||||
|
|
||||||
|
use super::Engine;
|
||||||
use crate::util::map_err;
|
use crate::util::map_err;
|
||||||
|
|
||||||
impl super::Engine {
|
#[implement(Engine)]
|
||||||
pub fn file_list(&self) -> impl Iterator<Item = Result<SstFile>> + Send + use<> {
|
pub fn file_list(&self) -> impl Iterator<Item = Result<SstFile>> + Send + use<> {
|
||||||
self.db
|
self.db
|
||||||
.live_files()
|
.live_files()
|
||||||
.map_err(map_err)
|
.map_err(map_err)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(Vec::into_iter)
|
.flat_map(Vec::into_iter)
|
||||||
.map(Ok)
|
.map(Ok)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use rocksdb::perf::get_memory_usage_stats;
|
use rocksdb::perf::get_memory_usage_stats;
|
||||||
|
|
||||||
|
use super::Engine;
|
||||||
use crate::or_else;
|
use crate::or_else;
|
||||||
|
|
||||||
impl super::Engine {
|
#[implement(Engine)]
|
||||||
pub fn memory_usage(&self) -> Result<String> {
|
pub fn memory_usage(&self) -> Result<String> {
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
let stats =
|
let stats = get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
|
||||||
get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
|
|
||||||
.or_else(or_else)?;
|
.or_else(or_else)?;
|
||||||
let mibs = |input| f64::from(u32::try_from(input / 1024).unwrap_or(0)) / 1024.0;
|
let mibs = |input| f64::from(u32::try_from(input / 1024).unwrap_or(0)) / 1024.0;
|
||||||
writeln!(
|
writeln!(
|
||||||
@@ -27,5 +27,4 @@ impl super::Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+14
-13
@@ -4,11 +4,11 @@ use std::{
|
|||||||
sync::{Arc, atomic::AtomicU32},
|
sync::{Arc, atomic::AtomicU32},
|
||||||
};
|
};
|
||||||
|
|
||||||
use conduwuit::{Result, debug, info, warn};
|
use conduwuit::{Result, debug, implement, info, warn};
|
||||||
use rocksdb::{ColumnFamilyDescriptor, Options};
|
use rocksdb::{ColumnFamilyDescriptor, Options};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Db,
|
Db, Engine,
|
||||||
cf_opts::cf_options,
|
cf_opts::cf_options,
|
||||||
db_opts::db_options,
|
db_opts::db_options,
|
||||||
descriptor::{self, Descriptor},
|
descriptor::{self, Descriptor},
|
||||||
@@ -16,9 +16,9 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{Context, or_else};
|
use crate::{Context, or_else};
|
||||||
|
|
||||||
impl super::Engine {
|
#[implement(Engine)]
|
||||||
#[tracing::instrument(skip_all, level = "info")]
|
#[tracing::instrument(skip_all, level = "info")]
|
||||||
pub(crate) async fn open(ctx: Arc<Context>, desc: &[Descriptor]) -> Result<Arc<Self>> {
|
pub(crate) async fn open(ctx: Arc<Context>, desc: &[Descriptor]) -> Result<Arc<Self>> {
|
||||||
let server = &ctx.server;
|
let server = &ctx.server;
|
||||||
let config = &server.config;
|
let config = &server.config;
|
||||||
let path = &config.database_path;
|
let path = &config.database_path;
|
||||||
@@ -51,14 +51,15 @@ impl super::Engine {
|
|||||||
checksums: config.rocksdb_checksums,
|
checksums: config.rocksdb_checksums,
|
||||||
corks: AtomicU32::new(0),
|
corks: AtomicU32::new(0),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "configure", skip_all, level = "debug")]
|
#[implement(Engine)]
|
||||||
fn configure_cfds(
|
#[tracing::instrument(name = "configure", skip_all, level = "debug")]
|
||||||
|
fn configure_cfds(
|
||||||
ctx: &Arc<Context>,
|
ctx: &Arc<Context>,
|
||||||
db_opts: &Options,
|
db_opts: &Options,
|
||||||
desc: &[Descriptor],
|
desc: &[Descriptor],
|
||||||
) -> Result<Vec<ColumnFamilyDescriptor>> {
|
) -> Result<Vec<ColumnFamilyDescriptor>> {
|
||||||
let server = &ctx.server;
|
let server = &ctx.server;
|
||||||
let config = &server.config;
|
let config = &server.config;
|
||||||
let path = &config.database_path;
|
let path = &config.database_path;
|
||||||
@@ -106,13 +107,13 @@ impl super::Engine {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(cfds)
|
Ok(cfds)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "discover", skip_all, level = "debug")]
|
#[implement(Engine)]
|
||||||
fn discover_cfs(path: &Path, opts: &Options) -> BTreeSet<String> {
|
#[tracing::instrument(name = "discover", skip_all, level = "debug")]
|
||||||
|
fn discover_cfs(path: &Path, opts: &Options) -> BTreeSet<String> {
|
||||||
Db::list_cf(opts, path)
|
Db::list_cf(opts, path)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<BTreeSet<_>>()
|
.collect::<BTreeSet<_>>()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+17
-18
@@ -1,31 +1,30 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result,
|
Result, implement,
|
||||||
utils::stream::{ReadyExt, TryIgnore},
|
utils::stream::{ReadyExt, TryIgnore},
|
||||||
};
|
};
|
||||||
use futures::{Stream, TryStreamExt};
|
use futures::{Stream, TryStreamExt};
|
||||||
|
|
||||||
use crate::keyval::Key;
|
use crate::keyval::Key;
|
||||||
|
|
||||||
impl super::Map {
|
/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
|
||||||
/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
|
///
|
||||||
///
|
/// See for_clear() with additional details.
|
||||||
/// See for_clear() with additional details.
|
#[implement(super::Map)]
|
||||||
#[tracing::instrument(level = "trace")]
|
#[tracing::instrument(level = "trace")]
|
||||||
pub async fn clear(self: &Arc<Self>) {
|
pub async fn clear(self: &Arc<Self>) {
|
||||||
// drops your entire database cutely :3
|
|
||||||
self.for_clear().ignore_err().ready_for_each(|_| ()).await;
|
self.for_clear().ignore_err().ready_for_each(|_| ()).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
|
/// Delete all data stored in this map. !!! USE WITH CAUTION !!!
|
||||||
///
|
///
|
||||||
/// Provides stream of keys undergoing deletion along with any errors.
|
/// Provides stream of keys undergoing deletion along with any errors.
|
||||||
///
|
///
|
||||||
/// Note this operation applies to a snapshot of the data when invoked.
|
/// Note this operation applies to a snapshot of the data when invoked.
|
||||||
/// Additional data written during or after this call may be missed.
|
/// Additional data written during or after this call may be missed.
|
||||||
#[tracing::instrument(level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn for_clear(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
#[tracing::instrument(level = "trace")]
|
||||||
|
pub fn for_clear(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
||||||
self.raw_keys().inspect_ok(|key| self.remove(key))
|
self.raw_keys().inspect_ok(|key| self.remove(key))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result, implement};
|
||||||
use rocksdb::{BottommostLevelCompaction, CompactOptions};
|
use rocksdb::{BottommostLevelCompaction, CompactOptions};
|
||||||
|
|
||||||
use crate::keyval::KeyBuf;
|
use crate::keyval::KeyBuf;
|
||||||
@@ -23,13 +23,14 @@ pub struct Options {
|
|||||||
pub exclusive: bool,
|
pub exclusive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
name = "compact",
|
name = "compact",
|
||||||
|
level = "info",
|
||||||
skip(self),
|
skip(self),
|
||||||
fields(%self),
|
fields(%self),
|
||||||
)]
|
)]
|
||||||
pub fn compact_blocking(&self, opts: Options) -> Result {
|
pub fn compact_blocking(&self, opts: Options) -> Result {
|
||||||
let mut co = CompactOptions::default();
|
let mut co = CompactOptions::default();
|
||||||
co.set_exclusive_manual_compaction(opts.exclusive);
|
co.set_exclusive_manual_compaction(opts.exclusive);
|
||||||
co.set_bottommost_level_compaction(match opts.exhaustive {
|
co.set_bottommost_level_compaction(match opts.exhaustive {
|
||||||
@@ -50,8 +51,7 @@ impl super::Map {
|
|||||||
co.set_change_level(false);
|
co.set_change_level(false);
|
||||||
co.set_target_level(level.try_into()?);
|
co.set_target_level(level.try_into()?);
|
||||||
},
|
},
|
||||||
| (Some(_), Some(_)) =>
|
| (Some(_), Some(_)) => return Err!("compacting between specific levels not supported"),
|
||||||
return Err!("compacting between specific levels not supported"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.db
|
self.db
|
||||||
@@ -59,5 +59,4 @@ impl super::Map {
|
|||||||
.compact_range_cf_opt(&self.cf(), opts.range.0, opts.range.1, &co);
|
.compact_range_cf_opt(&self.cf(), opts.range.0, opts.range.1, &co);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ use std::{convert::AsRef, fmt::Debug, future::Future, io::Write, sync::Arc};
|
|||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result,
|
Result,
|
||||||
arrayvec::ArrayVec,
|
arrayvec::ArrayVec,
|
||||||
err,
|
err, implement,
|
||||||
utils::{future::TryExtExt, result::FlatOk},
|
utils::{future::TryExtExt, result::FlatOk},
|
||||||
};
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
@@ -11,90 +11,93 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::{keyval::KeyBuf, ser};
|
use crate::{keyval::KeyBuf, ser};
|
||||||
|
|
||||||
impl super::Map {
|
/// Returns true if the map contains the key.
|
||||||
/// Returns true if the map contains the key.
|
/// - key is serialized into allocated buffer
|
||||||
/// - key is serialized into allocated buffer
|
/// - harder errors may not be reported
|
||||||
/// - harder errors may not be reported
|
#[inline]
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn contains<K>(
|
pub fn contains<K>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = bool> + Send + '_ + use<'_, K>
|
) -> impl Future<Output = bool> + Send + '_ + use<'_, K>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = KeyBuf::new();
|
let mut buf = KeyBuf::new();
|
||||||
self.bcontains(key, &mut buf)
|
self.bcontains(key, &mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the map contains the key.
|
/// Returns true if the map contains the key.
|
||||||
/// - key is serialized into stack-buffer
|
/// - key is serialized into stack-buffer
|
||||||
/// - harder errors will panic
|
/// - harder errors will panic
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn acontains<const MAX: usize, K>(
|
#[implement(super::Map)]
|
||||||
|
pub fn acontains<const MAX: usize, K>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = bool> + Send + '_ + use<'_, MAX, K>
|
) -> impl Future<Output = bool> + Send + '_ + use<'_, MAX, K>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = ArrayVec::<u8, MAX>::new();
|
let mut buf = ArrayVec::<u8, MAX>::new();
|
||||||
self.bcontains(key, &mut buf)
|
self.bcontains(key, &mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the map contains the key.
|
/// Returns true if the map contains the key.
|
||||||
/// - key is serialized into provided buffer
|
/// - key is serialized into provided buffer
|
||||||
/// - harder errors will panic
|
/// - harder errors will panic
|
||||||
#[tracing::instrument(skip(self, buf), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn bcontains<K, B>(
|
#[tracing::instrument(skip(self, buf), fields(%self), level = "trace")]
|
||||||
|
pub fn bcontains<K, B>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
buf: &mut B,
|
buf: &mut B,
|
||||||
) -> impl Future<Output = bool> + Send + '_ + use<'_, K, B>
|
) -> impl Future<Output = bool> + Send + '_ + use<'_, K, B>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
B: Write + AsRef<[u8]>,
|
B: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
||||||
self.exists(key).is_ok()
|
self.exists(key).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Ok if the map contains the key.
|
/// Returns Ok if the map contains the key.
|
||||||
/// - key is raw
|
/// - key is raw
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn exists<'a, K>(
|
#[implement(super::Map)]
|
||||||
|
pub fn exists<'a, K>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = Result> + Send + 'a + use<'a, K>
|
) -> impl Future<Output = Result> + Send + 'a + use<'a, K>
|
||||||
where
|
where
|
||||||
K: AsRef<[u8]> + ?Sized + Debug + 'a,
|
K: AsRef<[u8]> + ?Sized + Debug + 'a,
|
||||||
{
|
{
|
||||||
self.get(key).map(|res| res.map(|_| ()))
|
self.get(key).map(|res| res.map(|_| ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Ok if the map contains the key; NotFound otherwise. Harder
|
/// Returns Ok if the map contains the key; NotFound otherwise. Harder errors
|
||||||
/// errors may not always be reported properly.
|
/// may not always be reported properly.
|
||||||
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn exists_blocking<K>(&self, key: &K) -> Result
|
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
||||||
where
|
pub fn exists_blocking<K>(&self, key: &K) -> Result
|
||||||
|
where
|
||||||
K: AsRef<[u8]> + ?Sized + Debug,
|
K: AsRef<[u8]> + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
self.maybe_exists(key)
|
self.maybe_exists(key)
|
||||||
.then(|| self.get_blocking(key))
|
.then(|| self.get_blocking(key))
|
||||||
.flat_ok()
|
.flat_ok()
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.ok_or_else(|| err!(Request(NotFound("Not found in database"))))
|
.ok_or_else(|| err!(Request(NotFound("Not found in database"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rocksdb limits this to kBlockCacheTier internally so this is not
|
/// Rocksdb limits this to kBlockCacheTier internally so this is not actually a
|
||||||
/// actually a blocking call; in case that changes we set this as well in
|
/// blocking call; in case that changes we set this as well in our read_options.
|
||||||
/// our read_options.
|
#[implement(super::Map)]
|
||||||
pub(crate) fn maybe_exists<K>(&self, key: &K) -> bool
|
pub(crate) fn maybe_exists<K>(&self, key: &K) -> bool
|
||||||
where
|
where
|
||||||
K: AsRef<[u8]> + ?Sized,
|
K: AsRef<[u8]> + ?Sized,
|
||||||
{
|
{
|
||||||
self.db
|
self.db
|
||||||
.db
|
.db
|
||||||
.key_may_exist_cf_opt(&self.cf(), key, &self.cache_read_options)
|
.key_may_exist_cf_opt(&self.cf(), key, &self.cache_read_options)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+45
-41
@@ -1,68 +1,72 @@
|
|||||||
use std::{fmt::Debug, future::Future, sync::Arc};
|
use std::{fmt::Debug, future::Future, sync::Arc};
|
||||||
|
|
||||||
|
use conduwuit::implement;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
impl super::Map {
|
/// Count the total number of entries in the map.
|
||||||
/// Count the total number of entries in the map.
|
#[implement(super::Map)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn count(self: &Arc<Self>) -> impl Future<Output = usize> + Send + '_ {
|
pub fn count(self: &Arc<Self>) -> impl Future<Output = usize> + Send + '_ {
|
||||||
self.raw_keys().count()
|
self.raw_keys().count()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count the number of entries in the map starting from a lower-bound.
|
/// Count the number of entries in the map starting from a lower-bound.
|
||||||
///
|
///
|
||||||
/// - From is a structured key
|
/// - From is a structured key
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn count_from<'a, P>(
|
#[inline]
|
||||||
|
pub fn count_from<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Future<Output = usize> + Send + 'a + use<'a, P>
|
) -> impl Future<Output = usize> + Send + 'a + use<'a, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug + 'a,
|
P: Serialize + ?Sized + Debug + 'a,
|
||||||
{
|
{
|
||||||
self.keys_from_raw(from).count()
|
self.keys_from_raw(from).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count the number of entries in the map starting from a lower-bound.
|
/// Count the number of entries in the map starting from a lower-bound.
|
||||||
///
|
///
|
||||||
/// - From is a raw
|
/// - From is a raw
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn raw_count_from<'a, P>(
|
#[inline]
|
||||||
|
pub fn raw_count_from<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &'a P,
|
from: &'a P,
|
||||||
) -> impl Future<Output = usize> + Send + 'a
|
) -> impl Future<Output = usize> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.raw_keys_from(from).count()
|
self.raw_keys_from(from).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count the number of entries in the map matching a prefix.
|
/// Count the number of entries in the map matching a prefix.
|
||||||
///
|
///
|
||||||
/// - Prefix is structured key
|
/// - Prefix is structured key
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn count_prefix<'a, P>(
|
#[inline]
|
||||||
|
pub fn count_prefix<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Future<Output = usize> + Send + 'a + use<'a, P>
|
) -> impl Future<Output = usize> + Send + 'a + use<'a, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug + 'a,
|
P: Serialize + ?Sized + Debug + 'a,
|
||||||
{
|
{
|
||||||
self.keys_prefix_raw(prefix).count()
|
self.keys_prefix_raw(prefix).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count the number of entries in the map matching a prefix.
|
/// Count the number of entries in the map matching a prefix.
|
||||||
///
|
///
|
||||||
/// - Prefix is raw
|
/// - Prefix is raw
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn raw_count_prefix<'a, P>(
|
#[inline]
|
||||||
|
pub fn raw_count_prefix<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Future<Output = usize> + Send + 'a
|
) -> impl Future<Output = usize> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.raw_keys_prefix(prefix).count()
|
self.raw_keys_prefix(prefix).count()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+31
-29
@@ -1,6 +1,6 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{Err, Result, err, utils::result::MapExpect};
|
use conduwuit::{Err, Result, err, implement, utils::result::MapExpect};
|
||||||
use futures::{Future, FutureExt, TryFutureExt, future::ready};
|
use futures::{Future, FutureExt, TryFutureExt, future::ready};
|
||||||
use rocksdb::{DBPinnableSlice, ReadOptions};
|
use rocksdb::{DBPinnableSlice, ReadOptions};
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
@@ -10,17 +10,17 @@ use crate::{
|
|||||||
util::{is_incomplete, map_err, or_else},
|
util::{is_incomplete, map_err, or_else},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl super::Map {
|
/// Fetch a value from the database into cache, returning a reference-handle
|
||||||
/// Fetch a value from the database into cache, returning a reference-handle
|
/// asynchronously. The key is referenced directly to perform the query.
|
||||||
/// asynchronously. The key is referenced directly to perform the query.
|
#[implement(super::Map)]
|
||||||
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
||||||
pub fn get<K>(
|
pub fn get<K>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K>
|
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K>
|
||||||
where
|
where
|
||||||
K: AsRef<[u8]> + Debug + ?Sized,
|
K: AsRef<[u8]> + Debug + ?Sized,
|
||||||
{
|
{
|
||||||
use crate::pool::Get;
|
use crate::pool::Get;
|
||||||
|
|
||||||
let cached = self.get_cached(key);
|
let cached = self.get_cached(key);
|
||||||
@@ -42,40 +42,42 @@ impl super::Map {
|
|||||||
.execute_get(cmd)
|
.execute_get(cmd)
|
||||||
.and_then(|mut res| ready(res.remove(0)))
|
.and_then(|mut res| ready(res.remove(0)))
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a value from the cache without I/O.
|
/// Fetch a value from the cache without I/O.
|
||||||
#[tracing::instrument(skip(self, key), name = "cache", level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub(crate) fn get_cached<K>(&self, key: &K) -> Result<Option<Handle<'_>>>
|
#[tracing::instrument(skip(self, key), name = "cache", level = "trace")]
|
||||||
where
|
pub(crate) fn get_cached<K>(&self, key: &K) -> Result<Option<Handle<'_>>>
|
||||||
|
where
|
||||||
K: AsRef<[u8]> + Debug + ?Sized,
|
K: AsRef<[u8]> + Debug + ?Sized,
|
||||||
{
|
{
|
||||||
let res = self.get_blocking_opts(key, &self.cache_read_options);
|
let res = self.get_blocking_opts(key, &self.cache_read_options);
|
||||||
cached_handle_from(res)
|
cached_handle_from(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a value from the database into cache, returning a
|
/// Fetch a value from the database into cache, returning a reference-handle.
|
||||||
/// reference-handle. The key is referenced directly to perform the query.
|
/// The key is referenced directly to perform the query. This is a thread-
|
||||||
/// This is a thread- blocking call.
|
/// blocking call.
|
||||||
#[tracing::instrument(skip(self, key), name = "blocking", level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn get_blocking<K>(&self, key: &K) -> Result<Handle<'_>>
|
#[tracing::instrument(skip(self, key), name = "blocking", level = "trace")]
|
||||||
where
|
pub fn get_blocking<K>(&self, key: &K) -> Result<Handle<'_>>
|
||||||
|
where
|
||||||
K: AsRef<[u8]> + ?Sized,
|
K: AsRef<[u8]> + ?Sized,
|
||||||
{
|
{
|
||||||
let res = self.get_blocking_opts(key, &self.read_options);
|
let res = self.get_blocking_opts(key, &self.read_options);
|
||||||
handle_from(res)
|
handle_from(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_blocking_opts<K>(
|
#[implement(super::Map)]
|
||||||
|
fn get_blocking_opts<K>(
|
||||||
&self,
|
&self,
|
||||||
key: &K,
|
key: &K,
|
||||||
read_options: &ReadOptions,
|
read_options: &ReadOptions,
|
||||||
) -> Result<Option<DBPinnableSlice<'_>>, rocksdb::Error>
|
) -> Result<Option<DBPinnableSlice<'_>>, rocksdb::Error>
|
||||||
where
|
where
|
||||||
K: AsRef<[u8]> + ?Sized,
|
K: AsRef<[u8]> + ?Sized,
|
||||||
{
|
{
|
||||||
self.db.db.get_pinned_cf_opt(&self.cf(), key, read_options)
|
self.db.db.get_pinned_cf_opt(&self.cf(), key, read_options)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{convert::AsRef, sync::Arc};
|
use std::{convert::AsRef, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result,
|
Result, implement,
|
||||||
utils::{
|
utils::{
|
||||||
IterStream,
|
IterStream,
|
||||||
stream::{WidebandExt, automatic_amplification, automatic_width},
|
stream::{WidebandExt, automatic_amplification, automatic_width},
|
||||||
@@ -34,16 +34,16 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
#[tracing::instrument(skip(self, keys), level = "trace")]
|
#[tracing::instrument(skip(self, keys), level = "trace")]
|
||||||
pub(crate) fn get_batch<'a, S, K>(
|
pub(crate) fn get_batch<'a, S, K>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
keys: S,
|
keys: S,
|
||||||
) -> impl Stream<Item = Result<Handle<'a>>> + Send + 'a
|
) -> impl Stream<Item = Result<Handle<'a>>> + Send + 'a
|
||||||
where
|
where
|
||||||
S: Stream<Item = K> + Send + 'a,
|
S: Stream<Item = K> + Send + 'a,
|
||||||
K: AsRef<[u8]> + Send + Sync + 'a,
|
K: AsRef<[u8]> + Send + Sync + 'a,
|
||||||
{
|
{
|
||||||
use crate::pool::Get;
|
use crate::pool::Get;
|
||||||
|
|
||||||
keys.ready_chunks(automatic_amplification())
|
keys.ready_chunks(automatic_amplification())
|
||||||
@@ -56,30 +56,32 @@ impl super::Map {
|
|||||||
})
|
})
|
||||||
.map_ok(|results| results.into_iter().stream())
|
.map_ok(|results| results.into_iter().stream())
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "batch_blocking", level = "trace", skip_all)]
|
#[implement(super::Map)]
|
||||||
pub(crate) fn get_batch_blocking<'a, I, K>(
|
#[tracing::instrument(name = "batch_blocking", level = "trace", skip_all)]
|
||||||
|
pub(crate) fn get_batch_blocking<'a, I, K>(
|
||||||
&self,
|
&self,
|
||||||
keys: I,
|
keys: I,
|
||||||
) -> impl Iterator<Item = Result<Handle<'_>>> + Send + use<'_, I, K>
|
) -> impl Iterator<Item = Result<Handle<'_>>> + Send + use<'_, I, K>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a K> + ExactSizeIterator + Send,
|
I: Iterator<Item = &'a K> + ExactSizeIterator + Send,
|
||||||
K: AsRef<[u8]> + Send + ?Sized + Sync + 'a,
|
K: AsRef<[u8]> + Send + ?Sized + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.get_batch_blocking_opts(keys, &self.read_options)
|
self.get_batch_blocking_opts(keys, &self.read_options)
|
||||||
.map(handle_from)
|
.map(handle_from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_batch_blocking_opts<'a, I, K>(
|
#[implement(super::Map)]
|
||||||
|
fn get_batch_blocking_opts<'a, I, K>(
|
||||||
&self,
|
&self,
|
||||||
keys: I,
|
keys: I,
|
||||||
read_options: &ReadOptions,
|
read_options: &ReadOptions,
|
||||||
) -> impl Iterator<Item = Result<Option<DBPinnableSlice<'_>>, rocksdb::Error>> + Send + use<'_, I, K>
|
) -> impl Iterator<Item = Result<Option<DBPinnableSlice<'_>>, rocksdb::Error>> + Send + use<'_, I, K>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a K> + ExactSizeIterator + Send,
|
I: Iterator<Item = &'a K> + ExactSizeIterator + Send,
|
||||||
K: AsRef<[u8]> + Send + ?Sized + Sync + 'a,
|
K: AsRef<[u8]> + Send + ?Sized + Sync + 'a,
|
||||||
{
|
{
|
||||||
// Optimization can be `true` if key vector is pre-sorted **by the column
|
// Optimization can be `true` if key vector is pre-sorted **by the column
|
||||||
// comparator**.
|
// comparator**.
|
||||||
const SORTED: bool = false;
|
const SORTED: bool = false;
|
||||||
@@ -88,5 +90,4 @@ impl super::Map {
|
|||||||
.db
|
.db
|
||||||
.batched_multi_get_cf_opt(&self.cf(), keys, SORTED, read_options)
|
.batched_multi_get_cf_opt(&self.cf(), keys, SORTED, read_options)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+124
-113
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use std::{convert::AsRef, fmt::Debug, io::Write};
|
use std::{convert::AsRef, fmt::Debug, io::Write};
|
||||||
|
|
||||||
use conduwuit::arrayvec::ArrayVec;
|
use conduwuit::{arrayvec::ArrayVec, implement};
|
||||||
use rocksdb::WriteBatchWithTransaction;
|
use rocksdb::WriteBatchWithTransaction;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@@ -15,177 +15,188 @@ use crate::{
|
|||||||
util::or_else,
|
util::or_else,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl super::Map {
|
/// Insert Key/Value
|
||||||
/// Insert Key/Value
|
///
|
||||||
///
|
/// - Key is serialized
|
||||||
/// - Key is serialized
|
/// - Val is serialized
|
||||||
/// - Val is serialized
|
#[implement(super::Map)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn put<K, V>(&self, key: K, val: V)
|
pub fn put<K, V>(&self, key: K, val: V)
|
||||||
where
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut key_buf = KeyBuf::new();
|
let mut key_buf = KeyBuf::new();
|
||||||
let mut val_buf = ValBuf::new();
|
let mut val_buf = ValBuf::new();
|
||||||
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized
|
/// - Key is serialized
|
||||||
/// - Val is raw
|
/// - Val is raw
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn put_raw<K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn put_raw<K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: AsRef<[u8]>,
|
V: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let mut key_buf = KeyBuf::new();
|
let mut key_buf = KeyBuf::new();
|
||||||
self.bput_raw(key, val, &mut key_buf);
|
self.bput_raw(key, val, &mut key_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is raw
|
/// - Key is raw
|
||||||
/// - Val is serialized
|
/// - Val is serialized
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn raw_put<K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn raw_put<K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: AsRef<[u8]>,
|
K: AsRef<[u8]>,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut val_buf = ValBuf::new();
|
let mut val_buf = ValBuf::new();
|
||||||
self.raw_bput(key, val, &mut val_buf);
|
self.raw_bput(key, val, &mut val_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized
|
/// - Key is serialized
|
||||||
/// - Val is serialized to stack-buffer
|
/// - Val is serialized to stack-buffer
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn put_aput<const VMAX: usize, K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn put_aput<const VMAX: usize, K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut key_buf = KeyBuf::new();
|
let mut key_buf = KeyBuf::new();
|
||||||
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
||||||
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized to stack-buffer
|
/// - Key is serialized to stack-buffer
|
||||||
/// - Val is serialized
|
/// - Val is serialized
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn aput_put<const KMAX: usize, K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn aput_put<const KMAX: usize, K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
||||||
let mut val_buf = ValBuf::new();
|
let mut val_buf = ValBuf::new();
|
||||||
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized to stack-buffer
|
/// - Key is serialized to stack-buffer
|
||||||
/// - Val is serialized to stack-buffer
|
/// - Val is serialized to stack-buffer
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn aput<const KMAX: usize, const VMAX: usize, K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn aput<const KMAX: usize, const VMAX: usize, K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
||||||
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
||||||
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
self.bput(key, val, (&mut key_buf, &mut val_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized to stack-buffer
|
/// - Key is serialized to stack-buffer
|
||||||
/// - Val is raw
|
/// - Val is raw
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn aput_raw<const KMAX: usize, K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn aput_raw<const KMAX: usize, K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: AsRef<[u8]>,
|
V: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
let mut key_buf = ArrayVec::<u8, KMAX>::new();
|
||||||
self.bput_raw(key, val, &mut key_buf);
|
self.bput_raw(key, val, &mut key_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is raw
|
/// - Key is raw
|
||||||
/// - Val is serialized to stack-buffer
|
/// - Val is serialized to stack-buffer
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn raw_aput<const VMAX: usize, K, V>(&self, key: K, val: V)
|
#[inline]
|
||||||
where
|
pub fn raw_aput<const VMAX: usize, K, V>(&self, key: K, val: V)
|
||||||
|
where
|
||||||
K: AsRef<[u8]>,
|
K: AsRef<[u8]>,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
let mut val_buf = ArrayVec::<u8, VMAX>::new();
|
||||||
self.raw_bput(key, val, &mut val_buf);
|
self.raw_bput(key, val, &mut val_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized to supplied buffer
|
/// - Key is serialized to supplied buffer
|
||||||
/// - Val is serialized to supplied buffer
|
/// - Val is serialized to supplied buffer
|
||||||
pub fn bput<K, V, Bk, Bv>(&self, key: K, val: V, mut buf: (Bk, Bv))
|
#[implement(super::Map)]
|
||||||
where
|
pub fn bput<K, V, Bk, Bv>(&self, key: K, val: V, mut buf: (Bk, Bv))
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
Bk: Write + AsRef<[u8]>,
|
Bk: Write + AsRef<[u8]>,
|
||||||
Bv: Write + AsRef<[u8]>,
|
Bv: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let val = ser::serialize(&mut buf.1, val).expect("failed to serialize insertion val");
|
let val = ser::serialize(&mut buf.1, val).expect("failed to serialize insertion val");
|
||||||
self.bput_raw(key, val, &mut buf.0);
|
self.bput_raw(key, val, &mut buf.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is serialized to supplied buffer
|
/// - Key is serialized to supplied buffer
|
||||||
/// - Val is raw
|
/// - Val is raw
|
||||||
#[tracing::instrument(skip(self, val, buf), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn bput_raw<K, V, Bk>(&self, key: K, val: V, mut buf: Bk)
|
#[tracing::instrument(skip(self, val, buf), level = "trace")]
|
||||||
where
|
pub fn bput_raw<K, V, Bk>(&self, key: K, val: V, mut buf: Bk)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
V: AsRef<[u8]>,
|
V: AsRef<[u8]>,
|
||||||
Bk: Write + AsRef<[u8]>,
|
Bk: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let key = ser::serialize(&mut buf, key).expect("failed to serialize insertion key");
|
let key = ser::serialize(&mut buf, key).expect("failed to serialize insertion key");
|
||||||
self.insert(&key, val);
|
self.insert(&key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is raw
|
/// - Key is raw
|
||||||
/// - Val is serialized to supplied buffer
|
/// - Val is serialized to supplied buffer
|
||||||
pub fn raw_bput<K, V, Bv>(&self, key: K, val: V, mut buf: Bv)
|
#[implement(super::Map)]
|
||||||
where
|
pub fn raw_bput<K, V, Bv>(&self, key: K, val: V, mut buf: Bv)
|
||||||
|
where
|
||||||
K: AsRef<[u8]>,
|
K: AsRef<[u8]>,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
Bv: Write + AsRef<[u8]>,
|
Bv: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let val = ser::serialize(&mut buf, val).expect("failed to serialize insertion val");
|
let val = ser::serialize(&mut buf, val).expect("failed to serialize insertion val");
|
||||||
self.insert(&key, val);
|
self.insert(&key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert Key/Value
|
/// Insert Key/Value
|
||||||
///
|
///
|
||||||
/// - Key is raw
|
/// - Key is raw
|
||||||
/// - Val is raw
|
/// - Val is raw
|
||||||
#[tracing::instrument(skip_all, fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn insert<K, V>(&self, key: &K, val: V)
|
#[tracing::instrument(skip_all, fields(%self), level = "trace")]
|
||||||
where
|
pub fn insert<K, V>(&self, key: &K, val: V)
|
||||||
|
where
|
||||||
K: AsRef<[u8]> + ?Sized,
|
K: AsRef<[u8]> + ?Sized,
|
||||||
V: AsRef<[u8]>,
|
V: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let write_options = &self.write_options;
|
let write_options = &self.write_options;
|
||||||
self.db
|
self.db
|
||||||
.db
|
.db
|
||||||
@@ -198,15 +209,16 @@ impl super::Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.watchers.wake(key.as_ref());
|
self.watchers.wake(key.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, iter), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn insert_batch<'a, I, K, V>(&'a self, iter: I)
|
#[tracing::instrument(skip(self, iter), fields(%self), level = "trace")]
|
||||||
where
|
pub fn insert_batch<'a, I, K, V>(&'a self, iter: I)
|
||||||
|
where
|
||||||
I: Iterator<Item = (K, V)> + Send + Debug,
|
I: Iterator<Item = (K, V)> + Send + Debug,
|
||||||
K: AsRef<[u8]> + Sized + Debug + 'a,
|
K: AsRef<[u8]> + Sized + Debug + 'a,
|
||||||
V: AsRef<[u8]> + Sized + 'a,
|
V: AsRef<[u8]> + Sized + 'a,
|
||||||
{
|
{
|
||||||
let mut batch = WriteBatchWithTransaction::<false>::default();
|
let mut batch = WriteBatchWithTransaction::<false>::default();
|
||||||
for (key, val) in iter {
|
for (key, val) in iter {
|
||||||
batch.put_cf(&self.cf(), key.as_ref(), val.as_ref());
|
batch.put_cf(&self.cf(), key.as_ref(), val.as_ref());
|
||||||
@@ -222,5 +234,4 @@ impl super::Map {
|
|||||||
if !self.db.corked() {
|
if !self.db.corked() {
|
||||||
self.db.flush().expect("database flush error");
|
self.db.flush().expect("database flush error");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -9,15 +9,17 @@ use tokio::task;
|
|||||||
use super::stream::is_cached;
|
use super::stream::is_cached;
|
||||||
use crate::{keyval, keyval::Key, stream};
|
use crate::{keyval, keyval::Key, stream};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn keys<'a, K>(self: &'a Arc<Self>) -> impl Stream<Item = Result<Key<'a, K>>> + Send
|
pub fn keys<'a, K>(self: &'a Arc<Self>) -> impl Stream<Item = Result<Key<'a, K>>> + Send
|
||||||
where
|
where
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.raw_keys().map(keyval::result_deserialize_key::<K>)
|
self.raw_keys().map(keyval::result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
#[implement(super::Map)]
|
||||||
|
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||||
|
pub fn raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -46,5 +48,4 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -11,49 +11,52 @@ use crate::{
|
|||||||
stream,
|
stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn keys_from<'a, K, P>(
|
pub fn keys_from<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.keys_from_raw(from).map(result_deserialize_key::<K>)
|
self.keys_from_raw(from).map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn keys_from_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn keys_from_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(from).expect("failed to serialize query key");
|
let key = serialize_key(from).expect("failed to serialize query key");
|
||||||
self.raw_keys_from(&key)
|
self.raw_keys_from(&key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keys_raw_from<'a, K, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn keys_raw_from<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.raw_keys_from(from).map(result_deserialize_key::<K>)
|
self.raw_keys_from(from).map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn raw_keys_from<P>(
|
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||||
|
pub fn raw_keys_from<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug,
|
P: AsRef<[u8]> + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -77,5 +80,4 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,57 +1,59 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{Stream, StreamExt, TryStreamExt, future};
|
use futures::{Stream, StreamExt, TryStreamExt, future};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::keyval::{Key, result_deserialize_key, serialize_key};
|
use crate::keyval::{Key, result_deserialize_key, serialize_key};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn keys_prefix<'a, K, P>(
|
pub fn keys_prefix<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.keys_prefix_raw(prefix)
|
self.keys_prefix_raw(prefix)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn keys_prefix_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn keys_prefix_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(prefix).expect("failed to serialize query key");
|
let key = serialize_key(prefix).expect("failed to serialize query key");
|
||||||
self.raw_keys_from(&key)
|
self.raw_keys_from(&key)
|
||||||
.try_take_while(move |k: &Key<'_>| future::ok(k.starts_with(&key)))
|
.try_take_while(move |k: &Key<'_>| future::ok(k.starts_with(&key)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keys_raw_prefix<'a, K, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn keys_raw_prefix<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + 'a
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
K: Deserialize<'a> + Send + 'a,
|
K: Deserialize<'a> + Send + 'a,
|
||||||
{
|
{
|
||||||
self.raw_keys_prefix(prefix)
|
self.raw_keys_prefix(prefix)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_keys_prefix<'a, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn raw_keys_prefix<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<Key<'a>>> + Send + 'a
|
) -> impl Stream<Item = Result<Key<'a>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.raw_keys_from(prefix)
|
self.raw_keys_from(prefix)
|
||||||
.try_take_while(|k: &Key<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
.try_take_while(|k: &Key<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+29
-29
@@ -1,56 +1,56 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, io::Write, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, io::Write, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{Result, arrayvec::ArrayVec};
|
use conduwuit::{Result, arrayvec::ArrayVec, implement};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{Handle, keyval::KeyBuf, ser};
|
use crate::{Handle, keyval::KeyBuf, ser};
|
||||||
|
|
||||||
impl super::Map {
|
/// Fetch a value from the database into cache, returning a reference-handle
|
||||||
/// Fetch a value from the database into cache, returning a reference-handle
|
/// asynchronously. The key is serialized into an allocated buffer to perform
|
||||||
/// asynchronously. The key is serialized into an allocated buffer to
|
/// the query.
|
||||||
/// perform the query.
|
#[implement(super::Map)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn qry<K>(
|
pub fn qry<K>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K>
|
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = KeyBuf::new();
|
let mut buf = KeyBuf::new();
|
||||||
self.bqry(key, &mut buf)
|
self.bqry(key, &mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a value from the database into cache, returning a reference-handle
|
/// Fetch a value from the database into cache, returning a reference-handle
|
||||||
/// asynchronously. The key is serialized into a fixed-sized buffer to
|
/// asynchronously. The key is serialized into a fixed-sized buffer to perform
|
||||||
/// perform the query. The maximum size is supplied as const generic
|
/// the query. The maximum size is supplied as const generic parameter.
|
||||||
/// parameter.
|
#[implement(super::Map)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn aqry<const MAX: usize, K>(
|
pub fn aqry<const MAX: usize, K>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, MAX, K>
|
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, MAX, K>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = ArrayVec::<u8, MAX>::new();
|
let mut buf = ArrayVec::<u8, MAX>::new();
|
||||||
self.bqry(key, &mut buf)
|
self.bqry(key, &mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a value from the database into cache, returning a reference-handle
|
/// Fetch a value from the database into cache, returning a reference-handle
|
||||||
/// asynchronously. The key is serialized into a user-supplied Writer.
|
/// asynchronously. The key is serialized into a user-supplied Writer.
|
||||||
#[tracing::instrument(skip(self, buf), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn bqry<K, B>(
|
#[tracing::instrument(skip(self, buf), level = "trace")]
|
||||||
|
pub fn bqry<K, B>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
key: &K,
|
key: &K,
|
||||||
buf: &mut B,
|
buf: &mut B,
|
||||||
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K, B>
|
) -> impl Future<Output = Result<Handle<'_>>> + Send + use<'_, K, B>
|
||||||
where
|
where
|
||||||
K: Serialize + ?Sized + Debug,
|
K: Serialize + ?Sized + Debug,
|
||||||
B: Write + AsRef<[u8]>,
|
B: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
||||||
self.get(key)
|
self.get(key)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{fmt::Debug, sync::Arc};
|
use std::{fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result,
|
Result, implement,
|
||||||
utils::{
|
utils::{
|
||||||
IterStream,
|
IterStream,
|
||||||
stream::{WidebandExt, automatic_amplification, automatic_width},
|
stream::{WidebandExt, automatic_amplification, automatic_width},
|
||||||
@@ -32,16 +32,16 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
#[tracing::instrument(skip(self, keys), level = "trace")]
|
#[tracing::instrument(skip(self, keys), level = "trace")]
|
||||||
pub(crate) fn qry_batch<'a, S, K>(
|
pub(crate) fn qry_batch<'a, S, K>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
keys: S,
|
keys: S,
|
||||||
) -> impl Stream<Item = Result<Handle<'a>>> + Send + 'a
|
) -> impl Stream<Item = Result<Handle<'a>>> + Send + 'a
|
||||||
where
|
where
|
||||||
S: Stream<Item = K> + Send + 'a,
|
S: Stream<Item = K> + Send + 'a,
|
||||||
K: Serialize + Debug + 'a,
|
K: Serialize + Debug + 'a,
|
||||||
{
|
{
|
||||||
use crate::pool::Get;
|
use crate::pool::Get;
|
||||||
|
|
||||||
keys.ready_chunks(automatic_amplification())
|
keys.ready_chunks(automatic_amplification())
|
||||||
@@ -58,5 +58,4 @@ impl super::Map {
|
|||||||
})
|
})
|
||||||
.map_ok(|results| results.into_iter().stream())
|
.map_ok(|results| results.into_iter().stream())
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+24
-22
@@ -1,44 +1,47 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, io::Write};
|
use std::{convert::AsRef, fmt::Debug, io::Write};
|
||||||
|
|
||||||
use conduwuit::arrayvec::ArrayVec;
|
use conduwuit::{arrayvec::ArrayVec, implement};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{keyval::KeyBuf, ser, util::or_else};
|
use crate::{keyval::KeyBuf, ser, util::or_else};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn del<K>(&self, key: K)
|
pub fn del<K>(&self, key: K)
|
||||||
where
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = KeyBuf::new();
|
let mut buf = KeyBuf::new();
|
||||||
self.bdel(key, &mut buf);
|
self.bdel(key, &mut buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[implement(super::Map)]
|
||||||
pub fn adel<const MAX: usize, K>(&self, key: K)
|
#[inline]
|
||||||
where
|
pub fn adel<const MAX: usize, K>(&self, key: K)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
{
|
{
|
||||||
let mut buf = ArrayVec::<u8, MAX>::new();
|
let mut buf = ArrayVec::<u8, MAX>::new();
|
||||||
self.bdel(key, &mut buf);
|
self.bdel(key, &mut buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, buf), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn bdel<K, B>(&self, key: K, buf: &mut B)
|
#[tracing::instrument(skip(self, buf), level = "trace")]
|
||||||
where
|
pub fn bdel<K, B>(&self, key: K, buf: &mut B)
|
||||||
|
where
|
||||||
K: Serialize + Debug,
|
K: Serialize + Debug,
|
||||||
B: Write + AsRef<[u8]>,
|
B: Write + AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let key = ser::serialize(buf, key).expect("failed to serialize deletion key");
|
let key = ser::serialize(buf, key).expect("failed to serialize deletion key");
|
||||||
self.remove(key);
|
self.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn remove<K>(&self, key: &K)
|
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
|
||||||
where
|
pub fn remove<K>(&self, key: &K)
|
||||||
|
where
|
||||||
K: AsRef<[u8]> + ?Sized + Debug,
|
K: AsRef<[u8]> + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let write_options = &self.write_options;
|
let write_options = &self.write_options;
|
||||||
self.db
|
self.db
|
||||||
.db
|
.db
|
||||||
@@ -49,5 +52,4 @@ impl super::Map {
|
|||||||
if !self.db.corked() {
|
if !self.db.corked() {
|
||||||
self.db.flush().expect("database flush error");
|
self.db.flush().expect("database flush error");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -9,16 +9,17 @@ use tokio::task;
|
|||||||
use super::rev_stream::is_cached;
|
use super::rev_stream::is_cached;
|
||||||
use crate::{keyval, keyval::Key, stream};
|
use crate::{keyval, keyval::Key, stream};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn rev_keys<'a, K>(self: &'a Arc<Self>) -> impl Stream<Item = Result<Key<'a, K>>> + Send
|
pub fn rev_keys<'a, K>(self: &'a Arc<Self>) -> impl Stream<Item = Result<Key<'a, K>>> + Send
|
||||||
where
|
where
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_raw_keys().map(keyval::result_deserialize_key::<K>)
|
self.rev_raw_keys().map(keyval::result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||||
|
pub fn rev_raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -47,5 +48,4 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -11,51 +11,54 @@ use crate::{
|
|||||||
stream,
|
stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn rev_keys_from<'a, K, P>(
|
pub fn rev_keys_from<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_keys_from_raw(from)
|
self.rev_keys_from_raw(from)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_keys_from_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn rev_keys_from_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(from).expect("failed to serialize query key");
|
let key = serialize_key(from).expect("failed to serialize query key");
|
||||||
self.rev_raw_keys_from(&key)
|
self.rev_raw_keys_from(&key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rev_keys_raw_from<'a, K, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_keys_raw_from<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_raw_keys_from(from)
|
self.rev_raw_keys_from(from)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_raw_keys_from<P>(
|
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||||
|
pub fn rev_raw_keys_from<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug,
|
P: AsRef<[u8]> + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -79,5 +82,4 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,57 +1,59 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{Stream, StreamExt, TryStreamExt, future};
|
use futures::{Stream, StreamExt, TryStreamExt, future};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::keyval::{Key, result_deserialize_key, serialize_key};
|
use crate::keyval::{Key, result_deserialize_key, serialize_key};
|
||||||
|
|
||||||
impl super::Map {
|
#[implement(super::Map)]
|
||||||
pub fn rev_keys_prefix<'a, K, P>(
|
pub fn rev_keys_prefix<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + use<'a, K, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_keys_prefix_raw(prefix)
|
self.rev_keys_prefix_raw(prefix)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_keys_prefix_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn rev_keys_prefix_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<Key<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(prefix).expect("failed to serialize query key");
|
let key = serialize_key(prefix).expect("failed to serialize query key");
|
||||||
self.rev_raw_keys_from(&key)
|
self.rev_raw_keys_from(&key)
|
||||||
.try_take_while(move |k: &Key<'_>| future::ok(k.starts_with(&key)))
|
.try_take_while(move |k: &Key<'_>| future::ok(k.starts_with(&key)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rev_keys_raw_prefix<'a, K, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_keys_raw_prefix<'a, K, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + 'a
|
) -> impl Stream<Item = Result<Key<'a, K>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
K: Deserialize<'a> + Send + 'a,
|
K: Deserialize<'a> + Send + 'a,
|
||||||
{
|
{
|
||||||
self.rev_raw_keys_prefix(prefix)
|
self.rev_raw_keys_prefix(prefix)
|
||||||
.map(result_deserialize_key::<K>)
|
.map(result_deserialize_key::<K>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rev_raw_keys_prefix<'a, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_raw_keys_prefix<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<Key<'a>>> + Send + 'a
|
) -> impl Stream<Item = Result<Key<'a>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.rev_raw_keys_from(prefix)
|
self.rev_raw_keys_from(prefix)
|
||||||
.try_take_while(|k: &Key<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
.try_take_while(|k: &Key<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -8,26 +8,27 @@ use tokio::task;
|
|||||||
|
|
||||||
use crate::{keyval, keyval::KeyVal, stream};
|
use crate::{keyval, keyval::KeyVal, stream};
|
||||||
|
|
||||||
impl super::Map {
|
/// Iterate key-value entries in the map from the end.
|
||||||
/// Iterate key-value entries in the map from the end.
|
///
|
||||||
///
|
/// - Result is deserialized
|
||||||
/// - Result is deserialized
|
#[implement(super::Map)]
|
||||||
pub fn rev_stream<'a, K, V>(
|
pub fn rev_stream<'a, K, V>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send
|
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send
|
||||||
where
|
where
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
V: Deserialize<'a> + Send,
|
V: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_raw_stream()
|
self.rev_raw_stream()
|
||||||
.map(keyval::result_deserialize::<K, V>)
|
.map(keyval::result_deserialize::<K, V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map from the end.
|
/// Iterate key-value entries in the map from the end.
|
||||||
///
|
///
|
||||||
/// - Result is raw
|
/// - Result is raw
|
||||||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> + Send {
|
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||||
|
pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> + Send {
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -56,7 +57,6 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||||
use rocksdb::Direction;
|
use rocksdb::Direction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -12,69 +12,72 @@ use crate::{
|
|||||||
util::is_incomplete,
|
util::is_incomplete,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl super::Map {
|
/// Iterate key-value entries in the map starting from upper-bound.
|
||||||
/// Iterate key-value entries in the map starting from upper-bound.
|
///
|
||||||
///
|
/// - Query is serialized
|
||||||
/// - Query is serialized
|
/// - Result is deserialized
|
||||||
/// - Result is deserialized
|
#[implement(super::Map)]
|
||||||
pub fn rev_stream_from<'a, K, V, P>(
|
pub fn rev_stream_from<'a, K, V, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
V: Deserialize<'a> + Send,
|
V: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_stream_from_raw(from)
|
self.rev_stream_from_raw(from)
|
||||||
.map(result_deserialize::<K, V>)
|
.map(result_deserialize::<K, V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map starting from upper-bound.
|
/// Iterate key-value entries in the map starting from upper-bound.
|
||||||
///
|
///
|
||||||
/// - Query is serialized
|
/// - Query is serialized
|
||||||
/// - Result is raw
|
/// - Result is raw
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_stream_from_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn rev_stream_from_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(from).expect("failed to serialize query key");
|
let key = serialize_key(from).expect("failed to serialize query key");
|
||||||
self.rev_raw_stream_from(&key)
|
self.rev_raw_stream_from(&key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map starting from upper-bound.
|
/// Iterate key-value entries in the map starting from upper-bound.
|
||||||
///
|
///
|
||||||
/// - Query is raw
|
/// - Query is raw
|
||||||
/// - Result is deserialized
|
/// - Result is deserialized
|
||||||
pub fn rev_stream_raw_from<'a, K, V, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_stream_raw_from<'a, K, V, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
V: Deserialize<'a> + Send,
|
V: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_raw_stream_from(from)
|
self.rev_raw_stream_from(from)
|
||||||
.map(result_deserialize::<K, V>)
|
.map(result_deserialize::<K, V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map starting from upper-bound.
|
/// Iterate key-value entries in the map starting from upper-bound.
|
||||||
///
|
///
|
||||||
/// - Query is raw
|
/// - Query is raw
|
||||||
/// - Result is raw
|
/// - Result is raw
|
||||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_raw_stream_from<P>(
|
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||||
|
pub fn rev_raw_stream_from<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
from: &P,
|
from: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug,
|
P: AsRef<[u8]> + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
use crate::pool::Seek;
|
use crate::pool::Seek;
|
||||||
|
|
||||||
let opts = super::iter_options_default(&self.db);
|
let opts = super::iter_options_default(&self.db);
|
||||||
@@ -103,7 +106,6 @@ impl super::Map {
|
|||||||
.into_stream()
|
.into_stream()
|
||||||
.try_flatten()
|
.try_flatten()
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
|
|||||||
@@ -1,75 +1,77 @@
|
|||||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::{Result, implement};
|
||||||
use futures::{Stream, StreamExt, TryStreamExt, future};
|
use futures::{Stream, StreamExt, TryStreamExt, future};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::keyval::{KeyVal, result_deserialize, serialize_key};
|
use crate::keyval::{KeyVal, result_deserialize, serialize_key};
|
||||||
|
|
||||||
impl super::Map {
|
/// Iterate key-value entries in the map where the key matches a prefix.
|
||||||
/// Iterate key-value entries in the map where the key matches a prefix.
|
///
|
||||||
///
|
/// - Query is serialized
|
||||||
/// - Query is serialized
|
/// - Result is deserialized
|
||||||
/// - Result is deserialized
|
#[implement(super::Map)]
|
||||||
pub fn rev_stream_prefix<'a, K, V, P>(
|
pub fn rev_stream_prefix<'a, K, V, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + use<'a, K, V, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
K: Deserialize<'a> + Send,
|
K: Deserialize<'a> + Send,
|
||||||
V: Deserialize<'a> + Send,
|
V: Deserialize<'a> + Send,
|
||||||
{
|
{
|
||||||
self.rev_stream_prefix_raw(prefix)
|
self.rev_stream_prefix_raw(prefix)
|
||||||
.map(result_deserialize::<K, V>)
|
.map(result_deserialize::<K, V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map where the key matches a prefix.
|
/// Iterate key-value entries in the map where the key matches a prefix.
|
||||||
///
|
///
|
||||||
/// - Query is serialized
|
/// - Query is serialized
|
||||||
/// - Result is raw
|
/// - Result is raw
|
||||||
#[tracing::instrument(skip(self), level = "trace")]
|
#[implement(super::Map)]
|
||||||
pub fn rev_stream_prefix_raw<P>(
|
#[tracing::instrument(skip(self), level = "trace")]
|
||||||
|
pub fn rev_stream_prefix_raw<P>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
prefix: &P,
|
prefix: &P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + use<'_, P>
|
||||||
where
|
where
|
||||||
P: Serialize + ?Sized + Debug,
|
P: Serialize + ?Sized + Debug,
|
||||||
{
|
{
|
||||||
let key = serialize_key(prefix).expect("failed to serialize query key");
|
let key = serialize_key(prefix).expect("failed to serialize query key");
|
||||||
self.rev_raw_stream_from(&key)
|
self.rev_raw_stream_from(&key)
|
||||||
.try_take_while(move |(k, _): &KeyVal<'_>| future::ok(k.starts_with(&key)))
|
.try_take_while(move |(k, _): &KeyVal<'_>| future::ok(k.starts_with(&key)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map where the key matches a prefix.
|
/// Iterate key-value entries in the map where the key matches a prefix.
|
||||||
///
|
///
|
||||||
/// - Query is raw
|
/// - Query is raw
|
||||||
/// - Result is deserialized
|
/// - Result is deserialized
|
||||||
pub fn rev_stream_raw_prefix<'a, K, V, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_stream_raw_prefix<'a, K, V, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + 'a
|
) -> impl Stream<Item = Result<KeyVal<'a, K, V>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
K: Deserialize<'a> + Send + 'a,
|
K: Deserialize<'a> + Send + 'a,
|
||||||
V: Deserialize<'a> + Send + 'a,
|
V: Deserialize<'a> + Send + 'a,
|
||||||
{
|
{
|
||||||
self.rev_raw_stream_prefix(prefix)
|
self.rev_raw_stream_prefix(prefix)
|
||||||
.map(result_deserialize::<K, V>)
|
.map(result_deserialize::<K, V>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate key-value entries in the map where the key matches a prefix.
|
/// Iterate key-value entries in the map where the key matches a prefix.
|
||||||
///
|
///
|
||||||
/// - Query is raw
|
/// - Query is raw
|
||||||
/// - Result is raw
|
/// - Result is raw
|
||||||
pub fn rev_raw_stream_prefix<'a, P>(
|
#[implement(super::Map)]
|
||||||
|
pub fn rev_raw_stream_prefix<'a, P>(
|
||||||
self: &'a Arc<Self>,
|
self: &'a Arc<Self>,
|
||||||
prefix: &'a P,
|
prefix: &'a P,
|
||||||
) -> impl Stream<Item = Result<KeyVal<'a>>> + Send + 'a
|
) -> impl Stream<Item = Result<KeyVal<'a>>> + Send + 'a
|
||||||
where
|
where
|
||||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||||
{
|
{
|
||||||
self.rev_raw_stream_from(prefix)
|
self.rev_raw_stream_from(prefix)
|
||||||
.try_take_while(|(k, _): &KeyVal<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
.try_take_while(|(k, _): &KeyVal<'_>| future::ok(k.starts_with(prefix.as_ref())))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loaded 100 of 182 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user