Просмотр исходного кода

Use standard monotonic clock

- Go's time package has included a monotonic clock
  since Go 1.9

- Keep using monotime in cases where conversion to
  int64 for lock-free atomic operations is required
Rod Hynes 6 лет назад
Родитель
Сommit
107d9d80c2

+ 2 - 4
psiphon/common/net_test.go

@@ -25,8 +25,6 @@ import (
 	"testing"
 	"testing/iotest"
 	"time"
-
-	"github.com/Psiphon-Labs/goarista/monotime"
 )
 
 type dummyConn struct {
@@ -114,7 +112,7 @@ func TestActivityMonitoredConn(t *testing.T) {
 
 	realStartTime := time.Now().UTC()
 
-	monotonicStartTime := monotime.Now()
+	monotonicStartTime := time.Now()
 
 	time.Sleep(100 * time.Millisecond)
 
@@ -144,7 +142,7 @@ func TestActivityMonitoredConn(t *testing.T) {
 		t.Fatalf("previous write failed to extend timeout")
 	}
 
-	lastSuccessfulReadTime := monotime.Now()
+	lastSuccessfulReadTime := time.Now()
 
 	time.Sleep(100 * time.Millisecond)
 

+ 3 - 4
psiphon/common/quic/obfuscator.go

@@ -27,7 +27,6 @@ import (
 	"sync/atomic"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/Yawning/chacha20"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/hkdf"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
@@ -73,11 +72,11 @@ type ObfuscatedPacketConn struct {
 
 type peerMode struct {
 	isObfuscated   bool
-	lastPacketTime monotime.Time
+	lastPacketTime time.Time
 }
 
 func (p *peerMode) isStale() bool {
-	return monotime.Since(p.lastPacketTime) >= SERVER_IDLE_TIMEOUT
+	return time.Since(p.lastPacketTime) >= SERVER_IDLE_TIMEOUT
 }
 
 // NewObfuscatedPacketConn creates a new ObfuscatedPacketConn.
@@ -229,7 +228,7 @@ func (conn *ObfuscatedPacketConn) ReadFrom(p []byte) (int, net.Addr, error) {
 				mode.isObfuscated = false
 			}
 			isObfuscated = mode.isObfuscated
-			mode.lastPacketTime = monotime.Now()
+			mode.lastPacketTime = time.Now()
 			conn.peerModesMutex.Unlock()
 
 		}

+ 2 - 3
psiphon/common/tactics/tactics.go

@@ -166,7 +166,6 @@ import (
 	"sort"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/nacl/box"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
@@ -1353,11 +1352,11 @@ func FetchTactics(
 			p.Int(parameters.SpeedTestPaddingMinBytes),
 			p.Int(parameters.SpeedTestPaddingMaxBytes))
 
-		startTime := monotime.Now()
+		startTime := time.Now()
 
 		response, err := roundTripper(ctx, SPEED_TEST_END_POINT, request)
 
-		elapsedTime := monotime.Since(startTime)
+		elapsedTime := time.Since(startTime)
 
 		if err != nil {
 			return nil, errors.Trace(err)

+ 4 - 6
psiphon/common/throttled_test.go

@@ -28,8 +28,6 @@ import (
 	"net/http"
 	"testing"
 	"time"
-
-	"github.com/Psiphon-Labs/goarista/monotime"
 )
 
 const (
@@ -129,7 +127,7 @@ func run(t *testing.T, rateLimits RateLimits) {
 	testData, _ := MakeSecureRandomBytes(testDataSize)
 	requestBody := bytes.NewReader(testData)
 
-	startTime := monotime.Now()
+	startTime := time.Now()
 
 	response, err := client.Post("http://"+serverAddress, "application/octet-stream", requestBody)
 	if err == nil && response.StatusCode != http.StatusOK {
@@ -143,9 +141,9 @@ func run(t *testing.T, rateLimits RateLimits) {
 
 	// Test: elapsed upload time must reflect rate limit
 
-	checkElapsedTime(t, testDataSize, rateLimits.WriteBytesPerSecond, monotime.Since(startTime))
+	checkElapsedTime(t, testDataSize, rateLimits.WriteBytesPerSecond, time.Since(startTime))
 
-	startTime = monotime.Now()
+	startTime = time.Now()
 
 	body, err := ioutil.ReadAll(response.Body)
 	if err != nil {
@@ -157,7 +155,7 @@ func run(t *testing.T, rateLimits RateLimits) {
 
 	// Test: elapsed download time must reflect rate limit
 
-	checkElapsedTime(t, testDataSize, rateLimits.ReadBytesPerSecond, monotime.Since(startTime))
+	checkElapsedTime(t, testDataSize, rateLimits.ReadBytesPerSecond, time.Since(startTime))
 }
 
 func checkElapsedTime(t *testing.T, dataSize int, rateLimit int64, duration time.Duration) {

+ 14 - 15
psiphon/controller.go

@@ -32,7 +32,6 @@ import (
 	"sync"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
@@ -346,7 +345,7 @@ func (controller *Controller) remoteServerListFetcher(
 
 	defer controller.runWaitGroup.Done()
 
-	var lastFetchTime monotime.Time
+	var lastFetchTime time.Time
 
 fetcherLoop:
 	for {
@@ -363,8 +362,8 @@ fetcherLoop:
 		stalePeriod := controller.config.GetClientParameters().Get().Duration(
 			parameters.FetchRemoteServerListStalePeriod)
 
-		if lastFetchTime != 0 &&
-			lastFetchTime.Add(stalePeriod).After(monotime.Now()) {
+		if !lastFetchTime.IsZero() &&
+			lastFetchTime.Add(stalePeriod).After(time.Now()) {
 			continue
 		}
 
@@ -390,7 +389,7 @@ fetcherLoop:
 				controller.untunneledDialConfig)
 
 			if err == nil {
-				lastFetchTime = monotime.Now()
+				lastFetchTime = time.Now()
 				break retryLoop
 			}
 
@@ -536,7 +535,7 @@ func (controller *Controller) startOrSignalConnectedReporter() {
 func (controller *Controller) upgradeDownloader() {
 	defer controller.runWaitGroup.Done()
 
-	var lastDownloadTime monotime.Time
+	var lastDownloadTime time.Time
 
 downloadLoop:
 	for {
@@ -554,8 +553,8 @@ downloadLoop:
 		// Unless handshake is explicitly advertizing a new version, skip
 		// checking entirely when a recent download was successful.
 		if handshakeVersion == "" &&
-			lastDownloadTime != 0 &&
-			lastDownloadTime.Add(stalePeriod).After(monotime.Now()) {
+			!lastDownloadTime.IsZero() &&
+			lastDownloadTime.Add(stalePeriod).After(time.Now()) {
 			continue
 		}
 
@@ -582,7 +581,7 @@ downloadLoop:
 				controller.untunneledDialConfig)
 
 			if err == nil {
-				lastDownloadTime = monotime.Now()
+				lastDownloadTime = time.Now()
 				break retryLoop
 			}
 
@@ -1154,7 +1153,7 @@ func (p *protocolSelectionConstraints) selectProtocol(
 type candidateServerEntry struct {
 	serverEntry                *protocol.ServerEntry
 	isServerAffinityCandidate  bool
-	adjustedEstablishStartTime monotime.Time
+	adjustedEstablishStartTime time.Time
 }
 
 // startEstablishing creates a pool of worker goroutines which will
@@ -1632,7 +1631,7 @@ func (controller *Controller) establishCandidateGenerator() {
 	// networkWaitDuration is the elapsed time spent waiting
 	// for network connectivity. This duration will be excluded
 	// from reported tunnel establishment duration.
-	establishStartTime := monotime.Now()
+	establishStartTime := time.Now()
 	var totalNetworkWaitDuration time.Duration
 
 	applyServerAffinity, iterator, err := NewServerEntryIterator(controller.config)
@@ -1684,19 +1683,19 @@ loop:
 		// If the first round ends with no connection, remote server
 		// list and upgrade checks are launched.
 
-		roundStartTime := monotime.Now()
+		roundStartTime := time.Now()
 		var roundNetworkWaitDuration time.Duration
 
 		// Send each iterator server entry to the establish workers
 		for {
 
-			networkWaitStartTime := monotime.Now()
+			networkWaitStartTime := time.Now()
 			if !WaitForNetworkConnectivity(
 				controller.establishCtx,
 				controller.config.NetworkConnectivityChecker) {
 				break loop
 			}
-			networkWaitDuration := monotime.Since(networkWaitStartTime)
+			networkWaitDuration := time.Since(networkWaitStartTime)
 			roundNetworkWaitDuration += networkWaitDuration
 			totalNetworkWaitDuration += networkWaitDuration
 
@@ -1744,7 +1743,7 @@ loop:
 			workTime := controller.config.GetClientParameters().Get().Duration(
 				parameters.EstablishTunnelWorkTime)
 
-			if roundStartTime.Add(-roundNetworkWaitDuration).Add(workTime).Before(monotime.Now()) {
+			if roundStartTime.Add(-roundNetworkWaitDuration).Add(workTime).Before(time.Now()) {
 				// Start over, after a brief pause, with a new shuffle of the server
 				// entries, and potentially some newly fetched server entries.
 				break

+ 2 - 3
psiphon/interrupt_dials_test.go

@@ -29,7 +29,6 @@ import (
 	"testing"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/prng"
 )
@@ -188,7 +187,7 @@ func runInterruptDials(
 		cancelFunc()
 	}
 
-	startWaiting := monotime.Now()
+	startWaiting := time.Now()
 
 	for range addrs {
 		<-dialTerminated
@@ -196,7 +195,7 @@ func runInterruptDials(
 
 	// Test: dial interrupt must complete quickly
 
-	interruptDuration := monotime.Since(startWaiting)
+	interruptDuration := time.Since(startWaiting)
 
 	if interruptDuration > 100*time.Millisecond {
 		t.Fatalf("interrupt duration too long: %s", interruptDuration)

+ 2 - 3
psiphon/meekConn.go

@@ -37,7 +37,6 @@ import (
 	"sync/atomic"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/net/http2"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/nacl/box"
@@ -1100,7 +1099,7 @@ func (meek *MeekConn) relayRoundTrip(sendBuffer *bytes.Buffer) (int64, error) {
 	retries := uint(0)
 
 	p := meek.getCustomClientParameters()
-	retryDeadline := monotime.Now().Add(p.Duration(parameters.MeekRoundTripRetryDeadline))
+	retryDeadline := time.Now().Add(p.Duration(parameters.MeekRoundTripRetryDeadline))
 	retryDelay := p.Duration(parameters.MeekRoundTripRetryMinDelay)
 	retryMaxDelay := p.Duration(parameters.MeekRoundTripRetryMaxDelay)
 	retryMultiplier := p.Float(parameters.MeekRoundTripRetryMultiplier)
@@ -1242,7 +1241,7 @@ func (meek *MeekConn) relayRoundTrip(sendBuffer *bytes.Buffer) (int64, error) {
 		// retry if time remains; when the next delay exceeds the time
 		// remaining until the deadline, do not retry.
 
-		now := monotime.Now()
+		now := time.Now()
 
 		if retries >= 1 &&
 			(now.After(retryDeadline) || retryDeadline.Sub(now) <= retryDelay) {

+ 1 - 1
psiphon/server/dns.go

@@ -158,7 +158,7 @@ func (dns *DNSResolver) reloadWhenStale() {
 
 			// Unconditionally set last reload time. Even on failure only
 			// want to retry after another DNS_SYSTEM_CONFIG_RELOAD_PERIOD.
-			atomic.StoreInt64(&dns.lastReloadTime, time.Now().Unix())
+			atomic.StoreInt64(&dns.lastReloadTime, int64(monotime.Now()))
 
 			_, err := dns.Reload()
 			if err != nil {

+ 12 - 12
psiphon/server/meek.go

@@ -108,7 +108,7 @@ type MeekServer struct {
 	checksumTable     *crc64.Table
 	bufferPool        *CachedResponseBufferPool
 	rateLimitLock     sync.Mutex
-	rateLimitHistory  map[string][]monotime.Time
+	rateLimitHistory  map[string][]time.Time
 	rateLimitCount    int
 	rateLimitSignalGC chan struct{}
 }
@@ -144,7 +144,7 @@ func NewMeekServer(
 		sessions:          make(map[string]*meekSession),
 		checksumTable:     checksumTable,
 		bufferPool:        bufferPool,
-		rateLimitHistory:  make(map[string][]monotime.Time),
+		rateLimitHistory:  make(map[string][]time.Time),
 		rateLimitSignalGC: make(chan struct{}, 1),
 	}
 
@@ -684,19 +684,19 @@ func (server *MeekServer) rateLimit(clientIP string) bool {
 	limit := true
 	triggerGC := false
 
-	now := monotime.Now()
+	now := time.Now()
 	threshold := now.Add(-time.Duration(thresholdSeconds) * time.Second)
 
 	server.rateLimitLock.Lock()
 
 	history, ok := server.rateLimitHistory[clientIP]
 	if !ok || len(history) != historySize {
-		history = make([]monotime.Time, historySize)
+		history = make([]time.Time, historySize)
 		server.rateLimitHistory[clientIP] = history
 	}
 
 	for i := 0; i < len(history); i++ {
-		if history[i] == 0 || history[i].Before(threshold) {
+		if history[i].IsZero() || history[i].Before(threshold) {
 			limit = false
 		}
 		if i == len(history)-1 {
@@ -745,12 +745,12 @@ func (server *MeekServer) rateLimitWorker() {
 
 			server.rateLimitLock.Lock()
 
-			threshold := monotime.Now().Add(-time.Duration(thresholdSeconds) * time.Second)
+			threshold := time.Now().Add(-time.Duration(thresholdSeconds) * time.Second)
 
 			for key, history := range server.rateLimitHistory {
 				reap := true
 				for i := 0; i < len(history); i++ {
-					if history[i] != 0 && !history[i].Before(threshold) {
+					if !history[i].IsZero() && !history[i].Before(threshold) {
 						reap = false
 					}
 				}
@@ -761,7 +761,7 @@ func (server *MeekServer) rateLimitWorker() {
 
 			// Enable rate limit history map to be garbage collected when possible.
 			if len(server.rateLimitHistory) == 0 {
-				server.rateLimitHistory = make(map[string][]monotime.Time)
+				server.rateLimitHistory = make(map[string][]time.Time)
 			}
 
 			server.rateLimitLock.Unlock()
@@ -823,7 +823,7 @@ func (server *MeekServer) deleteExpiredSessions() {
 	}
 	server.sessionsLock.Unlock()
 
-	start := monotime.Now()
+	start := time.Now()
 
 	deleteWaitGroup := new(sync.WaitGroup)
 	for _, sessionID := range expiredSessionIDs {
@@ -836,7 +836,7 @@ func (server *MeekServer) deleteExpiredSessions() {
 	deleteWaitGroup.Wait()
 
 	log.WithTraceFields(
-		LogFields{"elapsed time": monotime.Since(start)}).Debug("deleted expired sessions")
+		LogFields{"elapsed time": time.Since(start)}).Debug("deleted expired sessions")
 }
 
 // httpConnStateCallback tracks open persistent HTTP/HTTPS connections to the
@@ -1255,7 +1255,7 @@ func (conn *meekConn) replaceReadBuffer(readBuffer *bytes.Buffer) {
 // Note: channel scheme assumes only one concurrent call to pumpWrites
 func (conn *meekConn) pumpWrites(writer io.Writer) (int, error) {
 
-	startTime := monotime.Now()
+	startTime := time.Now()
 	timeout := time.NewTimer(MEEK_TURN_AROUND_TIMEOUT)
 	defer timeout.Stop()
 
@@ -1279,7 +1279,7 @@ func (conn *meekConn) pumpWrites(writer io.Writer) (int, error) {
 				// MEEK_MAX_REQUEST_PAYLOAD_LENGTH response bodies
 				return n, nil
 			}
-			totalElapsedTime := monotime.Since(startTime) / time.Millisecond
+			totalElapsedTime := time.Since(startTime) / time.Millisecond
 			if totalElapsedTime >= MEEK_EXTENDED_TURN_AROUND_TIMEOUT {
 				return n, nil
 			}

+ 1 - 2
psiphon/server/sessionID_test.go

@@ -31,7 +31,6 @@ import (
 	"testing"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
@@ -175,7 +174,7 @@ func TestDuplicateSessionID(t *testing.T) {
 		tunnel, err := psiphon.ConnectTunnel(
 			ctx,
 			clientConfig,
-			monotime.Now(),
+			time.Now(),
 			dialParams)
 		if err != nil {
 			t.Fatalf("ConnectTunnel failed: %s", err)

+ 8 - 8
psiphon/server/tunnelServer.go

@@ -1617,7 +1617,7 @@ func (sshClient *sshClient) handleSSHRequests(requests <-chan *ssh.Request) {
 }
 
 type newTCPPortForward struct {
-	enqueueTime   monotime.Time
+	enqueueTime   time.Time
 	hostToConnect string
 	portToConnect int
 	newChannel    ssh.NewChannel
@@ -1692,7 +1692,7 @@ func (sshClient *sshClient) handleTCPPortForwards(
 
 		remainingDialTimeout :=
 			time.Duration(sshClient.getDialTCPPortForwardTimeoutMilliseconds())*time.Millisecond -
-				monotime.Since(newPortForward.enqueueTime)
+				time.Since(newPortForward.enqueueTime)
 
 		if remainingDialTimeout <= 0 {
 			sshClient.updateQualityMetricsWithRejectedDialingLimit()
@@ -1713,13 +1713,13 @@ func (sshClient *sshClient) handleTCPPortForwards(
 		// to become available. This blocks all dequeing.
 
 		if sshClient.isTCPDialingPortForwardLimitExceeded() {
-			blockStartTime := monotime.Now()
+			blockStartTime := time.Now()
 			ctx, cancelCtx := context.WithTimeout(sshClient.runCtx, remainingDialTimeout)
 			sshClient.setTCPPortForwardDialingAvailableSignal(cancelCtx)
 			<-ctx.Done()
 			sshClient.setTCPPortForwardDialingAvailableSignal(nil)
 			cancelCtx() // "must be called or the new context will remain live until its parent context is cancelled"
-			remainingDialTimeout -= monotime.Since(blockStartTime)
+			remainingDialTimeout -= time.Since(blockStartTime)
 		}
 
 		if remainingDialTimeout <= 0 {
@@ -1985,7 +1985,7 @@ func (sshClient *sshClient) handleNewTCPPortForwardChannel(
 		// is immediately rejected.
 
 		tcpPortForward := &newTCPPortForward{
-			enqueueTime:   monotime.Now(),
+			enqueueTime:   time.Now(),
 			hostToConnect: directTcpipExtraData.HostToConnect,
 			portToConnect: int(directTcpipExtraData.PortToConnect),
 			newChannel:    newChannel,
@@ -2911,7 +2911,7 @@ func (sshClient *sshClient) handleTCPChannel(
 	// Contexts are used for cancellation (via sshClient.runCtx, which is cancelled
 	// when the client is stopping) and timeouts.
 
-	dialStartTime := monotime.Now()
+	dialStartTime := time.Now()
 
 	log.WithTraceFields(LogFields{"hostToConnect": hostToConnect}).Debug("resolving")
 
@@ -2932,7 +2932,7 @@ func (sshClient *sshClient) handleTCPChannel(
 		err = std_errors.New("no IP address")
 	}
 
-	resolveElapsedTime := monotime.Since(dialStartTime)
+	resolveElapsedTime := time.Since(dialStartTime)
 
 	if err != nil {
 
@@ -2975,7 +2975,7 @@ func (sshClient *sshClient) handleTCPChannel(
 	cancelCtx() // "must be called or the new context will remain live until its parent context is cancelled"
 
 	// Record port forward success or failure
-	sshClient.updateQualityMetricsWithDialResult(err == nil, monotime.Since(dialStartTime))
+	sshClient.updateQualityMetricsWithDialResult(err == nil, time.Since(dialStartTime))
 
 	if err != nil {
 

+ 3 - 4
psiphon/splitTunnel.go

@@ -30,7 +30,6 @@ import (
 	"sync"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
@@ -80,7 +79,7 @@ type SplitTunnelClassifier struct {
 
 type classification struct {
 	isUntunneled bool
-	expiry       monotime.Time
+	expiry       time.Time
 }
 
 func NewSplitTunnelClassifier(config *Config, tunneler Tunneler) *SplitTunnelClassifier {
@@ -169,7 +168,7 @@ func (classifier *SplitTunnelClassifier) IsUntunneled(targetAddress string) bool
 	classifier.mutex.RLock()
 	cachedClassification, ok := classifier.cache[targetAddress]
 	classifier.mutex.RUnlock()
-	if ok && cachedClassification.expiry.After(monotime.Now()) {
+	if ok && cachedClassification.expiry.After(time.Now()) {
 		return cachedClassification.isUntunneled
 	}
 
@@ -179,7 +178,7 @@ func (classifier *SplitTunnelClassifier) IsUntunneled(targetAddress string) bool
 		NoticeAlert("failed to resolve address for split tunnel classification: %s", err)
 		return false
 	}
-	expiry := monotime.Now().Add(ttl)
+	expiry := time.Now().Add(ttl)
 
 	isUntunneled := classifier.ipAddressInRoutes(ipAddr)
 

+ 19 - 20
psiphon/tunnel.go

@@ -32,7 +32,6 @@ import (
 	"sync"
 	"time"
 
-	"github.com/Psiphon-Labs/goarista/monotime"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/ssh"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
@@ -97,9 +96,9 @@ type Tunnel struct {
 	stopOperate                context.CancelFunc
 	signalPortForwardFailure   chan struct{}
 	totalPortForwardFailures   int
-	adjustedEstablishStartTime monotime.Time
+	adjustedEstablishStartTime time.Time
 	establishDuration          time.Duration
-	establishedTime            monotime.Time
+	establishedTime            time.Time
 }
 
 // getCustomClientParameters helpers wrap the verbose function call chain
@@ -138,7 +137,7 @@ func getCustomClientParameters(
 func ConnectTunnel(
 	ctx context.Context,
 	config *Config,
-	adjustedEstablishStartTime monotime.Time,
+	adjustedEstablishStartTime time.Time,
 	dialParams *DialParameters) (*Tunnel, error) {
 
 	// Build transport layers and establish SSH connection. Note that
@@ -266,8 +265,8 @@ func (tunnel *Tunnel) Activate(
 	//
 	// This time period may include time spent unsuccessfully connecting to other
 	// servers. Time spent waiting for network connectivity is excluded.
-	tunnel.establishDuration = monotime.Since(tunnel.adjustedEstablishStartTime)
-	tunnel.establishedTime = monotime.Now()
+	tunnel.establishDuration = time.Since(tunnel.adjustedEstablishStartTime)
+	tunnel.establishedTime = time.Now()
 
 	// Use the Background context instead of the controller run context, as tunnels
 	// are terminated when the controller calls tunnel.Close.
@@ -582,9 +581,9 @@ func dialTunnel(
 	// Note: ensure DialDuration is set before calling any function which logs
 	// dial_duration.
 
-	startDialTime := monotime.Now()
+	startDialTime := time.Now()
 	defer func() {
-		dialParams.DialDuration = monotime.Since(startDialTime)
+		dialParams.DialDuration = time.Since(startDialTime)
 	}()
 
 	// Note: dialParams.MeekResolvedIPAddress isn't set until the dial begins,
@@ -907,9 +906,9 @@ func performLivenessTest(
 
 	metrics := new(livenessTestMetrics)
 
-	defer func(startTime monotime.Time) {
-		metrics.Duration = monotime.Since(startTime).String()
-	}(monotime.Now())
+	defer func(startTime time.Time) {
+		metrics.Duration = time.Since(startTime).String()
+	}(time.Now())
 
 	PRNG := prng.NewPRNGWithSeed(livenessTestPRNGSeed)
 
@@ -1009,7 +1008,7 @@ func performLivenessTest(
 func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 	defer tunnel.operateWaitGroup.Done()
 
-	now := monotime.Now()
+	now := time.Now()
 	lastBytesReceivedTime := now
 	lastTotalBytesTransferedTime := now
 	totalSent := int64(0)
@@ -1099,7 +1098,7 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 				tunnel.dialParams.ServerEntry.IpAddress)
 
 			if received > 0 {
-				lastBytesReceivedTime = monotime.Now()
+				lastBytesReceivedTime = time.Now()
 			}
 
 			totalSent += sent
@@ -1111,10 +1110,10 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 			replayTargetDownstreamBytes := p.Int(parameters.ReplayTargetDownstreamBytes)
 			replayTargetTunnelDuration := p.Duration(parameters.ReplayTargetTunnelDuration)
 
-			if lastTotalBytesTransferedTime.Add(noticePeriod).Before(monotime.Now()) {
+			if lastTotalBytesTransferedTime.Add(noticePeriod).Before(time.Now()) {
 				NoticeTotalBytesTransferred(
 					tunnel.dialParams.ServerEntry.GetDiagnosticID(), totalSent, totalReceived)
-				lastTotalBytesTransferedTime = monotime.Now()
+				lastTotalBytesTransferedTime = time.Now()
 			}
 
 			// Only emit the frequent BytesTransferred notice when tunnel is not idle.
@@ -1135,7 +1134,7 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 			if !setDialParamsSucceeded &&
 				totalSent >= int64(replayTargetUpstreamBytes) &&
 				totalReceived >= int64(replayTargetDownstreamBytes) &&
-				monotime.Since(tunnel.establishedTime) >= replayTargetTunnelDuration {
+				time.Since(tunnel.establishedTime) >= replayTargetTunnelDuration {
 
 				tunnel.dialParams.Succeeded()
 				setDialParamsSucceeded = true
@@ -1151,7 +1150,7 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 		case <-sshKeepAliveTimer.C:
 			p := tunnel.getCustomClientParameters()
 			inactivePeriod := p.Duration(parameters.SSHKeepAlivePeriodicInactivePeriod)
-			if lastBytesReceivedTime.Add(inactivePeriod).Before(monotime.Now()) {
+			if lastBytesReceivedTime.Add(inactivePeriod).Before(time.Now()) {
 				timeout := p.Duration(parameters.SSHKeepAlivePeriodicTimeout)
 				select {
 				case signalSshKeepAlive <- timeout:
@@ -1176,7 +1175,7 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 			} else {
 				p := tunnel.getCustomClientParameters()
 				inactivePeriod := p.Duration(parameters.SSHKeepAliveProbeInactivePeriod)
-				if lastBytesReceivedTime.Add(inactivePeriod).Before(monotime.Now()) {
+				if lastBytesReceivedTime.Add(inactivePeriod).Before(time.Now()) {
 					timeout := p.Duration(parameters.SSHKeepAliveProbeTimeout)
 					select {
 					case signalSshKeepAlive <- timeout:
@@ -1267,14 +1266,14 @@ func (tunnel *Tunnel) sendSshKeepAlive(isFirstKeepAlive bool, timeout time.Durat
 			p.Int(parameters.SSHKeepAlivePaddingMaxBytes))
 		p.Close()
 
-		startTime := monotime.Now()
+		startTime := time.Now()
 
 		// Note: reading a reply is important for last-received-time tunnel
 		// duration calculation.
 		requestOk, response, err := tunnel.sshClient.SendRequest(
 			"keepalive@openssh.com", true, request)
 
-		elapsedTime := monotime.Since(startTime)
+		elapsedTime := time.Since(startTime)
 
 		errChannel <- err