Skip to content

implemented p2p ping#139

Merged
akobrin1 merged 1 commit intomasterfrom
sncli-p2p
Aug 26, 2025
Merged

implemented p2p ping#139
akobrin1 merged 1 commit intomasterfrom
sncli-p2p

Conversation

@akobrin1
Copy link
Copy Markdown
Contributor

  • CLI: replace custom dispatcher with Cobra command tree

    • Root globals: --config, --grpc_endpoint, --p2p_endpoint, --address
    • Subcommands: health-check, get-status, list, p2p (with ping), completion
  • P2P: new command group

    • sncli p2p ping [timeout] (or --timeout)
    • Uses Kademlia P2P endpoint; prints "P2P is alive (host:port)" on success
    • Accepts endpoint from flag --p2p_endpoint or config [supernode].p2p_endpoint
  • Config:

    • Default config path moved to ~/.sncli/config.toml (can override with --config or SNCLI_CONFIG_PATH)
    • Add [supernode].p2p_endpoint to config schema
    • Wire CLI flag overrides for grpc_endpoint, p2p_endpoint, address

@akobrin1 akobrin1 requested a review from a-ok123 August 26, 2025 17:03
@a-ok123 a-ok123 requested a review from Copilot August 26, 2025 17:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the CLI application to use the Cobra command framework and adds P2P ping functionality. The change replaces the custom dispatcher pattern with a structured command tree while introducing new P2P utilities for connecting to Supernode Kademlia endpoints.

  • Replaces custom CLI dispatcher with Cobra command structure
  • Adds P2P ping command with timeout support and secure connection handling
  • Updates configuration system to support P2P endpoints and default to ~/.sncli/config.toml

Reviewed Changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cmd/sncli/main.go Simplified main function to use Cobra's Execute()
cmd/sncli/cmd/*.go New Cobra command implementations for root, p2p, ping, list, health-check, and get-status
cmd/sncli/cli/cli.go Refactored CLI initialization and configuration handling
cmd/sncli/cli/p2p.go New P2P functionality with secure connection and message encoding/decoding
cmd/sncli/cli/types.go Updated configuration types to include P2P endpoint
p2p/kademlia/dht.go Improved address parsing using net/url and net.SplitHostPort
cmd/sncli/go.mod Updated dependencies to include Cobra and related libraries
Comments suppressed due to low confidence (1)

cmd/sncli/cli/cmd_p2p_ping.go:1

  • This validation is redundant since time.ParseDuration already handles negative durations and the check at line 22-24 ensures t is positive when using the default.
package cli

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"net"
"time"
"strconv"
"encoding/binary"
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace after the import statement.

Suggested change
"encoding/binary"
"encoding/binary"

Copilot uses AI. Check for mistakes.
)

const (
defaultMaxPayloadSize = 2 // MB
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 2 should be defined with a more descriptive name or include units in the constant name, such as defaultMaxPayloadSizeMB.

Suggested change
defaultMaxPayloadSize = 2 // MB
defaultMaxPayloadSizeMB = 2 // MB

Copilot uses AI. Check for mistakes.
}
path = filepath.Join(home, path[1:])
}
path = filepath.Clean(path)
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation. This line uses spaces while other lines use tabs.

Suggested change
path = filepath.Clean(path)
path = filepath.Clean(path)

Copilot uses AI. Check for mistakes.
@@ -20,10 +18,22 @@ type CLIConfig struct {
Dir string `toml:"dir"`
KeyName string `toml:"key_name"`
LocalAddress string `toml:"local_address"`
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing passphrases in plain text configuration (PassPlain field) poses a security risk. Consider removing this option or adding a warning comment about the security implications.

Suggested change
LocalAddress string `toml:"local_address"`
LocalAddress string `toml:"local_address"`
// WARNING: Storing passphrases in plain text (PassPlain) is insecure and poses a security risk.
// Avoid using this field in production environments. Prefer PassFile or PassEnv instead.

Copilot uses AI. Check for mistakes.

// If no specific service is requested, list all services
if len(c.opts.CommandArgs) == 0 || c.opts.CommandArgs[0] == "" {
if len(service) == 0 || service == "" {
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition len(service) == 0 is redundant since service == \"\" already covers empty strings.

Suggested change
if len(service) == 0 || service == "" {
if service == "" {

Copilot uses AI. Check for mistakes.
@akobrin1 akobrin1 merged commit 42c814a into master Aug 26, 2025
7 checks passed
@akobrin1 akobrin1 deleted the sncli-p2p branch August 26, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants