Added documentation to existing functions

This commit is contained in:
Justin 2014-12-28 23:17:16 -05:00
parent fb9c587be4
commit 732e1bd69c
2 changed files with 9 additions and 13 deletions

View File

@ -27,18 +27,20 @@ func (s sshrpcSession) Write(p []byte) (n int, err error) {
return pipe.Write(p) return pipe.Write(p)
} }
// Client represents an RPC client using an SSH backed connection.
type Client struct { type Client struct {
*rpc.Client *rpc.Client
Config *ssh.ClientConfig Config *ssh.ClientConfig
Subsystem string Subsystem string
} }
// NewClient returns a new Client to handle RPC requests.
func NewClient() *Client { func NewClient() *Client {
config := &ssh.ClientConfig{ config := &ssh.ClientConfig{
User: "test", User: "sshrpc",
Auth: []ssh.AuthMethod{ 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) { func (c *Client) Connect(address string) {
sshClient, err := ssh.Dial("tcp", address, c.Config) sshClient, err := ssh.Dial("tcp", address, c.Config)

View File

@ -9,18 +9,18 @@ import (
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
) )
// Server represents an SSH Server that spins up RPC servers when requested.
type Server struct { type Server struct {
*rpc.Server *rpc.Server
Config *ssh.ServerConfig Config *ssh.ServerConfig
Subsystem string Subsystem string
} }
// NewServer returns a new Server to handle incoming SSH and RPC requests.
func NewServer() *Server { func NewServer() *Server {
c := &ssh.ServerConfig{ c := &ssh.ServerConfig{
// NoClientAuth: true,
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) { 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() == "sshrpc" && string(pass) == "sshrpc" {
if c.User() == "test" && string(pass) == "test" {
return nil, nil return nil, nil
} }
return nil, fmt.Errorf("password rejected for %q", c.User()) 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) { func (s *Server) StartServer(address string) {
// Once a ServerConfig has been configured, connections can be accepted. // Once a ServerConfig has been configured, connections can be accepted.
@ -84,14 +85,6 @@ func (s *Server) handleChannels(chans <-chan ssh.NewChannel) {
continue continue
} }
/*
close := func() {
channel.Close()
log.Printf("session closed")
}
defer close()
*/
// Sessions have out-of-band requests such as "shell", "pty-req" and "env" // Sessions have out-of-band requests such as "shell", "pty-req" and "env"
go func(in <-chan *ssh.Request) { go func(in <-chan *ssh.Request) {
for req := range in { for req := range in {