Skip to content

Commit

Permalink
Merge pull request #580 from libp2p/feat/expose-wan-active
Browse files Browse the repository at this point in the history
feat: expose WANActive
  • Loading branch information
Stebalien committed Apr 10, 2020
2 parents 7e74bc8 + 7847863 commit 6b94711
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dual/dual.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ func (dht *DHT) Close() error {
return combineErrors(dht.WAN.Close(), dht.LAN.Close())
}

func (dht *DHT) activeWAN() bool {
// WANActive returns true when the WAN DHT is active (has peers).
func (dht *DHT) WANActive() bool {
return dht.WAN.RoutingTable().Size() > 0
}

// Provide adds the given cid to the content routing system.
func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
if dht.activeWAN() {
if dht.WANActive() {
return dht.WAN.Provide(ctx, key, announce)
}
return dht.LAN.Provide(ctx, key, announce)
Expand Down Expand Up @@ -212,7 +213,7 @@ func (dht *DHT) Bootstrap(ctx context.Context) error {

// PutValue adds value corresponding to given Key.
func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...routing.Option) error {
if dht.activeWAN() {
if dht.WANActive() {
return dht.WAN.PutValue(ctx, key, val, opts...)
}
return dht.LAN.PutValue(ctx, key, val, opts...)
Expand Down

0 comments on commit 6b94711

Please sign in to comment.