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

Commit 4ac960c

Browse files
committedOct 9, 2017
Merge branch 'issue/api-update' into develop
2 parents 61e5e7e + dd0e2d1 commit 4ac960c

File tree

4 files changed

+72
-44
lines changed

4 files changed

+72
-44
lines changed
 

‎core/handler/device/converter.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package device
66
import (
77
pb_handler "github.com/TheThingsNetwork/api/handler"
88
pb_lorawan "github.com/TheThingsNetwork/api/protocol/lorawan"
9+
"github.com/TheThingsNetwork/ttn/core/types"
910
)
1011

1112
// ToPb converts a device struct to its protocol buffer
@@ -24,7 +25,7 @@ func (d Device) ToPb() *pb_handler.Device {
2425

2526
// ToLoRaWANPb converts a device struct to a LoRaWAN protocol buffer
2627
func (d Device) ToLoRaWANPb() *pb_lorawan.Device {
27-
return &pb_lorawan.Device{
28+
pbDev := &pb_lorawan.Device{
2829
AppID: d.AppID,
2930
AppEUI: d.AppEUI,
3031
DevID: d.DevID,
@@ -37,6 +38,13 @@ func (d Device) ToLoRaWANPb() *pb_lorawan.Device {
3738
Uses32BitFCnt: d.Options.Uses32BitFCnt,
3839
ActivationConstraints: d.Options.ActivationConstraints,
3940
}
41+
for _, nonce := range d.UsedDevNonces {
42+
pbDev.UsedDevNonces = append(pbDev.UsedDevNonces, types.DevNonce(nonce))
43+
}
44+
for _, nonce := range d.UsedAppNonces {
45+
pbDev.UsedAppNonces = append(pbDev.UsedAppNonces, types.AppNonce(nonce))
46+
}
47+
return pbDev
4048
}
4149

4250
// FromPb returns a new device from the given proto
@@ -77,6 +85,18 @@ func (d *Device) FromLoRaWANPb(lorawan *pb_lorawan.Device) {
7785
if lorawan.NwkSKey != nil {
7886
d.NwkSKey = *lorawan.NwkSKey
7987
}
88+
if len(lorawan.UsedDevNonces) > 0 {
89+
d.UsedDevNonces = make([]DevNonce, len(lorawan.UsedDevNonces))
90+
for i, nonce := range lorawan.UsedDevNonces {
91+
d.UsedDevNonces[i] = DevNonce(nonce)
92+
}
93+
}
94+
if len(lorawan.UsedAppNonces) > 0 {
95+
d.UsedAppNonces = make([]AppNonce, len(lorawan.UsedAppNonces))
96+
for i, nonce := range lorawan.UsedAppNonces {
97+
d.UsedAppNonces[i] = AppNonce(nonce)
98+
}
99+
}
80100
d.FCntUp = lorawan.FCntUp
81101
d.Options = Options{
82102
DisableFCntCheck: lorawan.DisableFCntCheck,

‎core/handler/device/converter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ var testDev = &Device{
2525
Options: Options{ActivationConstraints: "local"},
2626

2727
AppKey: [16]byte{0x10},
28-
UsedDevNonces: []DevNonce{},
29-
UsedAppNonces: []AppNonce{},
28+
UsedDevNonces: []DevNonce{DevNonce{1, 2}},
29+
UsedAppNonces: []AppNonce{AppNonce{1, 2, 3}},
3030

3131
DevAddr: types.DevAddr{byte(0x10)},
3232
NwkSKey: [16]byte{0x10},

‎core/handler/manager_server.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ func (h *handlerManager) SetDevice(ctx context.Context, in *pb_handler.Device) (
161161
var eventType types.EventType
162162
if dev != nil {
163163
eventType = types.UpdateEvent
164+
165+
// Not allowed to update join nonces after device is created
166+
lorawan.UsedDevNonces, lorawan.UsedAppNonces = nil, nil
167+
168+
// If the AppEUI or DevEUI is changed, we should remove the device from the NetworkServer and re-add it later
164169
if dev.AppEUI != lorawan.AppEUI || dev.DevEUI != lorawan.DevEUI {
165-
// If the AppEUI or DevEUI is changed, we should remove the device from the NetworkServer and re-add it later
166170
_, err = h.handler.ttnDeviceManager.DeleteDevice(ttnctx.OutgoingContextWithToken(ctx, token), &pb_lorawan.DeviceIdentifier{
167171
AppEUI: dev.AppEUI,
168172
DevEUI: dev.DevEUI,
@@ -171,6 +175,7 @@ func (h *handlerManager) SetDevice(ctx context.Context, in *pb_handler.Device) (
171175
return nil, errors.Wrap(errors.FromGRPCError(err), "Broker did not delete device")
172176
}
173177
}
178+
174179
dev.StartUpdate()
175180
} else {
176181
eventType = types.CreateEvent
@@ -186,12 +191,13 @@ func (h *handlerManager) SetDevice(ctx context.Context, in *pb_handler.Device) (
186191
dev = new(device.Device)
187192
}
188193

189-
// Reset join nonces when AppKey changes
190-
if lorawan.AppKey != nil && dev.AppKey != *lorawan.AppKey { // do this BEFORE dev.FromPb(in)
191-
dev.UsedAppNonces = []device.AppNonce{}
192-
dev.UsedDevNonces = []device.DevNonce{}
194+
if lorawan.AppKey != nil && dev.AppKey != *lorawan.AppKey {
195+
// Reset join nonces when AppKey changes
196+
dev.UsedDevNonces, dev.UsedAppNonces = []device.DevNonce{}, []device.AppNonce{}
193197
}
198+
194199
dev.FromPb(in)
200+
195201
if dev.Options.ActivationConstraints == "" {
196202
dev.Options.ActivationConstraints = "local"
197203
}
@@ -200,6 +206,8 @@ func (h *handlerManager) SetDevice(ctx context.Context, in *pb_handler.Device) (
200206
lorawanPb := dev.ToLoRaWANPb()
201207
lorawanPb.AppKey = nil
202208
lorawanPb.AppSKey = nil
209+
lorawanPb.UsedDevNonces = nil
210+
lorawanPb.UsedAppNonces = nil
203211
lorawanPb.FCntUp = lorawan.FCntUp
204212
lorawanPb.FCntDown = lorawan.FCntDown
205213

‎vendor/vendor.json

+36-36
Original file line numberDiff line numberDiff line change
@@ -11,104 +11,104 @@
1111
{
1212
"checksumSHA1": "HvKsUcdxKmlXEQIO5oH8Up+q454=",
1313
"path": "github.com/TheThingsNetwork/api",
14-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
15-
"revisionTime": "2017-10-03T11:59:44Z"
14+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
15+
"revisionTime": "2017-10-05T11:37:55Z"
1616
},
1717
{
1818
"checksumSHA1": "Qldi0EQWFinjkxfHch10mAsBD48=",
1919
"path": "github.com/TheThingsNetwork/api/broker",
20-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
21-
"revisionTime": "2017-10-03T11:59:44Z"
20+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
21+
"revisionTime": "2017-10-05T11:37:55Z"
2222
},
2323
{
2424
"checksumSHA1": "tKs2HN1clvlD9HZ4OhaNkT04PgM=",
2525
"path": "github.com/TheThingsNetwork/api/broker/brokerclient",
26-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
27-
"revisionTime": "2017-10-03T11:59:44Z"
26+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
27+
"revisionTime": "2017-10-05T11:37:55Z"
2828
},
2929
{
3030
"checksumSHA1": "w46Dzts3lwBI/wVWc8TBLZQfjxg=",
3131
"path": "github.com/TheThingsNetwork/api/discovery",
32-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
33-
"revisionTime": "2017-10-03T11:59:44Z"
32+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
33+
"revisionTime": "2017-10-05T11:37:55Z"
3434
},
3535
{
3636
"checksumSHA1": "ws6/Hzt73JGd/0tqOXPFBhKAoWw=",
3737
"path": "github.com/TheThingsNetwork/api/discovery/discoveryclient",
38-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
39-
"revisionTime": "2017-10-03T11:59:44Z"
38+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
39+
"revisionTime": "2017-10-05T11:37:55Z"
4040
},
4141
{
42-
"checksumSHA1": "+HTnTXUIFSrYOM2YWfhd8zukGP0=",
42+
"checksumSHA1": "F/uBNirJ4oJbv65ZnPaqeWgBIIw=",
4343
"path": "github.com/TheThingsNetwork/api/gateway",
44-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
45-
"revisionTime": "2017-10-03T11:59:44Z"
44+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
45+
"revisionTime": "2017-10-05T11:37:55Z"
4646
},
4747
{
4848
"checksumSHA1": "sE6s9aBQGFvMOuNiS71RBd20mlo=",
4949
"path": "github.com/TheThingsNetwork/api/handler",
50-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
51-
"revisionTime": "2017-10-03T11:59:44Z"
50+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
51+
"revisionTime": "2017-10-05T11:37:55Z"
5252
},
5353
{
5454
"checksumSHA1": "Wf1g3j9HQL33qpz1QpLGRr3JLt0=",
5555
"path": "github.com/TheThingsNetwork/api/handler/handlerclient",
56-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
57-
"revisionTime": "2017-10-03T11:59:44Z"
56+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
57+
"revisionTime": "2017-10-05T11:37:55Z"
5858
},
5959
{
6060
"checksumSHA1": "5ywHe4obsAQglqMJI2F1ecdOC3A=",
6161
"path": "github.com/TheThingsNetwork/api/logfields",
62-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
63-
"revisionTime": "2017-10-03T11:59:44Z"
62+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
63+
"revisionTime": "2017-10-05T11:37:55Z"
6464
},
6565
{
6666
"checksumSHA1": "UXeYeDQpDq8uNy1v85eBzljAtmI=",
6767
"path": "github.com/TheThingsNetwork/api/monitor",
68-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
69-
"revisionTime": "2017-10-03T11:59:44Z"
68+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
69+
"revisionTime": "2017-10-05T11:37:55Z"
7070
},
7171
{
7272
"checksumSHA1": "8308j9lxDoH99REc8EMOZz05vu8=",
7373
"path": "github.com/TheThingsNetwork/api/monitor/monitorclient",
74-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
75-
"revisionTime": "2017-10-03T11:59:44Z"
74+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
75+
"revisionTime": "2017-10-05T11:37:55Z"
7676
},
7777
{
7878
"checksumSHA1": "x6VxNzc3Vs1k+WWLiwM8S0t3KIs=",
7979
"path": "github.com/TheThingsNetwork/api/networkserver",
80-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
81-
"revisionTime": "2017-10-03T11:59:44Z"
80+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
81+
"revisionTime": "2017-10-05T11:37:55Z"
8282
},
8383
{
8484
"checksumSHA1": "OqxCDpa7rIq9mGFXcGqlvb8aNhA=",
8585
"path": "github.com/TheThingsNetwork/api/protocol",
86-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
87-
"revisionTime": "2017-10-03T11:59:44Z"
86+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
87+
"revisionTime": "2017-10-05T11:37:55Z"
8888
},
8989
{
90-
"checksumSHA1": "sdJIUqK2CaWtU7G/kGWHXJExw7A=",
90+
"checksumSHA1": "XU9nu3DN+yzkZiDnHifRJ+UjSeM=",
9191
"path": "github.com/TheThingsNetwork/api/protocol/lorawan",
92-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
93-
"revisionTime": "2017-10-03T11:59:44Z"
92+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
93+
"revisionTime": "2017-10-05T11:37:55Z"
9494
},
9595
{
9696
"checksumSHA1": "FbQxmR3Mu4ooEqD57opscswpQDQ=",
9797
"path": "github.com/TheThingsNetwork/api/router",
98-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
99-
"revisionTime": "2017-10-03T11:59:44Z"
98+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
99+
"revisionTime": "2017-10-05T11:37:55Z"
100100
},
101101
{
102102
"checksumSHA1": "NY7Vvw615PhmCwQ2S7bgecRQUfQ=",
103103
"path": "github.com/TheThingsNetwork/api/router/routerclient",
104-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
105-
"revisionTime": "2017-10-03T11:59:44Z"
104+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
105+
"revisionTime": "2017-10-05T11:37:55Z"
106106
},
107107
{
108108
"checksumSHA1": "Dm/o7cjKomQRUFO6uVQoR/ef5/k=",
109109
"path": "github.com/TheThingsNetwork/api/trace",
110-
"revision": "6e1ec9f9f2d8a8c5f30fa0c77b4418a36781e63e",
111-
"revisionTime": "2017-10-03T11:59:44Z"
110+
"revision": "f074ae7262444b3fac2149635e16e66b13413510",
111+
"revisionTime": "2017-10-05T11:37:55Z"
112112
},
113113
{
114114
"checksumSHA1": "t0RI2WKlx2C+y/BNqHPrhPcYOPE=",

0 commit comments

Comments
 (0)
This repository has been archived.