Skip to content

Commit 7847863

Browse files
committed
feat: expose WANActive
That way, external users can easily determine which DHT they should use. E.g., in go-ipfs, I'd like to call GetClosestPeers in the `ipfs dht` commands based on the "active" DHT.
1 parent bfa23ff commit 7847863

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

dual/dual.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ func (dht *DHT) Close() error {
7777
return multierror.Append(dht.WAN.Close(), dht.LAN.Close()).ErrorOrNil()
7878
}
7979

80-
func (dht *DHT) activeWAN() bool {
80+
// WANActive returns true when the WAN DHT is active (has peers).
81+
func (dht *DHT) WANActive() bool {
8182
return dht.WAN.RoutingTable().Size() > 0
8283
}
8384

8485
// Provide adds the given cid to the content routing system.
8586
func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
86-
if dht.activeWAN() {
87+
if dht.WANActive() {
8788
return dht.WAN.Provide(ctx, key, announce)
8889
}
8990
return dht.LAN.Provide(ctx, key, announce)
@@ -167,7 +168,7 @@ func (dht *DHT) Bootstrap(ctx context.Context) error {
167168

168169
// PutValue adds value corresponding to given Key.
169170
func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...routing.Option) error {
170-
if dht.activeWAN() {
171+
if dht.WANActive() {
171172
return dht.WAN.PutValue(ctx, key, val, opts...)
172173
}
173174
return dht.LAN.PutValue(ctx, key, val, opts...)

0 commit comments

Comments
 (0)