fn handle_start(&mut self, token: Token, remote_addr: SocketAddr, id: Uuid) -> () {
        if let Some(registered_addr) = self.token_map.remove(&token) {
            if remote_addr == registered_addr {
                // The channel we received the start on was already registered with the appropriate address.
                // There is no need to change anything, we can simply transition the channel.
                debug!(
                    self.log,
                    "Got Start({}, ...) from {}, already registered with correct addr",
                    &remote_addr,
                    &registered_addr
                );
            } else {
                // Make sure we only have one channel and that it's registered with the remote_addr
                if let Some(mut channel) = self.channel_map.remove(&registered_addr) {
                    // There's a channel registered with the remote_addr

                    if let Some(mut other_channel) = self.channel_map.remove(&remote_addr) {
                        // There's another channel for the same host, only one can survive.
                        // If we don't knw the Uuid yet the channel can safely be killed. The remote host must obey our Ack.
                        // It can not discard the other channel without receiving a Start(...) or Ack(...) for the other channel.
                        if let Some(other_id) = other_channel.get_id() {
                            // The other channel has a known id, if it doesn't there is no reason to keep it.

                            if other_channel.connected() || other_id > id || other_channel.closed()
                            {
                                // The other channel should be kept and this one should be discarded.
                                debug!(
                                    self.log,
                                    "Got Start({}, ...) from {}, already connected",
                                    &remote_addr,
                                    &registered_addr
                                );
                                let _ = self.poll.registry().deregister(channel.stream_mut());
                                channel.graceful_shutdown();
                                self.channel_map.insert(remote_addr, other_channel);
                                // It will be driven to completion on its own.
                                return;
                            }
                        }
                        // We will keep this channel, not the other channel
                        info!(
                            self.log,
                            "Dropping other_channel while starting channel {}", &remote_addr
                        );
                        let _ = self
                            .poll
                            .registry()
                            .deregister(other_channel.stream_mut())
                            .ok();
                        other_channel.shutdown();
                        drop(other_channel);
                        // Continue with `channel`
                    }
                    // Re-insert the channel and continue starting it.
                    self.channel_map.insert(remote_addr, channel);
                } else if let Some(channel) = self.channel_map.remove(&remote_addr) {
                    // Only one channel, re-insert the channel with the correct key
                    debug!(
                        self.log,
                        "Got Start({}, ...) from {}, changing name of channel.",
                        &remote_addr,
                        &registered_addr
                    );
                    self.channel_map.insert(remote_addr, channel);
                }
            }

            // Make sure that the channel is registered correctly and in Connected State.
            if let Some(channel) = self.channel_map.get_mut(&remote_addr) {
                debug!(
                    self.log,
                    "Sending ack for {}, {}", &remote_addr, &channel.token.0
                );
                channel.handle_start(&remote_addr, id);
                channel.token = token;
                self.token_map.insert(token, remote_addr);
                if let Err(e) = self.poll.registry().reregister(
                    channel.stream_mut(),
                    token,
                    Interest::WRITABLE | Interest::READABLE,
                ) {
                    warn!(
                        self.log,
                        "Error when reregistering Poll for channel in handle_hello: {:?}", e
                    );
                };

                self.dispatcher_ref
                    .tell(DispatchEnvelope::Event(EventEnvelope::Network(
                        NetworkEvent::Connection(
                            remote_addr,
                            ConnectionState::Connected(remote_addr),
                        ),
                    )));
            }
        } else {
            panic!(
                "No address registered for a token which yielded a hello msg, \
            should not be possible"
            );
        }
    }
/// During channel initialization the threeway handshake to establish connections culminates with this function
/// The Start(remote_addr, id) is received by the host on the receiving end of the channel initialisation.
/// The decision is made here and now.
/// If no other connection is registered for the remote host the decision is easy, we start the channel and send the ack.
/// If there are other connection attempts underway there are multiple possibilities:
///     The other connection has not started and does not have a known UUID: it will be killed, this channel will start.
///     The connection has already started, in which case this channel must be killed.
///     The connection has a known UUID but is not connected: Use the UUID as a tie breaker for which to kill and which to keep.
During channel initialization the threeway handshake to establish connections culminates with this function
The Start(remote_addr, id) is received by the host on the receiving end of the channel initialisation.
The decision is made here and now.
If no other connection is registered for the remote host the decision is easy, we start the channel and send the ack.
If there are other connection attempts underway there are multiple possibilities:
The other connection has not started and does not have a known UUID: it will be killed, this channel will start.
The connection has already started, in which case this channel must be killed.
The connection has a known UUID but is not connected: Use the UUID as a tie breaker for which to kill and which to keep.
During channel initialization the threeway handshake to establish connections culminates with this function The Start ( remote_addr id ) is received by the host on the receiving end of the channel initialisation . The decision is made here and now . If no other connection is registered for the remote host the decision is easy we start the channel and send the ack . If there are other connection attempts underway there are multiple possibilities : The other connection has not started and does not have a known UUID : it will be killed this channel will start . The connection has already started in which case this channel must be killed . The connection has a known UUID but is not connected : Use the UUID as a tie breaker for which to kill and which to keep .
fn handle_start(&mut self, token: Token, remote_addr: SocketAddr, id: Uuid) -> () {
        if let Some(registered_addr) = self.token_map.remove(&token) {
            if remote_addr == registered_addr {
                // The channel we received the start on was already registered with the appropriate address.
                // There is no need to change anything, we can simply transition the channel.
                debug!(
                    self.log,
                    "Got Start({}, ...) from {}, already registered with correct addr",
                    &remote_addr,
                    &registered_addr
                );
            } else {
                // Make sure we only have one channel and that it's registered with the remote_addr
                if let Some(mut channel) = self.channel_map.remove(&registered_addr) {
                    // There's a channel registered with the remote_addr
                    if let Some(mut other_channel) = self.channel_map.remove(&remote_addr) {
                        // There's another channel for the same host, only one can survive.
                        // If we don't knw the Uuid yet the channel can safely be killed. The remote host must obey our Ack.
                        // It can not discard the other channel without receiving a Start(...) or Ack(...) for the other channel.
                        if let Some(other_id) = other_channel.get_id() {
                            // The other channel has a known id, if it doesn't there is no reason to keep it.
                            if other_channel.connected() || other_id > id || other_channel.closed()
                            {
                                // The other channel should be kept and this one should be discarded.
                                debug!(
                                    self.log,
                                    "Got Start({}, ...) from {}, already connected",
                                    &remote_addr,
                                    &registered_addr
                                );
                                let _ = self.poll.registry().deregister(channel.stream_mut());
                                channel.graceful_shutdown();
                                self.channel_map.insert(remote_addr, other_channel);
                                // It will be driven to completion on its own.
                                return;
                            }
                        }
                        // We will keep this channel, not the other channel
                        info!(
                            self.log,
                            "Dropping other_channel while starting channel {}", &remote_addr
                        );
                        let _ = self
                            .poll
                            .registry()
                            .deregister(other_channel.stream_mut())
                            .ok();
                        other_channel.shutdown();
                        drop(other_channel);
                        // Continue with `channel`
                    }
                    // Re-insert the channel and continue starting it.
                    self.channel_map.insert(remote_addr, channel);
                } else if let Some(channel) = self.channel_map.remove(&remote_addr) {
                    // Only one channel, re-insert the channel with the correct key
                    debug!(
                        self.log,
                        "Got Start({}, ...) from {}, changing name of channel.",
                        &remote_addr,
                        &registered_addr
                    );
                    self.channel_map.insert(remote_addr, channel);
                }
            }
            // Make sure that the channel is registered correctly and in Connected State.
            if let Some(channel) = self.channel_map.get_mut(&remote_addr) {
                debug!(
                    self.log,
                    "Sending ack for {}, {}", &remote_addr, &channel.token.0
                );
                channel.handle_start(&remote_addr, id);
                channel.token = token;
                self.token_map.insert(token, remote_addr);
                if let Err(e) = self.poll.registry().reregister(
                    channel.stream_mut(),
                    token,
                    Interest::WRITABLE | Interest::READABLE,
                ) {
                    warn!(
                        self.log,
                        "Error when reregistering Poll for channel in handle_hello: {:?}", e
                    );
                };
                self.dispatcher_ref
                    .tell(DispatchEnvelope::Event(EventEnvelope::Network(
                        NetworkEvent::Connection(
                            remote_addr,
                            ConnectionState::Connected(remote_addr),
                        ),
                    )));
            }
        } else {
            panic!(
                "No address registered for a token which yielded a hello msg, \
            should not be possible"
            );
        }
    }
fn handle_start ( & mut self , token : Token , remote_addr : SocketAddr , id : Uuid ) -> ( ) { if let Some ( registered_addr ) = self . token_map . remove ( & token ) { if remote_addr == registered_addr { // The channel we received the start on was already registered with the appropriate address. // There is no need to change anything, we can simply transition the channel. debug ! ( self log " " remote_addr registered_addr ) ; } else { // Make sure we only have one channel and that it's registered with the remote_addr if let Some ( mut channel ) = self . channel_map . remove ( & registered_addr ) { // There's a channel registered with the remote_addr if let Some ( mut other_channel ) = self . channel_map . remove ( & remote_addr ) { // There's another channel for the same host, only one can survive. // If we don't knw the Uuid yet the channel can safely be killed. The remote host must obey our Ack. // It can not discard the other channel without receiving a Start(...) or Ack(...) for the other channel. if let Some ( other_id ) = other_channel . get_id ( ) { // The other channel has a known id, if it doesn't there is no reason to keep it. if other_channel . connected ( ) || other_id > id || other_channel . closed ( ) { // The other channel should be kept and this one should be discarded. debug ! ( self log " " remote_addr registered_addr ) ; let _ = self . poll . registry ( ) . deregister ( channel . stream_mut ( ) ) ; channel . graceful_shutdown ( ) ; self . channel_map . insert ( remote_addr , other_channel ) ; // It will be driven to completion on its own. return ; } } // We will keep this channel, not the other channel info ! ( self log " " remote_addr ) ; let _ = self . poll . registry ( ) . deregister ( other_channel . stream_mut ( ) ) . ok ( ) ; other_channel . shutdown ( ) ; drop ( other_channel ) ; // Continue with `channel` } // Re-insert the channel and continue starting it. self . channel_map . insert ( remote_addr , channel ) ; } else if let Some ( channel ) = self . channel_map . remove ( & remote_addr ) { // Only one channel, re-insert the channel with the correct key debug ! ( self log " " remote_addr registered_addr ) ; self . channel_map . insert ( remote_addr , channel ) ; } } // Make sure that the channel is registered correctly and in Connected State. if let Some ( channel ) = self . channel_map . get_mut ( & remote_addr ) { debug ! ( self log " " remote_addr channel token 0 ) ; channel . handle_start ( & remote_addr , id ) ; channel . token = token ; self . token_map . insert ( token , remote_addr ) ; if let Err ( e ) = self . poll . registry ( ) . reregister ( channel . stream_mut ( ) , token , Interest :: WRITABLE | Interest :: READABLE , ) { warn ! ( self log " " e ) ; } ; self . dispatcher_ref . tell ( DispatchEnvelope :: Event ( EventEnvelope :: Network ( NetworkEvent :: Connection ( remote_addr , ConnectionState :: Connected ( remote_addr ) , ) , ) ) ) ; } } else { panic ! ( " \
 " ) ; } }
During channel initialization the threeway handshake to establish connections culminates with this function
The Start(remote_addr, id) is received by the host on the receiving end of the channel initialisation.
During channel initialization the threeway handshake to establish connections culminates with this function The Start ( remote_addr id ) is received by the host on the receiving end of the channel initialisation .
&mut self
token
Token
remote_addr
SocketAddr
id
Uuid
&mut self
token
Token
remote_addr
SocketAddr
id
Uuid