~emersion/soju-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v2] Fix NICK on upstreams supporting MONITOR

Details
Message ID
<20220822195952.21167-1-ecs@d2evs.net>
DKIM signature
pass
Download raw message
Patch: +12 -2
Previously, uc.network.Network.Nick wasn't successfully updated on
downstream NICK. This would cause soju to immediately switch back to the
old nick when the upstream supported MONITOR, so long as the network had
a nick configured as of initialization.

In addition, stop monitoring our desired nick once we've successfully
switched to it once, in order to not immediately undo server-induced
nick changes.
---
v1 => v2: only update network.Network.Nick if err == nil, and only
monitor the desired nick once on connection if it wasn't available.
 downstream.go |  1 +
 upstream.go   | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/downstream.go b/downstream.go
index f9d1d38..9497052 100644
--- a/downstream.go
+++ b/downstream.go
@@ -1838,6 +1838,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
		}

		if dc.network != nil {
			dc.network.Network.Nick = nick
			if uc := dc.upstream(); uc != nil {
				uc.SendMessageLabeled(ctx, dc.id, &irc.Message{
					Command: "NICK",
diff --git a/upstream.go b/upstream.go
index 0587dca..28d495d 100644
--- a/upstream.go
+++ b/upstream.go
@@ -159,6 +159,8 @@ type upstreamConn struct {
	regainNickBackoff *backoffer

	gotMotd bool

	hasDesiredNick bool
}

func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, error) {
@@ -269,6 +271,7 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
		isupport:              make(map[string]*string),
		pendingCmds:           make(map[string][]pendingUpstreamCommand),
		monitored:             monitorCasemapMap{newCasemapMap()},
		hasDesiredNick:        true,
	}
	return uc, nil
}
@@ -948,6 +951,10 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
				uc.pendingRegainNick = ""
				uc.stopRegainNickTimer()
			}
			wantNick := database.GetNick(&uc.user.User, &uc.network.Network)
			if uc.network.equalCasemap(wantNick, newNick) {
				uc.hasDesiredNick = true
			}
		}

		uc.channels.ForEach(func(ch *upstreamChannel) {
@@ -1581,7 +1588,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err

		// Check if the nick we want is now free
		wantNick := database.GetNick(&uc.user.User, &uc.network.Network)
		if !online && !uc.isOurNick(wantNick) {
		if !online && !uc.isOurNick(wantNick) && !uc.hasDesiredNick {
			found := false
			for _, target := range targets {
				prefix := irc.ParsePrefix(target)
@@ -1790,6 +1797,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
		// servers have NICKLEN=30 so let's just use that.
		if !uc.registered && len(uc.nick)+1 < 30 {
			uc.nick = uc.nick + "_"
			uc.hasDesiredNick = false
			uc.logger.Printf("desired nick is not available, falling back to %q", uc.nick)
			uc.SendMessage(ctx, &irc.Message{
				Command: "NICK",
@@ -2240,7 +2248,8 @@ func (uc *upstreamConn) updateMonitor() {

	wantNick := database.GetNick(&uc.user.User, &uc.network.Network)
	wantNickCM := uc.network.casemap(wantNick)
	if _, ok := add[wantNickCM]; !ok && !uc.monitored.Has(wantNick) && !uc.isOurNick(wantNick) {
	if _, ok := add[wantNickCM]; !ok && !uc.monitored.Has(wantNick) &&
			!uc.isOurNick(wantNick) && !uc.hasDesiredNick {
		addList = append(addList, wantNickCM)
		add[wantNickCM] = struct{}{}
	}
-- 
2.37.1
Details
Message ID
<SOpTUC_0mrV_-B0xJd1ZdMXfwlmt_LGlNRPkGaq-Y9w2MIRCVOcKlKQD2p6nXoC7AvZ_gGhFv9DIPf0LgqyDMT9rj_QaZdQdWi7pIcYVbZk=@emersion.fr>
In-Reply-To
<20220822195952.21167-1-ecs@d2evs.net> (view parent)
DKIM signature
pass
Download raw message
Pushed, thanks!
Reply to thread Export thread (mbox)