Skip to content

Commit 87e863e

Browse files
authored
refactor(dcutr): remove direct::Handler
With recent refactorings in `libp2p-swarm`, there is no more need for `handler::direct` at all. Resolves libp2p#4013. Pull-Request: libp2p#4016.
1 parent 92c8cc4 commit 87e863e

File tree

3 files changed

+15
-125
lines changed

3 files changed

+15
-125
lines changed

protocols/dcutr/src/behaviour_impl.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub enum Error {
7070

7171
pub struct Behaviour {
7272
/// Queue of actions to return when polled.
73-
queued_events: VecDeque<ToSwarm<Event, Either<handler::relayed::Command, Either<Void, Void>>>>,
73+
queued_events: VecDeque<ToSwarm<Event, Either<handler::relayed::Command, Void>>>,
7474

7575
/// All direct (non-relayed) connections.
7676
direct_connections: HashMap<PeerId, HashSet<ConnectionId>>,
@@ -233,10 +233,7 @@ impl Behaviour {
233233
}
234234

235235
impl NetworkBehaviour for Behaviour {
236-
type ConnectionHandler = Either<
237-
handler::relayed::Handler,
238-
Either<handler::direct::Handler, dummy::ConnectionHandler>,
239-
>;
236+
type ConnectionHandler = Either<handler::relayed::Handler, dummy::ConnectionHandler>;
240237
type ToSwarm = Event;
241238

242239
fn handle_established_inbound_connection(
@@ -262,7 +259,7 @@ impl NetworkBehaviour for Behaviour {
262259
"state mismatch"
263260
);
264261

265-
Ok(Either::Right(Either::Right(dummy::ConnectionHandler)))
262+
Ok(Either::Right(dummy::ConnectionHandler))
266263
}
267264

268265
fn handle_established_outbound_connection(
@@ -293,12 +290,19 @@ impl NetworkBehaviour for Behaviour {
293290
);
294291
}
295292

296-
return Ok(Either::Right(Either::Left(
297-
handler::direct::Handler::default(),
298-
)));
293+
self.queued_events.extend([
294+
ToSwarm::NotifyHandler {
295+
peer_id: peer,
296+
handler: NotifyHandler::One(relayed_connection_id),
297+
event: Either::Left(handler::relayed::Command::UpgradeFinishedDontKeepAlive),
298+
},
299+
ToSwarm::GenerateEvent(Event::DirectConnectionUpgradeSucceeded {
300+
remote_peer_id: peer,
301+
}),
302+
]);
299303
}
300304

301-
Ok(Either::Right(Either::Right(dummy::ConnectionHandler)))
305+
Ok(Either::Right(dummy::ConnectionHandler))
302306
}
303307

304308
fn on_connection_handler_event(
@@ -383,21 +387,7 @@ impl NetworkBehaviour for Behaviour {
383387
.or_default() += 1;
384388
self.queued_events.push_back(ToSwarm::Dial { opts });
385389
}
386-
Either::Right(Either::Left(handler::direct::Event::DirectConnectionEstablished)) => {
387-
self.queued_events.extend([
388-
ToSwarm::NotifyHandler {
389-
peer_id: event_source,
390-
handler: NotifyHandler::One(relayed_connection_id),
391-
event: Either::Left(
392-
handler::relayed::Command::UpgradeFinishedDontKeepAlive,
393-
),
394-
},
395-
ToSwarm::GenerateEvent(Event::DirectConnectionUpgradeSucceeded {
396-
remote_peer_id: event_source,
397-
}),
398-
]);
399-
}
400-
Either::Right(Either::Right(never)) => void::unreachable(never),
390+
Either::Right(never) => void::unreachable(never),
401391
};
402392
}
403393

protocols/dcutr/src/handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
pub(crate) mod direct;
2221
pub(crate) mod relayed;

protocols/dcutr/src/handler/direct.rs

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)