@@ -13,6 +13,7 @@ import (
13
13
pb "github.com/ipfs/go-ipfs/namesys/pb"
14
14
path "github.com/ipfs/go-ipfs/path"
15
15
routing "github.com/ipfs/go-ipfs/routing"
16
+ u "github.com/ipfs/go-ipfs/util"
16
17
logging "github.com/ipfs/go-ipfs/vendor/QmXJkcEXB6C9h6Ytb6rrUTFU56Ro62zxgrbxTT3dgjQGA8/go-log"
17
18
)
18
19
@@ -31,25 +32,25 @@ func (r *routingResolver) cacheGet(name string) (path.Path, bool) {
31
32
r .cachelock .Lock ()
32
33
entry , ok := r .cache [name ]
33
34
r .cachelock .Unlock ()
34
- if ok && time .Now ().Sub (entry .recvd ) < r . cachelife {
35
+ if ok && time .Now ().Before (entry .eol ) {
35
36
return entry .val , true
36
37
}
37
38
38
39
return "" , false
39
40
}
40
41
41
- func (r * routingResolver ) cacheSet (name string , val path.Path ) {
42
+ func (r * routingResolver ) cacheSet (name string , val path.Path , eol time. Time ) {
42
43
r .cachelock .Lock ()
43
44
r .cache [name ] = cacheEntry {
44
- val : val ,
45
- recvd : time . Now () ,
45
+ val : val ,
46
+ eol : eol ,
46
47
}
47
48
r .cachelock .Unlock ()
48
49
}
49
50
50
51
type cacheEntry struct {
51
- val path.Path
52
- recvd time.Time
52
+ val path.Path
53
+ eol time.Time
53
54
}
54
55
55
56
// NewRoutingResolver constructs a name resolver using the IPFS Routing system
@@ -133,13 +134,31 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
133
134
if err != nil {
134
135
return "" , err
135
136
}
136
- r .cacheSet (name , p )
137
+
138
+ cacheTil := time .Now ().Add (r .cachelife )
139
+ eol , ok := checkEOL (entry )
140
+ if ok && eol .Before (cacheTil ) {
141
+ cacheTil = eol
142
+ }
143
+
144
+ r .cacheSet (name , p , cacheTil )
137
145
return p , nil
138
146
} else {
139
147
// Its an old style multihash record
140
148
log .Warning ("Detected old style multihash record" )
141
149
p := path .FromKey (key .Key (valh ))
142
- r .cacheSet (name , p )
150
+ r .cacheSet (name , p , time . Now (). Add ( r . cachelife ) )
143
151
return p , nil
144
152
}
145
153
}
154
+
155
+ func checkEOL (e * pb.IpnsEntry ) (time.Time , bool ) {
156
+ if e .GetValidityType () == pb .IpnsEntry_EOL {
157
+ eol , err := u .ParseRFC3339 (string (e .GetValidity ()))
158
+ if err != nil {
159
+ return time.Time {}, false
160
+ }
161
+ return eol , true
162
+ }
163
+ return time.Time {}, false
164
+ }
0 commit comments