Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions cmd/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"os/signal"
"syscall"

"github.com/libp2p/go-libp2p/core/host"
"github.com/spf13/cobra"

"github.com/substantialcattle5/sietch/internal/config"
Expand Down Expand Up @@ -40,6 +39,7 @@
port, _ := cmd.Flags().GetInt("port")
verbose, _ := cmd.Flags().GetBool("verbose")
vaultPath, _ := cmd.Flags().GetString("vault-path")
allAddresses, _ := cmd.Flags().GetBool("all-addresses")

// If no vault path specified, use current directory
if vaultPath == "" {
Expand Down Expand Up @@ -72,7 +72,7 @@

fmt.Printf("🔍 Starting peer discovery with node ID: %s\n", host.ID().String())
if verbose {
displayHostAddresses(host)
discover.DisplayHostAddresses(host, allAddresses)
}

// Create a vault manager
Expand Down Expand Up @@ -101,17 +101,11 @@
defer func() { _ = discovery.Stop() }()

// Run the discovery loop
return discover.RunDiscoveryLoop(ctx, host, syncService, peerChan, timeout, continuous)
return discover.RunDiscoveryLoop(ctx, host, syncService, peerChan, timeout, continuous, allAddresses)
},
}

// displayHostAddresses prints the addresses the host is listening on
func displayHostAddresses(h host.Host) {
fmt.Println("Listening on:")
for _, addr := range h.Addrs() {
fmt.Printf(" %s/p2p/%s\n", addr, h.ID().String())
}
}

Check failure on line 108 in cmd/discover.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)

func init() {
rootCmd.AddCommand(discoverCmd)
Expand All @@ -122,4 +116,5 @@
discoverCmd.Flags().IntP("port", "p", 0, "Port to use for libp2p (0 for random port)")
discoverCmd.Flags().BoolP("verbose", "v", false, "Enable verbose output")
discoverCmd.Flags().StringP("vault-path", "V", "", "Path to the vault directory (defaults to current directory)")
discoverCmd.Flags().Bool("all-addresses", false, "Show all network addresses including Docker, VPN, and virtual interfaces")
}
86 changes: 86 additions & 0 deletions internal/discover/address_display.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package discover

import (
"fmt"

"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
)

// DisplayHostAddresses prints the addresses the host is listening on with filtering
func DisplayHostAddresses(h host.Host, showAll bool) {
filter := NewAddressFilter(showAll)
filtered := filter.FilterAddresses(h.Addrs())

Check failure on line 14 in internal/discover/address_display.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)
fmt.Println("Listening on:")

if len(filtered) == 0 {
fmt.Println(" No suitable addresses found")
return
}

for _, addr := range filtered {
if showAll {
// Show full multiaddr format with peer ID
fmt.Printf(" %s/p2p/%s", addr.Original, h.ID().String())
if addr.Label != "" {
fmt.Printf(" %s", addr.Label)
}
fmt.Println()
} else {
// Show simplified format
fmt.Printf(" %s", addr.DisplayAddr)
if addr.Label != "" {
fmt.Printf(" %s", addr.Label)
}
fmt.Println()
}
}

// Show summary of filtered addresses if any were hidden
if !showAll {
hiddenCount := filter.CountFilteredAddresses(h.Addrs())
if hiddenCount > 0 {
fmt.Printf(" [+%d more, use --all-addresses to show]\n", hiddenCount)
}
}
}

// DisplayPeerAddresses prints the addresses for a discovered peer with filtering
func DisplayPeerAddresses(peerInfo peer.AddrInfo, showAll bool) {
filter := NewAddressFilter(showAll)
filtered := filter.FilterAddresses(peerInfo.Addrs)

fmt.Println(" Addresses:")

if len(filtered) == 0 {
fmt.Println(" No suitable addresses found")
return
}

for _, addr := range filtered {
if showAll {
// Show full multiaddr format
fmt.Printf(" - %s", addr.Original)
if addr.Label != "" {
fmt.Printf(" %s", addr.Label)
}
fmt.Println()
} else {
// Show simplified format
fmt.Printf(" - %s", addr.DisplayAddr)
if addr.Label != "" {
fmt.Printf(" %s", addr.Label)
}
fmt.Println()
}
}

// Show summary of filtered addresses if any were hidden
if !showAll {
hiddenCount := filter.CountFilteredAddresses(peerInfo.Addrs)
if hiddenCount > 0 {
fmt.Printf(" [+%d more, use --all-addresses to show]\n", hiddenCount)
}
}
}
Loading
Loading