Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed loop to routegroup for hypervisor endpoints, function names, struct types and comments. #207

Merged
merged 10 commits into from
Mar 6, 2020
Merged
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ communication API over the pipe.
// Setup setups app using default pair of pipes
func Setup(config *Config) (*App, error) {}

// Accept awaits for incoming loop confirmation request from a Visor and
// returns net.Conn for a received loop.
// Accept awaits for incoming route group confirmation request from a Visor and
// returns net.Conn for a received route group.
func (app *App) Accept() (net.Conn, error) {}

// Addr implements net.Addr for App connections.
&Addr{PubKey: pk, Port: 12}
// Dial sends create loop request to a Visor and returns net.Conn for created loop.
// Dial sends create route group request to a Visor and returns net.Conn for created route group.
func (app *App) Dial(raddr *Addr) (net.Conn, error) {}

// Close implements io.Closer for App.
Expand Down
20 changes: 10 additions & 10 deletions ci_scripts/run-pkg-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ 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/SkycoinProject/skywire-mainnet/pkg/visor -run TestRPC >> ./logs/pkg/TestRPC.log

go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerInit >> ./logs/pkg/TestAppManagerInit.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerSetupLoop >> ./logs/pkg/TestAppManagerSetupLoop.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerCloseLoop >> ./logs/pkg/TestAppManagerCloseLoop.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerSetupRouteGroup >> ./logs/pkg/TestAppManagerSetupRouteGroup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerCloseRouteGRoup >> ./logs/pkg/TestAppManagerCloseRouteGroup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestAppManagerForward >> ./logs/pkg/TestAppManagerForward.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestManagedRoutingTableCleanup >> ./logs/pkg/TestManagedRoutingTableCleanup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestPortManager >> ./logs/pkg/TestPortManager.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerGetRule >> ./logs/pkg/TestRouteManagerGetRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerRemoveLoopRule >> ./logs/pkg/TestRouteManagerRemoveLoopRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerRemoveRouteGroupRule >> ./logs/pkg/TestRouteManagerRemoveRouteGroupRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerAddRemoveRule >> ./logs/pkg/TestRouteManagerAddRemoveRule.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerDeleteRules >> ./logs/pkg/TestRouteManagerDeleteRules.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerConfirmLoop >> ./logs/pkg/TestRouteManagerConfirmLoop.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerLoopClosed >> ./logs/pkg/TestRouteManagerLoopClosed.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerConfirmRouteGroup >> ./logs/pkg/TestRouteManagerConfirmRouteGroup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouteManagerRouteGroupClosed >> ./logs/pkg/TestRouteManagerRouteGroupClosed.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterForwarding >> ./logs/pkg/TestRouterForwarding.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterAppInit >> ./logs/pkg/TestRouterAppInit.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterApp >> ./logs/pkg/TestRouterApp.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterLocalApp >> ./logs/pkg/TestRouterLocalApp.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterSetup >> ./logs/pkg/TestRouterSetup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterSetupLoop >> ./logs/pkg/TestRouterSetupLoop.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterSetupLoopLocal >> ./logs/pkg/TestRouterSetupLoopLocal.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseLoop >> ./logs/pkg/TestRouterCloseLoop.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseLoopOnAppClose >> ./logs/pkg/TestRouterCloseLoopOnAppClose.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseLoopOnRouterClose >> ./logs/pkg/TestRouterCloseLoopOnRouterClose.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterSetupRouteGroup >> ./logs/pkg/TestRouterSetupRouteGroup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterSetupRouteGroupLocal >> ./logs/pkg/TestRouterSetupRouteGroupLocal.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseRouteGroup >> ./logs/pkg/TestRouterCloseRouteGroup.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseRouteGroupOnAppClose >> ./logs/pkg/TestRouterCloseRouteGroupOnAppClose.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterCloseRouteGroupOnRouterClose >> ./logs/pkg/TestRouterCloseRouteGroupOnRouterClose.log
go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/router -run TestRouterRouteExpiration >> ./logs/pkg/TestRouterRouteExpiration.log

go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/SkycoinProject/skywire-mainnet/pkg/routing -run TestBoltDBRoutingTable >> ./logs/pkg/TestBoltDBRoutingTable.log
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/appnet/skywire_networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ func (r *SkywireNetworker) ListenContext(ctx context.Context, addr Addr) (net.Li

if atomic.CompareAndSwapInt32(&r.isServing, 0, 1) {
go func() {
if err := r.serveLoop(ctx); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
r.log.WithError(err).Error("serveLoop stopped unexpectedly.")
if err := r.serveRouteGroup(ctx); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
r.log.WithError(err).Error("serveRouteGroup stopped unexpectedly.")
}
}()
}

return lis, nil
}

// serveLoop accepts and serves routes.
func (r *SkywireNetworker) serveLoop(ctx context.Context) error {
log := r.log.WithField("func", "serveLoop")
// serveRouteGroup accepts and serves routes.
func (r *SkywireNetworker) serveRouteGroup(ctx context.Context) error {
log := r.log.WithField("func", "serveRouteGroup")

for {
log.Debug("Awaiting to accept route group...")
Expand Down
20 changes: 10 additions & 10 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (hv *Hypervisor) ServeHTTP(w http.ResponseWriter, req *http.Request) {
r.Get("/visors/{pk}/routes/{rid}", hv.getRoute())
r.Put("/visors/{pk}/routes/{rid}", hv.putRoute())
r.Delete("/visors/{pk}/routes/{rid}", hv.deleteRoute())
r.Get("/visors/{pk}/loops", hv.getLoops())
r.Get("/visors/{pk}/routegroups", hv.getRouteGroups())
r.Get("/visors/{pk}/restart", hv.restart())
r.Post("/visors/{pk}/exec", hv.exec())
r.Post("/visors/{pk}/update", hv.update())
Expand Down 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) getLoops() http.HandlerFunc {
func (hv *Hypervisor) getRouteGroups() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
loops, err := ctx.RPC.Loops()
routegroups, 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(routegroups))
for i, l := range routegroups {
resp[i] = makeRouteGroupResp(l)
}

httputil.WriteJSON(w, r, http.StatusOK, resp)
Expand Down
8 changes: 4 additions & 4 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ func (rg *RouteGroup) close(code routing.CloseCode) error {
// if this visor initiated closing, we need to wait for close packets
// to come back, or to exit with a timeout if anything goes wrong in
// the network
if err := rg.waitForCloseLoop(closeRoutineTimeout); err != nil {
rg.logger.Errorf("Error during close loop: %v", err)
if err := rg.waitForCloseRouteGroup(closeRoutineTimeout); err != nil {
rg.logger.Errorf("Error during close route group: %v", err)
}
}

Expand Down Expand Up @@ -496,7 +496,7 @@ func (rg *RouteGroup) broadcastClosePackets(code routing.CloseCode) {
}
}

func (rg *RouteGroup) waitForCloseLoop(waitTimeout time.Duration) error {
func (rg *RouteGroup) waitForCloseRouteGroup(waitTimeout time.Duration) error {
closeCtx, closeCancel := context.WithTimeout(context.Background(), waitTimeout)
defer closeCancel()

Expand All @@ -509,7 +509,7 @@ func (rg *RouteGroup) waitForCloseLoop(waitTimeout time.Duration) error {

select {
case <-closeCtx.Done():
return fmt.Errorf("close loop timed out: %v", closeCtx.Err())
return fmt.Errorf("close route group timed out: %v", closeCtx.Err())
case <-closeDoneCh:
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type Router interface {

// Router implements visor.PacketRouter. It manages routing table by
// communicating with setup nodes, forward packets according to local
// rules and manages loops for apps.
// rules and manages route groups for apps.
type router struct {
mx sync.Mutex
conf *Config
Expand Down Expand Up @@ -537,7 +537,7 @@ func (r *router) Close() error {
return nil
}

r.logger.Info("Closing all App connections and Loops")
r.logger.Info("Closing all App connections and RouteGroups")

r.once.Do(func() {
close(r.done)
Expand Down Expand Up @@ -594,7 +594,7 @@ func (r *router) forwardPacket(ctx context.Context, packet routing.Packet, rule
return nil
}

// RemoveRouteDescriptor removes loop rule.
// RemoveRouteDescriptor removes route group rule.
func (r *router) RemoveRouteDescriptor(desc routing.RouteDescriptor) {
rules := r.rt.AllRules()
for _, rule := range rules {
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Test_router_DialRoutes(t *testing.T) {
r0.conf.RouteGroupDialer = setupclient.NewMockDialer()
r1.conf.RouteGroupDialer = setupclient.NewMockDialer()

// prepare loop creation (client_1 will use this to request loop creation with setup node).
// prepare route group creation (client_1 will use this to request route group creation with setup node).
desc := routing.NewRouteDescriptor(r0.conf.PubKey, r1.conf.PubKey, 1, 1)

forwardHops := []routing.Hop{
Expand Down
4 changes: 2 additions & 2 deletions pkg/setup/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (sn *Node) handleDialRouteGroup(ctx context.Context, route routing.Bidirect

forwardRoute, reverseRoute := route.ForwardAndReverse()

// Determine the rules to send to visors using loop descriptor and reserved route IDs.
// Determine the rules to send to visors using route group descriptor and reserved route IDs.
forwardRules, consumeRules, intermediaryRules, err := idr.GenerateRules(forwardRoute, reverseRoute)

if err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func (sn *Node) handleDialRouteGroup(ctx context.Context, route routing.Bidirect
// Confirm routes with responding visor.
ok, err := routerclient.AddEdgeRules(ctx, sn.logger, sn.dmsgC, route.Desc.DstPK(), respRouteRules)
if err != nil || !ok {
return routing.EdgeRules{}, fmt.Errorf("failed to confirm loop with destination visor: %v", err)
return routing.EdgeRules{}, fmt.Errorf("failed to confirm route group with destination visor: %v", err)
}

sn.logger.Infof("Returning route rules to initiating visor: %v", initRouteRules)
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func testDialRouteGroup(t *testing.T, keys []snettest.KeyPair, nEnv *snettest.En
}

func prepBidirectionalRoute(clients []clientWithDMSGAddrAndListener) routing.BidirectionalRoute {
// prepare loop creation (client_1 will use this to request loop creation with setup node).
// prepare route group creation (client_1 will use this to request a route group creation with setup node).
desc := routing.NewRouteDescriptor(clients[1].Addr.PK, clients[4].Addr.PK, 1, 1)

forwardHops := []routing.Hop{
Expand Down
18 changes: 9 additions & 9 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,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
}

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

var loops []LoopInfo
var routegroups []RouteGroupInfo

rules := r.visor.router.Rules()
for _, rule := range rules {
Expand All @@ -453,13 +453,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
22 changes: 11 additions & 11 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

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

Restart() error
Exec(command string) ([]byte, error)
Expand Down Expand Up @@ -230,11 +230,11 @@ func (rc *rpcClient) RemoveRoutingRule(key routing.RouteID) error {
return rc.Call("RemoveRoutingRule", &key, &struct{}{})
}

// Loops calls Loops.
func (rc *rpcClient) Loops() ([]LoopInfo, error) {
var loops []LoopInfo
err := rc.Call("Loops", &struct{}{}, &loops)
return loops, err
// RouteGroups calls RouteGroups.
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 @@ -580,9 +580,9 @@ func (mc *mockRPCClient) RemoveRoutingRule(key routing.RouteID) error {
return nil
}

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

rules := mc.rt.AllRules()
for _, rule := range rules {
Expand All @@ -595,13 +595,13 @@ func (mc *mockRPCClient) Loops() ([]LoopInfo, error) {
if err != nil {
return nil, err
}
loops = append(loops, LoopInfo{
routeGroups = append(routeGroups, RouteGroupInfo{
ConsumeRule: rule,
FwdRule: fwdRule,
})
}

return loops, nil
return routeGroups, nil
}

// Restart implements RPCClient.
Expand Down