Skip to content

Commit

Permalink
Improve cln IsConnected
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Jun 30, 2023
1 parent aa54cea commit c37a745
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cln/cln_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"path/filepath"
"strings"
"time"

"github.com/breez/lspd/basetypes"
Expand Down Expand Up @@ -59,17 +60,19 @@ func (c *ClnClient) GetInfo() (*lightning.GetInfoResult, error) {

func (c *ClnClient) IsConnected(destination []byte) (bool, error) {
pubKey := hex.EncodeToString(destination)
peers, err := c.client.ListPeers()
peer, err := c.client.GetPeer(pubKey)
if err != nil {
log.Printf("CLN: client.ListPeers() error: %v", err)
return false, fmt.Errorf("CLN: client.ListPeers() error: %w", err)
if strings.Contains(err.Error(), "not found") {
return false, nil
}

log.Printf("CLN: client.GetPeer(%v) error: %v", pubKey, err)
return false, fmt.Errorf("CLN: client.GetPeer(%v) error: %w", pubKey, err)
}

for _, peer := range peers {
if pubKey == peer.Id && peer.Connected {
log.Printf("destination online: %x", destination)
return true, nil
}
if peer.Connected {
log.Printf("CLN: destination online: %x", destination)
return true, nil
}

log.Printf("CLN: destination offline: %x", destination)
Expand Down

0 comments on commit c37a745

Please sign in to comment.