Skip to content

Commit

Permalink
rename functions, types and comments loops to routegroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kifen committed Mar 6, 2020
1 parent 749b11c commit 4019f78
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
16 changes: 8 additions & 8 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,33 +656,33 @@ func (hv *Hypervisor) deleteRoute() http.HandlerFunc {
})
}

type loopResp struct {
type routeGroupResp struct {
routing.RuleConsumeFields
FwdRule routing.RuleForwardFields `json:"resp"`
}

func makeLoopResp(info visor.LoopInfo) loopResp {
func makeRouteGroupResp(info visor.RouteGroupInfo) routeGroupResp {
if len(info.FwdRule) == 0 || len(info.ConsumeRule) == 0 {
return loopResp{}
return routeGroupResp{}
}

return loopResp{
return routeGroupResp{
RuleConsumeFields: *info.ConsumeRule.Summary().ConsumeFields,
FwdRule: *info.FwdRule.Summary().ForwardFields,
}
}

func (hv *Hypervisor) getRouteGroup() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
loops, err := ctx.RPC.RouteGroups()
rg, err := ctx.RPC.RouteGroups()
if err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}

resp := make([]loopResp, len(loops))
for i, l := range loops {
resp[i] = makeLoopResp(l)
resp := make([]routeGroupResp, len(rg))
for i, l := range rg {
resp[i] = makeRouteGroupResp(l)
}

httputil.WriteJSON(w, r, http.StatusOK, resp)
Expand Down
16 changes: 8 additions & 8 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,21 +450,21 @@ func (r *RPC) RemoveRoutingRule(key *routing.RouteID, _ *struct{}) (err error) {
}

/*
<<< LOOPS MANAGEMENT >>>
<<< ROUTEGROUPS MANAGEMENT >>>
>>> TODO(evanlinjin): Implement.
*/

// LoopInfo is a human-understandable representation of a loop.
type LoopInfo struct {
// RouteGroupInfo is a human-understandable representation of a RouteGroup.
type RouteGroupInfo struct {
ConsumeRule routing.Rule
FwdRule routing.Rule
}

// RouteGroups retrieves loops via rules of the routing table.
func (r *RPC) Loops(_ *struct{}, out *[]LoopInfo) (err error) {
// RouteGroups retrieves routegroups via rules of the routing table.
func (r *RPC) RouteGroups(_ *struct{}, out *[]RouteGroupInfo) (err error) {
defer r.logReq("RouteGroups", nil)(out, &err)

var loops []LoopInfo
var routegroups []RouteGroupInfo

rules := r.visor.router.Rules()
for _, rule := range rules {
Expand All @@ -478,13 +478,13 @@ func (r *RPC) Loops(_ *struct{}, out *[]LoopInfo) (err error) {
return err
}

loops = append(loops, LoopInfo{
routegroups = append(routegroups, RouteGroupInfo{
ConsumeRule: rule,
FwdRule: rule,
})
}

*out = loops
*out = routegroups
return nil
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type RPCClient interface {
SaveRoutingRule(rule routing.Rule) error
RemoveRoutingRule(key routing.RouteID) error

RouteGroups() ([]LoopInfo, error)
RouteGroups() ([]RouteGroupInfo, error)

Restart() error
Exec(command string) ([]byte, error)
Expand Down Expand Up @@ -231,10 +231,10 @@ func (rc *rpcClient) RemoveRoutingRule(key routing.RouteID) error {
}

// RouteGroups calls RouteGroups.
func (rc *rpcClient) RouteGroups() ([]LoopInfo, error) {
var loops []LoopInfo
err := rc.Call("RouteGroups", &struct{}{}, &loops)
return loops, err
func (rc *rpcClient) RouteGroups() ([]RouteGroupInfo, error) {
var routegroups []RouteGroupInfo
err := rc.Call("RouteGroups", &struct{}{}, &routegroups)
return routegroups, err
}

// Restart calls Restart.
Expand Down Expand Up @@ -581,8 +581,8 @@ func (mc *mockRPCClient) RemoveRoutingRule(key routing.RouteID) error {
}

// RouteGroups implements RPCClient.
func (mc *mockRPCClient) RouteGroups() ([]LoopInfo, error) {
var loops []LoopInfo
func (mc *mockRPCClient) RouteGroups() ([]RouteGroupInfo, error) {
var loops []RouteGroupInfo

rules := mc.rt.AllRules()
for _, rule := range rules {
Expand All @@ -595,7 +595,7 @@ func (mc *mockRPCClient) RouteGroups() ([]LoopInfo, error) {
if err != nil {
return nil, err
}
loops = append(loops, LoopInfo{
loops = append(loops, RouteGroupInfo{
ConsumeRule: rule,
FwdRule: fwdRule,
})
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/SkycoinProject/dmsg/disc/entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/SkycoinProject/dmsg/httputil/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/SkycoinProject/dmsg v0.0.0-20200304115237-130cc9d98ffb
# github.com/SkycoinProject/dmsg v0.0.0-20200304115237-130cc9d98ffb => ../dmsg
github.com/SkycoinProject/dmsg
github.com/SkycoinProject/dmsg/cipher
github.com/SkycoinProject/dmsg/disc
Expand Down

0 comments on commit 4019f78

Please sign in to comment.