-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sentry: serial node db execution in a strand (#1302)
- Loading branch information
1 parent
de48426
commit 1c09f16
Showing
8 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2023 The Silkworm Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "serial_node_db.hpp" | ||
|
||
#include <boost/asio/co_spawn.hpp> | ||
#include <boost/asio/use_awaitable.hpp> | ||
|
||
namespace silkworm::sentry::discovery::node_db { | ||
|
||
using namespace boost::asio; | ||
|
||
Task<void> SerialNodeDb::upsert_node_address(NodeId id, NodeAddress address) { | ||
return co_spawn(strand_, db_.upsert_node_address(std::move(id), std::move(address)), use_awaitable); | ||
} | ||
|
||
Task<std::optional<NodeAddress>> SerialNodeDb::find_node_address_v4(NodeId id) { | ||
return co_spawn(strand_, db_.find_node_address_v4(std::move(id)), use_awaitable); | ||
} | ||
|
||
Task<std::optional<NodeAddress>> SerialNodeDb::find_node_address_v6(NodeId id) { | ||
return co_spawn(strand_, db_.find_node_address_v6(std::move(id)), use_awaitable); | ||
} | ||
|
||
Task<void> SerialNodeDb::update_last_pong_time(NodeId id, Time value) { | ||
return co_spawn(strand_, db_.update_last_pong_time(std::move(id), std::move(value)), use_awaitable); | ||
} | ||
|
||
Task<void> SerialNodeDb::delete_node(NodeId id) { | ||
return co_spawn(strand_, db_.delete_node(std::move(id)), use_awaitable); | ||
} | ||
|
||
} // namespace silkworm::sentry::discovery::node_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2023 The Silkworm Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <boost/asio/any_io_executor.hpp> | ||
#include <boost/asio/strand.hpp> | ||
|
||
#include "node_db.hpp" | ||
|
||
namespace silkworm::sentry::discovery::node_db { | ||
|
||
class SerialNodeDb : public NodeDb { | ||
public: | ||
SerialNodeDb( | ||
NodeDb& db, | ||
boost::asio::any_io_executor executor) | ||
: db_(db), | ||
strand_(boost::asio::make_strand(std::move(executor))) {} | ||
~SerialNodeDb() override = default; | ||
|
||
Task<void> upsert_node_address(NodeId id, NodeAddress address) override; | ||
Task<std::optional<NodeAddress>> find_node_address_v4(NodeId id) override; | ||
Task<std::optional<NodeAddress>> find_node_address_v6(NodeId id) override; | ||
Task<void> update_last_pong_time(NodeId id, Time value) override; | ||
Task<void> delete_node(NodeId id) override; | ||
|
||
private: | ||
NodeDb& db_; | ||
boost::asio::strand<boost::asio::any_io_executor> strand_; | ||
}; | ||
|
||
} // namespace silkworm::sentry::discovery::node_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters