@@ -125,7 +125,7 @@ func computeOffset(timeQuery ntpQuery, servers []string, allowedFailures int) (t
125125 return offsets [mid ], nil
126126}
127127
128- var defaultTimeSource = & NTPTimeSource {
128+ var defaultNTPTimeSource = & ntpTimeSource {
129129 servers : defaultServers ,
130130 allowedFailures : DefaultMaxAllowedFailures ,
131131 fastNTPSyncPeriod : FastNTPSyncPeriod ,
@@ -134,14 +134,9 @@ var defaultTimeSource = &NTPTimeSource{
134134 now : time .Now ,
135135}
136136
137- // Default initializes time source with default config values.
138- func Default () * NTPTimeSource {
139- return defaultTimeSource
140- }
141-
142- // NTPTimeSource provides source of time that tries to be resistant to time skews.
137+ // ntpTimeSource provides source of time that tries to be resistant to time skews.
143138// It does so by periodically querying time offset from ntp servers.
144- type NTPTimeSource struct {
139+ type ntpTimeSource struct {
145140 servers []string
146141 allowedFailures int
147142 fastNTPSyncPeriod time.Duration
@@ -160,7 +155,7 @@ type NTPTimeSource struct {
160155
161156// Now returns time adjusted by latest known offset
162157// and detects system time changes
163- func (s * NTPTimeSource ) Now () time.Time {
158+ func (s * ntpTimeSource ) Now () time.Time {
164159 s .timeDataMu .RLock ()
165160
166161 currentTime := s .now ()
@@ -197,7 +192,7 @@ func (s *NTPTimeSource) Now() time.Time {
197192 return adjustedTime
198193}
199194
200- func (s * NTPTimeSource ) updateOffset () error {
195+ func (s * ntpTimeSource ) updateOffset () error {
201196 offset , err := computeOffset (s .timeQuery , s .servers , s .allowedFailures )
202197 if err != nil {
203198 logutils .ZapLogger ().Error ("failed to compute offset" , zap .Error (err ))
@@ -208,14 +203,14 @@ func (s *NTPTimeSource) updateOffset() error {
208203 defer s .timeDataMu .Unlock ()
209204 s .latestOffset = offset
210205 //TBD: if we found offset is too large, we should notify user that system time might not be accurate via emit signal,
211- // and because go-waku doesn't use NTPTimeSource ATM (it just use time.Now()), this might be a problem for MissingMessageVerifier work normally.
206+ // and because go-waku doesn't use ntpTimeSource ATM (it just use time.Now()), this might be a problem for MissingMessageVerifier work normally.
212207 // e.g. might get errInvalidTimeRange when validate StoreQueryRequest
213208 return nil
214209}
215210
216- // runPeriodically runs periodically the given function based on NTPTimeSource
211+ // runPeriodically runs periodically the given function based on ntpTimeSource
217212// synchronization limits (fastNTPSyncPeriod / slowNTPSyncPeriod)
218- func (s * NTPTimeSource ) runPeriodically (ctx context.Context , fn func () error , starWithSlowSyncPeriod bool ) {
213+ func (s * ntpTimeSource ) runPeriodically (ctx context.Context , fn func () error , starWithSlowSyncPeriod bool ) {
219214 if s .started {
220215 return
221216 }
@@ -243,7 +238,7 @@ func (s *NTPTimeSource) runPeriodically(ctx context.Context, fn func() error, st
243238}
244239
245240// Start initializes the local offset and starts a goroutine that periodically updates the local offset.
246- func (s * NTPTimeSource ) Start (ctx context.Context ) error {
241+ func (s * ntpTimeSource ) Start (ctx context.Context ) error {
247242 s .stateMu .Lock ()
248243 defer s .stateMu .Unlock ()
249244 if s .started {
@@ -272,28 +267,28 @@ func (s *NTPTimeSource) Start(ctx context.Context) error {
272267}
273268
274269// Stop goroutine that updates time source.
275- func (s * NTPTimeSource ) Stop () {
270+ func (s * ntpTimeSource ) Stop () {
276271 if s .cancel == nil {
277272 return
278273 }
279274 s .cancel ()
280275 s .started = false
281276}
282277
283- func (s * NTPTimeSource ) GetCurrentTime () time.Time {
278+ func (s * ntpTimeSource ) GetCurrentTime () time.Time {
284279 err := s .Start (context .Background ())
285280 if err != nil {
286281 panic ("could not obtain timesource: " + err .Error ())
287282 }
288283 return s .Now ()
289284}
290285
291- func (s * NTPTimeSource ) GetCurrentTimeInMillis () uint64 {
286+ func (s * ntpTimeSource ) GetCurrentTimeInMillis () uint64 {
292287 return convertToMillis (s .GetCurrentTime ())
293288}
294289
295290func GetCurrentTime () time.Time {
296- ts := Default ()
291+ ts := DefaultService ()
297292 err := ts .Start (context .Background ())
298293 if err != nil {
299294 panic ("could not obtain timesource: " + err .Error ())
0 commit comments