@@ -122,24 +122,13 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
122
122
123
123
key := segments [2 ]
124
124
125
- if p , ok := ns .cacheGet (key ); ok {
126
- var err error
127
- if len (segments ) > 3 {
128
- p , err = path .FromSegments ("" , strings .TrimRight (p .String (), "/" ), segments [3 ])
129
- }
130
-
131
- out <- onceResult {value : p , err : err }
132
- close (out )
133
- return out
134
- }
135
-
136
125
// Resolver selection:
137
126
// 1. if it is a PeerID/CID/multihash resolve through "ipns".
138
127
// 2. if it is a domain name, resolve through "dns"
139
128
// 3. otherwise resolve through the "proquint" resolver
140
129
141
130
var res resolver
142
- _ , err := peer .Decode (key )
131
+ ipnsKey , err := peer .Decode (key )
143
132
144
133
// CIDs in IPNS are expected to have libp2p-key multicodec
145
134
// We ease the transition by returning a more meaningful error with a valid CID
@@ -155,6 +144,22 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
155
144
}
156
145
}
157
146
147
+ cacheKey := key
148
+ if err == nil {
149
+ cacheKey = string (ipnsKey )
150
+ }
151
+
152
+ if p , ok := ns .cacheGet (cacheKey ); ok {
153
+ var err error
154
+ if len (segments ) > 3 {
155
+ p , err = path .FromSegments ("" , strings .TrimRight (p .String (), "/" ), segments [3 ])
156
+ }
157
+
158
+ out <- onceResult {value : p , err : err }
159
+ close (out )
160
+ return out
161
+ }
162
+
158
163
if err == nil {
159
164
res = ns .ipnsResolver
160
165
} else if isd .IsDomain (key ) {
@@ -172,7 +177,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
172
177
case res , ok := <- resCh :
173
178
if ! ok {
174
179
if best != (onceResult {}) {
175
- ns .cacheSet (key , best .value , best .ttl )
180
+ ns .cacheSet (cacheKey , best .value , best .ttl )
176
181
}
177
182
return
178
183
}
@@ -218,7 +223,7 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
218
223
if err := ns .ipnsPublisher .PublishWithEOL (ctx , name , value , eol ); err != nil {
219
224
// Invalidate the cache. Publishing may _partially_ succeed but
220
225
// still return an error.
221
- ns .cacheInvalidate (peer . Encode (id ))
226
+ ns .cacheInvalidate (string (id ))
222
227
return err
223
228
}
224
229
ttl := DefaultResolverCacheTTL
@@ -228,6 +233,6 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
228
233
if ttEol := time .Until (eol ); ttEol < ttl {
229
234
ttl = ttEol
230
235
}
231
- ns .cacheSet (peer . Encode (id ), value , ttl )
236
+ ns .cacheSet (string (id ), value , ttl )
232
237
return nil
233
238
}
0 commit comments