From 867e9db15f3d3e5e430e3adda577364e455b9dac Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Wed, 25 Apr 2018 15:31:55 +0200 Subject: ssh: Create doc for the ssh_daemon_channel behaviour --- lib/ssh/doc/src/Makefile | 1 + lib/ssh/doc/src/ref_man.xml | 1 + lib/ssh/doc/src/specs.xml | 1 + lib/ssh/doc/src/ssh.xml | 7 +- lib/ssh/doc/src/ssh_channel.xml | 49 ++++++---- lib/ssh/doc/src/ssh_daemon_channel.xml | 169 +++++++++++++++++++++++++++++++++ lib/ssh/doc/src/ssh_protocol.xml | 6 +- lib/ssh/doc/src/ssh_sftpd.xml | 3 +- 8 files changed, 210 insertions(+), 27 deletions(-) create mode 100644 lib/ssh/doc/src/ssh_daemon_channel.xml diff --git a/lib/ssh/doc/src/Makefile b/lib/ssh/doc/src/Makefile index 0063484f72..f47a1bfb40 100644 --- a/lib/ssh/doc/src/Makefile +++ b/lib/ssh/doc/src/Makefile @@ -40,6 +40,7 @@ RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN) XML_APPLICATION_FILES = ref_man.xml XML_REF3_FILES = ssh.xml \ ssh_channel.xml \ + ssh_daemon_channel.xml \ ssh_connection.xml \ ssh_client_key_api.xml \ ssh_server_key_api.xml \ diff --git a/lib/ssh/doc/src/ref_man.xml b/lib/ssh/doc/src/ref_man.xml index 140ebd8c76..1e1cff9119 100644 --- a/lib/ssh/doc/src/ref_man.xml +++ b/lib/ssh/doc/src/ref_man.xml @@ -36,6 +36,7 @@ + diff --git a/lib/ssh/doc/src/specs.xml b/lib/ssh/doc/src/specs.xml index 3ab4f43aec..f7837f9c5c 100644 --- a/lib/ssh/doc/src/specs.xml +++ b/lib/ssh/doc/src/specs.xml @@ -1,6 +1,7 @@ + diff --git a/lib/ssh/doc/src/ssh.xml b/lib/ssh/doc/src/ssh.xml index 03078cfd83..c403989ba9 100644 --- a/lib/ssh/doc/src/ssh.xml +++ b/lib/ssh/doc/src/ssh.xml @@ -68,8 +68,8 @@ ssh_sftp:start_channel/1,2,3.

To write your own client channel handler, use the behaviour - ssh_channel. For own server channel handlers use the ssh_daemon_channel - behaviour: see the note in ssh_channel. + ssh_channel. and server channel handlers use + ssh_daemon_channel behaviour.

Both clients and daemons accepts options that controls the exact behaviour. Some options are common to both. The three sets are called @@ -378,7 +378,8 @@

The subsystem_name is the name that a client requests to start with for example ssh_connection:subsystem/4.

-

The channel_callback is the module that implements the ssh_daemon_channel +

The channel_callback is the module that implements the + ssh_daemon_channel behaviour in the daemon. See the section Creating a Subsystem in the User's Guide for more information and an example. diff --git a/lib/ssh/doc/src/ssh_channel.xml b/lib/ssh/doc/src/ssh_channel.xml index 0355f7bf52..2ee6ab566b 100644 --- a/lib/ssh/doc/src/ssh_channel.xml +++ b/lib/ssh/doc/src/ssh_channel.xml @@ -37,7 +37,7 @@ that are multiplexed over an SSH connection and communicates over the SSH Connection Protocol. This module provides a callback API - that takes care of generic channel aspects, such as flow control + that takes care of generic channel aspects for clients, such as flow control and close messages. It lets the callback functions take care of the service (application) specific parts. This behavior also ensures that the channel process honors the principal of an OTP-process so @@ -46,14 +46,17 @@ the ssh applications supervisor tree.

- -

When implementing an ssh subsystem, use - -behaviour(ssh_daemon_channel) instead of -behaviour(ssh_channel). - The reason is that the only relevant callback functions for subsystems are - init/1, handle_ssh_msg/2, handle_msg/2, and terminate/2. - So, the ssh_daemon_channel behaviour is a limited version of the - ssh_channel behaviour. -

+

When implementing a ssh subsystem for daemons, use + -behaviour(ssh_daemon_channel) instead. +

+
+ + +

Functions in this module are not supposed to be called outside a module implementing this + behaviour! +

+
+ @@ -100,7 +103,7 @@ - + enter_loop(State) -> _ Makes an existing process an ssh_channel process. @@ -217,13 +220,19 @@
- - CALLBACK TIME-OUTS - -

The time-out values that can be returned by the callback functions - have the same semantics as in a gen_server. - If the time-out occurs, handle_msg/2 - is called as handle_msg(timeout, State).

+ Callback Functions +

+ The following functions are to be exported from a + ssh_daemon_channel callback module. +

+
+ + Callback timeouts +

The timeout values that can be returned by the callback functions + have the same semantics as in a gen_server. + If the time-out occurs, handle_msg/2 + is called as handle_msg(timeout, State).

+
@@ -286,7 +295,7 @@ state if the initializations succeed.

For more detailed information on time-outs, see Section - CALLBACK TIME-OUTS.

+ Callback timeouts.

@@ -313,7 +322,7 @@ call/[2,3]

For more detailed information on time-outs,, see Section - CALLBACK TIME-OUTS.

+ Callback timeouts.

@@ -334,7 +343,7 @@ cast/2.

For more detailed information on time-outs, see Section - CALLBACK TIME-OUTS.

+ Callback timeouts.

diff --git a/lib/ssh/doc/src/ssh_daemon_channel.xml b/lib/ssh/doc/src/ssh_daemon_channel.xml new file mode 100644 index 0000000000..8b0ff93f5f --- /dev/null +++ b/lib/ssh/doc/src/ssh_daemon_channel.xml @@ -0,0 +1,169 @@ + + + + +
+ + 2009 + 2016 + Ericsson AB, All Rights Reserved + + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + The Initial Developer of the Original Code is Ericsson AB. + + ssh_daemon_channel + + + + +
+ ssh_daemon_channel + -behaviour(ssh_daemon_channel). + + +

SSH services (clients and servers) are implemented as channels + that are multiplexed over an SSH connection and communicates over + the SSH + Connection Protocol. This module provides a callback API + that takes care of generic channel aspects for daemons, such as flow control + and close messages. It lets the callback functions take care of + the service (application) specific parts. This behavior also ensures + that the channel process honors the principal of an OTP-process so + that it can be part of a supervisor tree. This is a requirement of + channel processes implementing a subsystem that will be added to + the ssh applications supervisor tree. +

+ +

When implementing a client subsystem handler, use + -behaviour(ssh_channel) instead. +

+
+ +
+ +
+ Callback Functions +

+ The following functions are to be exported from a + ssh_daemon_channel callback module. +

+
+ + + + Module:init(Args) -> {ok, State} | {ok, State, timeout()} | + {stop, Reason} + Makes necessary initializations and returns the + initial channel state if the initializations succeed. + + Args = term() + Last argument to start_link/4. + State = term() + Reason = term() + + +

Makes necessary initializations and returns the initial channel + state if the initializations succeed. +

+

The time-out values that can be returned + have the same semantics as in a gen_server. + If the time-out occurs, handle_msg/2 + is called as handle_msg(timeout, State). +

+
+
+ + + Module:handle_msg(Msg, State) -> {ok, State} | + {stop, ChannelId, State} + + Handles other messages than SSH connection protocol, + call, or cast messages sent to the channel. + + Msg = timeout | term() + ChannelId = ssh:channel_id() + State = term() + + +

Handles other messages than SSH Connection Protocol, call, or + cast messages sent to the channel. +

+ +

Possible Erlang 'EXIT' messages is to be handled by this + function and all channels are to handle the following message.

+ + + {ssh_channel_up, ssh:channel_id(), ssh:connection_ref()} +

This is the first message that the channel receives. + This is especially useful if the + server wants to send a message to the client without first + receiving a message from it. If the message is not + useful for your particular scenario, ignore it by + immediately returning {ok, State}. +

+
+
+
+ + + Module:handle_ssh_msg(Msg, State) -> {ok, State} | {stop, + ChannelId, State} + Handles ssh connection protocol messages. + + Msg = ssh_connection:event() + ChannelId = ssh:channel_id() + State = term() + + +

Handles SSH Connection Protocol messages that may need + service-specific attention. For details, + see ssh_connection:event(). +

+ +

The following message is taken care of by the + ssh_daemon_channel behavior.

+ + + {closed, ssh:channel_id()} +

The channel behavior sends a close message to the + other side, if such a message has not already been sent. + Then it terminates the channel with reason normal.

+
+
+
+ + + Module:terminate(Reason, State) -> _ + Does cleaning up before channel process termination. + + + Reason = term() + State = term() + + +

This function is called by a channel process when it is + about to terminate. Before this function is called, ssh_connection:close/2 + is called, if it has not been called earlier. + This function does any necessary cleaning + up. When it returns, the channel process terminates with + reason Reason. The return value is ignored. +

+
+
+ +
+ +
diff --git a/lib/ssh/doc/src/ssh_protocol.xml b/lib/ssh/doc/src/ssh_protocol.xml index a0032ab449..21c755b48e 100644 --- a/lib/ssh/doc/src/ssh_protocol.xml +++ b/lib/ssh/doc/src/ssh_protocol.xml @@ -87,8 +87,10 @@ connection, and all channels are flow-controlled. Typically an SSH client will open a channel, send data/commands, receive data/"control information" and when it is done close the - channel. The ssh_channel behaviour makes it easy to + channel. The + ssh_channel / + ssh_daemon_channel + behaviours makes it easy to write your own SSH client/server processes that use flow control. It handles generic parts of SSH channel management and lets you focus on the application logic. diff --git a/lib/ssh/doc/src/ssh_sftpd.xml b/lib/ssh/doc/src/ssh_sftpd.xml index 1be29b3b29..4c599a7fb9 100644 --- a/lib/ssh/doc/src/ssh_sftpd.xml +++ b/lib/ssh/doc/src/ssh_sftpd.xml @@ -44,8 +44,7 @@

"sftp"

channel_callback() =

atom() - Name of the Erlang module implementing the subsystem using the - ssh_channel behavior, see the - ssh_channel(3) manual page.

+ ssh_daemon_channel behaviour.

channel_init_args() =

list() - The one given as argument to function subsystem_spec/1.

-- cgit v1.2.3