MCPcopy Create free account
hub / github.com/DNAProject/DNA / viewHandler

Function viewHandler

http/nodeinfo/server.go:77–116  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

75}
76
77func viewHandler(w http.ResponseWriter, r *http.Request) {
78 var ngbrNodersInfo []NgbNodeInfo
79 var ngbId string
80 var ngbAddr string
81 var ngbType string
82 var ngbInfoPort uint16
83 var ngbInfoState bool
84 var ngbHttpInfoAddr string
85 var ngbVersion string
86
87 curNodeType := SERVICENODE
88
89 ngbrNoders := node.GetNeighbors()
90 ngbrsLen := len(ngbrNoders)
91 for i := 0; i < ngbrsLen; i++ {
92 ngbType = SERVICENODE
93 ngbAddr = ngbrNoders[i].GetAddr()
94 ngbInfoPort = ngbrNoders[i].GetHttpInfoPort()
95 ngbInfoState = ngbrNoders[i].GetHttpInfoState()
96 ngbHttpInfoAddr = ngbAddr + ":" + strconv.Itoa(int(ngbInfoPort))
97 ngbId = fmt.Sprintf("0x%x", ngbrNoders[i].GetID())
98 ngbVersion = ngbrNoders[i].GetSoftVersion()
99
100 ngbrInfo := newNgbNodeInfo(ngbId, ngbType, ngbAddr, ngbHttpInfoAddr, ngbInfoPort, ngbInfoState, ngbVersion)
101 ngbrNodersInfo = append(ngbrNodersInfo, *ngbrInfo)
102 }
103 sort.Sort(NgbNodeInfoSlice(ngbrNodersInfo))
104
105 blockHeight := ledger.DefLedger.GetCurrentBlockHeight()
106 pageInfo, err := initPageInfo(blockHeight, curNodeType, ngbrsLen, ngbrNodersInfo)
107 if err != nil {
108 http.Redirect(w, r, "/info", http.StatusFound)
109 return
110 }
111
112 err = templates.ExecuteTemplate(w, "info", pageInfo)
113 if err != nil {
114 http.Error(w, err.Error(), http.StatusInternalServerError)
115 }
116}
117
118func StartServer(n p2p.P2P) {
119 node = n

Callers

nothing calls this directly

Calls 11

newNgbNodeInfoFunction · 0.85
NgbNodeInfoSliceTypeAlias · 0.85
initPageInfoFunction · 0.85
GetHttpInfoStateMethod · 0.80
GetNeighborsMethod · 0.65
GetHttpInfoPortMethod · 0.65
GetIDMethod · 0.65
GetCurrentBlockHeightMethod · 0.65
ErrorMethod · 0.65
GetAddrMethod · 0.45
GetSoftVersionMethod · 0.45

Tested by

no test coverage detected