Skip to content

Commit 295cf59

Browse files
committed
Same provOutput for a provider with both http and bitswap
1 parent d56eb26 commit 295cf59

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

daemon.go

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,27 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
221221
wg.Add(1)
222222
go func(provider peer.AddrInfo, src string) {
223223
defer wg.Done()
224+
225+
provOutput := providerOutput{
226+
ID: provider.ID.String(),
227+
Source: src,
228+
DataAvailableOverBitswap: BitswapCheckOutput{},
229+
DataAvailableOverHTTP: HTTPCheckOutput{},
230+
}
231+
232+
testHost, err := d.createTestHost()
233+
if err != nil {
234+
log.Printf("Error creating test host: %v\n", err)
235+
return
236+
}
237+
defer testHost.Close()
238+
224239
// Get http retrieval out of the way if this is such
225240
// provider.
226241
httpInfo, libp2pInfo := network.SplitHTTPAddrs(provider)
227242
if len(httpInfo.Addrs) > 0 && httpRetrieval {
243+
provOutput.DataAvailableOverHTTP.Enabled = true
228244

229-
provOutput := providerOutput{
230-
ID: provider.ID.String(),
231-
DataAvailableOverBitswap: BitswapCheckOutput{
232-
Enabled: false,
233-
},
234-
DataAvailableOverHTTP: HTTPCheckOutput{
235-
Enabled: true,
236-
},
237-
Source: src,
238-
}
239245
for _, ma := range httpInfo.Addrs {
240246
provOutput.Addrs = append(provOutput.Addrs, ma.String())
241247
}
@@ -255,14 +261,15 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
255261
provOutput.ConnectionMaddrs = append(provOutput.ConnectionMaddrs, ma.String())
256262
}
257263

258-
mu.Lock()
259-
out = append(out, provOutput)
260-
mu.Unlock()
261-
262264
// Do not continue processing if there are no
263265
// other addresses as we would trigger dht
264266
// lookups etc.
265267
if len(libp2pInfo.Addrs) == 0 {
268+
provOutput.DataAvailableOverBitswap.Enabled = false
269+
mu.Lock()
270+
out = append(out, provOutput)
271+
mu.Unlock()
272+
266273
return
267274
}
268275
}
@@ -291,24 +298,8 @@ func (d *daemon) runCidCheck(ctx context.Context, cidKey cid.Cid, ipniURL string
291298
}
292299
}
293300

294-
provOutput := providerOutput{
295-
ID: provider.ID.String(),
296-
Addrs: outputAddrs,
297-
DataAvailableOverBitswap: BitswapCheckOutput{
298-
Enabled: true,
299-
},
300-
DataAvailableOverHTTP: HTTPCheckOutput{
301-
Enabled: false,
302-
},
303-
Source: src,
304-
}
305-
306-
testHost, err := d.createTestHost()
307-
if err != nil {
308-
log.Printf("Error creating test host: %v\n", err)
309-
return
310-
}
311-
defer testHost.Close()
301+
provOutput.Addrs = append(provOutput.Addrs, outputAddrs...)
302+
provOutput.DataAvailableOverBitswap.Enabled = true
312303

313304
// Test Is the target connectable
314305
dialCtx, dialCancel := context.WithTimeout(ctx, time.Second*15)

0 commit comments

Comments
 (0)