Browse Source

Merge pull request #755 from adotkhan/dsl

Implement Stringer and TextMarshaler interfaces for ServerEntryTag
Rod Hynes 4 months ago
parent
commit
2509b89067
2 changed files with 16 additions and 3 deletions
  1. 14 0
      psiphon/common/dsl/api.go
  2. 2 3
      psiphon/common/dsl/relay.go

+ 14 - 0
psiphon/common/dsl/api.go

@@ -34,6 +34,8 @@
 package dsl
 
 import (
+	"encoding/base64"
+
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 )
 
@@ -63,6 +65,18 @@ type DiscoverServerEntriesRequest struct {
 // for compactness.
 type ServerEntryTag []byte
 
+// MarshalText emits server entry tag as base64 with padding.
+// Uses the same string encoding as protocol.GenerateServerEntryTag.
+func (tag ServerEntryTag) MarshalText() ([]byte, error) {
+	return []byte(tag.String()), nil
+}
+
+// String emits server entry tag as base64 with padding.
+// Uses the same string encoding as protocol.GenerateServerEntryTag.
+func (tag ServerEntryTag) String() string {
+	return base64.StdEncoding.EncodeToString(tag)
+}
+
 // VersionedServerEntryTag is a server entry tag and version pair.
 type VersionedServerEntryTag struct {
 	Tag     ServerEntryTag `cbor:"1,keyasint,omitempty"`

+ 2 - 3
psiphon/common/dsl/relay.go

@@ -532,9 +532,8 @@ func (r *Relay) getCachedGetServerEntriesResponse(
 		// The cached entry's TTL is not extended on a hit.
 
 		// serverEntryTags are used for logging the request event when served
-		// from the cache. Use the same same string encoding as
-		// protocol.GenerateServerEntryTag.
-		serverEntryTags[i] = base64.StdEncoding.EncodeToString(serverEntryTag)
+		// from the cache.
+		serverEntryTags[i] = serverEntryTag.String()
 
 		response.SourcedServerEntries[i] = cacheEntry.(*SourcedServerEntry)
 	}