Skip to content

Commit

Permalink
Add a lot of debug logs, probably fix setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Nov 26, 2019
1 parent 3e98062 commit 2ade0f9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
8 changes: 7 additions & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ func (r *router) serveSetup() {
}

func (r *router) saveRouteGroupRules(rules routing.EdgeRules) *RouteGroup {
r.logger.Infof("Saving route group rules with desc: %s", &rules.Desc)
r.mx.Lock()
defer r.mx.Unlock()

rg, ok := r.rgs[rules.Desc]
if !ok || rg == nil {
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
}
Expand Down Expand Up @@ -319,14 +321,17 @@ func (r *router) handleDataPacket(ctx context.Context, packet routing.Packet) er
}

if rule.Type() == routing.RuleIntermediaryForward {
r.logger.Infoln("Handling intermediary packet")
return r.forwardPacket(ctx, packet.Payload(), rule)
}

desc := rule.RouteDescriptor()
rg, ok := r.routeGroup(desc)

r.logger.Infof("Handling packet with descriptor %s", &desc)

if !ok {
r.logger.Infof("Descriptor not found for rule with type %s", rule.Type())
r.logger.Infof("Descriptor not found for rule with type %s, descriptor: %s", rule.Type(), &desc)
return errors.New("route descriptor does not exist")
}

Expand Down Expand Up @@ -488,6 +493,7 @@ func (r *router) SetupIsTrusted(sPK cipher.PubKey) bool {
func (r *router) SaveRoutingRules(rules ...routing.Rule) error {
for _, rule := range rules {
if err := r.rt.SaveRule(rule); err != nil {
r.logger.WithError(err).Error("Error saving rule to routing table")
return fmt.Errorf("routing table: %s", err)
}

Expand Down
25 changes: 22 additions & 3 deletions pkg/router/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ func NewRPCGateway(router Router) *RPCGateway {
}

func (r *RPCGateway) AddEdgeRules(rules routing.EdgeRules, ok *bool) error {
if err := r.router.IntroduceRules(rules); err != nil {
return err
}
/*if err := r.router.IntroduceRules(rules); err != nil {
*ok = false
r.logger.WithError(err).Warnf("Request completed with error.")
return routing.Failure{Code: routing.FailureAddRules, Msg: err.Error()}
}*/

r.logger.Infof("Adding Edge rules: forward: %s, reverse: %s", rules.Forward, rules.Reverse)
if err := r.router.SaveRoutingRules(rules.Forward, rules.Reverse); err != nil {
*ok = false

Expand All @@ -31,6 +36,20 @@ func (r *RPCGateway) AddEdgeRules(rules routing.EdgeRules, ok *bool) error {
return routing.Failure{Code: routing.FailureAddRules, Msg: err.Error()}
}

router, assertOk := r.router.(*router)
if !assertOk {
panic("Wrong router type")
}
router.saveRouteGroupRules(rules)

/*if err := r.router.SaveRoutingRules(rules.Forward, rules.Reverse); err != nil {
*ok = false
r.logger.WithError(err).Warnf("Request completed with error.")
return routing.Failure{Code: routing.FailureAddRules, Msg: err.Error()}
}*/

*ok = true

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/route_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ func (rd *RouteDescriptor) Invert() RouteDescriptor {
}

func (rd *RouteDescriptor) String() string {
return fmt.Sprintf("rPK:%s, lPK:%s, rPort:%d, lPort:%d", rd.DstPK(), rd.SrcPK(), rd.DstPort(), rd.SrcPK())
return fmt.Sprintf("rPK:%s, lPK:%s, rPort:%d, lPort:%d", rd.DstPK(), rd.SrcPK(), rd.DstPort(), rd.SrcPort())
}
1 change: 1 addition & 0 deletions pkg/routing/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (mt *memTable) SaveRule(rule Rule) error {
defer mt.Unlock()

mt.rules[key] = rule
fmt.Printf("ROUTING TABLE CONTENTS: %v\n", mt.rules)
mt.activity[key] = now

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/setup/idreservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (idr *idReservoir) GenerateRules(fwd, rev routing.Route) (
rID = nxtRID
}

fmt.Printf("GENERATING CONSUME RULE WITH SRC %s")
rule := routing.ConsumeRule(route.KeepAlive, rID, dstPK, srcPort, dstPort)
consumeRules[dstPK] = rule
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/setup/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (sn *Node) Serve() error {
}

func (sn *Node) handleDialRouteGroup(ctx context.Context, route routing.BidirectionalRoute) (routing.EdgeRules, error) {
sn.logger.Infof("Setup route from %s to %s", route.Desc.SrcPK(), route.Desc.DstPK())

idr, err := sn.reserveRouteIDs(ctx, route)
if err != nil {
return routing.EdgeRules{}, err
Expand Down Expand Up @@ -134,6 +136,8 @@ func (sn *Node) handleDialRouteGroup(ctx context.Context, route routing.Bidirect
for pk, rules := range intermediaryRules {
pk, rules := pk, rules

sn.logger.WithField("remote", pk).Info("Adding rules to intermediary node")

wg.Add(1)

go func() {
Expand All @@ -153,12 +157,12 @@ func (sn *Node) handleDialRouteGroup(ctx context.Context, route routing.Bidirect
}

initRouteRules := routing.EdgeRules{
Desc: forwardRoute.Desc,
Desc: reverseRoute.Desc,
Forward: forwardRules[route.Desc.SrcPK()],
Reverse: consumeRules[route.Desc.SrcPK()],
}
respRouteRules := routing.EdgeRules{
Desc: reverseRoute.Desc,
Desc: forwardRoute.Desc,
Forward: forwardRules[route.Desc.DstPK()],
Reverse: consumeRules[route.Desc.DstPK()],
}
Expand Down
2 changes: 0 additions & 2 deletions vendor/github.com/SkycoinProject/dmsg/disc/client.go

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

0 comments on commit 2ade0f9

Please sign in to comment.