Permalink
Browse files

sshrpc_client now working, finally

  • Loading branch information...
1 parent 0f91407 commit d9058c3c79c4022f190f0747485c10e843765a38 @jj1bdx committed Mar 21, 2010
Showing with 88 additions and 10 deletions.
  1. +2 −1 src/Makefile
  2. +67 −0 src/client_test.erl
  3. +2 −2 src/{client_subsystest.erl → client_test_nonotp.erl}
  4. +10 −4 src/readme.txt
  5. +1 −1 src/server_test.erl
  6. +6 −2 src/sshrpc_client.erl
View
@@ -23,7 +23,8 @@
ERL = erl -boot start_clean
-MODS = sshrpc_subsystem server_test client_subsystest
+MODS = sshrpc_subsystem server_test client_test_nonotp \
+ sshrpc_client client_test
all: compile
View
@@ -0,0 +1,67 @@
+%% Copyright (c) 2009-2010 Kenji Rikitake. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+
+%% @author Kenji Rikitake <kenji.rikitake@acm.org>
+%% @copyright 2009-2010 Kenji Rikitake
+
+%% @doc example code for testing SSH RPC client site
+%% TODO: this code must be OTP-nized!
+
+-module(client_test).
+-export([startup/0, linkup/0, test/2]).
+
+-include("sshrpc.hrl").
+
+-define(TIMEOUT, 30000). % in milliseconds
+
+%% specifyclient configuration key directory
+%% (put id_rsa and id_rsa.pub)
+
+-define(CLIENT_CONFIG, "/your/client_config").
+
+startup() ->
+ ok = crypto:start(),
+ ok = ssh:start().
+
+linkup() ->
+ {ok, Pid, Cm} = sshrpc_client:start_channel("127.0.0.1", % server address
+ 11122, % port number
+ [
+ %% note: private user key (id_rsa) and
+ %% public host key (known_hosts) must exist
+ %% in the "user_dir" for public-key auth
+ %% NOTE WELL: user key has NULL password protected
+ %% (password-protected is UNSUPPORTED)
+ {user_dir, ?CLIENT_CONFIG},
+ %% the following user/password pair needed for
+ %% plain password-based authentication
+ %% {user,"test"}
+ %% {password,"shiken"}
+ %%
+ %% nodelay must be set true for immediate response!
+ {nodelay, true}
+ ]),
+ io:format("Pid: ~p Cm: ~p ~n", [Pid, Cm]),
+ {Pid, Cm}.
+
+test(M,N) ->
+ {Pid, _Cm} = linkup(),
+ Status = lists:map(
+ fun(X) ->
+ sshrpc_client:sync_call(Pid, lists, seq, [1, M]),
+ io:format("NR: ~p Time: ~p~n", [X, erlang:now()]) end,
+ lists:seq(1,N)),
+ io:format("Time: ~p Status: ~p~n", [erlang:now(),Status]),
+ sshrpc_client:stop_channel(Pid).
+
+%% end of file
@@ -17,7 +17,7 @@
%% @doc example code for testing SSH RPC client site
%% TODO: this code must be OTP-nized!
--module(client_subsystest).
+-module(client_test_nonotp).
-export([startup/0, linkup/0, doit/2, test/2]).
-include("sshrpc.hrl").
@@ -27,7 +27,7 @@
%% specifyclient configuration key directory
%% (put id_rsa and id_rsa.pub)
--define(CLIENT_CONFIG, "/your/client/directory").
+-define(CLIENT_CONFIG, "/your/client_config").
startup() ->
ok = crypto:start(),
View
@@ -1,7 +1,7 @@
sshrpc readme.txt
by Kenji Rikitake
kenji.rikitake@acm.org
-25-FEB-2010
+21-MAR-2010
This is sshrpc, an experimental module for Erlang RPC over SSH.
@@ -22,10 +22,16 @@ subsystem code: sshrpc_subsystem.erl
* client code
client code is still incomplete and under development.
-client_subsystest.erl is an ad-hoc implementation;
-sshrpc_client.erl will be the ssh_channel based implementation.
-* NOTYET: sshrpc_client module functions
+client_test_nonotp.erl: an ad-hoc implementation without OTP;
+sshrpc_client.erl: OTP ssh_channel based client code implementation,
+client_test.erl: example code using sshrpc_client.erl.
+
+NOTE: R13B04 ssh_connection:send/4 has an argument parsing bug
+ to treat the Timeout 'infinity' atom as a Data and
+ crashes when trying to erlang:size([infinity]).
+
+* sshrpc_client module functions (still experimental)
sync_call(Pid, Module, Function, Arguments) -> result | {badrpc, Reason}
synchronous function evaluation on the remote node
View
@@ -25,7 +25,7 @@
%% (put id_rsa.pub, ssh_host_rsa_key{.pub}, and authorized_keys
-define(SERVER_CONFIG,
- "/your/server/directory").
+ "/your/server_config").
startup() ->
ok = crypto:start(),
View
@@ -269,9 +269,13 @@ call(Pid, Msg, TimeOut) ->
send_command(Pid, ChannelId, Cmd) ->
Bin = term_to_binary(Cmd),
Len = size(Bin),
+ %% R13B04 ssh_connection:send/4 has a bug:
+ %% if the send(ConnectionRef, ChannelId, Data, Timeout)'s
+ %% Timeout = 'infinity' (an atom), this is interpreted as a Data in
+ %% send(ConnectionRef, ChannelId, Type, Data);
+ %% the atom 'infinity' removed for disambiguation and a workaround
ssh_connection:send(Pid, ChannelId,
- <<?UINT32(Len), Bin/binary>>,
- infinity).
+ <<?UINT32(Len), Bin/binary>>).
handle_reply(State, <<?UINT32(Len),Reply:Len/binary,Rest/binary>>) ->
do_handle_reply(State, Reply, Rest);

0 comments on commit d9058c3

Please sign in to comment.