Skip to content

Commit

Permalink
SshChannel -> SSHChannel by lint demand
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed May 24, 2019
1 parent 11bf94f commit 925d548
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions internal/therealssh/chan_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import "sync"
type chanList struct {
sync.Mutex

chans []*SshChannel
chans []*SSHChannel
}

func newChanList() *chanList {
return &chanList{chans: []*SshChannel{}}
return &chanList{chans: []*SSHChannel{}}
}

func (c *chanList) add(sshCh *SshChannel) uint32 {
func (c *chanList) add(sshCh *SSHChannel) uint32 {
c.Lock()
defer c.Unlock()

Expand All @@ -27,7 +27,7 @@ func (c *chanList) add(sshCh *SshChannel) uint32 {
return uint32(len(c.chans) - 1)
}

func (c *chanList) getChannel(id uint32) *SshChannel {
func (c *chanList) getChannel(id uint32) *SSHChannel {
c.Lock()
defer c.Unlock()

Expand All @@ -38,10 +38,10 @@ func (c *chanList) getChannel(id uint32) *SshChannel {
return nil
}

func (c *chanList) dropAll() []*SshChannel {
func (c *chanList) dropAll() []*SSHChannel {
c.Lock()
defer c.Unlock()
var r []*SshChannel
var r []*SSHChannel

for _, ch := range c.chans {
if ch == nil {
Expand Down
40 changes: 20 additions & 20 deletions internal/therealssh/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const Port = 2
// Debug enables debug messages.
var Debug = false

// SshChannel defines communication channel parameters.
type SshChannel struct {
// SSHChannel defines communication channel parameters.
type SSHChannel struct {
RemoteID uint32
RemoteAddr *app.Addr

Expand All @@ -38,25 +38,25 @@ type SshChannel struct {
dataCh chan []byte
}

// OpenChannel constructs new SshChannel with empty Session.
func OpenChannel(remoteID uint32, remoteAddr *app.Addr, conn net.Conn) *SshChannel {
return &SshChannel{RemoteID: remoteID, conn: conn, RemoteAddr: remoteAddr, msgCh: make(chan []byte), dataCh: make(chan []byte)}
// OpenChannel constructs new SSHChannel with empty Session.
func OpenChannel(remoteID uint32, remoteAddr *app.Addr, conn net.Conn) *SSHChannel {
return &SSHChannel{RemoteID: remoteID, conn: conn, RemoteAddr: remoteAddr, msgCh: make(chan []byte), dataCh: make(chan []byte)}
}

// OpenClientChannel constructs new client SshChannel with empty Session.
func OpenClientChannel(remoteID uint32, remotePK cipher.PubKey, conn net.Conn) *SshChannel {
// OpenClientChannel constructs new client SSHChannel with empty Session.
func OpenClientChannel(remoteID uint32, remotePK cipher.PubKey, conn net.Conn) *SSHChannel {
ch := OpenChannel(remoteID, &app.Addr{PubKey: remotePK, Port: Port}, conn)
return ch
}

// Send sends command message.
func (sshCh *SshChannel) Send(cmd CommandType, payload []byte) error {
func (sshCh *SSHChannel) Send(cmd CommandType, payload []byte) error {
data := appendU32([]byte{byte(cmd)}, sshCh.RemoteID)
_, err := sshCh.conn.Write(append(data, payload...))
return err
}

func (sshCh *SshChannel) Read(p []byte) (int, error) {
func (sshCh *SSHChannel) Read(p []byte) (int, error) {
data, more := <-sshCh.dataCh
if !more {
return 0, io.EOF
Expand All @@ -65,14 +65,14 @@ func (sshCh *SshChannel) Read(p []byte) (int, error) {
return copy(p, data), nil
}

func (sshCh *SshChannel) Write(p []byte) (n int, err error) {
func (sshCh *SSHChannel) Write(p []byte) (n int, err error) {
n = len(p)
err = sshCh.Send(CmdChannelData, p)
return
}

// Request sends request message and waits for response.
func (sshCh *SshChannel) Request(requestType RequestType, payload []byte) ([]byte, error) {
func (sshCh *SSHChannel) Request(requestType RequestType, payload []byte) ([]byte, error) {
debug("sending request %x", requestType)
req := append([]byte{byte(requestType)}, payload...)

Expand All @@ -89,7 +89,7 @@ func (sshCh *SshChannel) Request(requestType RequestType, payload []byte) ([]byt
}

// Serve starts request handling loop.
func (sshCh *SshChannel) Serve() error {
func (sshCh *SSHChannel) Serve() error {
for data := range sshCh.msgCh {
var err error
debug("new request %x", data[0])
Expand Down Expand Up @@ -136,12 +136,12 @@ func (sshCh *SshChannel) Serve() error {

// SocketPath returns unix socket location. This socket is normally
// used by the CLI to exchange PTY data with a client app.
func (sshCh *SshChannel) SocketPath() string {
func (sshCh *SSHChannel) SocketPath() string {
return filepath.Join(os.TempDir(), fmt.Sprintf("therealsshd-%d", sshCh.RemoteID))
}

// ServeSocket starts socket handling loop.
func (sshCh *SshChannel) ServeSocket() error {
func (sshCh *SSHChannel) ServeSocket() error {
os.Remove(sshCh.SocketPath())
debug("waiting for new socket connections on: %s", sshCh.SocketPath())
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sshCh.SocketPath(), Net: "unix"})
Expand Down Expand Up @@ -178,7 +178,7 @@ func (sshCh *SshChannel) ServeSocket() error {
}

// OpenPTY creates new PTY Session for the Channel.
func (sshCh *SshChannel) OpenPTY(user *user.User, sz *pty.Winsize) (err error) {
func (sshCh *SSHChannel) OpenPTY(user *user.User, sz *pty.Winsize) (err error) {
if sshCh.session != nil {
return errors.New("session is already started")
}
Expand All @@ -194,12 +194,12 @@ func (sshCh *SshChannel) OpenPTY(user *user.User, sz *pty.Winsize) (err error) {
}

// Shell starts shell process on Channel's PTY session.
func (sshCh *SshChannel) Shell() error {
func (sshCh *SSHChannel) Shell() error {
return sshCh.Start("shell")
}

// Start executes provided command on Channel's PTY session.
func (sshCh *SshChannel) Start(command string) error {
func (sshCh *SSHChannel) Start(command string) error {
if sshCh.session == nil {
return errors.New("session is not started")
}
Expand All @@ -214,7 +214,7 @@ func (sshCh *SshChannel) Start(command string) error {
return sshCh.session.Start(command)
}

func (sshCh *SshChannel) serveSession() error {
func (sshCh *SSHChannel) serveSession() error {
defer func() {
sshCh.Send(CmdChannelServerClose, nil) // nolint
sshCh.Close()
Expand All @@ -236,7 +236,7 @@ func (sshCh *SshChannel) serveSession() error {
}

// WindowChange resize PTY Session size.
func (sshCh *SshChannel) WindowChange(sz *pty.Winsize) error {
func (sshCh *SSHChannel) WindowChange(sz *pty.Winsize) error {
if sshCh.session == nil {
return errors.New("session is not started")
}
Expand All @@ -245,7 +245,7 @@ func (sshCh *SshChannel) WindowChange(sz *pty.Winsize) error {
}

// Close safely closes Channel resources.
func (sshCh *SshChannel) Close() error {
func (sshCh *SSHChannel) Close() error {
select {
case <-sshCh.dataCh:
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/therealssh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewClient(rpcAddr string, d Dialer) (net.Listener, *Client, error) {
}

// OpenChannel requests new Channel on the remote Server.
func (c *Client) OpenChannel(remotePK cipher.PubKey) (localID uint32, sshCh *SshChannel, cErr error) {
func (c *Client) OpenChannel(remotePK cipher.PubKey) (localID uint32, sshCh *SSHChannel, cErr error) {
conn, err := c.dialer.Dial(&app.Addr{PubKey: remotePK, Port: Port})
if err != nil {
cErr = fmt.Errorf("dial failed: %s", err)
Expand Down Expand Up @@ -80,7 +80,7 @@ func (c *Client) OpenChannel(remotePK cipher.PubKey) (localID uint32, sshCh *Ssh
return localID, sshCh, cErr
}

func (c *Client) resolveChannel(remotePK cipher.PubKey, localID uint32) (*SshChannel, error) {
func (c *Client) resolveChannel(remotePK cipher.PubKey, localID uint32) (*SSHChannel, error) {
sshCh := c.chans.getChannel(localID)
if sshCh == nil {
return nil, errors.New("channel is not opened")
Expand Down
2 changes: 1 addition & 1 deletion internal/therealssh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestClientOpenChannel(t *testing.T) {
c := &Client{dialer, newChanList()}

type data struct {
ch *SshChannel
ch *SSHChannel
err error
}
resCh := make(chan data)
Expand Down

0 comments on commit 925d548

Please sign in to comment.