From 732e1bd69c173e4b5ebf0f91ed95f7a3d6b12907 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 28 Dec 2014 23:17:16 -0500 Subject: [PATCH] Added documentation to existing functions --- client.go | 7 +++++-- server.go | 15 ++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/client.go b/client.go index 293cc48..4c494cf 100644 --- a/client.go +++ b/client.go @@ -27,18 +27,20 @@ func (s sshrpcSession) Write(p []byte) (n int, err error) { return pipe.Write(p) } +// Client represents an RPC client using an SSH backed connection. type Client struct { *rpc.Client Config *ssh.ClientConfig Subsystem string } +// NewClient returns a new Client to handle RPC requests. func NewClient() *Client { config := &ssh.ClientConfig{ - User: "test", + User: "sshrpc", Auth: []ssh.AuthMethod{ - ssh.Password("test"), + ssh.Password("sshrpc"), }, } @@ -46,6 +48,7 @@ func NewClient() *Client { } +// Connect starts a client connection to the given SSH/RPC server. func (c *Client) Connect(address string) { sshClient, err := ssh.Dial("tcp", address, c.Config) diff --git a/server.go b/server.go index 417b421..dc3980b 100644 --- a/server.go +++ b/server.go @@ -9,18 +9,18 @@ import ( "golang.org/x/crypto/ssh" ) +// Server represents an SSH Server that spins up RPC servers when requested. type Server struct { *rpc.Server Config *ssh.ServerConfig Subsystem string } +// NewServer returns a new Server to handle incoming SSH and RPC requests. func NewServer() *Server { c := &ssh.ServerConfig{ - // NoClientAuth: true, PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) { - // Should use constant-time compare (or better, salt+hash) in a production setting. - if c.User() == "test" && string(pass) == "test" { + if c.User() == "sshrpc" && string(pass) == "sshrpc" { return nil, nil } return nil, fmt.Errorf("password rejected for %q", c.User()) @@ -30,6 +30,7 @@ func NewServer() *Server { } +// StartServer starts the server listening for requests func (s *Server) StartServer(address string) { // Once a ServerConfig has been configured, connections can be accepted. @@ -84,14 +85,6 @@ func (s *Server) handleChannels(chans <-chan ssh.NewChannel) { continue } - /* - close := func() { - channel.Close() - log.Printf("session closed") - } - defer close() - */ - // Sessions have out-of-band requests such as "shell", "pty-req" and "env" go func(in <-chan *ssh.Request) { for req := range in {