~samwhited/mellium-devel

xmpp: xmpp: remove duplicate stream feature data cache v1 APPLIED

Sam Whited: 1
 xmpp: remove duplicate stream feature data cache

 1 files changed, 7 insertions(+), 11 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~samwhited/mellium-devel/patches/10511/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH xmpp] xmpp: remove duplicate stream feature data cache Export this patch

Data returned for caching from stream feature negotiation is always
stored on the session so that it can be accessed later.
Previously it was also being stored on the current stream features list
cache, but this is redundant since we always have access to the session.

Signed-off-by: Sam Whited <sam@samwhited.com>
---
 features.go | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/features.go b/features.go
index c6eaabb73d69..80248aa166aa 100644
--- a/features.go
+++ b/features.go
@@ -178,8 +178,8 @@ func negotiateFeatures(ctx context.Context, s *Session, first bool, features []S
					feature: startTLS,
				}
			} else {
				// If we're the client, iterate through the cached features and select one
				// to negotiate.
				// If we're the client, iterate through the cached features and select
				// one to negotiate.
				for _, v := range list.cache {
					if _, ok := s.negotiated[v.feature.Name.Space]; ok {
						// If this feature has already been negotiated, skip it.
@@ -192,8 +192,8 @@ func negotiateFeatures(ctx context.Context, s *Session, first bool, features []S
						break
					}

					// If the feature is required, tentatively select it (but finish looking
					// for optional features).
					// If the feature is required, tentatively select it (but finish
					// looking for optional features).
					if v.req {
						data = v
					}
@@ -206,7 +206,7 @@ func negotiateFeatures(ctx context.Context, s *Session, first bool, features []S
			}
		}

		mask, rw, err = data.feature.Negotiate(ctx, s, data.data)
		mask, rw, err = data.feature.Negotiate(ctx, s, s.features[data.feature.Name.Space])
		if err == nil {
			s.state |= mask
		}
@@ -219,7 +219,8 @@ func negotiateFeatures(ctx context.Context, s *Session, first bool, features []S
		}
	}

	// If the list contains no required features, negotiation is complete.
	// If the list contains no required features and a stream restart is not
	// required,  negotiation is complete.
	if !list.req {
		mask |= Ready
	}
@@ -229,7 +230,6 @@ func negotiateFeatures(ctx context.Context, s *Session, first bool, features []S

type sfData struct {
	req     bool
	data    interface{}
	feature StreamFeature
}

@@ -276,7 +276,6 @@ func writeStreamFeatures(ctx context.Context, s *Session, features []StreamFeatu
			}
			list.cache[feature.Name.Space] = sfData{
				req:     r,
				data:    nil,
				feature: feature,
			}
			if r {
@@ -330,11 +329,8 @@ parsefeatures:
					return nil, err
				}

				// TODO: Since we're storing the features data on s.features we can
				// probably remove it from this temporary cache.
				sf.cache[tok.Name.Space] = sfData{
					req:     req,
					data:    data,
					feature: feature,
				}

-- 
2.26.2