Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Report direct peers via connection type attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
awh committed Aug 4, 2015
1 parent 1940bcd commit def1e5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions prog/weaver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/weaveworks/weave/nameserver"
"github.com/weaveworks/weave/net/address"
weave "github.com/weaveworks/weave/router"
"net"
"net/http"
"strings"
"text/template"
Expand Down Expand Up @@ -38,6 +39,16 @@ var rootTemplate = template.New("root").Funcs(map[string]interface{}{
}
return s
},
"connectionType": func(directPeers []string, address string) string {
addressHost, _, _ := net.SplitHostPort(address)
for _, directPeer := range directPeers {
_, _, err := net.SplitHostPort(directPeer)
if err == nil && directPeer == address || directPeer == addressHost {
return "direct"
}
}
return "discovered"
},
})

// Strip escaped newlines from template
Expand Down Expand Up @@ -90,40 +101,38 @@ var peersTemplate = defTemplate("peers", `\
{{range .Router.Peers}}\
{{.Name}}({{.NickName}}) ({{.Version}}) (UID {{.UID}})
{{range .Connections}}\
-> {{.Name}}({{.NickName}}) [{{.TCPAddr}}]{{if not .Established}} UNESTABLISHED{{end}}
-> {{.Name}}({{.NickName}}) [{{.Address}}]{{if not .Established}} UNESTABLISHED{{end}}
{{end}}\
{{end}}\
`)

var connectionsTemplate = defTemplate("connectionsTemplate", `\
{{range $index, $ := .Router.ConnectionMaker.DirectPeers}}\
{{if eq $index 0}}\
DirectPeers: {{.}}
{{else}}\
{{.}}
{{end}}\
{{end}}\
{{$directPeers := .Router.ConnectionMaker.DirectPeers}}\
{{$ourself := .Router.Name}}\
{{range .Router.Peers}}\
{{if eq .Name $ourself}}\
{{range $index, $ := .Connections}}\
{{if ne $index 0}}\
{{end}}\
Address: {{.TCPAddr}}
Address: {{.Address}}
Type: {{connectionType $directPeers .Address}}
Name: {{.Name}}
NickName: {{.NickName}}
Direction: {{if .Outbound}}outbound{{else}}inbound{{end}}
State: {{if .Established}}established{{else}}unestablished{{end}}
{{end}}\
{{end}}\
{{end}}\
{{if len .Router.ConnectionMaker.Reconnects}}\
{{end}}\
{{range $index, $ := .Router.ConnectionMaker.Reconnects}}\
{{if ne $index 0}}\
{{end}}\
Address: {{.Address}}
Type: {{connectionType $directPeers .Address}}
LastError: {{.LastError}}
TryInterval: {{.TryInterval}}
{{if .Attempting}}\
Expand Down
2 changes: 1 addition & 1 deletion router/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type PeerStatus struct {
type ConnectionStatus struct {
Name string
NickName string
TCPAddr string
Address string
Outbound bool
Established bool
}
Expand Down

0 comments on commit def1e5e

Please sign in to comment.