Skip to content

Conversation

@trevarj
Copy link
Contributor

@trevarj trevarj commented Aug 19, 2020

If the server sends back a 477 reply, meaning that we can't join the
channel without being registered and identified with NickServ, then we
check to see if nickserv_ident is configured. If it is configured then
we wait for 10 seconds and retry joining the channel. We do this 3 times
and then stop.

Also cleaned up channel tuple and made it into a struct so that I could add a retry count for each channel.
Closes #236

@osa1
Copy link
Owner

osa1 commented Aug 21, 2020

Thanks @trevarj ! Just added some inline comments.

@trevarj trevarj force-pushed the nickserv-477 branch 2 times, most recently from a2d54d2 to d6b68df Compare August 21, 2020 13:49
@osa1 osa1 added this to the 0.7.0 milestone Aug 22, 2020
/// Channel joined state
join_state: JoinState,
/// Join attempts
join_attempts: u8,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved join_attempts out of the Joining variant in JoinState because when the state is Initial there should be join attempts. I thought it's nicer than keeping the value in Initial and in Joining.

@trevarj
Copy link
Contributor Author

trevarj commented Aug 24, 2020

All simple feedback has been applied. I commented on some code that needs another closer review. Sorry this is taking so long!

Copy link
Owner

@osa1 osa1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this code again, I think the initial state is fine. We can remove it, but if we do it we'll need an additional state for "currently joined channels" that we'll join again on reconnect, and move the chans vec to that field in StateInner::reset. Perhaps currently solution is fine.

I'll do another pass later.

Currnetly the state transitions are:

  • Initial -> Joining: when we get 477 for the channel
  • Initial -> Joined: when we were able to join on first attempt
  • Joining -> Joined: when we get a JOIN message for the channel
  • Joining -> Initial: I think when user does /connect while we're trying to join?
  • Joined -> Initial: Connection reset
  • Joined -> Joining: Is this currently invalid?

I think it'd be good to make sure the last one won't happen, or if it will then explain when.

Would be good to document this in the code also (maybe in the documentation for JoinState).

Btw, one bug I just discovered is if I do C-c enter and close tiny while there's a join task we want until the next iteration (~10 seconds) before tiny finally quits.

@trevarj
Copy link
Contributor Author

trevarj commented Aug 25, 2020

* Joining -> Initial: I think when user does `/connect` while we're trying to join?

Right, just a reconnect.

Joined -> Joining: Is this currently invalid?

Yes, this is unexpected/invalid.

I will add these state transitions to the doc comment of JoinState.

I think it'd be good to make sure the last one won't happen, or if it will then explain when.

This match should prevent the bad state. I suppose it doesn't prevent the programmer from doing it somewhere later on, but hopefully the state transition doc will prevent that.

match &mut chan.join_state {
                JoinState::NotJoined => chan.set_joining(snd_abort),
                JoinState::Joining { stop_task, .. } => *stop_task = snd_abort,
                JoinState::Joined => {
                error!("Unexpected JoinState for channel.");
                      return;
                }
}

Copy link
Owner

@osa1 osa1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did another pass.. This is looking quite good now. Thanks again, @trevarj !

warn!("Could not find channel in server state channel list.");
}
} else {
warn!("Received 477 reply but nickserv_ident is not configured.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, let's make this debug! maybe. Note that 477 does not always mean we need to register. Even if it does, it's perfectly fine for a user to try to join to a +R channel without being registered. It's not a problem with tiny that may need debugging later.

If the server sends back a 477 reply, meaning that we can't join the
channel without being registered and identified with NickServ, then we
check to see if nickserv_ident is configured. If it is configured then
we wait for 10 seconds and retry joining the channel. We do this 3 times
and then stop.

Removed some unwraps. Changed UX to alert user of retries

Added new Event to libtiny_client to send a channel message when a 477
reply comes from the server and we want to tell the user that a retry
will be made.

Also, the 477 reply from the server will show up in a channel tab which
lets the user know what is going on instead of not opening a tab at all.

Closing a tab that is in the process of joining a channel kills join
task.
Only send PART message to channel when we are actually joined (in the
channel).

PR feedback changes. Removed optional Sender in JoinState. Cleaned up
log messages. Moved async lambda into own function.

Added doc comment to JoinState. Renamed Initial state to NotJoined

Fixed bug that delays quitting when join task is running

More PR feedback
match utils::find_idx(&self.chans, |c| &c.name == chan) {
None => {
self.chans.push((chan.to_owned(), HashSet::new()));
self.chans.push(Chan::new(chan.to_owned()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initializes the Chan state with NotJoined instead of Joined, which is a bug probably.

Copy link
Contributor Author

@trevarj trevarj Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand this part. I'm assuming that when it's not found / None then the channel is not actually joined. Possibly an unexpected state that should be logged?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of at least two cases where this can happen:

  • User sends a JOIN ... message in the server tab, instead of using /join.
  • The server for whatever reason adds the user to a channel. I think this happened to me before, though I don't remember the details.

I think both branches of this match should initialize the Chan state as Joined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

} else {
false
};
let is_notice = matches!(msg_ty, MsgType::Cmd("NOTICE"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this random clippy warning

@osa1 osa1 merged commit 19f1fa2 into osa1:master Aug 28, 2020
@trevarj trevarj deleted the nickserv-477 branch August 28, 2020 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wait for NickServ response before joining channels when nickserv_ident is used

2 participants