Skip to content

Commit

Permalink
Fix the issue when establishing the already existing route. Probably
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Feb 24, 2020
1 parent 5704066 commit 8b2d488
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/skysocks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (s *Server) Serve(l net.Listener) error {
return fmt.Errorf("accept: %s", err)
}

s.log.Infoln("ACCEPTED NEW SKYSOCKS CONN")

sessionCfg := yamux.DefaultConfig()
sessionCfg.EnableKeepAlive = false
session, err := yamux.Server(conn, sessionCfg)
Expand Down
3 changes: 3 additions & 0 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func (rg *RouteGroup) read(p []byte) (int, error) {
func (rg *RouteGroup) write(data []byte, tp *transport.ManagedTransport, rule routing.Rule) (int, error) {
packet := routing.MakeDataPacket(rule.NextRouteID(), data)

rg.logger.Infof("WRITING PACKET OF TYPE %s AND ROUTE ID %d AND NEXT ID %d", packet.Type(),
rule.KeyRouteID(), rule.NextRouteID())

ctx, cancel := context.WithCancel(context.Background())

errCh := rg.writePacketAsync(ctx, tp, packet)
Expand Down
49 changes: 47 additions & 2 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,34 @@ func (r *router) saveRouteGroupRules(rules routing.EdgeRules) *RouteGroup {
r.logger.Infof("Creating new route group rule with desc: %s", &rules.Desc)
rg = NewRouteGroup(DefaultRouteGroupConfig(), r.rt, rules.Desc)
r.rgs[rules.Desc] = rg

rg.fwd = append(rg.fwd, rules.Forward)
rg.rvs = append(rg.rvs, rules.Reverse)

tp := r.tm.Transport(rules.Forward.NextTransportID())
rg.tps = append(rg.tps, tp)
} else {
r.logger.Infoln("ROUTE GROUP ALREADY EXISTS")

if err := rg.Close(); err != nil {
r.logger.Errorf("Error closing already existing route group: %v", err)
}

rg = NewRouteGroup(DefaultRouteGroupConfig(), r.rt, rules.Desc)
r.rgs[rules.Desc] = rg

rg.fwd = append(rg.fwd, rules.Forward)
rg.rvs = append(rg.rvs, rules.Reverse)

tp := r.tm.Transport(rules.Forward.NextTransportID())
rg.tps = append(rg.tps, tp)
}

rg.fwd = append(rg.fwd, rules.Forward)
/*rg.fwd = append(rg.fwd, rules.Forward)
rg.rvs = append(rg.rvs, rules.Reverse)
tp := r.tm.Transport(rules.Forward.NextTransportID())
rg.tps = append(rg.tps, tp)
rg.tps = append(rg.tps, tp)*/

return rg
}
Expand All @@ -360,6 +381,14 @@ func (r *router) handleDataPacket(ctx context.Context, packet routing.Packet) er
return err
}

if rule.Type() == routing.RuleConsume {
r.logger.Infof("HANDLING PACKET OF TYPE %s WITH ROUTE ID %d", packet.Type(),
packet.RouteID())
} else {
r.logger.Infof("HANDLING PACKET OF TYPE %s WITH ROUTE ID %d AND NEXT ID %d", packet.Type(),
packet.RouteID(), rule.NextRouteID())
}

switch rule.Type() {
case routing.RuleForward, routing.RuleIntermediaryForward:
r.logger.Infoln("Handling intermediary data packet")
Expand Down Expand Up @@ -396,6 +425,14 @@ func (r *router) handleClosePacket(ctx context.Context, packet routing.Packet) e
return err
}

if rule.Type() == routing.RuleConsume {
r.logger.Infof("HANDLING PACKET OF TYPE %s WITH ROUTE ID %d", packet.Type(),
packet.RouteID())
} else {
r.logger.Infof("HANDLING PACKET OF TYPE %s WITH ROUTE ID %d AND NEXT ID %d", packet.Type(),
packet.RouteID(), rule.NextRouteID())
}

defer func() {
routeIDs := []routing.RouteID{routeID}
r.rt.DelRules(routeIDs)
Expand Down Expand Up @@ -449,6 +486,14 @@ func (r *router) handleKeepAlivePacket(ctx context.Context, packet routing.Packe
return err
}

if rule.Type() == routing.RuleConsume {
r.logger.Infof("HANDLING PACKET OF TYPE %S WITH ROUTE ID %d", packet.Type(),
packet.RouteID())
} else {
r.logger.Infof("HANDLING PACKET OF TYPE %S WITH ROUTE ID %d AND NEXT ID %d", packet.Type(),
packet.RouteID(), rule.NextRouteID())
}

// propagate packet only for intermediary rule. forward rule workflow doesn't get here,
// consume rules should be omitted, activity is already updated
if t := rule.Type(); t == routing.RuleIntermediaryForward {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ github.com/stretchr/testify/mock
github.com/stretchr/testify/require
# go.etcd.io/bbolt v1.3.3
go.etcd.io/bbolt
# golang.org/x/crypto v0.0.0-20200219234226-1ad67e1f0ef4
# golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/crypto/blake2b
golang.org/x/crypto/blake2s
golang.org/x/crypto/chacha20
Expand Down

0 comments on commit 8b2d488

Please sign in to comment.