github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/src/server/db/time.go (about) 1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package db 16 17 import ( 18 "time" 19 20 log "github.com/golang/glog" 21 22 "github.com/google/fleetspeak/fleetspeak/src/server/internal/ftime" 23 tspb "google.golang.org/protobuf/types/known/timestamppb" 24 ) 25 26 // Now is the clock used by the server. Normally just time.Now, but can be replaced to support testing. It should be used by db.Store implementations to determine the time. 27 func Now() time.Time { 28 return ftime.Now() 29 } 30 31 // NowProto returns a proto representation of Now(). 32 func NowProto() *tspb.Timestamp { 33 n := tspb.New(Now()) 34 if err := n.CheckValid(); err != nil { 35 // Really shouldn't happen; the most likely situation is that we 36 // are in a test using a badly broken Now. 37 log.Fatalf("Unable to convert Now() to a protocol buffer: %s", err) 38 } 39 return n 40 } 41 42 // ClientRetryTime returns when a client message, being sent to the client 43 // approximately Now(), will be considered timed out and eligible to be sent 44 // again. It should be used by MessageStore implementations to determine when a 45 // message can next be provided by ClientMessagesForProcessing. 46 func ClientRetryTime() time.Time { 47 return ftime.ClientRetryTime() 48 } 49 50 // ServerRetryTime returns when server message, whose processing is about to 51 // start, will be considered timed out and eligible to be processed again. 52 // It should be used by MessageStore implementations to determine when a message 53 // can next be provided to a MessageProcessor. 54 func ServerRetryTime(retryCount uint32) time.Time { 55 return ftime.ServerRetryTime(retryCount) 56 }