Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/downlink-schedule-race'
Browse files Browse the repository at this point in the history
  • Loading branch information
htdvisser committed Jan 17, 2017
2 parents 4a71eaa + 0aa557e commit a18dd6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 0 additions & 2 deletions core/router/downlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ func (r *router) SubscribeDownlink(gatewayID string, subscriptionID string) (<-c
go func() {
ctx.Debug("Activate downlink")
for message := range fromSchedule {
gateway.Utilization.AddTx(message)
ctx.Debug("Send downlink")
message.Trace = message.Trace.WithEvent(trace.SendEvent)
toGateway <- message
}
ctx.Debug("Deactivate downlink")
Expand Down
4 changes: 3 additions & 1 deletion core/router/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import (
// NewGateway creates a new in-memory Gateway structure
func NewGateway(ctx log.Interface, id string) *Gateway {
ctx = ctx.WithField("GatewayID", id)
return &Gateway{
gtw := &Gateway{
ID: id,
Status: NewStatusStore(),
Utilization: NewUtilization(),
Schedule: NewSchedule(ctx),
Ctx: ctx,
}
gtw.Schedule.(*schedule).gateway = gtw // FIXME: Issue #420
return gtw
}

// Gateway contains the state of a gateway
Expand Down
6 changes: 6 additions & 0 deletions core/router/gateway/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

pb_lorawan "github.com/TheThingsNetwork/ttn/api/protocol/lorawan"
router_pb "github.com/TheThingsNetwork/ttn/api/router"
"github.com/TheThingsNetwork/ttn/api/trace"
"github.com/TheThingsNetwork/ttn/utils/errors"
"github.com/TheThingsNetwork/ttn/utils/random"
"github.com/TheThingsNetwork/ttn/utils/toa"
Expand Down Expand Up @@ -79,6 +80,7 @@ type schedule struct {
downlink chan *router_pb.DownlinkMessage
downlinkSubscriptionsLock sync.RWMutex
downlinkSubscriptions map[string]chan *router_pb.DownlinkMessage
gateway *Gateway
}

func (s *schedule) GoString() (str string) {
Expand Down Expand Up @@ -245,6 +247,10 @@ func (s *schedule) Subscribe(subscriptionID string) <-chan *router_pb.DownlinkMe
s.downlink = make(chan *router_pb.DownlinkMessage)
go func() {
for downlink := range s.downlink {
if s.gateway != nil && s.gateway.Utilization != nil {
s.gateway.Utilization.AddTx(downlink) // FIXME: Issue #420
}
downlink.Trace = downlink.Trace.WithEvent(trace.SendEvent)
s.downlinkSubscriptionsLock.RLock()
for _, ch := range s.downlinkSubscriptions {
select {
Expand Down

0 comments on commit a18dd6f

Please sign in to comment.