Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
spec fixes and tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Apr 6, 2022
1 parent 9d5674e commit eee9851
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 253 deletions.
8 changes: 4 additions & 4 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{<<"base64url">>,{pkg,<<"base64url">>,<<"1.0.1">>},1},
{<<"blockchain">>,
{git,"https://github.com/helium/blockchain-core.git",
{ref,"774944d6b39e7f96563ecd380503be95df968e3f"}},
{ref,"619485b2ae4fcadc83aad39a8a516849623bbfda"}},
0},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
{<<"chatterbox">>,
Expand Down Expand Up @@ -86,7 +86,7 @@
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.8.0">>},2},
{<<"grpc_client">>,
{git,"https://github.com/Bluehouse-Technology/grpc_client.git",
{ref,"f29516eaf590c63c0c300f98c9b75feff24f8351"}},
{ref,"02689e7992ef70b42b6b890db450ae4a7c21a50c"}},
0},
{<<"grpc_lib">>,
{git,"https://github.com/Bluehouse-Technology/grpc_lib",
Expand All @@ -107,7 +107,7 @@
0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"51df6195545a3ff75689e2377988681da467ab7a"}},
{ref,"c88928d7e794372411674e98580e940b542a8d4f"}},
1},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3},
{<<"http2_client">>,
Expand Down Expand Up @@ -176,7 +176,7 @@
3},
{<<"sibyl">>,
{git,"https://github.com/helium/sibyl.git",
{ref,"293c4acafe57cc49bc8943a7691bda7dfd720ef4"}},
{ref,"f7b290638b7c55dac95383abc9936580420350cb"}},
0},
{<<"sidejob">>,{pkg,<<"sidejob">>,<<"2.1.0">>},2},
{<<"small_ints">>,{pkg,<<"small_ints">>,<<"0.1.0">>},4},
Expand Down
29 changes: 16 additions & 13 deletions src/poc/grpc_client_custom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
%% Passed on to the HTTP/2 client. See the documentation of 'http2_client' for the options
%% that can be specified for the default HTTP2/2 client.

-type connection() :: grpc_client_connection:connection().
-type connection() :: #{http_connection := pid(),
host := binary(),
scheme := binary(),
client := module()}.

-type metadata_key() :: binary().
-type metadata_value() :: binary().
Expand All @@ -106,12 +109,12 @@
-type unary_response() :: ok_response() | error_response().

-type ok_response() ::
{ok, #{result => any(),
status_message => binary(),
http_status => 200,
grpc_status => 0,
headers => metadata(),
trailers => metadata()}}.
{ok, #{result := any(),
status_message := binary(),
http_status := 200,
grpc_status := 0,
headers := metadata(),
trailers := metadata()}}.

-type error_response() ::
{error, #{error_type => error_type(),
Expand Down Expand Up @@ -183,7 +186,7 @@ connect(Transport, Host, Port, Options) ->
-spec new_stream(Connection::connection(),
Service::atom(),
Rpc::atom(),
DecoderModule::module()) -> {ok, client_stream()}.
DecoderModule::module()) -> {ok, Pid::pid()} | {error, Reason::term()}.
%% @equiv new_stream(Connection, Service, Rpc, DecoderModule, [])
new_stream(Connection, Service, Rpc, DecoderModule) ->
new_stream(Connection, Service, Rpc, DecoderModule, []).
Expand All @@ -192,7 +195,7 @@ new_stream(Connection, Service, Rpc, DecoderModule) ->
Service::atom(),
Rpc::atom(),
DecoderModule::module(),
Options::[stream_option()]) -> {ok, client_stream()}.
Options::[stream_option()]) -> {ok, Pid::pid()} | {error, Reason::term()}.
%% @doc Create a new stream to start a new RPC.
new_stream(Connection, Service, Rpc, DecoderModule, Options) ->
CBMod = proplists:get_value(callback_mod, Options),
Expand Down Expand Up @@ -232,9 +235,9 @@ rcv(Stream, Timeout) ->
get(Stream) ->
grpc_client_stream_custom:get(Stream).

-spec ping(Connection::connection(),
Timeout::timeout()) -> {ok, RoundTripTime::integer()} |
{error, term()}.
-spec ping(
Connection::connection(),
Timeout::timeout()) -> {ok, RoundTripTime::integer()} | {error, term()}.
%% @doc Send a PING request.
ping(Connection, Timeout) ->
grpc_client_connection:ping(Connection, Timeout).
Expand Down Expand Up @@ -280,4 +283,4 @@ unary(Connection, Message, Service, Rpc, Decoder, Options) ->
lager:warning("Failed to create stream. Type: ~p, Error: ~p, Stack:~p", [_Type, _Error, _Stack]),
{error, #{error_type => client,
status_message => <<"stream create failed">>}}
end.
end.
40 changes: 20 additions & 20 deletions src/poc/grpc_client_stream_custom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@
%% gen_server behaviors
-export([code_change/3, handle_call/3, handle_cast/2, handle_info/2, init/1, terminate/2]).

%%-type stream() ::
%% #{stream_id := integer(),
%% package := string(),
%% service := string(),
%% rpc := string(),
%% queue := queue:queue(),
%% response_pending := boolean(),
%% state := idle | open | half_closed_local | half_closed_remote | closed,
%% encoder := module(),
%% connection := grpc_client_custom:connection(),
%% headers_sent := boolean(),
%% metadata := grpc_client_custom:metadata(),
%% compression := grpc_client_custom:compression_method(),
%% buffer := binary(),
%% handler_callback := undefined,
%% handler_state := undefined,
%% type := unary | streaming | undefined}.

-spec new(Connection::pid(),
-type stream() ::
#{stream_id := integer(),
package := string(),
service := string(),
rpc := string(),
queue := queue:queue(),
response_pending := boolean(),
state := idle | open | half_closed_local | half_closed_remote | closed,
encoder := module(),
connection := grpc_client_custom:connection(),
headers_sent := boolean(),
metadata := grpc_client_custom:metadata(),
compression := grpc_client_custom:compression_method(),
buffer := binary(),
handler_callback := undefined,
handler_state := undefined,
type := unary | streaming | undefined}.

-spec new(Connection::grpc_client_custom:connection(),
Service::atom(),
Rpc::atom(),
Encoder::module(),
Options::list(),
HandlerMod::atom() ) -> {ok, Pid::pid()} | {error, Reason::term()}.
HandlerMod::module() ) -> {ok, Pid::pid()} | {error, Reason::term()}.
new(Connection, Service, Rpc, Encoder, Options, HandlerMod) ->
gen_server:start_link(?MODULE,
{Connection, Service, Rpc, Encoder, Options, HandlerMod}, []).
Expand Down
3 changes: 1 addition & 2 deletions src/poc/miner_poc_grpc_client_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ connect(PeerP2P) ->
connect(PeerP2P, PeerIP, GRPCPort) ->
try
lager:debug("connecting over grpc to peer ~p via IP ~p and port ~p", [PeerP2P, PeerIP, GRPCPort]),
{ok, Connection} = grpc_client_custom:connect(tcp, PeerIP, GRPCPort),
{ok, Connection}
grpc_client_custom:connect(tcp, PeerIP, GRPCPort)
catch _Error:_Reason:_Stack ->
lager:warning("*** failed to connect over grpc to peer ~p. Reason ~p Stack ~p", [PeerP2P, _Reason, _Stack]),
{error, failed_to_connect_to_grpc_peer}
Expand Down
Loading

0 comments on commit eee9851

Please sign in to comment.