Skip to content

Commit

Permalink
Rename appRule to consumeRule
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Sep 10, 2019
1 parent 371fc71 commit 37fbb89
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion ci_scripts/run-pkg-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestBoltDBRoutingTable >> ./logs/pkg/TestBoltDBRoutingTable.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestMakePacket >> ./logs/pkg/TestMakePacket.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestRoutingTable >> ./logs/pkg/TestRoutingTable.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestAppRule >> ./logs/pkg/TestAppRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestConsumeRule >> ./logs/pkg/TestConsumeRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestForwardRule >> ./logs/pkg/TestForwardRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/routing -run TestIntermediaryForwardRule >> ./logs/pkg/TestIntermediaryForwardRule.log

go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/setup -run TestNewProtocol >> ./logs/pkg/TestNewProtocol.log

Expand Down
4 changes: 2 additions & 2 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ type loopResp struct {
}

func makeLoopResp(info visor.LoopInfo) loopResp {
if len(info.FwdRule) == 0 || len(info.AppRule) == 0 {
if len(info.FwdRule) == 0 || len(info.ConsumeRule) == 0 {
return loopResp{}
}
return loopResp{
RuleConsumeFields: *info.AppRule.Summary().ConsumeFields,
RuleConsumeFields: *info.ConsumeRule.Summary().ConsumeFields,
FwdRule: *info.FwdRule.Summary().ForwardFields,
}
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/router/route_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (rm *routeManager) GetRule(routeID routing.RouteID) (routing.Rule, error) {
// RemoveLoopRule removes loop rule.
func (rm *routeManager) RemoveLoopRule(loop routing.Loop) error {
var appRouteID routing.RouteID
var appRule routing.Rule
var consumeRule routing.Rule
rm.rt.RangeRules(func(routeID routing.RouteID, rule routing.Rule) bool {
if rule.Type() != routing.RuleConsume || rule.RouteDescriptor().DstPK() != loop.Remote.PubKey ||
rule.RouteDescriptor().DstPort() != loop.Remote.Port ||
Expand All @@ -178,13 +178,13 @@ func (rm *routeManager) RemoveLoopRule(loop routing.Loop) error {
}

appRouteID = routeID
appRule = make(routing.Rule, len(rule))
copy(appRule, rule)
consumeRule = make(routing.Rule, len(rule))
copy(consumeRule, rule)

return false
})

if len(appRule) == 0 {
if len(consumeRule) == 0 {
return nil
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (rm *routeManager) confirmLoop(data []byte) error {
}

var appRouteID routing.RouteID
var appRule routing.Rule
var consumeRule routing.Rule
rm.rt.RangeRules(func(routeID routing.RouteID, rule routing.Rule) bool {
if rule.Type() != routing.RuleConsume || rule.RouteDescriptor().DstPK() != ld.Loop.Remote.PubKey ||
rule.RouteDescriptor().DstPort() != ld.Loop.Remote.Port ||
Expand All @@ -239,12 +239,12 @@ func (rm *routeManager) confirmLoop(data []byte) error {
}

appRouteID = routeID
appRule = make(routing.Rule, len(rule))
copy(appRule, rule)
consumeRule = make(routing.Rule, len(rule))
copy(consumeRule, rule)
return false
})

if appRule == nil {
if consumeRule == nil {
return errors.New("unknown loop")
}

Expand All @@ -262,8 +262,8 @@ func (rm *routeManager) confirmLoop(data []byte) error {
}

rm.Logger.Infof("Setting reverse route ID %d for rule with ID %d", ld.RouteID, appRouteID)
appRule.SetKeyRouteID(ld.RouteID)
if rErr := rm.rt.SaveRule(appRouteID, appRule); rErr != nil {
consumeRule.SetKeyRouteID(ld.RouteID)
if rErr := rm.rt.SaveRule(appRouteID, consumeRule); rErr != nil {
return fmt.Errorf("routing table: %s", rErr)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,21 @@ func (r *RPC) RemoveRoutingRule(key *routing.RouteID, _ *struct{}) error {

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

// Loops retrieves loops via rules of the routing table.
func (r *RPC) Loops(_ *struct{}, out *[]LoopInfo) error {
var loops []LoopInfo
r.node.rt.RangeRules(func(_ routing.RouteID, rule routing.Rule) (next bool) {
if rule.Type() == routing.RuleConsume {
loops = append(loops, LoopInfo{AppRule: rule})
loops = append(loops, LoopInfo{ConsumeRule: rule})
}
return true
})
for i, l := range loops {
fwdRID := l.AppRule.NextRouteID()
fwdRID := l.ConsumeRule.NextRouteID()
rule, err := r.node.rt.Rule(fwdRID)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ func NewMockRPCClient(r *rand.Rand, maxTps int, maxRules int) (cipher.PubKey, RP
if err != nil {
panic(err)
}
appRule := routing.ConsumeRule(ruleKeepAlive, appRID, remotePK, lp, rp)
if err := rt.SaveRule(appRID, appRule); err != nil {
consumeRule := routing.ConsumeRule(ruleKeepAlive, appRID, remotePK, lp, rp)
if err := rt.SaveRule(appRID, consumeRule); err != nil {
panic(err)
}
log.Infof("rt[%2da]: %v %v", i, fwdRID, fwdRule.Summary().ForwardFields)
log.Infof("rt[%2db]: %v %v", i, appRID, appRule.Summary().ConsumeFields)
log.Infof("rt[%2db]: %v %v", i, appRID, consumeRule.Summary().ConsumeFields)
}
log.Printf("rtCount: %d", rt.Count())
client := &mockRPCClient{
Expand Down Expand Up @@ -505,12 +505,12 @@ func (mc *mockRPCClient) Loops() ([]LoopInfo, error) {
var loops []LoopInfo
mc.rt.RangeRules(func(_ routing.RouteID, rule routing.Rule) (next bool) {
if rule.Type() == routing.RuleConsume {
loops = append(loops, LoopInfo{AppRule: rule})
loops = append(loops, LoopInfo{ConsumeRule: rule})
}
return true
})
for i, l := range loops {
fwdRID := l.AppRule.NextRouteID()
fwdRID := l.ConsumeRule.NextRouteID()
rule, err := mc.rt.Rule(fwdRID)
if err != nil {
return nil, err
Expand Down

0 comments on commit 37fbb89

Please sign in to comment.