@cryptotaxi247 / kubo / commits / 0864c8e20

namesys: fix case where there is no cache

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Dec 15, 2016 at 02:16 UTC 0864c8e20e67db9f897032b013894296c5c8f4b7
1 file changed +10 -5
namesys/namesys.go
+10 -5
@@ -107,6 +107,16 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
107 }
108
109 func (ns *mpns) addToDHTCache(key ci.PrivKey, value path.Path, eol time.Time) {
110 + rr, ok := ns.resolvers["dht"].(*routingResolver)
111 + if !ok {
112 + // should never happen, purely for sanity
113 + log.Panicf("unexpected type %T as DHT resolver.", ns.resolvers["dht"])
114 + }
115 + if rr.cache == nil {
116 + // resolver has no caching
117 + return
118 + }
119 +
120 var err error
121 value, err = path.ParsePath(value.String())
122 if err != nil {
@@ -120,11 +130,6 @@ func (ns *mpns) addToDHTCache(key ci.PrivKey, value path.Path, eol time.Time) {
130 return
131 }
132
123 - rr, ok := ns.resolvers["dht"].(*routingResolver)
124 - if !ok {
125 - // should never happen, purely for sanity
126 - log.Panicf("unexpected type %T as DHT resolver.", ns.resolvers["dht"])
127 - }
133 if time.Now().Add(DefaultResolverCacheTTL).Before(eol) {
134 eol = time.Now().Add(DefaultResolverCacheTTL)
135 }