Skip to content

Commit

Permalink
Merge pull request #310 from evanlinjin/feature/tp-status-cli-#302
Browse files Browse the repository at this point in the history
Added 'is_up' to transport status CLI.
  • Loading branch information
jdknives authored Apr 9, 2020
2 parents 653ce22 + 258e782 commit 2f93bb2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/visor/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ var rmTpCmd = &cobra.Command{
func printTransports(tps ...*visor.TransportSummary) {
sortTransports(tps...)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err := fmt.Fprintln(w, "type\tid\tremote\tmode")
_, err := fmt.Fprintln(w, "type\tid\tremote\tmode\tis_up")
internal.Catch(err)
for _, tp := range tps {
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)
_, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%v\n", tp.Type, tp.ID, tp.Remote, tpMode, tp.IsUp)
internal.Catch(err)
}
internal.Catch(w.Flush())
Expand Down
8 changes: 8 additions & 0 deletions pkg/transport/managed_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ func NewManagedTransport(n *snet.Network, dc DiscoveryClient, ls LogStore, rPK c
return mt
}

// IsUp returns true if transport status is up.
func (mt *ManagedTransport) IsUp() bool {
mt.isUpMux.Lock()
isUp := mt.isUp && mt.isUpErr == nil
mt.isUpMux.Unlock()
return isUp
}

// Serve serves and manages the transport.
func (mt *ManagedTransport) Serve(readCh chan<- routing.Packet) {
defer mt.wg.Done()
Expand Down
3 changes: 2 additions & 1 deletion pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ type TransportSummary struct {
Type string `json:"type"`
Log *transport.LogEntry `json:"log,omitempty"`
IsSetup bool `json:"is_setup"`
IsUp bool `json:"is_up"`
}

func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport, includeLogs, isSetup bool) *TransportSummary {

summary := &TransportSummary{
ID: tp.Entry.ID,
Local: tm.Local(),
Remote: tp.Remote(),
Type: tp.Type(),
IsSetup: isSetup,
IsUp: tp.IsUp(),
}
if includeLogs {
summary.Log = tp.LogEntry
Expand Down

0 comments on commit 2f93bb2

Please sign in to comment.