Skip to content

Commit

Permalink
refactor: make self for offer_snapshot mutable (#27)
Browse files Browse the repository at this point in the history
* refactor: make self for offer_snapshot mutable
  • Loading branch information
shotonoff authored Jul 13, 2023
1 parent c161fd6 commit f9f4685
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion abci/examples/echo_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn main() {
let app = EchoApp {};

let cancel = CANCEL_TOKEN.clone();
let server = ServerBuilder::new(app, &socket)
let mut server = ServerBuilder::new(app, &socket)
.with_cancel_token(cancel)
.build()
.expect("server failed");
Expand Down
6 changes: 3 additions & 3 deletions abci/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait Application {

/// Called when bootstrapping the node using state sync.
fn offer_snapshot(
&self,
&mut self,
_request: abci::RequestOfferSnapshot,
) -> Result<abci::ResponseOfferSnapshot, abci::ResponseException> {
Ok(Default::default())
Expand Down Expand Up @@ -144,12 +144,12 @@ pub trait RequestDispatcher {
///
/// `RequestDispatcher` can indicate that it will no longer process new
/// requests by returning `None` variant.
fn handle(&self, request: abci::Request) -> Option<abci::Response>;
fn handle(&mut self, request: abci::Request) -> Option<abci::Response>;
}

// Implement `RequestDispatcher` for all `Application`s.
impl<A: Application> RequestDispatcher for A {
fn handle(&self, request: abci::Request) -> Option<abci::Response> {
fn handle(&mut self, request: abci::Request) -> Option<abci::Response> {
tracing::trace!(?request, "received request");

let response: Result<response::Value, abci::ResponseException> = match request.value? {
Expand Down
6 changes: 3 additions & 3 deletions abci/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ pub trait Server {
/// however, errors must be examined and handled, as the connection
/// should not terminate. One exception is [Error::Cancelled], which
/// means server shutdown was requested.
fn next_client(&self) -> Result<(), Error>;
fn next_client(&mut self) -> Result<(), Error>;

#[deprecated = "use `next_client()`"]
fn handle_connection(&self) -> Result<(), Error> {
fn handle_connection(&mut self) -> Result<(), Error> {
self.next_client()
}
}
Expand All @@ -56,7 +56,7 @@ pub trait Server {
/// impl tenderdash_abci::Application for MyAbciApplication {};
/// let app = MyAbciApplication {};
/// let bind_address = "unix:///tmp/abci.sock";
/// let server = tenderdash_abci::ServerBuilder::new(app, &bind_address).build().expect("server failed");
/// let mut server = tenderdash_abci::ServerBuilder::new(app, &bind_address).build().expect("server failed");
/// loop {
/// if let Err(tenderdash_abci::Error::Cancelled()) = server.next_client() {
/// break;
Expand Down
2 changes: 1 addition & 1 deletion abci/src/server/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
L::Addr: Send + Debug,
L::Io: Send,
{
fn next_client(&self) -> Result<(), Error> {
fn next_client(&mut self) -> Result<(), Error> {
// we create child token to stop the codec but not kill the app
let cancel_token = self.cancel.child_token();
let listener = Arc::clone(&self.listener);
Expand Down
2 changes: 1 addition & 1 deletion abci/tests/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn test_kvstore() {
let bind_address = format!("unix://{}", SOCKET);

let cancel = CANCEL_TOKEN.clone();
let server = ServerBuilder::new(abci_app, &bind_address)
let mut server = ServerBuilder::new(abci_app, &bind_address)
.with_cancel_token(cancel)
.build()
.expect("server failed");
Expand Down
4 changes: 2 additions & 2 deletions abci/tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn tcp_server_test(test_name: &str, bind_address: &str) {

let app = TestDispatcher {};

let server = ServerBuilder::new(app, &bind_address)
let mut server = ServerBuilder::new(app, &bind_address)
.build()
.expect("server failed");
let socket_uri = bind_address.to_string();
Expand All @@ -72,7 +72,7 @@ fn tcp_server_test(test_name: &str, bind_address: &str) {
pub struct TestDispatcher {}

impl RequestDispatcher for TestDispatcher {
fn handle(&self, request: proto::abci::Request) -> Option<proto::abci::Response> {
fn handle(&mut self, request: proto::abci::Request) -> Option<proto::abci::Response> {
// Assert that Info request will is received and close the connection
assert!(matches!(
request.value,
Expand Down
4 changes: 2 additions & 2 deletions abci/tests/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn test_unix_socket_server() {

let app = TestDispatcher {};

let server = ServerBuilder::new(app, &bind_address)
let mut server = ServerBuilder::new(app, &bind_address)
.build()
.expect("server failed");

Expand All @@ -53,7 +53,7 @@ fn test_unix_socket_server() {
pub struct TestDispatcher {}

impl RequestDispatcher for TestDispatcher {
fn handle(&self, request: proto::abci::Request) -> Option<proto::abci::Response> {
fn handle(&mut self, request: proto::abci::Request) -> Option<proto::abci::Response> {
// Assert that Info request will is received and close the connection
assert!(matches!(
request.value,
Expand Down

0 comments on commit f9f4685

Please sign in to comment.