Skip to content

Commit d4411ba

Browse files
committed
refactor: rename Resolve*Result to *Result
1 parent 8d4e7dd commit d4411ba

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed

gateway/utilities_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func newMockNamesysItem(p path.Path, ttl time.Duration) *mockNamesysItem {
6262

6363
type mockNamesys map[string]*mockNamesysItem
6464

65-
func (m mockNamesys) Resolve(ctx context.Context, p path.Path, opts ...namesys.ResolveOption) (result namesys.ResolveResult, err error) {
65+
func (m mockNamesys) Resolve(ctx context.Context, p path.Path, opts ...namesys.ResolveOption) (result namesys.Result, err error) {
6666
cfg := namesys.DefaultResolveOptions()
6767
for _, o := range opts {
6868
o(&cfg)
@@ -79,27 +79,27 @@ func (m mockNamesys) Resolve(ctx context.Context, p path.Path, opts ...namesys.R
7979
name := path.SegmentsToString(p.Segments()[:2]...)
8080
for strings.HasPrefix(name, "/ipns/") {
8181
if depth == 0 {
82-
return namesys.ResolveResult{Path: value, TTL: ttl}, namesys.ErrResolveRecursion
82+
return namesys.Result{Path: value, TTL: ttl}, namesys.ErrResolveRecursion
8383
}
8484
depth--
8585

8686
v, ok := m[name]
8787
if !ok {
88-
return namesys.ResolveResult{}, namesys.ErrResolveFailed
88+
return namesys.Result{}, namesys.ErrResolveFailed
8989
}
9090
value = v.path
9191
ttl = v.ttl
9292
name = value.String()
9393
}
9494

9595
value, err = path.Join(value, p.Segments()[2:]...)
96-
return namesys.ResolveResult{Path: value, TTL: ttl}, err
96+
return namesys.Result{Path: value, TTL: ttl}, err
9797
}
9898

99-
func (m mockNamesys) ResolveAsync(ctx context.Context, p path.Path, opts ...namesys.ResolveOption) <-chan namesys.ResolveAsyncResult {
100-
out := make(chan namesys.ResolveAsyncResult, 1)
99+
func (m mockNamesys) ResolveAsync(ctx context.Context, p path.Path, opts ...namesys.ResolveOption) <-chan namesys.AsyncResult {
100+
out := make(chan namesys.AsyncResult, 1)
101101
res, err := m.Resolve(ctx, p, opts...)
102-
out <- namesys.ResolveAsyncResult{Path: res.Path, TTL: res.TTL, LastMod: res.LastMod, Err: err}
102+
out <- namesys.AsyncResult{Path: res.Path, TTL: res.TTL, LastMod: res.LastMod, Err: err}
103103
close(out)
104104
return out
105105
}

namesys/dns_resolver.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,34 @@ func NewDNSResolver(lookup LookupTXTFunc) *DNSResolver {
3131
return &DNSResolver{lookupTXT: lookup}
3232
}
3333

34-
func (r *DNSResolver) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (ResolveResult, error) {
34+
func (r *DNSResolver) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (Result, error) {
3535
ctx, span := startSpan(ctx, "DNSResolver.Resolve", trace.WithAttributes(attribute.Stringer("Path", p)))
3636
defer span.End()
3737

3838
return resolve(ctx, r, p, ProcessResolveOptions(options))
3939
}
4040

41-
func (r *DNSResolver) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan ResolveAsyncResult {
41+
func (r *DNSResolver) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan AsyncResult {
4242
ctx, span := startSpan(ctx, "DNSResolver.ResolveAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
4343
defer span.End()
4444

4545
return resolveAsync(ctx, r, p, ProcessResolveOptions(options))
4646
}
4747

48-
func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan ResolveAsyncResult {
48+
func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan AsyncResult {
4949
ctx, span := startSpan(ctx, "DNSResolver.ResolveOnceAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
5050
defer span.End()
5151

52-
out := make(chan ResolveAsyncResult, 1)
52+
out := make(chan AsyncResult, 1)
5353
if p.Namespace() != path.IPNSNamespace {
54-
out <- ResolveAsyncResult{Err: fmt.Errorf("unsupported namespace: %q", p.Namespace())}
54+
out <- AsyncResult{Err: fmt.Errorf("unsupported namespace: %q", p.Namespace())}
5555
close(out)
5656
return out
5757
}
5858

5959
fqdn := p.Segments()[1]
6060
if _, ok := dns.IsDomainName(fqdn); !ok {
61-
out <- ResolveAsyncResult{Err: fmt.Errorf("not a valid domain name: %q", fqdn)}
61+
out <- AsyncResult{Err: fmt.Errorf("not a valid domain name: %q", fqdn)}
6262
close(out)
6363
return out
6464
}
@@ -69,10 +69,10 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options
6969
fqdn += "."
7070
}
7171

72-
rootChan := make(chan ResolveAsyncResult, 1)
72+
rootChan := make(chan AsyncResult, 1)
7373
go workDomain(ctx, r, fqdn, rootChan)
7474

75-
subChan := make(chan ResolveAsyncResult, 1)
75+
subChan := make(chan AsyncResult, 1)
7676
go workDomain(ctx, r, "_dnslink."+fqdn, subChan)
7777

7878
go func() {
@@ -90,7 +90,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options
9090
}
9191
if subRes.Err == nil {
9292
p, err := joinPaths(subRes.Path, p)
93-
emitOnceResult(ctx, out, ResolveAsyncResult{Path: p, LastMod: time.Now(), Err: err})
93+
emitOnceResult(ctx, out, AsyncResult{Path: p, LastMod: time.Now(), Err: err})
9494
// Return without waiting for rootRes, since this result
9595
// (for "_dnslink."+fqdn) takes precedence
9696
return
@@ -103,7 +103,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options
103103
}
104104
if rootRes.Err == nil {
105105
p, err := joinPaths(rootRes.Path, p)
106-
emitOnceResult(ctx, out, ResolveAsyncResult{Path: p, LastMod: time.Now(), Err: err})
106+
emitOnceResult(ctx, out, AsyncResult{Path: p, LastMod: time.Now(), Err: err})
107107
// Do not return here. Wait for subRes so that it is
108108
// output last if good, thereby giving subRes precedence.
109109
} else {
@@ -120,7 +120,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options
120120
if rootResErr == ErrResolveFailed && subResErr == ErrResolveFailed {
121121
// Wrap error so that it can be tested if it is a ErrResolveFailed
122122
err := fmt.Errorf("%w: _dnslink subdomain at %q is missing a TXT record (https://docs.ipfs.tech/concepts/dnslink/)", ErrResolveFailed, gopath.Base(fqdn))
123-
emitOnceResult(ctx, out, ResolveAsyncResult{Err: err})
123+
emitOnceResult(ctx, out, AsyncResult{Err: err})
124124
}
125125
return
126126
}
@@ -130,7 +130,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options
130130
return out
131131
}
132132

133-
func workDomain(ctx context.Context, r *DNSResolver, name string, res chan ResolveAsyncResult) {
133+
func workDomain(ctx context.Context, r *DNSResolver, name string, res chan AsyncResult) {
134134
ctx, span := startSpan(ctx, "DNSResolver.WorkDomain", trace.WithAttributes(attribute.String("Name", name)))
135135
defer span.End()
136136

@@ -146,20 +146,20 @@ func workDomain(ctx context.Context, r *DNSResolver, name string, res chan Resol
146146
}
147147
}
148148
// Could not look up any text records for name
149-
res <- ResolveAsyncResult{Err: err}
149+
res <- AsyncResult{Err: err}
150150
return
151151
}
152152

153153
for _, t := range txt {
154154
p, err := parseEntry(t)
155155
if err == nil {
156-
res <- ResolveAsyncResult{Path: p}
156+
res <- AsyncResult{Path: p}
157157
return
158158
}
159159
}
160160

161161
// There were no TXT records with a dnslink
162-
res <- ResolveAsyncResult{Err: ErrResolveFailed}
162+
res <- AsyncResult{Err: ErrResolveFailed}
163163
}
164164

165165
func parseEntry(txt string) (path.Path, error) {

namesys/interface.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ type NameSystem interface {
5858
Publisher
5959
}
6060

61-
// ResolveResult is the return type for [Resolver.Resolve].
62-
type ResolveResult struct {
61+
// Result is the return type for [Resolver.Resolve].
62+
type Result struct {
6363
Path path.Path
6464
TTL time.Duration
6565
LastMod time.Time
6666
}
6767

68-
// ResolveAsyncResult is the return type for [Resolver.ResolveAsync].
69-
type ResolveAsyncResult struct {
68+
// AsyncResult is the return type for [Resolver.ResolveAsync].
69+
type AsyncResult struct {
7070
Path path.Path
7171
TTL time.Duration
7272
LastMod time.Time
@@ -96,12 +96,12 @@ type Resolver interface {
9696
//
9797
// There is a default depth-limit to avoid infinite recursion. Most users will be fine with
9898
// this default limit, but if you need to adjust the limit you can specify it as an option.
99-
Resolve(context.Context, path.Path, ...ResolveOption) (ResolveResult, error)
99+
Resolve(context.Context, path.Path, ...ResolveOption) (Result, error)
100100

101101
// ResolveAsync performs recursive name lookup, like Resolve, but it returns entries as
102102
// they are discovered in the DHT. Each returned result is guaranteed to be "better"
103103
// (which usually means newer) than the previous one.
104-
ResolveAsync(context.Context, path.Path, ...ResolveOption) <-chan ResolveAsyncResult
104+
ResolveAsync(context.Context, path.Path, ...ResolveOption) <-chan AsyncResult
105105
}
106106

107107
// ResolveOptions specifies options for resolving an IPNS Path.

namesys/ipns_resolver.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ func NewIPNSResolver(route routing.ValueStore) *IPNSResolver {
3737
}
3838
}
3939

40-
func (r *IPNSResolver) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (ResolveResult, error) {
40+
func (r *IPNSResolver) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (Result, error) {
4141
ctx, span := startSpan(ctx, "IPNSResolver.Resolve", trace.WithAttributes(attribute.Stringer("Path", p)))
4242
defer span.End()
4343

4444
return resolve(ctx, r, p, ProcessResolveOptions(options))
4545
}
4646

47-
func (r *IPNSResolver) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan ResolveAsyncResult {
47+
func (r *IPNSResolver) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan AsyncResult {
4848
ctx, span := startSpan(ctx, "IPNSResolver.ResolveAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
4949
defer span.End()
5050

5151
return resolveAsync(ctx, r, p, ProcessResolveOptions(options))
5252
}
5353

54-
func (r *IPNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan ResolveAsyncResult {
54+
func (r *IPNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan AsyncResult {
5555
ctx, span := startSpan(ctx, "IPNSResolver.ResolveOnceAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
5656
defer span.End()
5757

58-
out := make(chan ResolveAsyncResult, 1)
58+
out := make(chan AsyncResult, 1)
5959
if p.Namespace() != path.IPNSNamespace {
60-
out <- ResolveAsyncResult{Err: fmt.Errorf("unsupported namespace: %s", p.Namespace())}
60+
out <- AsyncResult{Err: fmt.Errorf("unsupported namespace: %s", p.Namespace())}
6161
close(out)
6262
return out
6363
}
@@ -70,15 +70,15 @@ func (r *IPNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, option
7070

7171
name, err := ipns.NameFromString(p.Segments()[1])
7272
if err != nil {
73-
out <- ResolveAsyncResult{Err: err}
73+
out <- AsyncResult{Err: err}
7474
close(out)
7575
cancel()
7676
return out
7777
}
7878

7979
vals, err := r.routing.SearchValue(ctx, string(name.RoutingKey()), dht.Quorum(int(options.DhtRecordCount)))
8080
if err != nil {
81-
out <- ResolveAsyncResult{Err: err}
81+
out <- AsyncResult{Err: err}
8282
close(out)
8383
cancel()
8484
return out
@@ -99,31 +99,31 @@ func (r *IPNSResolver) resolveOnceAsync(ctx context.Context, p path.Path, option
9999

100100
rec, err := ipns.UnmarshalRecord(val)
101101
if err != nil {
102-
emitOnceResult(ctx, out, ResolveAsyncResult{Err: err})
102+
emitOnceResult(ctx, out, AsyncResult{Err: err})
103103
return
104104
}
105105

106106
resolvedBase, err := rec.Value()
107107
if err != nil {
108-
emitOnceResult(ctx, out, ResolveAsyncResult{Err: err})
108+
emitOnceResult(ctx, out, AsyncResult{Err: err})
109109
return
110110
}
111111

112112
resolvedBase, err = joinPaths(resolvedBase, p)
113113
if err != nil {
114-
emitOnceResult(ctx, out, ResolveAsyncResult{Err: err})
114+
emitOnceResult(ctx, out, AsyncResult{Err: err})
115115
return
116116
}
117117

118118
ttl, err := calculateBestTTL(rec)
119119
if err != nil {
120-
emitOnceResult(ctx, out, ResolveAsyncResult{Err: err})
120+
emitOnceResult(ctx, out, AsyncResult{Err: err})
121121
return
122122
}
123123

124124
// TODO: in the future it would be interesting to set the last modified date
125125
// as the date in which the record has been signed.
126-
emitOnceResult(ctx, out, ResolveAsyncResult{Path: resolvedBase, TTL: ttl, LastMod: time.Now()})
126+
emitOnceResult(ctx, out, AsyncResult{Path: resolvedBase, TTL: ttl, LastMod: time.Now()})
127127
case <-ctx.Done():
128128
return
129129
}

namesys/namesys.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,36 @@ func NewNameSystem(r routing.ValueStore, opts ...Option) (NameSystem, error) {
138138
}
139139

140140
// Resolve implements Resolver.
141-
func (ns *namesys) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (ResolveResult, error) {
141+
func (ns *namesys) Resolve(ctx context.Context, p path.Path, options ...ResolveOption) (Result, error) {
142142
ctx, span := startSpan(ctx, "namesys.Resolve", trace.WithAttributes(attribute.Stringer("Path", p)))
143143
defer span.End()
144144

145145
return resolve(ctx, ns, p, ProcessResolveOptions(options))
146146
}
147147

148-
func (ns *namesys) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan ResolveAsyncResult {
148+
func (ns *namesys) ResolveAsync(ctx context.Context, p path.Path, options ...ResolveOption) <-chan AsyncResult {
149149
ctx, span := startSpan(ctx, "namesys.ResolveAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
150150
defer span.End()
151151

152152
return resolveAsync(ctx, ns, p, ProcessResolveOptions(options))
153153
}
154154

155155
// resolveOnce implements resolver.
156-
func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan ResolveAsyncResult {
156+
func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options ResolveOptions) <-chan AsyncResult {
157157
ctx, span := startSpan(ctx, "namesys.ResolveOnceAsync", trace.WithAttributes(attribute.Stringer("Path", p)))
158158
defer span.End()
159159

160-
out := make(chan ResolveAsyncResult, 1)
160+
out := make(chan AsyncResult, 1)
161161
if !p.Mutable() {
162-
out <- ResolveAsyncResult{Path: p}
162+
out <- AsyncResult{Path: p}
163163
close(out)
164164
return out
165165
}
166166

167167
segments := p.Segments()
168168
resolvablePath, err := path.NewPathFromSegments(segments[0], segments[1])
169169
if err != nil {
170-
out <- ResolveAsyncResult{Err: err}
170+
out <- AsyncResult{Err: err}
171171
close(out)
172172
return out
173173
}
@@ -176,7 +176,7 @@ func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options Re
176176
p, err = joinPaths(resolvedBase, p)
177177
span.SetAttributes(attribute.Bool("CacheHit", true))
178178
span.RecordError(err)
179-
out <- ResolveAsyncResult{Path: p, TTL: ttl, LastMod: lastMod, Err: err}
179+
out <- AsyncResult{Path: p, TTL: ttl, LastMod: lastMod, Err: err}
180180
close(out)
181181
return out
182182
} else {
@@ -200,24 +200,24 @@ func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options Re
200200
fixedCid := cid.NewCidV1(cid.Libp2pKey, ipnsCid.Hash()).String()
201201
codecErr := fmt.Errorf("peer ID represented as CIDv1 require libp2p-key multicodec: retry with /ipns/%s", fixedCid)
202202
log.Debugf("RoutingResolver: could not convert public key hash %q to peer ID: %s\n", segments[1], codecErr)
203-
out <- ResolveAsyncResult{Err: codecErr}
203+
out <- AsyncResult{Err: codecErr}
204204
} else {
205-
out <- ResolveAsyncResult{Err: fmt.Errorf("cannot resolve: %q", resolvablePath.String())}
205+
out <- AsyncResult{Err: fmt.Errorf("cannot resolve: %q", resolvablePath.String())}
206206
}
207207

208208
close(out)
209209
return out
210210
}
211211

212212
resCh := res.resolveOnceAsync(ctx, resolvablePath, options)
213-
var best ResolveAsyncResult
213+
var best AsyncResult
214214
go func() {
215215
defer close(out)
216216
for {
217217
select {
218218
case res, ok := <-resCh:
219219
if !ok {
220-
if best != (ResolveAsyncResult{}) {
220+
if best != (AsyncResult{}) {
221221
ns.cacheSet(resolvablePath.String(), best.Path, best.TTL, best.LastMod)
222222
}
223223
return
@@ -233,7 +233,7 @@ func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options Re
233233
res.Err = multierr.Combine(err, res.Err)
234234
}
235235

236-
emitOnceResult(ctx, out, ResolveAsyncResult{Path: p, TTL: res.TTL, LastMod: res.LastMod, Err: res.Err})
236+
emitOnceResult(ctx, out, AsyncResult{Path: p, TTL: res.TTL, LastMod: res.LastMod, Err: res.Err})
237237
case <-ctx.Done():
238238
return
239239
}
@@ -243,7 +243,7 @@ func (ns *namesys) resolveOnceAsync(ctx context.Context, p path.Path, options Re
243243
return out
244244
}
245245

246-
func emitOnceResult(ctx context.Context, outCh chan<- ResolveAsyncResult, r ResolveAsyncResult) {
246+
func emitOnceResult(ctx context.Context, outCh chan<- AsyncResult, r AsyncResult) {
247247
select {
248248
case outCh <- r:
249249
case <-ctx.Done():
@@ -294,12 +294,12 @@ func (ns *namesys) Publish(ctx context.Context, name ci.PrivKey, value path.Path
294294
// Resolve is an utility function that takes a [NameSystem] and a [path.Path], and
295295
// returns the result of [NameSystem.Resolve] for the given path. If the given namesys
296296
// is nil, [ErrNoNamesys] is returned.
297-
func Resolve(ctx context.Context, ns NameSystem, p path.Path) (ResolveResult, error) {
297+
func Resolve(ctx context.Context, ns NameSystem, p path.Path) (Result, error) {
298298
ctx, span := startSpan(ctx, "Resolve", trace.WithAttributes(attribute.Stringer("Path", p)))
299299
defer span.End()
300300

301301
if ns == nil {
302-
return ResolveResult{}, ErrNoNamesys
302+
return Result{}, ErrNoNamesys
303303
}
304304

305305
return ns.Resolve(ctx, p)

0 commit comments

Comments
 (0)