Browse Source

Log Conjure cache size

Rod Hynes 4 years ago
parent
commit
9fef23a208

+ 3 - 0
psiphon/common/refraction/config.go

@@ -85,4 +85,7 @@ type ConjureConfig struct {
 	// Transport may be protocol.CONJURE_TRANSPORT_MIN_OSSH or
 	// protocol.CONJURE_TRANSPORT_OBFS4_OSSH.
 	Transport string
+
+	// Logger is used for logging diagnostics.
+	Logger common.Logger
 }

+ 12 - 0
psiphon/common/refraction/refraction.go

@@ -306,6 +306,7 @@ func dial(
 		// after canceling or success, but not on phantom dial failure.
 
 		conjureCachedRegistration = conjureRegistrationCache.pop(
+			conjureConfig.Logger,
 			conjureConfig.RegistrationCacheTTL,
 			conjureConfig.RegistrationCacheKey)
 
@@ -440,6 +441,7 @@ func dial(
 			registration.TcpDialer = nil
 
 			conjureRegistrationCache.put(
+				conjureConfig.Logger,
 				conjureConfig.RegistrationCacheTTL,
 				conjureConfig.RegistrationCacheKey,
 				registration)
@@ -484,6 +486,7 @@ func newRegistrationCache() *registrationCache {
 }
 
 func (c *registrationCache) put(
+	logger common.Logger,
 	TTL time.Duration,
 	key string,
 	registration *refraction_networking_client.ConjureReg) {
@@ -500,6 +503,10 @@ func (c *registrationCache) put(
 		c.TTL = TTL
 	}
 
+	logger.WithTraceFields(
+		common.LogFields{"size": c.cache.ItemCount()}).Info(
+		"Conjure cache")
+
 	c.cache.Set(
 		key,
 		registration,
@@ -507,6 +514,7 @@ func (c *registrationCache) put(
 }
 
 func (c *registrationCache) pop(
+	logger common.Logger,
 	TTL time.Duration,
 	key string) *refraction_networking_client.ConjureReg {
 
@@ -519,6 +527,10 @@ func (c *registrationCache) pop(
 		c.TTL = TTL
 	}
 
+	logger.WithTraceFields(
+		common.LogFields{"size": c.cache.ItemCount()}).Info(
+		"Conjure cache")
+
 	entry, found := c.cache.Get(key)
 	if found {
 		c.cache.Delete(key)

+ 0 - 1
psiphon/notice.go

@@ -306,7 +306,6 @@ func makeNoticeInternalError(errorMessage string) []byte {
 	// Format an Alert Notice (_without_ using json.Marshal, since that can fail)
 	alertNoticeFormat := "{\"noticeType\":\"InternalError\",\"timestamp\":\"%s\",\"data\":{\"message\":\"%s\"}}\n"
 	return []byte(fmt.Sprintf(alertNoticeFormat, time.Now().UTC().Format(common.RFC3339Milli), errorMessage))
-
 }
 
 func (nl *noticeLogger) outputNoticeToHomepageFile(noticeFlags uint32, output []byte) error {

+ 2 - 1
psiphon/tunnel.go

@@ -809,12 +809,13 @@ func dialTunnel(
 		// will be assigned the original public IP on network A; so there's some
 		// chance the registration cannot be reused.
 
-		cacheKey := dialParams.NetworkID + "-" + dialParams.ServerEntry.IpAddress
+		cacheKey := dialParams.NetworkID + "-" + dialParams.ServerEntry.GetDiagnosticID()
 
 		conjureConfig := &refraction.ConjureConfig{
 			RegistrationCacheTTL: dialParams.ConjureCachedRegistrationTTL,
 			RegistrationCacheKey: cacheKey,
 			Transport:            dialParams.ConjureTransport,
+			Logger:               NoticeCommonLogger(),
 		}
 
 		if dialParams.ConjureAPIRegistration {