(n *Nylon, req *protocol.StatusRequest)
| 98 | } |
| 99 | |
| 100 | func handleStatus(n *Nylon, req *protocol.StatusRequest) *protocol.IpcResponse { |
| 101 | activeEps := 0 |
| 102 | for _, neigh := range n.RouterState.Neighbours { |
| 103 | for _, ep := range neigh.Eps { |
| 104 | if ep.IsActive() { |
| 105 | activeEps++ |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | txBytes := uint64(0) |
| 111 | rxBytes := uint64(0) |
| 112 | wgStats := wireGuardPeerStats(n) |
| 113 | for _, stat := range wgStats { |
| 114 | txBytes += stat.TxBytes |
| 115 | rxBytes += stat.RxBytes |
| 116 | } |
| 117 | |
| 118 | listenPort := uint32(n.LocalCfg.Port) |
| 119 | if n.Device != nil { |
| 120 | listenPort = uint32(n.Device.ListenPort()) |
| 121 | } |
| 122 | |
| 123 | return &protocol.IpcResponse{ |
| 124 | Ok: true, |
| 125 | Response: &protocol.IpcResponse_Status{Status: &protocol.StatusResponse{ |
| 126 | Node: &protocol.NodeStatus{ |
| 127 | NodeId: string(n.LocalCfg.Id), |
| 128 | Interface: n.Interface, |
| 129 | PublicKey: keyString(n.LocalCfg.Key.Pubkey()), |
| 130 | ListenPort: listenPort, |
| 131 | ConfigTimestamp: n.CentralCfg.Timestamp, |
| 132 | TraceEnabled: n.DBG_trace_tc, |
| 133 | Advertised: buildAdvertisements(n), |
| 134 | Seqnos: buildSeqnos(n), |
| 135 | Stats: &protocol.NodeStats{ |
| 136 | NeighbourCount: int32(len(n.RouterState.Neighbours)), |
| 137 | ActiveEndpointCount: int32(activeEps), |
| 138 | SelectedRouteCount: int32(len(n.RouterState.Routes)), |
| 139 | AdvertisedPrefixCount: int32(len(n.RouterState.Advertised)), |
| 140 | TxBytes: txBytes, |
| 141 | RxBytes: rxBytes, |
| 142 | }, |
| 143 | }, |
| 144 | Neighbours: buildNeighbours(n, wgStats), |
| 145 | Routes: buildRouteTables(n), |
| 146 | FeasibilityDistances: buildFeasibilityDistances(n), |
| 147 | }}, |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | func buildAdvertisements(n *Nylon) []*protocol.Advertisement { |
| 152 | entries := make([]*protocol.Advertisement, 0, len(n.RouterState.Advertised)) |
no test coverage detected