summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorUlf Wiger <ulf@wiger.net>2016-02-24 18:10:16 +0100
committerUlf Wiger <ulf@wiger.net>2016-02-24 18:10:16 +0100
commitf7ea6e3b12dd343cefd0565be87cef4329e51124 (patch)
tree1df3bc1855cc2bcd344d31801bd0302b6c762402 /components
parent935a8a230608fae5bfcb13a22afeacf218ae59aa (diff)
downloadrvi_core-f7ea6e3b12dd343cefd0565be87cef4329e51124.tar.gz
doc and code bug fixes
Diffstat (limited to 'components')
-rw-r--r--components/dlink_bt/src/dlink_bt_rpc.erl19
-rw-r--r--components/dlink_sms/src/dlink_sms_rpc.erl25
-rw-r--r--components/dlink_tcp/src/dlink_tcp_rpc.erl58
-rw-r--r--components/dlink_tls/src/dlink_tls_rpc.erl47
-rw-r--r--components/proto_json/src/proto_json_rpc.erl13
-rw-r--r--components/proto_msgpack/src/proto_msgpack_rpc.erl10
-rw-r--r--components/service_edge/src/service_edge_rpc.erl2
7 files changed, 90 insertions, 84 deletions
diff --git a/components/dlink_bt/src/dlink_bt_rpc.erl b/components/dlink_bt/src/dlink_bt_rpc.erl
index 74a49cc..c4276bd 100644
--- a/components/dlink_bt/src/dlink_bt_rpc.erl
+++ b/components/dlink_bt/src/dlink_bt_rpc.erl
@@ -338,6 +338,13 @@ process_authorize(FromPid, PeerBTAddr, PeerBTChannel,
?info("dlink_bt:authorize(): Protocol: ~p", [ Protocol ]),
?debug("dlink_bt:authorize(): Credentials: ~p", [ Credentials ]),
+ case Protocol of
+ <<"1.", _/binary>> -> ok;
+ undefined -> ok;
+ _ ->
+ throw({protocol_failure, {unknown_version, Protocol}})
+ end,
+
%% If FromPid (the genserver managing the socket) is not yet registered
%% with the conneciton manager, this is an incoming connection
%% from the client. We should respond with our own authorize followed by
@@ -368,9 +375,15 @@ handle_socket(FromPid, PeerBTAddr, PeerChannel, data,
?DLINK_ARG_CREDENTIALS],
Elems, undefined),
- process_authorize(FromPid, PeerBTAddr, RemoteChannel,
- RemoteAddress, RemoteChannel,
- RVIProtocol, Credentials, CS);
+ try
+ process_authorize(FromPid, PeerBTAddr, RemoteChannel,
+ RemoteAddress, RemoteChannel,
+ RVIProtocol, Credentials, CS)
+ catch
+ throw:{protocol_failure, What} ->
+ ?error("Protocol failure (~p): ~p", [FromPid, What]),
+ exit(FromPid, protocol_failure)
+ end;
?DLINK_CMD_SERVICE_ANNOUNCE ->
[ Status,
diff --git a/components/dlink_sms/src/dlink_sms_rpc.erl b/components/dlink_sms/src/dlink_sms_rpc.erl
index 4bf5f14..2f20d2d 100644
--- a/components/dlink_sms/src/dlink_sms_rpc.erl
+++ b/components/dlink_sms/src/dlink_sms_rpc.erl
@@ -305,12 +305,10 @@ handle_sms(FromPid, Addr, data, Payload, [CompSpec]) ->
case opt(?DLINK_ARG_CMD, Elems, undefined) of
?DLINK_CMD_AUTHORIZE ->
[ TransactionID,
- RemoteAddress,
ProtoVersion,
CertificatesTmp,
Signature ] =
opts([?DLINK_ARG_TRANSACTION_ID,
- ?DLINK_ARG_ADDRESS,
?DLINK_ARG_VERSION,
?DLINK_ARG_CERTIFICATES,
?DLINK_ARG_SIGNATURE],
@@ -321,8 +319,15 @@ handle_sms(FromPid, Addr, data, Payload, [CompSpec]) ->
{array, C} -> C;
undefined -> []
end,
- process_authorize(FromPid, Addr, TransactionID, RemoteAddress,
- ProtoVersion, Signature, Certificates, CompSpec);
+ try
+ process_authorize(
+ FromPid, Addr, TransactionID,
+ ProtoVersion, Signature, Certificates, CompSpec)
+ catch
+ throw:{protocol_failure, What} ->
+ ?error("Protocol failure (~p): ~p", [FromPid, What]),
+ exit(FromPid, protocol_failure)
+ end;
?DLINK_CMD_SERVICE_ANNOUNCE ->
[ TransactionID,
@@ -613,14 +618,20 @@ availability_msg(Availability, Services) ->
status_string(available ) -> ?DLINK_ARG_AVAILABLE;
status_string(unavailable) -> ?DLINK_ARG_UNAVAILABLE.
-process_authorize(FromPid, PeerAddr, TransactionID, RemoteAddress,
+process_authorize(FromPid, PeerAddr, TransactionID,
ProtoVersion, Signature, Certificates, CompSpec) ->
?info("dlink_sms:authorize(): Peer Address: ~p" , [PeerAddr]),
- ?info("dlink_sms:authorize(): Remote Address: ~p" , [RemoteAddress]),
?info("dlink_sms:authorize(): Protocol Ver: ~p" , [ProtoVersion]),
?debug("dlink_sms:authorize(): TransactionID: ~p", [TransactionID]),
?debug("dlink_sms:authorize(): Signature: ~p", [Signature]),
+ case ProtoVersion of
+ <<"1.", _/binary>> -> ok;
+ undefined -> ok;
+ _ ->
+ throw({protocol_failure, {unknown_version, ProtoVersion}})
+ end,
+
Conn = {PeerAddr, 0}, % add dummy port (necessary?)
case validate_auth_jwt(Signature, Certificates, Conn, CompSpec) of
true ->
@@ -631,14 +642,12 @@ process_authorize(FromPid, PeerAddr, TransactionID, RemoteAddress,
end.
send_authorize(Pid, CompSpec) ->
- LocalAddr = rvi_common:node_msisdn(),
sms_connection:send_auth(
Pid,
term_to_json(
{struct,
[ { ?DLINK_ARG_TRANSACTION_ID, 1 },
{ ?DLINK_ARG_CMD, ?DLINK_CMD_AUTHORIZE },
- { ?DLINK_ARG_ADDRESS, LocalAddr },
{ ?DLINK_ARG_VERSION, ?DLINK_SMS_VERSION },
{ ?DLINK_ARG_CERTIFICATES, {array, get_certificates(CompSpec)} },
{ ?DLINK_ARG_SIGNATURE, get_authorize_jwt(CompSpec) } ]})).
diff --git a/components/dlink_tcp/src/dlink_tcp_rpc.erl b/components/dlink_tcp/src/dlink_tcp_rpc.erl
index 31184bd..f094fff 100644
--- a/components/dlink_tcp/src/dlink_tcp_rpc.erl
+++ b/components/dlink_tcp/src/dlink_tcp_rpc.erl
@@ -338,19 +338,20 @@ handle_socket_(FromPid, PeerIP, PeerPort, data, Elems, CompSpec) ->
case opt(?DLINK_ARG_CMD, Elems, undefined) of
?DLINK_CMD_AUTHORIZE ->
?debug("got authorize ~s:~w", [PeerIP, PeerPort]),
- [ RemoteAddress,
- RemotePort,
- ProtoVersion,
+ [ ProtoVersion,
Credentials ] =
- opts([?DLINK_ARG_ADDRESS,
- ?DLINK_ARG_PORT,
- ?DLINK_ARG_VERSION,
+ opts([?DLINK_ARG_VERSION,
?DLINK_ARG_CREDENTIALS],
Elems, undefined),
- process_authorize(FromPid, PeerIP, PeerPort,
- RemoteAddress, RemotePort,
- ProtoVersion, Credentials, CS);
+ try
+ process_authorize(FromPid, PeerIP, PeerPort,
+ ProtoVersion, Credentials, CS)
+ catch
+ throw:{protocol_failure, What} ->
+ ?error("Protocol failure (~p): ~p", [FromPid, What]),
+ exit(FromPid, protocol_failure)
+ end;
?DLINK_CMD_SERVICE_ANNOUNCE ->
?debug("got service_announce ~s:~w", [PeerIP, PeerPort]),
@@ -663,19 +664,18 @@ availability_msg(Availability, Services, CompSpec) ->
status_string(available ) -> ?DLINK_ARG_AVAILABLE;
status_string(unavailable) -> ?DLINK_ARG_UNAVAILABLE.
-bin(S) ->
- iolist_to_binary(S).
+%% bin(S) ->
+%% iolist_to_binary(S).
-process_authorize(FromPid, PeerIP, PeerPort, RemoteAddress,
- RemotePort, ProtoVersion, Credentials, CompSpec) ->
+process_authorize(FromPid, PeerIP, PeerPort,
+ ProtoVersion, Credentials, CompSpec) ->
?info("dlink_tcp:authorize(): Peer Address: ~p:~p", [PeerIP, PeerPort ]),
- ?info("dlink_tcp:authorize(): Remote Address: ~p~p", [ RemoteAddress, RemotePort ]),
?info("dlink_tcp:authorize(): Protocol Ver: ~p", [ ProtoVersion ]),
?debug("dlink_tcp:authorize(): Credentials: ~p", [ [authorize_keys:abbrev_bin(C) || C <- Credentials] ]),
F = fun() ->
- process_authorize_(FromPid, PeerIP, PeerPort, RemoteAddress,
- RemotePort, ProtoVersion, Credentials, CompSpec)
+ process_authorize_(FromPid, PeerIP, PeerPort,
+ ProtoVersion, Credentials, CompSpec)
end,
case connection_manager:find_connection_by_address(PeerIP, PeerPort) of
not_found ->
@@ -704,27 +704,23 @@ deconflict_conns(APid, BPid, CsA, F) ->
end.
-process_authorize_(FromPid, PeerIP, PeerPort, RemoteAddress, RemotePort,
- _ProtoVersion, Credentials, CompSpec) ->
- {NRemoteAddress, NRemotePort} = Conn = {PeerIP, PeerPort},
- %% {NRemoteAddress, NRemotePort} = Conn =
- %% case { RemoteAddress, RemotePort } of
- %% { "0.0.0.0", 0 } ->
- %% ?info("dlink_tcp:authorize(): Remote is behind firewall. Will use ~p:~p",
- %% [ PeerIP, PeerPort]),
- %% { PeerIP, PeerPort };
- %% _ -> { RemoteAddress, RemotePort}
- %% end,
- log(result, "auth ~s:~w", [NRemoteAddress, NRemotePort], CompSpec),
+process_authorize_(FromPid, PeerIP, PeerPort,
+ ProtoVersion, Credentials, CompSpec) ->
+ case ProtoVersion of
+ <<"1.", _/binary>> -> ok;
+ undefined -> ok;
+ _ ->
+ ?error("Unknown/unsupported protocol version: ~p", [ProtoVersion]),
+ throw({protocol_failure, {unknown_version, ProtoVersion}})
+ end,
+ Conn = {PeerIP, PeerPort},
+ log(result, "auth ~s:~w", [PeerIP, PeerPort], CompSpec),
authorize_rpc:store_creds(CompSpec, Credentials, Conn),
connection_authorized(FromPid, Conn, CompSpec).
send_authorize(Pid, CompSpec) ->
- {LocalIP, LocalPort} = rvi_common:node_address_tuple(),
connection:send(Pid,
[{ ?DLINK_ARG_CMD, ?DLINK_CMD_AUTHORIZE },
- { ?DLINK_ARG_ADDRESS, bin(LocalIP) },
- { ?DLINK_ARG_PORT, integer_to_binary(LocalPort) },
{ ?DLINK_ARG_VERSION, ?DLINK_TCP_VERSION },
{ ?DLINK_ARG_CREDENTIALS, get_credentials(CompSpec) }
| log_id_tail(CompSpec) ]).
diff --git a/components/dlink_tls/src/dlink_tls_rpc.erl b/components/dlink_tls/src/dlink_tls_rpc.erl
index 6a90129..ad0d512 100644
--- a/components/dlink_tls/src/dlink_tls_rpc.erl
+++ b/components/dlink_tls/src/dlink_tls_rpc.erl
@@ -365,16 +365,20 @@ handle_socket(FromPid, PeerIP, PeerPort, data, Elems, CompSpec) ->
case opt(?DLINK_ARG_CMD, Elems, undefined) of
?DLINK_CMD_AUTHORIZE ->
?debug("got authorize ~s:~w", [PeerIP, PeerPort]),
- [ RemoteAddress,
- RemotePort,
+ [ ProtoVersion,
Credentials ] =
- opts([?DLINK_ARG_ADDRESS,
- ?DLINK_ARG_PORT,
+ opts([?DLINK_ARG_VERSION,
?DLINK_ARG_CREDENTIALS],
Elems, undefined),
- process_authorize(FromPid, PeerIP, PeerPort, RemoteAddress, RemotePort,
- Credentials, CS);
+ try
+ process_authorize(FromPid, PeerIP, PeerPort,
+ Credentials, ProtoVersion, CS)
+ catch
+ throw:{protocol_failure, What} ->
+ ?error("Protocol failure (~p): ~p", [FromPid, What]),
+ exit(FromPid, protocol_failure)
+ end;
%% ?DLINK_CMD_CRED_EXCHANGE ->
%% ?debug("got cred exch ~s:~w", [PeerIP, PeerPort]),
@@ -684,40 +688,29 @@ availability_msg(Availability, Services) ->
status_string(available ) -> ?DLINK_ARG_AVAILABLE;
status_string(unavailable) -> ?DLINK_ARG_UNAVAILABLE.
-process_authorize(FromPid, PeerIP, PeerPort, RemoteAddress,
- RemotePort, Credentials, CompSpec) ->
+process_authorize(FromPid, PeerIP, PeerPort,
+ Credentials, ProtoVersion, CompSpec) ->
?info("dlink_tls:authorize(): Peer Address: ~s:~p", [PeerIP, PeerPort ]),
- ?info("dlink_tls:authorize(): Remote Address: ~s:~p", [ RemoteAddress, RemotePort ]),
-
- {NRemoteAddress, NRemotePort} = Conn = {PeerIP, PeerPort},
- %% { NRemoteAddress, NRemotePort} = Conn =
- %% case { RemoteAddress, RemotePort } of
- %% { <<"0.0.0.0">>, 0 } ->
-
- %% ?info("dlink_tls:authorize(): Remote is behind firewall. Will use ~p:~p",
- %% [ PeerIP, PeerPort]),
- %% { PeerIP, PeerPort };
- %% _ -> { RemoteAddress, RemotePort}
- %% end,
- log("auth ~s:~w", [NRemoteAddress, NRemotePort], CompSpec),
+ case ProtoVersion of
+ <<"1.", _/binary>> -> ok;
+ undefined -> ok;
+ _ ->
+ throw({protocol_failure, {unknown_version, ProtoVersion}})
+ end,
+ Conn = {PeerIP, PeerPort},
+ log("auth ~s:~w", [PeerIP, PeerPort], CompSpec),
PeerCert = rvi_common:get_value(dlink_tls_peer_cert, not_found, CompSpec),
authorize_rpc:store_creds(CompSpec, Credentials, Conn, PeerCert),
connection_authorized(FromPid, Conn, CompSpec).
send_authorize(Pid, CompSpec) ->
?debug("send_authorize() Pid = ~p; CompSpec = ~p", [Pid, abbrev(CompSpec)]),
- {LocalIP, LocalPort} = rvi_common:node_address_tuple(),
Creds = get_credentials(CompSpec),
dlink_tls_conn:send(Pid, rvi_common:pass_log_id(
[{?DLINK_ARG_CMD, ?DLINK_CMD_AUTHORIZE},
{?DLINK_ARG_VERSION, ?DLINK_TLS_VERSION},
- {?DLINK_ARG_ADDRESS, bin(LocalIP)},
- {?DLINK_ARG_PORT, LocalPort},
{?DLINK_ARG_CREDENTIALS, Creds}], CompSpec)).
-bin(S) ->
- iolist_to_binary(S).
-
connection_authorized(FromPid, {RemoteIP, RemotePort} = Conn, CompSpec) ->
%% If FromPid (the genserver managing the socket) is not yet registered
%% with the connection manager, this is an incoming connection
diff --git a/components/proto_json/src/proto_json_rpc.erl b/components/proto_json/src/proto_json_rpc.erl
index 9f10ee3..85f1aa6 100644
--- a/components/proto_json/src/proto_json_rpc.erl
+++ b/components/proto_json/src/proto_json_rpc.erl
@@ -129,12 +129,10 @@ handle_call({rvi, send_message,
?debug(" protocol:send(): data_link_mod: ~p~n", [DataLinkMod]),
?debug(" protocol:send(): data_link_opts: ~p~n", [DataLinkOpts]),
?debug(" protocol:send(): parameters: ~p~n", [Parameters]),
- Data = jsx:encode([
- { <<"tid">>, TID },
- { <<"service">>, ServiceName },
- { <<"timeout">>, Timeout },
- { <<"parameters">>, Parameters }
- ]),
+ Data = [{ <<"service">>, ServiceName },
+ { <<"timeout">>, Timeout },
+ { <<"parameters">>, Parameters }
+ ],
RviOpts = rvi_common:rvi_options(Parameters),
Res = DataLinkMod:send_data(
St#st.cs, ?MODULE, ServiceName, RviOpts ++ DataLinkOpts, Data),
@@ -145,9 +143,8 @@ handle_call(Other, _From, St) ->
{ reply, [ invalid_command ], St}.
%% Convert list-based data to binary.
-handle_cast({rvi, receive_message, [Payload, IP, Port | _LogId]} = Msg, St) ->
+handle_cast({rvi, receive_message, [Elems, IP, Port | _LogId]} = Msg, St) ->
?debug("~p:handle_cast(~p)", [?MODULE, Msg]),
- Elems = jsx:decode(iolist_to_binary(Payload)),
[ ServiceName, Timeout, Parameters ] =
opts([<<"service">>, <<"timeout">>, <<"parameters">>],
diff --git a/components/proto_msgpack/src/proto_msgpack_rpc.erl b/components/proto_msgpack/src/proto_msgpack_rpc.erl
index c8b083a..07352eb 100644
--- a/components/proto_msgpack/src/proto_msgpack_rpc.erl
+++ b/components/proto_msgpack/src/proto_msgpack_rpc.erl
@@ -132,10 +132,9 @@ handle_call({rvi, send_message,
?debug(" protocol:send(): data_link_mod: ~p~n", [DataLinkMod]),
?debug(" protocol:send(): data_link_opts: ~p~n", [DataLinkOpts]),
?debug(" protocol:send(): parameters: ~p~n", [Parameters]),
- Data = msgpack:pack([ { <<"tid">>, TID },
- { <<"service">>, ServiceName },
- { <<"timeout">>, Timeout },
- { <<"parameters">>, Parameters } ], St#st.pack_opts),
+ Data = [ { <<"service">>, ServiceName },
+ { <<"timeout">>, Timeout },
+ { <<"parameters">>, Parameters } ],
RviOpts = rvi_common:rvi_options(Parameters),
Res = DataLinkMod:send_data(
St#st.cs, ?MODULE, ServiceName, RviOpts ++ DataLinkOpts, Data),
@@ -147,9 +146,8 @@ handle_call(Other, _From, St) ->
%% Convert list-based data to binary.
-handle_cast({rvi, receive_message, [Payload, IP, Port | LogId]} = Msg, St) ->
+handle_cast({rvi, receive_message, [Elems, IP, Port | LogId]} = Msg, St) ->
?debug("~p:handle_cast(~p)", [?MODULE, Msg]),
- {ok, Elems} = msgpack:unpack(Payload, St#st.pack_opts),
[ ServiceName, Timeout, Parameters ] =
opts([<<"service">>, <<"timeout">>, <<"parameters">>],
diff --git a/components/service_edge/src/service_edge_rpc.erl b/components/service_edge/src/service_edge_rpc.erl
index f27448e..bee503e 100644
--- a/components/service_edge/src/service_edge_rpc.erl
+++ b/components/service_edge/src/service_edge_rpc.erl
@@ -619,7 +619,7 @@ do_handle_local_message_([SvcName, TimeoutArg, Parameters | _Tail], CS) ->
[TimeoutArg]),
(Now * 1000) + TimeoutArg;
- false -> %% Absolute timoeut. Convert to unix time msec
+ false -> %% Absolute timeout. Convert to unix time msec
TimeoutArg * 1000
end,
%%