Skip to content
Merged
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
7 changes: 1 addition & 6 deletions cmd/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"time"

"github.com/encodeous/nylon/core"
"github.com/encodeous/nylon/protocol"
"github.com/spf13/cobra"
)
Expand All @@ -23,7 +22,7 @@ var probeCmd = &cobra.Command{
fmt.Fprintln(os.Stderr, "Error: timeout must be positive")
os.Exit(1)
}
resp, err := core.SendIPCRequest(itf, &protocol.IpcRequest{
resp, err := ipcRequest(itf, &protocol.IpcRequest{
Request: &protocol.IpcRequest_Probe{Probe: &protocol.ProbeRequest{
PeerId: args[0],
TimeoutMs: durationMillis(timeout),
Expand All @@ -33,10 +32,6 @@ var probeCmd = &cobra.Command{
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
if !resp.Ok {
fmt.Fprintln(os.Stderr, "Error:", resp.Error)
os.Exit(1)
}
if jsonOut {
printJSON(resp)
return
Expand Down
7 changes: 1 addition & 6 deletions cmd/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/encodeous/nylon/core"
"github.com/encodeous/nylon/protocol"
"github.com/spf13/cobra"
)
Expand All @@ -17,17 +16,13 @@ var reloadCmd = &cobra.Command{
itf, _ := cmd.Flags().GetString("interface")
jsonOut, _ := cmd.Flags().GetBool("json")

resp, err := core.SendIPCRequest(itf, &protocol.IpcRequest{
resp, err := ipcRequest(itf, &protocol.IpcRequest{
Request: &protocol.IpcRequest_Reload{Reload: &protocol.ReloadRequest{}},
})
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
if !resp.Ok {
fmt.Fprintln(os.Stderr, "Error:", resp.Error)
os.Exit(1)
}
if jsonOut {
printJSON(resp)
return
Expand Down
11 changes: 11 additions & 0 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/encodeous/nylon/ipc"
"github.com/encodeous/nylon/protocol"
"github.com/encodeous/nylon/state"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -163,6 +164,16 @@ func formatDurationNs(ns int64) string {
return time.Duration(ns).String()
}

// ipcRequest sends one request to the nylon serving interface itf.
func ipcRequest(itf string, req *protocol.IpcRequest) (*protocol.IpcResponse, error) {
client, err := ipc.Dial(itf)
if err != nil {
return nil, err
}
defer client.Close()
return client.Do(req)
}

func printJSON(resp *protocol.IpcResponse) {
m := protojson.MarshalOptions{Indent: " ", EmitUnpopulated: true}
data, _ := m.Marshal(resp)
Expand Down
17 changes: 6 additions & 11 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"strings"

"github.com/encodeous/nylon/core"
"github.com/encodeous/nylon/protocol"
"github.com/encodeous/nylon/state"
"github.com/moby/term"
Expand All @@ -23,17 +22,13 @@ var statusCmd = &cobra.Command{
showFull, _ := cmd.Flags().GetBool("full")
noColor, _ := cmd.Flags().GetBool("no-color")

resp, err := core.SendIPCRequest(itf, &protocol.IpcRequest{
resp, err := ipcRequest(itf, &protocol.IpcRequest{
Request: &protocol.IpcRequest_Status{Status: &protocol.StatusRequest{}},
})
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
if !resp.Ok {
fmt.Fprintln(os.Stderr, "Error:", resp.Error)
os.Exit(1)
}
if jsonOut {
printJSON(resp)
return
Expand Down Expand Up @@ -103,12 +98,12 @@ func renderStatus(s *protocol.StatusResponse, opts statusRenderOptions) {
if best != nil {
bestMetric = best.Metric
}
wg := neigh.GetWireguard()
peerStats := neigh.GetTransport()
statHeaders := []string{"best metric", "latest handshake", "tx", "rx"}
statRow := []string{metricText(p, bestMetric), formatHandshake(wg.LatestHandshakeUnix), formatBytes(wg.TxBytes), formatBytes(wg.RxBytes)}
if wg.Endpoint != nil {
statHeaders = append(statHeaders, "wireguard endpoint")
statRow = append(statRow, *wg.Endpoint)
statRow := []string{metricText(p, bestMetric), formatHandshake(peerStats.LatestHandshakeUnix), formatBytes(peerStats.TxBytes), formatBytes(peerStats.RxBytes)}
if peerStats.Endpoint != nil {
statHeaders = append(statHeaders, "transport endpoint")
statRow = append(statRow, *peerStats.Endpoint)
}
printTable(p, 2, statHeaders, [][]string{statRow})
if len(neigh.Endpoints) > 0 {
Expand Down
29 changes: 11 additions & 18 deletions cmd/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/encodeous/nylon/core"
"github.com/encodeous/nylon/ipc"
"github.com/encodeous/nylon/protocol"
"github.com/spf13/cobra"
)
Expand All @@ -15,23 +15,16 @@ var traceCmd = &cobra.Command{
GroupID: "ny",
Run: func(cmd *cobra.Command, args []string) {
itf, _ := cmd.Flags().GetString("interface")
first := true
err := core.SendIPCStream(itf, &protocol.IpcRequest{
Request: &protocol.IpcRequest_Trace{Trace: &protocol.TraceRequest{}},
}, func(resp *protocol.IpcResponse) error {
if first {
first = false
if !resp.Ok {
fmt.Fprintln(os.Stderr, "Error:", resp.Error)
os.Exit(1)
}
return nil
}
if t := resp.GetTrace(); t != nil {
fmt.Print(t.Line)
}
return nil
})
client, err := ipc.Dial(itf)
if err == nil {
defer client.Close()
err = client.Stream(&protocol.IpcRequest{
Request: &protocol.IpcRequest_Trace{Trace: &protocol.TraceRequest{}},
}, func(resp *protocol.IpcResponse) bool {
fmt.Print(resp.GetTrace().GetLine())
return true
})
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
Expand Down
90 changes: 0 additions & 90 deletions core/ipc_client.go

This file was deleted.

Loading
Loading