diff -U2 -r /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/TorrentsDHT.cpp /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/TorrentsDHT.cpp --- /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/TorrentsDHT.cpp 2026-09-22 01:06:18.000000000 +0000 +++ /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/TorrentsDHT.cpp 2026-09-22 00:51:14.000000000 +0000 @@ -18,18 +18,16 @@ namespace torrents { - std::optional Bucket::GetMiddleID () const + NodeID Bucket::GetMiddleID () const { - uint8_t bit = std::max (start.FindLowestBit (), next ? next->start.FindLowestBit () : -1) + 1; - if (bit >= NodeID::len * 8) return {}; NodeID middleID = start; + int bit = std::max (start.FindLowestBit (), next ? next->start.FindLowestBit () : -1) + 1; middleID[bit >> 3] |= (0x80 >> (bit & 0x07)); - return { middleID }; + return middleID; } - bool Bucket::Split () + void Bucket::Split () { auto middleID = GetMiddleID (); - if (!middleID) return false; - auto newBucket = new Bucket (*middleID); + auto newBucket = new Bucket (middleID); newBucket->next = next; next = newBucket; @@ -38,5 +36,5 @@ while (it != nodes.end ()) { - if ((*it)->id < *middleID) + if ((*it)->id < middleID) it++; // stay in old bucket else @@ -48,5 +46,4 @@ } } - return true; } @@ -108,16 +105,14 @@ auto bucket = FindBucket (id); if (!bucket) return nullptr; - if (bucket->IsFull ()) + if (bucket->IsFull () && !bucket->IsInBucket (m_OurNode)) return nullptr; + + std::shared_ptr node; + do { - if (!bucket->IsInBucket (m_OurNode)) return nullptr; - do - { - if (!bucket->Split ()) return nullptr; - bucket = FindBucket (id); - } - while (bucket->IsFull ()); + bucket->Split (); + bucket = FindBucket (id); } + while (bucket->IsFull ()); - std::shared_ptr node; if (bucket) { diff -U2 -r /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/TorrentsDHT.h /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/TorrentsDHT.h --- /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/TorrentsDHT.h 2026-09-22 01:06:18.000000000 +0000 +++ /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/TorrentsDHT.h 2026-09-22 00:51:14.000000000 +0000 @@ -19,5 +19,4 @@ #include #include -#include #include "Identity.h" #include "I2PService.h" @@ -77,6 +76,6 @@ bool IsFull () const { return nodes.size () >= MAX_BUCKET_CAPACITY; } bool IsInBucket (const NodeID& id) const { return id >= start && (!next || id < next->start); } - std::optional GetMiddleID () const; - bool Split (); + NodeID GetMiddleID () const; + void Split (); };