Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit b171cb8

Browse files
author
macpie
committed
group stteam docs
1 parent 8e38eb7 commit b171cb8

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

src/group/libp2p_ack_stream.erl

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
%%%-------------------------------------------------------------------
2+
%% @doc
3+
%% == Libp2p Ack Stream ==
4+
%% @see libp2p_framed_stream
5+
%% @end
6+
%%%-------------------------------------------------------------------
17
-module(libp2p_ack_stream).
28

39
-include("pb/libp2p_ack_stream_pb.hrl").
@@ -10,9 +16,14 @@
1016
{ok, Ref::any()} | {error, term()}.
1117
-callback handle_ack(State::any(), Ref::any(), Seq::[pos_integer()], Reset::boolean()) -> ok.
1218

13-
%% API
19+
%% ------------------------------------------------------------------
20+
%% API Function Exports
21+
%% ------------------------------------------------------------------
1422
-export([send_ack/3]).
15-
%% libp2p_framed_stream
23+
24+
%% ------------------------------------------------------------------
25+
%% libp2p_framed_stream Function Exports
26+
%% ------------------------------------------------------------------
1627
-export([server/4, client/2, init/3, handle_data/3, handle_send/5, handle_info/3]).
1728

1829

@@ -25,22 +36,33 @@
2536

2637
-define(ACK_STREAM_TIMEOUT, timer:minutes(5)).
2738

28-
%% API
29-
%%
39+
%% ------------------------------------------------------------------
40+
%% API Function Definitions
41+
%% ------------------------------------------------------------------
3042

43+
%%%-------------------------------------------------------------------
44+
%% @doc
45+
%% Send ack message
46+
%% @end
47+
%%%-------------------------------------------------------------------
3148
-spec send_ack(pid(), pos_integer(), boolean()) -> ok.
3249
send_ack(Pid, Seq, Reset) ->
3350
Pid ! {send_ack, Seq, Reset},
3451
ok.
3552

36-
%% libp2p_framed_stream
37-
%%
53+
%% ------------------------------------------------------------------
54+
%% libp2p_framed_stream Function Definitions
55+
%% ------------------------------------------------------------------
56+
57+
%% @hidden
3858
client(Connection, Args) ->
3959
libp2p_framed_stream:client(?MODULE, Connection, Args).
4060

61+
%% @hidden
4162
server(Connection, Path, _TID, Args) ->
4263
libp2p_framed_stream:server(?MODULE, Connection, [Path | Args]).
4364

65+
%% @hidden
4466
init(server, Connection, [Path, AckModule, AckState | _]) ->
4567
case AckModule:accept_stream(AckState, self(), Path) of
4668
{ok, AckRef} ->
@@ -55,6 +77,7 @@ init(client, Connection, [AckRef, AckModule, AckState | _]) ->
5577
{ok, #state{connection=Connection,
5678
ack_ref=AckRef, ack_module=AckModule, ack_state=AckState}}.
5779

80+
%% @hidden
5881
handle_data(_Kind, Data, State=#state{ack_ref=AckRef, ack_module=AckModule, ack_state=AckState}) ->
5982
case libp2p_ack_stream_pb:decode_msg(Data, libp2p_ack_frame_pb) of
6083
#libp2p_ack_frame_pb{messages=Bin, seqs=Seq} when Bin /= [] ->
@@ -71,6 +94,7 @@ handle_data(_Kind, Data, State=#state{ack_ref=AckRef, ack_module=AckModule, ack_
7194
{noreply, State}
7295
end.
7396

97+
%% @hidden
7498
handle_send(_Kind, From, Msgs, Timeout, State=#state{}) when is_list(Msgs) ->
7599
{Seqs, Data} = lists:unzip(Msgs),
76100
Msg = #libp2p_ack_frame_pb{messages=Data, seqs=Seqs},
@@ -79,6 +103,7 @@ handle_send(_Kind, From, {Data, Seq}, Timeout, State=#state{}) ->
79103
Msg = #libp2p_ack_frame_pb{messages=[Data], seqs=[Seq]},
80104
{ok, {reply, From, pending}, libp2p_ack_stream_pb:encode_msg(Msg), Timeout, State#state{}}.
81105

106+
%% @hidden
82107
handle_info(_Kind, {send_ack, Seq, Reset}, State=#state{}) ->
83108
Msg = #libp2p_ack_frame_pb{seqs=Seq, reset=Reset},
84109
{noreply, State, libp2p_ack_stream_pb:encode_msg(Msg)}.

src/group/libp2p_gossip_stream.erl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
%%%-------------------------------------------------------------------
2+
%% @doc
3+
%% == Libp2p Gossip Stream ==
4+
%% @see libp2p_framed_stream
5+
%% @end
6+
%%%-------------------------------------------------------------------
17
-module(libp2p_gossip_stream).
28

39
-include("pb/libp2p_gossip_pb.hrl").
@@ -9,9 +15,14 @@
915
Session::pid(),
1016
Stream::pid()) -> ok | {error, term()}.
1117

12-
%% API
18+
%% ------------------------------------------------------------------
19+
%% API Function Exports
20+
%% ------------------------------------------------------------------
1321
-export([encode/2]).
14-
%% libp2p_framed_stream
22+
23+
%% ------------------------------------------------------------------
24+
%% libp2p_framed_stream Function Exports
25+
%% ------------------------------------------------------------------
1526
-export([server/4, client/2, init/3, handle_data/3]).
1627

1728

@@ -21,20 +32,27 @@
2132
handler_state :: any()
2233
}).
2334

24-
%% API
25-
%%
35+
%% ------------------------------------------------------------------
36+
%% API Function Definitions
37+
%% ------------------------------------------------------------------
38+
2639
encode(Key, Data) ->
2740
Msg = #libp2p_gossip_frame_pb{key=Key, data=Data},
2841
libp2p_gossip_pb:encode_msg(Msg).
2942

30-
%% libp2p_framed_stream
31-
%%
43+
%% ------------------------------------------------------------------
44+
%% libp2p_framed_stream Function Definitions
45+
%% ------------------------------------------------------------------
46+
47+
%% @hidden
3248
client(Connection, Args) ->
3349
libp2p_framed_stream:client(?MODULE, Connection, Args).
3450

51+
%% @hidden
3552
server(Connection, _Path, _TID, Args) ->
3653
libp2p_framed_stream:server(?MODULE, Connection, Args).
3754

55+
%% @hidden
3856
init(server, Connection, [HandlerModule, HandlerState]) ->
3957
{ok, Session} = libp2p_connection:session(Connection),
4058
State = #state{connection=Connection,
@@ -59,6 +77,7 @@ init(client, Connection, [HandlerModule, HandlerState]) ->
5977
handler_module=HandlerModule,
6078
handler_state=HandlerState}}.
6179

80+
%% @hidden
6281
handle_data(_, Data, State=#state{handler_module=HandlerModule,
6382
handler_state=HandlerState}) ->
6483
#libp2p_gossip_frame_pb{key=Key, data=Bin} =

0 commit comments

Comments
 (0)