Преглед на файлове

consume resume token during VerifyToken

Independently of this, ClientLookupSet.Resume ensures that at most one
resume can succeed, so this doesn't actually change the behavior.
But ResumeManager should be a standalone example of how to implement
resume without race conditions.
tags/v1.1.0-rc1
Shivaram Lingamneni преди 5 години
родител
ревизия
d43ce07b66
променени са 1 файла, в които са добавени 4 реда и са изтрити 1 реда
  1. 4
    1
      irc/resume.go

+ 4
- 1
irc/resume.go Целия файл

@@ -52,7 +52,8 @@ func (rm *ResumeManager) GenerateToken(client *Client) (token string) {
52 52
 }
53 53
 
54 54
 // VerifyToken looks up the client corresponding to a resume token, returning
55
-// nil if there is no such client or the token is invalid.
55
+// nil if there is no such client or the token is invalid. If successful,
56
+// the token is consumed and cannot be used to resume again.
56 57
 func (rm *ResumeManager) VerifyToken(token string) (client *Client) {
57 58
 	if len(token) != 2*utils.SecretTokenLength {
58 59
 		return
@@ -68,6 +69,8 @@ func (rm *ResumeManager) VerifyToken(token string) (client *Client) {
68 69
 			// disallow resume of an unregistered client; this prevents the use of
69 70
 			// resume as an auth bypass
70 71
 			if pair.client.Registered() {
72
+				// consume the token, ensuring that at most one resume can succeed
73
+				delete(rm.resumeIDtoCreds, id)
71 74
 				return pair.client
72 75
 			}
73 76
 		}

Loading…
Отказ
Запис