-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sync Routes can add a new route from config service If a route does not exist locally, we will insert it, and fetch all of its parts. DevaddrRanges, Skfs, Euis. * handle removing routes that are left over after syncing * move syncing routes to cli module - add cli config test suite - pretty print the added and removed ids or routes The diffing for the routes is done in the cli module, this way the route stream worker doesn't start to become like the xor filter worker where it started to hold the kitchen sink. Routes are only sent to the route stream worker after they have been inserted and need their parts updated. * add modules for org list request and response
- Loading branch information
1 parent
5222fc7
commit fe56018
Showing
11 changed files
with
750 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-module(hpr_org). | ||
|
||
-include("../autogen/iot_config_pb.hrl"). | ||
|
||
-export([ | ||
oui/1, | ||
owner/1, | ||
payer/1, | ||
delegate_keys/1, | ||
locked/1 | ||
]). | ||
|
||
-type org() :: #iot_config_org_v1_pb{}. | ||
|
||
-ifdef(TEST). | ||
|
||
-export([test_new/1]). | ||
|
||
-endif. | ||
|
||
-spec oui(Org :: org()) -> non_neg_integer(). | ||
oui(Org) -> | ||
Org#iot_config_org_v1_pb.oui. | ||
|
||
-spec owner(Org :: org()) -> binary(). | ||
owner(Org) -> | ||
Org#iot_config_org_v1_pb.owner. | ||
|
||
-spec payer(Org :: org()) -> binary(). | ||
payer(Org) -> | ||
Org#iot_config_org_v1_pb.payer. | ||
|
||
-spec delegate_keys(Org :: org()) -> list(binary()). | ||
delegate_keys(Org) -> | ||
Org#iot_config_org_v1_pb.delegate_keys. | ||
|
||
-spec locked(Org :: org()) -> boolean(). | ||
locked(Org) -> | ||
Org#iot_config_org_v1_pb.locked. | ||
|
||
%% ------------------------------------------------------------------ | ||
%% Tests Functions | ||
%% ------------------------------------------------------------------ | ||
-ifdef(TEST). | ||
|
||
-spec test_new(RouteMap :: map()) -> org(). | ||
test_new(RouteMap) -> | ||
#iot_config_org_v1_pb{ | ||
oui = maps:get(oui, RouteMap), | ||
owner = maps:get(owner, RouteMap, <<"owner-test-value">>), | ||
payer = maps:get(payer, RouteMap, <<"payer-test-value">>), | ||
delegate_keys = maps:get(delegate_keys, RouteMap, []), | ||
locked = maps:get(locked, RouteMap, false) | ||
}. | ||
|
||
-endif. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-module(hpr_org_list_req). | ||
|
||
-include("../autogen/iot_config_pb.hrl"). | ||
|
||
-export([new/0]). | ||
|
||
-type req() :: #iot_config_org_list_req_v1_pb{}. | ||
|
||
-spec new() -> req(). | ||
new() -> | ||
#iot_config_org_list_req_v1_pb{}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-module(hpr_org_list_res). | ||
|
||
-include("../autogen/iot_config_pb.hrl"). | ||
|
||
-export([ | ||
orgs/1, | ||
timestamp/1, | ||
signer/1, | ||
signature/1 | ||
]). | ||
|
||
-export([ | ||
org_ouis/1 | ||
]). | ||
|
||
-type res() :: #iot_config_org_list_res_v1_pb{}. | ||
|
||
-spec orgs(Res :: res()) -> list(hpr_org:org()). | ||
orgs(Res) -> | ||
Res#iot_config_org_list_res_v1_pb.orgs. | ||
|
||
-spec timestamp(Res :: res()) -> non_neg_integer(). | ||
timestamp(Res) -> | ||
Res#iot_config_org_list_res_v1_pb.timestamp. | ||
|
||
-spec signer(Res :: res()) -> binary(). | ||
signer(Res) -> | ||
Res#iot_config_org_list_res_v1_pb.signer. | ||
|
||
-spec signature(Res :: res()) -> binary(). | ||
signature(Res) -> | ||
Res#iot_config_org_list_res_v1_pb.signature. | ||
|
||
-spec org_ouis(Res :: res()) -> list(non_neg_integer()). | ||
org_ouis(Res) -> | ||
[hpr_org:oui(Org) || Org <- ?MODULE:orgs(Res)]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-module(hpr_route_list_req). | ||
|
||
-include("../autogen/iot_config_pb.hrl"). | ||
|
||
-export([ | ||
new/2, | ||
timestamp/1, | ||
signer/1, | ||
signature/1 | ||
]). | ||
|
||
-export([ | ||
sign/2, | ||
verify/1 | ||
]). | ||
|
||
-type req() :: #iot_config_route_list_req_v1_pb{}. | ||
|
||
-spec new(Signer :: libp2p_crypto:pubkey_bin(), Oui :: non_neg_integer()) -> req(). | ||
new(Signer, Oui) -> | ||
#iot_config_route_list_req_v1_pb{ | ||
oui = Oui, | ||
timestamp = erlang:system_time(millisecond), | ||
signer = Signer | ||
}. | ||
|
||
-spec timestamp(Req :: req()) -> non_neg_integer(). | ||
timestamp(Req) -> | ||
Req#iot_config_route_list_req_v1_pb.timestamp. | ||
|
||
-spec signer(Req:: req()) -> binary(). | ||
signer(Req) -> | ||
Req#iot_config_route_list_req_v1_pb.signer. | ||
|
||
-spec signature(Req:: req()) -> binary(). | ||
signature(Req) -> | ||
Req#iot_config_route_list_req_v1_pb.signature. | ||
|
||
-spec sign(RouteListReq :: req(), SigFun :: fun()) -> req(). | ||
sign(RouteListReq, SigFun) -> | ||
EncodedRouteListReq = iot_config_pb:encode_msg( | ||
RouteListReq, iot_config_route_list_req_v1_pb | ||
), | ||
RouteListReq#iot_config_route_list_req_v1_pb{signature = SigFun(EncodedRouteListReq)}. | ||
|
||
-spec verify(RouteListReq :: req()) -> boolean(). | ||
verify(RouteListReq) -> | ||
EncodedRouteListReq = iot_config_pb:encode_msg( | ||
RouteListReq#iot_config_route_list_req_v1_pb{ | ||
signature = <<>> | ||
}, | ||
iot_config_route_list_req_v1_pb | ||
), | ||
libp2p_crypto:verify( | ||
EncodedRouteListReq, | ||
?MODULE:signature(RouteListReq), | ||
libp2p_crypto:bin_to_pubkey(?MODULE:signer(RouteListReq)) | ||
). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-module(hpr_route_list_res). | ||
|
||
-include("../autogen/iot_config_pb.hrl"). | ||
|
||
-export([ | ||
routes/1 | ||
]). | ||
|
||
-type res() :: #iot_config_route_list_res_v1_pb{}. | ||
|
||
-spec routes(Res :: res()) -> list(hpr_route:route()). | ||
routes(Res) -> | ||
Res#iot_config_route_list_res_v1_pb.routes. |
Oops, something went wrong.