Skip to content

Commit

Permalink
Merge pull request #87 from Darkren/fix/propagate-keep-alive
Browse files Browse the repository at this point in the history
Add keep-alive packet propagation between nodes
  • Loading branch information
Darkren authored Dec 25, 2019
2 parents 164c995 + fe4a0a1 commit 6e30191
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 61 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ require (
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a
)

// replace github.com/SkycoinProject/dmsg => ../dmsg
//replace github.com/SkycoinProject/dmsg => ../dmsg
30 changes: 22 additions & 8 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ func (r *router) handleDataPacket(ctx context.Context, packet routing.Packet) er

switch rule.Type() {
case routing.RuleForward, routing.RuleIntermediaryForward:
r.logger.Infoln("Handling intermediary packet")
return r.forwardPacket(ctx, packet.Payload(), rule)
r.logger.Infoln("Handling intermediary data packet")
return r.forwardPacket(ctx, packet, rule)
}

desc := rule.RouteDescriptor()
Expand Down Expand Up @@ -398,17 +398,22 @@ func (r *router) handleClosePacket(_ context.Context, packet routing.Packet) err
return nil
}

func (r *router) handleKeepAlivePacket(_ context.Context, packet routing.Packet) error {
func (r *router) handleKeepAlivePacket(ctx context.Context, packet routing.Packet) error {
routeID := packet.RouteID()

r.logger.Infof("Received keepalive packet for route ID %v", routeID)

_, err := r.GetRule(routeID)
rule, err := r.GetRule(routeID)
if err != nil {
return err
}

// TODO: propagate keep-alive packet down the line
// 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 {
r.logger.Infoln("Handling intermediary keep-alive packet")
return r.forwardPacket(ctx, packet, rule)
}

r.logger.Infof("Route ID %v found, updated activity", routeID)

Expand Down Expand Up @@ -460,14 +465,23 @@ func (r *router) Close() error {
return r.tm.Close()
}

func (r *router) forwardPacket(ctx context.Context, payload []byte, rule routing.Rule) error {
func (r *router) forwardPacket(ctx context.Context, packet routing.Packet, rule routing.Rule) error {
tp := r.tm.Transport(rule.NextTransportID())
if tp == nil {
return errors.New("unknown transport")
}

packet := routing.MakeDataPacket(rule.NextRouteID(), payload)
if err := tp.WritePacket(ctx, packet); err != nil {
var p routing.Packet
switch packet.Type() {
case routing.DataPacket:
p = routing.MakeDataPacket(rule.NextRouteID(), packet.Payload())
case routing.KeepAlivePacket:
p = routing.MakeKeepAlivePacket(rule.NextRouteID())
default:
return fmt.Errorf("packet of type %s can't be forwarded", packet.Type())
}

if err := tp.WritePacket(ctx, p); err != nil {
return err
}

Expand Down
4 changes: 1 addition & 3 deletions vendor/github.com/SkycoinProject/dmsg/go.mod

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

5 changes: 2 additions & 3 deletions vendor/github.com/SkycoinProject/dmsg/go.sum

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

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

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

6 changes: 3 additions & 3 deletions vendor/github.com/mattn/go-colorable/colorable_appengine.go

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

6 changes: 3 additions & 3 deletions vendor/github.com/mattn/go-colorable/colorable_others.go

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

43 changes: 9 additions & 34 deletions vendor/github.com/mattn/go-colorable/colorable_windows.go

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

6 changes: 3 additions & 3 deletions vendor/github.com/mattn/go-colorable/noncolorable.go

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

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/SkycoinProject/dmsg v0.0.0-20191106075825-cabc26522b11 => ../dmsg
# github.com/SkycoinProject/dmsg v0.0.0-20191106075825-cabc26522b11
github.com/SkycoinProject/dmsg
github.com/SkycoinProject/dmsg/cipher
github.com/SkycoinProject/dmsg/disc
Expand Down Expand Up @@ -40,9 +40,9 @@ github.com/gorilla/handlers
github.com/gorilla/securecookie
# github.com/inconshreveable/mousetrap v1.0.0
github.com/inconshreveable/mousetrap
# github.com/konsorten/go-windows-terminal-sequences v1.0.1
# github.com/konsorten/go-windows-terminal-sequences v1.0.2
github.com/konsorten/go-windows-terminal-sequences
# github.com/mattn/go-colorable v0.1.4
# github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-colorable
# github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-isatty
Expand Down

0 comments on commit 6e30191

Please sign in to comment.