Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move NetworkRouterStatus into its own file
- Loading branch information
Showing
2 changed files
with
43 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package router | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type NetworkRouterStatus struct { | ||
*Status | ||
Interface string | ||
CaptureStats map[string]int | ||
MACs []MACStatus | ||
} | ||
|
||
type MACStatus struct { | ||
Mac string | ||
Name string | ||
NickName string | ||
LastSeen time.Time | ||
} | ||
|
||
func NewNetworkRouterStatus(router *NetworkRouter) *NetworkRouterStatus { | ||
return &NetworkRouterStatus{ | ||
NewStatus(router.Router), | ||
router.Bridge.String(), | ||
router.Bridge.Stats(), | ||
NewMACStatusSlice(router.Macs)} | ||
} | ||
|
||
func NewMACStatusSlice(cache *MacCache) []MACStatus { | ||
cache.RLock() | ||
defer cache.RUnlock() | ||
|
||
var slice []MACStatus | ||
for key, entry := range cache.table { | ||
slice = append(slice, MACStatus{ | ||
intmac(key).String(), | ||
entry.peer.Name.String(), | ||
entry.peer.NickName, | ||
entry.lastSeen}) | ||
} | ||
|
||
return slice | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters