| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/subtle" | 8 "crypto/subtle" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 log.ErrorKey: err, | 102 log.ErrorKey: err, |
| 103 "id": pfx.ID, | 103 "id": pfx.ID, |
| 104 "prefix": prefix, | 104 "prefix": prefix, |
| 105 }.Errorf(c, "Failed to load log stream prefix.") | 105 }.Errorf(c, "Failed to load log stream prefix.") |
| 106 if err == ds.ErrNoSuchEntity { | 106 if err == ds.ErrNoSuchEntity { |
| 107 return nil, grpcutil.Errf(codes.FailedPrecondition, "pre
fix is not registered") | 107 return nil, grpcutil.Errf(codes.FailedPrecondition, "pre
fix is not registered") |
| 108 } | 108 } |
| 109 return nil, grpcutil.Internal | 109 return nil, grpcutil.Internal |
| 110 } | 110 } |
| 111 | 111 |
| 112 // If we're past prefix's expiration, reject this stream. |
| 113 // |
| 114 // If the prefix doesn't have an expiration, use its creation time and a
pply |
| 115 // the maximum expiration. |
| 116 expirationTime := pfx.Expiration |
| 117 if expirationTime.IsZero() { |
| 118 expiration := endpoints.MinDuration(cfg.Coordinator.PrefixExpira
tion, pcfg.PrefixExpiration) |
| 119 if expiration > 0 { |
| 120 expirationTime = pfx.Created.Add(expiration) |
| 121 } |
| 122 } |
| 123 if now := clock.Now(c); expirationTime.IsZero() || !now.Before(expiratio
nTime) { |
| 124 log.Fields{ |
| 125 "prefix": pfx.Prefix, |
| 126 "expiration": expirationTime, |
| 127 }.Errorf(c, "The log stream Prefix has expired.") |
| 128 return nil, grpcutil.Errf(codes.FailedPrecondition, "prefix has
expired") |
| 129 } |
| 130 |
| 112 // The prefix secret must match the request secret. If it does, we know
this | 131 // The prefix secret must match the request secret. If it does, we know
this |
| 113 // is a legitimate registration attempt. | 132 // is a legitimate registration attempt. |
| 114 if subtle.ConstantTimeCompare(pfx.Secret, req.Secret) != 1 { | 133 if subtle.ConstantTimeCompare(pfx.Secret, req.Secret) != 1 { |
| 115 log.Errorf(c, "Request secret does not match prefix secret.") | 134 log.Errorf(c, "Request secret does not match prefix secret.") |
| 116 return nil, grpcutil.Errf(codes.InvalidArgument, "invalid secret
") | 135 return nil, grpcutil.Errf(codes.InvalidArgument, "invalid secret
") |
| 117 } | 136 } |
| 118 | 137 |
| 119 // Check for registration, and that the prefix did not expire | 138 // Check for registration, and that the prefix did not expire |
| 120 // (non-transactional). | 139 // (non-transactional). |
| 121 ls := &coordinator.LogStream{ID: coordinator.LogStreamID(path)} | 140 ls := &coordinator.LogStream{ID: coordinator.LogStreamID(path)} |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return nil, grpcutil.Internal | 255 return nil, grpcutil.Internal |
| 237 } | 256 } |
| 238 } | 257 } |
| 239 | 258 |
| 240 return nil, nil | 259 return nil, nil |
| 241 } | 260 } |
| 242 | 261 |
| 243 func (m *registerStreamMutation) Root(c context.Context) *ds.Key { | 262 func (m *registerStreamMutation) Root(c context.Context) *ds.Key { |
| 244 return ds.Get(c).KeyForObj(m.ls) | 263 return ds.Get(c).KeyForObj(m.ls) |
| 245 } | 264 } |
| OLD | NEW |