Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
acerone85 committed Oct 28, 2024
1 parent 138716b commit 58ffe67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
6 changes: 0 additions & 6 deletions crates/services/p2p/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ impl<'a> Encoder for Cow<'a, [u8]> {
}
}

impl<const SIZE: usize> Encoder for [u8; SIZE] {
fn as_bytes(&self) -> Cow<[u8]> {
Cow::Borrowed(self.as_slice())
}
}

/// Implement this in order to handle serialization & deserialization of Gossipsub messages
pub trait GossipsubCodec {
type RequestMessage;
Expand Down
5 changes: 1 addition & 4 deletions crates/services/p2p/src/codecs/gossipsub.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
io,
marker::PhantomData,
};
use std::io;

use fuel_core_types::fuel_tx::Transaction;

Expand Down
32 changes: 13 additions & 19 deletions crates/services/p2p/src/codecs/request_response.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
use std::{
io,
marker::PhantomData,
};

use async_trait::async_trait;
use futures::{
AsyncRead,
AsyncReadExt,
AsyncWriteExt,
};
use libp2p::request_response;
use strum::IntoEnumIterator as _;
use std::io;

use crate::request_response::{
messages::{
Expand All @@ -20,6 +8,14 @@ use crate::request_response::{
},
protocols::RequestResponseProtocol,
};
use async_trait::async_trait;
use futures::{
AsyncRead,
AsyncReadExt,
AsyncWriteExt,
};
use libp2p::request_response;
use strum::IntoEnumIterator as _;

use super::{
Decode,
Expand Down Expand Up @@ -127,15 +123,13 @@ where
match protocol {
RequestResponseProtocol::V1 => {
let v1_response: V1ResponseMessage = res.into();
let res = self
.data_format
.encode(&v1_response)?
.as_bytes()
.into_owned();
let res = self.data_format.encode(&v1_response)?;
let res = res.as_bytes();
socket.write_all(&res).await?;
}
RequestResponseProtocol::V2 => {
let res = self.data_format.encode(&res)?.as_bytes().into_owned();
let res = self.data_format.encode(&res)?;
let res = res.as_bytes();
socket.write_all(&res).await?;
}
};
Expand Down

0 comments on commit 58ffe67

Please sign in to comment.