Skip to content

Commit

Permalink
Remerged with mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed May 23, 2019
2 parents 27da1fa + f531cc5 commit 367dadc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
9 changes: 7 additions & 2 deletions cmd/skywire-cli/commands/node/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\tremote\tmode")
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\n", tp.Type, tp.ID, tp.Remote, tpMode)
internal.Catch(err)
}
internal.Catch(w.Flush())
Expand Down
1 change: 1 addition & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,7 @@ func (r *mockRouter) Close() error {
r.Unlock()
return nil
}

func (r *mockRouter) IsSetupTransport(tr transport.Transport) bool {
return false
}
32 changes: 18 additions & 14 deletions pkg/node/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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)
Expand All @@ -104,7 +104,7 @@ func (r *Router) Serve(ctx context.Context) error {

go func() {
for tr := range r.tm.DialedTrChan {
if r.isSetupTransport(tr) {
if r.IsSetupTransport(tr) {
continue
}

Expand Down Expand Up @@ -482,7 +482,8 @@ func (r *Router) advanceNoiseHandshake(addr *app.LoopAddr, noiseMsg []byte) (ni
return
}

func (r *Router) isSetupTransport(tr transport.Transport) bool {
// 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())
if ok && (remote == pk) {
Expand Down

0 comments on commit 367dadc

Please sign in to comment.