Skip to content

Commit

Permalink
Refactored dmsgpty for easier readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
志宇 committed Jan 30, 2020
1 parent f91d15d commit 8cda7a1
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 730 deletions.
4 changes: 2 additions & 2 deletions pkg/dmsgpty/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *CLI) RequestPty() error {
return err
}

ptyC := pty.NewPtyClient(ctx, c.Log, conn)
ptyC := pty.NewSessionClient(ctx, c.Log, conn)

c.Log.
WithField("cmd", fmt.Sprint(append([]string{c.Cmd}, c.Arg...))).
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *CLI) RequestPty() error {
}

// Loop that informs the remote of changes to the local CLI terminal window size.
func (c *CLI) ptyResizeLoop(ctx context.Context, ptyC *pty.Client) error {
func (c *CLI) ptyResizeLoop(ctx context.Context, ptyC *pty.SessionClient) error {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)

Expand Down
16 changes: 8 additions & 8 deletions pkg/dmsgpty/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ type Host struct {
cliNet string
cliAddr string

dmsgC *dmsg.Client // Communicates with other 'ptycli.Host's.
dmsgL *dmsg.Listener //
ptyS *pty.Server // Access to local ptys.
dmsgC *dmsg.Client // Communicates with other 'ptycli.Host's.
dmsgL *dmsg.Listener //
ptyS *pty.SessionServer // Access to local ptys.

cliL net.Listener // Listens for CLI connections.
cliI int32 // CLI index.
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewHostFromDmsgClient(
return nil, err
}

ptyS, err := pty.NewServer(
ptyS, err := pty.NewSessionServer(
logging.MustGetLogger("dmsgpty-server"),
pk,
sk,
Expand Down Expand Up @@ -240,7 +240,7 @@ func (h *Host) handleCLIConn(ctx context.Context, cliConn net.Conn) {

func (h *Host) handleCfgReq(ctx context.Context) (*rpc.Server, error) {
rpcS := rpc.NewServer()
if err := rpcS.RegisterName(ptycfg.GatewayName, ptycfg.NewGateway(ctx, h.ptyS.Auth())); err != nil {
if err := rpcS.RegisterName(ptycfg.GatewayName, ptycfg.NewConfigGateway(ctx, h.ptyS.Auth())); err != nil {
return nil, fmt.Errorf("failed to register 'CfgGateway': %v", err)
}
return rpcS, nil
Expand All @@ -251,7 +251,7 @@ func (h *Host) handlePtyReq(ctx context.Context, log logrus.FieldLogger, req *Pt
var dialLocalPty = func() (*rpc.Server, error) {
rpcS := rpc.NewServer()
if err := rpcS.RegisterName(pty.GatewayName, pty.NewDirectGateway()); err != nil {
return nil, fmt.Errorf("failed to register 'DirectGateway': %v", err)
return nil, fmt.Errorf("failed to register 'LocalSessionGateway': %v", err)
}
return rpcS, nil
}
Expand All @@ -265,11 +265,11 @@ func (h *Host) handlePtyReq(ctx context.Context, log logrus.FieldLogger, req *Pt
return nil, nil, fmt.Errorf("failed to dial dmsg: %v", err)
}
gateway := pty.NewProxyGateway(
pty.NewPtyClient(ctx, logging.MustGetLogger("pty_client"), dmsgConn))
pty.NewSessionClient(ctx, logging.MustGetLogger("pty_client"), dmsgConn))

rpcS := rpc.NewServer()
if err := rpcS.RegisterName(pty.GatewayName, gateway); err != nil {
return nil, nil, fmt.Errorf("failed to register 'DirectGateway': %v", err)
return nil, nil, fmt.Errorf("failed to register 'LocalSessionGateway': %v", err)
}
return dmsgConn, rpcS, nil
}
Expand Down
143 changes: 0 additions & 143 deletions pkg/dmsgpty/pty/client.go

This file was deleted.

152 changes: 0 additions & 152 deletions pkg/dmsgpty/pty/gateway.go

This file was deleted.

Loading

0 comments on commit 8cda7a1

Please sign in to comment.