Skip to content

Commit

Permalink
chore: Use correct arguments and check for external addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 24, 2023
1 parent 79f7987 commit 30c48ad
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
8 changes: 6 additions & 2 deletions tools/shuttle/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use rust_ipfs::{
core::Endpoint,
request_response::{RequestId, ResponseChannel},
swarm::{
ConnectionDenied, ConnectionId, FromSwarm, PollParameters, THandler, THandlerInEvent,
THandlerOutEvent, ToSwarm,
ConnectionDenied, ConnectionId, ExternalAddresses, FromSwarm, PollParameters, THandler,
THandlerInEvent, THandlerOutEvent, ToSwarm,
},
},
Keypair, Multiaddr, NetworkBehaviour, PeerId,
Expand Down Expand Up @@ -58,6 +58,8 @@ pub struct Behaviour {
process_command: Option<futures::channel::mpsc::Receiver<IdentityCommand>>,

queue_event: HashMap<RequestId, (Option<ResponseChannel<Response>>, Either<Request, Response>)>,

external_addresses: ExternalAddresses,
}

#[derive(Debug)]
Expand Down Expand Up @@ -129,6 +131,7 @@ impl Behaviour {
waiting_on_request: Default::default(),
waiting_on_response: Default::default(),
queue_event: Default::default(),
external_addresses: ExternalAddresses::default(),
}
}

Expand Down Expand Up @@ -426,6 +429,7 @@ impl NetworkBehaviour for Behaviour {
}

fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
self.external_addresses.on_swarm_event(&event);
self.inner.on_swarm_event(event)
}

Expand Down
7 changes: 7 additions & 0 deletions tools/shuttle/src/identity/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use super::document::IdentityDocument;

pub const PROTOCOL: StreamProtocol = StreamProtocol::new("/shuttle/identity/0.0.1");

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Message {
Request(Request),
Response(Response),
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Request {
Expand Down
8 changes: 8 additions & 0 deletions tools/shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ impl PeerIdExt for PeerId {
Ok(public_key)
}
}

pub enum ShuttleNodeQuorum {
Primary,
Seconary,
Select(PeerId),
All,
}

22 changes: 12 additions & 10 deletions tools/shuttle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (id_event_tx, mut id_event_rx) = futures::channel::mpsc::channel(1);

let mut uninitialized = UninitializedIpfs::empty()
.set_custom_behaviour(Behaviour {
identity: identity::Behaviour::new(&keypair, id_event_tx, None),
dummy: ext_behaviour::Behaviour,
})
.disable_kad()
.disable_delay()
.set_identify_configuration(IdentifyConfiguration {
.with_identify(Some(IdentifyConfiguration {
agent_version: format!("shuttle/{}", env!("CARGO_PKG_VERSION")),
..Default::default()
}))
.with_autonat()
.with_bitswap(None)
.with_ping(None)
.with_pubsub(None)
.with_custom_behaviour(Behaviour {
identity: identity::Behaviour::new(&keypair, id_event_tx, None),
dummy: ext_behaviour::Behaviour,
})
.enable_relay(true)
.enable_relay_server(Some(RelayConfig {
.with_relay(true)
.with_relay_server(Some(RelayConfig {
max_circuits: 512,
max_circuits_per_peer: 8,
max_circuit_duration: Duration::from_secs(2 * 60),
Expand Down Expand Up @@ -179,7 +181,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
},
],
}))
.enable_rendezvous_server()
.with_rendezvous_server()
.fd_limit(FDLimit::Max)
.set_keypair(keypair)
.set_idle_connection_timeout(120)
Expand Down

0 comments on commit 30c48ad

Please sign in to comment.