From 4db207a20104fcfbd2750c205e4550c0c514a476 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 21 May 2019 19:36:56 +0300 Subject: [PATCH 1/7] Modify `Transports` func to return `IsSetup` flag - `isSetupTransport` was exported. Its declaration moved to `PackageRouterz ifc - `TransportSummary` modified to include `IsSetup` bool flag --- pkg/node/node.go | 1 + pkg/node/rpc.go | 32 ++++++++++++++++++-------------- pkg/router/router.go | 6 +++--- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index a294a3054..5953d2c17 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -71,6 +71,7 @@ type PacketRouter interface { io.Closer Serve(ctx context.Context) error ServeApp(conn net.Conn, port uint16, appConf *app.Config) error + IsSetupTransport(tr transport.Transport) bool } // Node provides messaging runtime for Apps by setting up all diff --git a/pkg/node/rpc.go b/pkg/node/rpc.go index 4ab05069b..affe6c0f4 100644 --- a/pkg/node/rpc.go +++ b/pkg/node/rpc.go @@ -40,24 +40,27 @@ type RPC struct { // TransportSummary summarizes a Transport. type TransportSummary struct { - ID uuid.UUID `json:"id"` - Local cipher.PubKey `json:"local_pk"` - Remote cipher.PubKey `json:"remote_pk"` - Type string `json:"type"` - Log *transport.LogEntry `json:"log,omitempty"` + ID uuid.UUID `json:"id"` + Local cipher.PubKey `json:"local_pk"` + Remote cipher.PubKey `json:"remote_pk"` + Type string `json:"type"` + Log *transport.LogEntry `json:"log,omitempty"` + IsSetup bool `json:"is_setup"` } -func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport, includeLogs bool) *TransportSummary { +func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport, + includeLogs bool, isSetup bool) *TransportSummary { remote, ok := tm.Remote(tp.Edges()) if !ok { return &TransportSummary{} } summary := &TransportSummary{ - ID: tp.ID, - Local: tm.Local(), - Remote: remote, - Type: tp.Type(), + ID: tp.ID, + Local: tm.Local(), + Remote: remote, + Type: tp.Type(), + IsSetup: isSetup, } if includeLogs { summary.Log = tp.LogEntry @@ -79,7 +82,8 @@ type Summary struct { func (r *RPC) Summary(_ *struct{}, out *Summary) error { var summaries []*TransportSummary r.node.tm.WalkTransports(func(tp *transport.ManagedTransport) bool { - summaries = append(summaries, newTransportSummary(r.node.tm, tp, false)) + summaries = append(summaries, + newTransportSummary(r.node.tm, tp, false, r.node.router.IsSetupTransport(tp))) return true }) *out = Summary{ @@ -168,7 +172,7 @@ func (r *RPC) Transports(in *TransportsIn, out *[]*TransportSummary) error { r.node.tm.WalkTransports(func(tp *transport.ManagedTransport) bool { if remote, ok := r.node.tm.Remote(tp.Edges()); ok { if typeIncluded(tp.Type()) && pkIncluded(r.node.tm.Local(), remote) { - *out = append(*out, newTransportSummary(r.node.tm, tp, in.ShowLogs)) + *out = append(*out, newTransportSummary(r.node.tm, tp, in.ShowLogs, r.node.router.IsSetupTransport(tp))) } return true } @@ -183,7 +187,7 @@ func (r *RPC) Transport(in *uuid.UUID, out *TransportSummary) error { if tp == nil { return ErrNotFound } - *out = *newTransportSummary(r.node.tm, tp, true) + *out = *newTransportSummary(r.node.tm, tp, true, r.node.router.IsSetupTransport(tp)) return nil } @@ -208,7 +212,7 @@ func (r *RPC) AddTransport(in *AddTransportIn, out *TransportSummary) error { if err != nil { return err } - *out = *newTransportSummary(r.node.tm, tp, false) + *out = *newTransportSummary(r.node.tm, tp, false, r.node.router.IsSetupTransport(tp)) return nil } diff --git a/pkg/router/router.go b/pkg/router/router.go index 65213b151..4ba188f7b 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -84,7 +84,7 @@ func (r *Router) Serve(ctx context.Context) error { go func(t transport.Transport) { for { var err error - if r.isSetupTransport(t) { + if r.IsSetupTransport(t) { err = r.rm.Serve(t) } else { err = r.serveTransport(t) @@ -103,7 +103,7 @@ func (r *Router) Serve(ctx context.Context) error { go func() { for tr := range dialCh { - if r.isSetupTransport(tr) { + if r.IsSetupTransport(tr) { continue } @@ -481,7 +481,7 @@ func (r *Router) advanceNoiseHandshake(addr *app.LoopAddr, noiseMsg []byte) (ni return } -func (r *Router) isSetupTransport(tr transport.Transport) bool { +func (r *Router) IsSetupTransport(tr transport.Transport) bool { for _, pk := range r.config.SetupNodes { remote, ok := r.tm.Remote(tr.Edges()) if ok && (remote == pk) { From 06bb3ccf07f59bb60571938cf7393ce3a8d27d08 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 21 May 2019 19:56:50 +0300 Subject: [PATCH 2/7] Fix `mockRouter` to implement ifc, fix lint errors --- pkg/node/node_test.go | 4 ++++ pkg/router/router.go | 1 + 2 files changed, 5 insertions(+) diff --git a/pkg/node/node_test.go b/pkg/node/node_test.go index 40085ce75..f9248631f 100644 --- a/pkg/node/node_test.go +++ b/pkg/node/node_test.go @@ -253,3 +253,7 @@ func (r *mockRouter) Close() error { r.Unlock() return nil } + +func (r *mockRouter) IsSetupTransport(tr transport.Transport) bool { + return false +} diff --git a/pkg/router/router.go b/pkg/router/router.go index 4ba188f7b..7224728b5 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -481,6 +481,7 @@ func (r *Router) advanceNoiseHandshake(addr *app.LoopAddr, noiseMsg []byte) (ni return } +// IsSetupTransport checks whether `tr` is running in the `setup`mode. func (r *Router) IsSetupTransport(tr transport.Transport) bool { for _, pk := range r.config.SetupNodes { remote, ok := r.tm.Remote(tr.Edges()) From 690481c5eeff698d8fa6653a2773ed40b3620370 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 21 May 2019 20:06:11 +0300 Subject: [PATCH 3/7] Modify `printTransports` to include `mode-of-operation` column --- cmd/skywire-cli/commands/node/transports.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index 4fbc0cf41..9ecfa5fa7 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -108,10 +108,15 @@ var rmTpCmd = &cobra.Command{ func printTransports(tps ...*node.TransportSummary) { sortTransports(tps...) w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent) - _, err := fmt.Fprintln(w, "type\tid\tlocal\tremote") + _, err := fmt.Fprintln(w, "type\tid\tlocal\tremote\tmode-of-operation") internal.Catch(err) for _, tp := range tps { - _, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", tp.Type, tp.ID, tp.Local, tp.Remote) + tpMode := "regular" + if tp.IsSetup { + tpMode = "setup" + } + + _, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", tp.Type, tp.ID, tp.Local, tp.Remote, tpMode) internal.Catch(err) } internal.Catch(w.Flush()) From b30014012b2058a248c9696482ad608ee4bd3109 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 21 May 2019 20:22:19 +0300 Subject: [PATCH 4/7] Add missing space --- pkg/router/router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/router/router.go b/pkg/router/router.go index 7224728b5..288f5a6ae 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -481,7 +481,7 @@ func (r *Router) advanceNoiseHandshake(addr *app.LoopAddr, noiseMsg []byte) (ni return } -// IsSetupTransport checks whether `tr` is running in the `setup`mode. +// IsSetupTransport checks whether `tr` is running in the `setup` mode. func (r *Router) IsSetupTransport(tr transport.Transport) bool { for _, pk := range r.config.SetupNodes { remote, ok := r.tm.Remote(tr.Edges()) From 18ed94ca59f1fcec75f81f568122e5169b5fc724 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 21 May 2019 22:23:53 +0300 Subject: [PATCH 5/7] Change `mode-of-operation` col header to `mode` --- cmd/skywire-cli/commands/node/transports.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index 9ecfa5fa7..a07cbeba8 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -108,7 +108,7 @@ var rmTpCmd = &cobra.Command{ func printTransports(tps ...*node.TransportSummary) { sortTransports(tps...) w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent) - _, err := fmt.Fprintln(w, "type\tid\tlocal\tremote\tmode-of-operation") + _, err := fmt.Fprintln(w, "type\tid\tlocal\tremote\tmode") internal.Catch(err) for _, tp := range tps { tpMode := "regular" From 7a4413fa6fe1769ff00df925c6913f64cb06bee0 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 22 May 2019 08:26:57 +0300 Subject: [PATCH 6/7] Remove `local` column from `printTransports` output --- cmd/skywire-cli/commands/node/transports.go | 4 ++-- routing.db | Bin 0 -> 32768 bytes 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 routing.db diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index a07cbeba8..ef9e1afd1 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -108,7 +108,7 @@ var rmTpCmd = &cobra.Command{ func printTransports(tps ...*node.TransportSummary) { sortTransports(tps...) w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent) - _, err := fmt.Fprintln(w, "type\tid\tlocal\tremote\tmode") + _, err := fmt.Fprintln(w, "type\tid\tremote\tmode") internal.Catch(err) for _, tp := range tps { tpMode := "regular" @@ -116,7 +116,7 @@ func printTransports(tps ...*node.TransportSummary) { tpMode = "setup" } - _, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", tp.Type, tp.ID, tp.Local, tp.Remote, tpMode) + _, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", tp.Type, tp.ID, tp.Remote, tpMode) internal.Catch(err) } internal.Catch(w.Flush()) diff --git a/routing.db b/routing.db new file mode 100644 index 0000000000000000000000000000000000000000..9c9b955ee905573eb3707b3560bebea6c14deec4 GIT binary patch literal 32768 zcmeI)F>b;z6aY{|fi9I`hJ}f#Tg4q1y7Ux?0gw<3?NNIN*x5*k{{Vsw2}?Xnj-AA@ zzTWn2D=9UlliU6O$G%(tGiUT)80tN!Y1^!c|u9%7u9009C72oNAZfB*pk z1PBl)N1&BMxtIUHU4lgg}4*0RjXF5FkK+009C72s~OK_V;5Q;L-D&j{pGz1PBlyK!5-N0t5&Uc)mcK z<8Pw4xzEfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk Q1PBlyK!5-N00{My#-2eap literal 0 HcmV?d00001 From 080f64c35e01ff72df5157be0953a103f91788c2 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 22 May 2019 14:18:10 +0300 Subject: [PATCH 7/7] Remove `routing.db` --- routing.db | Bin 32768 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 routing.db diff --git a/routing.db b/routing.db deleted file mode 100644 index 9c9b955ee905573eb3707b3560bebea6c14deec4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeI)F>b;z6aY{|fi9I`hJ}f#Tg4q1y7Ux?0gw<3?NNIN*x5*k{{Vsw2}?Xnj-AA@ zzTWn2D=9UlliU6O$G%(tGiUT)80tN!Y1^!c|u9%7u9009C72oNAZfB*pk z1PBl)N1&BMxtIUHU4lgg}4*0RjXF5FkK+009C72s~OK_V;5Q;L-D&j{pGz1PBlyK!5-N0t5&Uc)mcK z<8Pw4xzEfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk Q1PBlyK!5-N00{My#-2eap