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
Binary file added CLIENT.exe
Binary file not shown.
1,332 changes: 14 additions & 1,318 deletions cmd/CLIENT/main.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.33.1 // indirect
github.com/ipfs/go-datastore v0.8.2 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
Expand All @@ -24,6 +25,8 @@ require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -87,6 +88,8 @@ github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iP
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ipfs/boxo v0.33.1 h1:89m+ksw+cYi0ecTNTJ71IRS5ZrLiovmO6XWHIOGhAEg=
github.com/ipfs/boxo v0.33.1/go.mod h1:KwlJTzv5fb1GLlA9KyMqHQmvP+4mrFuiE3PnjdrPJHs=
github.com/ipfs/go-block-format v0.2.2 h1:uecCTgRwDIXyZPgYspaLXoMiMmxQpSx2aq34eNc4YvQ=
Expand Down Expand Up @@ -304,6 +307,7 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down Expand Up @@ -338,6 +342,10 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down Expand Up @@ -382,6 +390,7 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
20 changes: 20 additions & 0 deletions internal/cli/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add <path>",
Short: "Share a file on the network",
Long: `Add a file to the P2P network for sharing. The file will be announced to the DHT.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
return client.AddFile(args[0])
},
}
20 changes: 20 additions & 0 deletions internal/cli/announce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var announceCmd = &cobra.Command{
Use: "announce <cid>",
Short: "Re-announce a file to DHT",
Long: `Re-announce a file's CID to the DHT to refresh its availability.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
return client.AnnounceFile(args[0])
},
}
20 changes: 20 additions & 0 deletions internal/cli/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var debugCmd = &cobra.Command{
Use: "debug",
Short: "Show detailed network debug info",
Long: `Display detailed network debugging information including peer IDs, addresses, and shared files.`,
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
client.DebugNetworkStatus()
return nil
},
}
20 changes: 20 additions & 0 deletions internal/cli/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var downloadCmd = &cobra.Command{
Use: "download <cid>",
Short: "Download a file by CID",
Long: `Download a file from the P2P network using its Content Identifier (CID).`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
return client.DownloadFile(args[0])
},
}
20 changes: 20 additions & 0 deletions internal/cli/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var healthCmd = &cobra.Command{
Use: "health",
Short: "Check connection health",
Long: `Display the current health status of your P2P connections and DHT routing table.`,
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
client.CheckConnectionHealth()
return nil
},
}
171 changes: 171 additions & 0 deletions internal/cli/interactive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package cli

import (
"bufio"
"fmt"
"log"
"os"
"strings"

"github.com/spf13/cobra"
)

var interactiveCmd = &cobra.Command{
Use: "interactive",
Short: "Start interactive CLI mode",
Long: `Start an interactive command-line interface for continuous operation.`,
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
CommandLoop()
return nil
},
}

// CommandLoop runs the interactive CLI mode
func CommandLoop() {
scanner := bufio.NewScanner(os.Stdin)
PrintInstructions()
for {
fmt.Print("> ")
if !scanner.Scan() {
break
}
parts := strings.Fields(scanner.Text())
if len(parts) == 0 {
continue
}
cmd, args := parts[0], parts[1:]
var err error
switch cmd {
case "help":
PrintInstructions()
case "add":
if len(args) != 1 {
fmt.Println("Usage: add <path>")
} else {
err = client.AddFile(args[0])
}
case "list":
client.ListLocalFiles()
case "search":
if len(args) != 1 {
fmt.Println("Usage: search <cid|text>")
} else {
client.CheckConnectionHealth()
if strings.HasPrefix(args[0], "bafy") || strings.HasPrefix(args[0], "Qm") {
err = client.EnhancedSearchByCID(args[0])
} else {
err = client.SearchByText(args[0])
}
}
case "download":
if len(args) != 1 {
fmt.Println("Usage: download <cid>")
} else {
err = client.DownloadFile(args[0])
}
case "peers":
client.ListConnectedPeers()
case "announce":
if len(args) != 1 {
fmt.Println("Usage: announce <cid>")
} else {
err = client.AnnounceFile(args[0])
}
case "health":
client.CheckConnectionHealth()
case "debug":
client.DebugNetworkStatus()
case "exit":
return
default:
fmt.Println("Unknown command. Type 'help' for available commands.")
}
if err != nil {
log.Printf("Error: %v", err)
}
}
}

// PrintInstructions displays the help banner
func PrintInstructions() {
peerID := client.Host.ID().String()
minWidth := len(" Your Peer ID: "+peerID) + 4
width := 80
if minWidth > width {
width = minWidth + 10
}

topBorder := "┌" + strings.Repeat("─", width-2) + "┐"
bottomBorder := "└" + strings.Repeat("─", width-2) + "┘"

centerLine := func(text string) string {
if len(text) >= width-4 {
return "│ " + text[:width-6] + "... │"
}
padding := (width - 4 - len(text)) / 2
leftPad := strings.Repeat(" ", padding)
rightPad := strings.Repeat(" ", width-4-len(text)-padding)
return "│ " + leftPad + text + rightPad + " │"
}

leftLine := func(text string) string {
if len(text) >= width-4 {
return "│ " + text[:width-6] + "... │"
}
rightPad := strings.Repeat(" ", width-4-len(text))
return "│ " + text + rightPad + " │"
}

fmt.Println()
fmt.Println(topBorder)
fmt.Println(centerLine("DECENTRALIZED P2P FILE SHARING"))
fmt.Println("│" + strings.Repeat("─", width-2) + "│")
fmt.Println(centerLine("Available Commands"))
fmt.Println("│" + strings.Repeat(" ", width-2) + "│")

commands := [][]string{
{"add <path>", "Share a file on the network"},
{"list", "List your shared files"},
{"search <cid|text>", "Search by CID or filename text"},
{"download <cid>", "Download a file by CID"},
{"peers", "Show connected peers"},
{"announce <cid>", "Re-announce a file to DHT"},
{"health", "Check connection health"},
{"debug", "Show detailed network debug info"},
{"help", "Show this help"},
{"exit", "Exit the application"},
}

for _, cmd := range commands {
cmdText := fmt.Sprintf(" %-20s - %s", cmd[0], cmd[1])
fmt.Println(leftLine(cmdText))
}

fmt.Println("│" + strings.Repeat(" ", width-2) + "│")
fmt.Println("│" + strings.Repeat("─", width-2) + "│")

peerID = client.Host.ID().String()
fmt.Println(leftLine(" Your Peer ID: " + peerID))

addrs := client.Host.Addrs()
fmt.Println(leftLine(" Listening on:"))

for i, addr := range addrs {
if i >= 3 {
moreAddrs := len(addrs) - 3
fmt.Println(leftLine(fmt.Sprintf(" ... and %d more", moreAddrs)))
break
}
addrStr := addr.String()
if len(addrStr) > width-8 {
addrStr = addrStr[:width-11] + "..."
}
fmt.Println(leftLine(" " + addrStr))
}

fmt.Println(bottomBorder)
fmt.Println()
}
20 changes: 20 additions & 0 deletions internal/cli/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List your shared files",
Long: `Display all files that you are currently sharing on the P2P network.`,
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
client.ListLocalFiles()
return nil
},
}
20 changes: 20 additions & 0 deletions internal/cli/peers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"
)

var peersCmd = &cobra.Command{
Use: "peers",
Short: "Show connected peers",
Long: `Display all peers currently connected to your node.`,
RunE: func(cmd *cobra.Command, args []string) error {
if client == nil {
return fmt.Errorf("client not initialized")
}
client.ListConnectedPeers()
return nil
},
}
Loading