diff --git a/pkg/dmsgpty/cli.go b/pkg/dmsgpty/cli.go index 5273c7a885..ad90fb42b1 100644 --- a/pkg/dmsgpty/cli.go +++ b/pkg/dmsgpty/cli.go @@ -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...))). @@ -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) diff --git a/pkg/dmsgpty/host.go b/pkg/dmsgpty/host.go index 14d4c5ac5e..905c583713 100644 --- a/pkg/dmsgpty/host.go +++ b/pkg/dmsgpty/host.go @@ -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. @@ -119,7 +119,7 @@ func NewHostFromDmsgClient( return nil, err } - ptyS, err := pty.NewServer( + ptyS, err := pty.NewSessionServer( logging.MustGetLogger("dmsgpty-server"), pk, sk, @@ -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 @@ -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 } @@ -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 } diff --git a/pkg/dmsgpty/pty/client.go b/pkg/dmsgpty/pty/client.go deleted file mode 100644 index cf45b7a51c..0000000000 --- a/pkg/dmsgpty/pty/client.go +++ /dev/null @@ -1,143 +0,0 @@ -package pty - -import ( - "context" - "io" - "net/rpc" - "os" - - "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/creack/pty" - "github.com/sirupsen/logrus" -) - -var empty = &struct{}{} - -// Client is a pty client. -type Client struct { - ctx context.Context - log logrus.FieldLogger - rpcC *rpc.Client -} - -// NewPtyClient creates a new pty client. -func NewPtyClient(ctx context.Context, log logrus.FieldLogger, conn io.ReadWriteCloser) *Client { - if log == nil { - log = logging.MustGetLogger("dmsgpty-client") - } - return &Client{ - ctx: ctx, - log: log, - rpcC: rpc.NewClient(conn), - } -} - -// TODO(evanlinjin): determine if needed. -//func NewPtyClientWithTp(log logrus.FieldLogger, _ cipher.SecKey, tp *dmsg.Transport) (*Client, error) { -// if log == nil { -// log = logging.MustGetLogger("dmsgpty-client") -// } -// -// // TODO(evanlinjin): Wrap connection with noise. -// //ns, err := noise.New(noise.HandshakeXK, noise.Config{ -// // LocalPK: tp.LocalPK(), -// // LocalSK: sk, -// // RemotePK: tp.RemotePK(), -// // Initiator: true, -// //}) -// //if err != nil { -// // log.WithError(err).Fatal("NewPtyClientWithTp: failed to init noise") -// // return nil, err -// //} -// //conn, err := noise.WrapConn(tp, ns, noise.AcceptHandshakeTimeout) -// //if err != nil { -// // return nil, err -// //} -// -// return &Client{ -// log: log, -// rpcC: rpc.NewClient(tp), -// }, nil -//} - -// Close closes the pty and closes the connection to the remote. -func (c *Client) Close() error { - if err := c.Stop(); err != nil { - c.log.WithError(err).Warn("failed to stop remote pty") - } - return c.rpcC.Close() -} - -// Start starts the pty. -func (c *Client) Start(name string, arg ...string) error { - size, err := pty.GetsizeFull(os.Stdin) - if err != nil { - c.log.WithError(err).Warn("failed to obtain terminal size") - size = nil - } - return c.call("Start", &CommandReq{Name: name, Arg: arg, Size: size}, empty) -} - -// Stop stops the pty. -func (c *Client) Stop() error { - return c.call("Stop", empty, empty) -} - -// Read reads from the pty. -func (c *Client) Read(b []byte) (int, error) { - reqN := len(b) - var respB []byte - err := c.call("Read", &reqN, &respB) - return copy(b, respB), processRPCError(err) -} - -// Write writes to the pty. -func (c *Client) Write(b []byte) (int, error) { - var n int - err := c.call("Write", &b, &n) - return n, processRPCError(err) -} - -// SetPtySize sets the pty size. -func (c *Client) SetPtySize(size *pty.Winsize) error { - return c.call("SetPtySize", size, empty) -} - -func (c *Client) call(method string, args, reply interface{}) error { - call := c.rpcC.Go(ptyMethod(method), args, reply, nil) - select { - case <-c.ctx.Done(): - return c.ctx.Err() - case <-call.Done: - return call.Error - } -} - -func ptyMethod(m string) string { - return GatewayName + "." + m -} - -// GetPtySize obtains the size of the local terminal. -func GetPtySize(t *os.File) (*pty.Winsize, error) { return pty.GetsizeFull(t) } - -func processRPCError(err error) error { - if err != nil { - switch err.Error() { - case io.EOF.Error(): - return io.EOF - case io.ErrUnexpectedEOF.Error(): - return io.ErrUnexpectedEOF - case io.ErrClosedPipe.Error(): - return io.ErrClosedPipe - case io.ErrNoProgress.Error(): - return io.ErrNoProgress - case io.ErrShortBuffer.Error(): - return io.ErrShortBuffer - case io.ErrShortWrite.Error(): - return io.ErrShortWrite - default: - return err - } - } - return nil -} diff --git a/pkg/dmsgpty/pty/gateway.go b/pkg/dmsgpty/pty/gateway.go deleted file mode 100644 index c7fd96152a..0000000000 --- a/pkg/dmsgpty/pty/gateway.go +++ /dev/null @@ -1,152 +0,0 @@ -package pty - -import ( - "errors" - "os" - "os/exec" - "sync" - - "github.com/creack/pty" -) - -// Pty errors. -var ( - ErrPtyAlreadyRunning = errors.New("a pty session is already running") - ErrPtyNotRunning = errors.New("no active pty session") -) - -// GatewayName is the universal RPC gateway name. -const GatewayName = "DirectGateway" - -// Gateway represents a pty gateway. -type Gateway interface { - Start(req *CommandReq, _ *struct{}) error - Stop(_, _ *struct{}) error - Read(reqN *int, respB *[]byte) error - Write(reqB *[]byte, respN *int) error - SetPtySize(size *pty.Winsize, _ *struct{}) error -} - -// DirectGateway is the gateway to a local pty. -type DirectGateway struct { - pty *os.File - mx sync.RWMutex -} - -// NewDirectGateway creates a new gateway to a local pty. -func NewDirectGateway() Gateway { - return new(DirectGateway) -} - -// CommandReq represents a pty command. -type CommandReq struct { - Name string - Arg []string - Size *pty.Winsize -} - -// Start starts the local pty. -func (g *DirectGateway) Start(req *CommandReq, _ *struct{}) error { - g.mx.Lock() - defer g.mx.Unlock() - - if g.pty != nil { - return ErrPtyAlreadyRunning - } - - f, err := pty.StartWithSize(exec.Command(req.Name, req.Arg...), req.Size) //nolint:gosec - if err != nil { - return err - } - - g.pty = f - return nil -} - -// Stop stops the local pty. -func (g *DirectGateway) Stop(_, _ *struct{}) error { - g.mx.Lock() - defer g.mx.Unlock() - - if g.pty == nil { - return ErrPtyNotRunning - } - - err := g.pty.Close() - g.pty = nil - return err -} - -// Read reads from the local pty. -func (g *DirectGateway) Read(reqN *int, respB *[]byte) error { - return ptyReadLock(g, func() error { - b := make([]byte, *reqN) - n, err := g.pty.Read(b) - *respB = b[:n] - return err - }) -} - -// Write writes to the local pty. -func (g *DirectGateway) Write(wb *[]byte, n *int) error { - return ptyReadLock(g, func() (err error) { - *n, err = g.pty.Write(*wb) - return - }) -} - -// SetPtySize sets the local pty's window size. -func (g *DirectGateway) SetPtySize(size *pty.Winsize, _ *struct{}) error { - return ptyReadLock(g, func() error { - return pty.Setsize(g.pty, size) - }) -} - -func ptyReadLock(g *DirectGateway, fn func() error) error { - g.mx.RLock() - defer g.mx.RUnlock() - if g.pty == nil { - return ErrPtyNotRunning - } - return fn() -} - -// ProxyGateway is an RPC gateway for a remote pty. -type ProxyGateway struct { - ptyC *Client -} - -// NewProxyGateway creates a new pty-proxy gateway -func NewProxyGateway(ptyC *Client) Gateway { - return &ProxyGateway{ptyC: ptyC} -} - -// Start starts the remote pty. -func (g *ProxyGateway) Start(req *CommandReq, _ *struct{}) error { - return g.ptyC.Start(req.Name, req.Arg...) -} - -// Stop stops the remote pty. -func (g *ProxyGateway) Stop(_, _ *struct{}) error { - return g.ptyC.Stop() -} - -// Read reads from the remote pty. -func (g *ProxyGateway) Read(reqN *int, respB *[]byte) error { - b := make([]byte, *reqN) - n, err := g.ptyC.Read(b) - *respB = b[:n] - return err -} - -// Write writes to the remote pty. -func (g *ProxyGateway) Write(reqB *[]byte, respN *int) error { - var err error - *respN, err = g.ptyC.Write(*reqB) - return err -} - -// SetPtySize sets the remote pty's window size. -func (g *ProxyGateway) SetPtySize(size *pty.Winsize, _ *struct{}) error { - return g.ptyC.SetPtySize(size) -} diff --git a/pkg/dmsgpty/pty/server.go b/pkg/dmsgpty/pty/server.go deleted file mode 100644 index 2b03a952a0..0000000000 --- a/pkg/dmsgpty/pty/server.go +++ /dev/null @@ -1,152 +0,0 @@ -package pty - -import ( - "context" - "encoding/json" - "net" - "net/rpc" - "sync" - - "github.com/SkycoinProject/skywire-mainnet/pkg/dmsgpty/ptycfg" - - "github.com/SkycoinProject/dmsg" - "github.com/SkycoinProject/dmsg/cipher" - "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/sirupsen/logrus" -) - -// Server represents the dmsgpty-server. -type Server struct { - log logrus.FieldLogger - - pk cipher.PubKey - sk cipher.SecKey - auth ptycfg.Whitelist -} - -// NewServer instantiates a dmsgpty-server. -func NewServer(log logrus.FieldLogger, pk cipher.PubKey, sk cipher.SecKey, authFile string) (*Server, error) { - if log == nil { - log = logging.MustGetLogger("dmsgpty-server") - } - - auth, err := ptycfg.NewJSONFileWhiteList(authFile) - if err != nil { - return nil, err - } - - authAll, err := auth.All() - if err != nil { - return nil, err - } - - authStr, _ := json.MarshalIndent(authAll, "", "\t") //nolint:errcheck - - log.Info("whitelist:", string(authStr)) - - return &Server{ - log: log, - pk: pk, - sk: sk, - auth: auth, - }, nil -} - -// Auth returns the internal whitelist used by dmsgpty-server. -func (s *Server) Auth() ptycfg.Whitelist { return s.auth } - -// Serve serves the dmsgpty-server for remote requests over dmsg. -func (s *Server) Serve(ctx context.Context, lis *dmsg.Listener) { - wg := new(sync.WaitGroup) - defer wg.Wait() - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - for { - st, err := lis.AcceptStream() - if err != nil { - if err, ok := err.(net.Error); ok && err.Temporary() { - s.log.WithError(err).Warn("acceptTransport temporary error.") - continue - } - s.log.WithError(err).Warn("acceptTransport error.") - return - } - - remote := st.RemoteAddr().(dmsg.Addr) - log := s.log.WithField("remote_pk", remote.PK) - log.Info("received request") - - ok, err := s.auth.Get(remote.PK) - if err != nil { - log.WithError(err).Error("dmsgpty-server whitelist error") - return - } - if !ok { - log.Warn("rejected by whitelist") - if err := st.Close(); err != nil { - log.WithError(err).Warn("close transport error") - } - - continue - } - - log.Info("request accepted") - wg.Add(1) - - go func(st *dmsg.Stream) { - done := make(chan struct{}) - defer func() { - close(done) - wg.Done() - }() - go func() { - select { - case <-done: - case <-ctx.Done(): - _ = st.Close() //nolint:errcheck - } - }() - s.handleConn(log, remote.PK, st) - }(st) - } -} - -// handles connection (assumes remote party is authorized to connect). -func (s *Server) handleConn(log logrus.FieldLogger, _ cipher.PubKey, conn net.Conn) { - - // TODO(evanlinjin): Wrap connection with noise. - //ns, err := noise.New(noise.HandshakeXK, noise.Config{ - // LocalPK: s.conf.PK, - // LocalSK: s.conf.SK, - // RemotePK: rPK, - // Initiator: false, - //}) - //if err != nil { - // log.WithError(err).Fatal("handleConn: failed to init noise") - //} - //conn, err = noise.WrapConn(conn, ns, noise.AcceptHandshakeTimeout) - //if err != nil { - // log.WithError(err).Warn("handleConn: noise handshake failed") - // return - //} - - // Prepare and serve gateway to connection. - ptyG := NewDirectGateway() - - defer func() { _ = ptyG.Stop(nil, nil) }() //nolint:errcheck - - rpcS := rpc.NewServer() - if err := rpcS.Register(ptyG); err != nil { - log.WithError(err).Fatal("handleConn: failed to register pty gateway") - return - } - rpcS.ServeConn(conn) -} - -// RequestPty requests a remote pty over dmsg. -func (s *Server) RequestPty(ctx context.Context, rPK cipher.PubKey, conn net.Conn) Gateway { - log := logging.MustGetLogger("dmsgpty-client:" + rPK.String()) - return NewProxyGateway(NewPtyClient(ctx, log, conn)) -} diff --git a/pkg/dmsgpty/pty/server_test.go b/pkg/dmsgpty/pty/server_test.go deleted file mode 100644 index 1c606484fa..0000000000 --- a/pkg/dmsgpty/pty/server_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package pty - -// TODO(evanlinjin): Fix this test. -//func TestServer_Serve(t *testing.T) { -// // prepare PKs -// aPK, aSK, err := cipher.GenerateDeterministicKeyPair([]byte("a seed")) -// require.NoError(t, err) -// bPK, bSK, err := cipher.GenerateDeterministicKeyPair([]byte("b seed")) -// require.NoError(t, err) -// -// // prepare auth file -// authF, err := ioutil.TempFile(os.TempDir(), "") -// require.NoError(t, err) -// authFName := authF.Name() -// defer func() { require.NoError(t, os.Remove(authFName)) }() -// require.NoError(t, authF.Close()) -// auth, err := ptycfg2.NewJsonFileWhiteList(authFName) -// require.NoError(t, err) -// require.NoError(t, auth.Add(aPK, bPK)) -// -// t.Run("Whitelist_Get", func(t *testing.T) { -// for _, pk := range []cipher.PubKey{aPK, bPK} { -// ok, err := auth.Get(pk) -// require.NoError(t, err) -// require.True(t, ok) -// } -// }) -// -// // prepare dmsg env -// dmsgD := disc.NewMock() -// sPK, sSK, err := cipher.GenerateDeterministicKeyPair([]byte("dmsg server seed")) -// require.NoError(t, err) -// sL, err := nettest.NewLocalListener("tcp") -// require.NoError(t, err) -// defer func() { _ = sL.Close() }() //nolint:errcheck -// dmsgS, err := dmsg.NewServer(sPK, sSK, "", sL, dmsgD) -// require.NoError(t, err) -// go func() { _ = dmsgS.Serve() }() //nolint:errcheck -// -// dcA := dmsg.NewClient(aPK, aSK, dmsgD, dmsg.SetLogger(logging.MustGetLogger("dmsgC_A"))) -// require.NoError(t, dcA.InitiateServerConnections(context.TODO(), 1)) -// -// dcB := dmsg.NewClient(bPK, bSK, dmsgD, dmsg.SetLogger(logging.MustGetLogger("dmsgC_B"))) -// require.NoError(t, dcB.InitiateServerConnections(context.TODO(), 1)) -// -// // prepare server (a) -// srv, err := NewServer(nil, aPK, aSK, authFName) -// require.NoError(t, err) -// -// // serve (a) -// port := uint16(22) -// lis, err := dcA.Listen(port) -// require.NoError(t, err) -// -// ctx, cancel := context.WithCancel(context.TODO()) -// defer cancel() -// go srv.Serve(ctx, lis) -// -// // prepare client (b) -// tpB, err := dcB.Dial(context.TODO(), aPK, port) -// require.NoError(t, err) -// -// ptyB, err := NewPtyClientWithTp(nil, bSK, tpB) -// require.NoError(t, err) -// -// cmds := []string{"ls", /*"ps", "pwd"*/} -// for _, cmd := range cmds { -// require.NoError(t, ptyB.Start(cmd)) -// readB, err := ioutil.ReadAll(ptyB) -// require.EqualError(t, err, "EOF") -// fmt.Println(string(readB)) -// } -// -// //fmt.Println("starting!") -// //_ = ptyB.Start("ls") -// //fmt.Println("started!") -// // -// //readB, err := ioutil.ReadAll(ptyB) -// //require.EqualError(t, err, "EOF") -// //fmt.Println(string(readB)) -// -// require.NoError(t, ptyB.Close()) -//} diff --git a/pkg/dmsgpty/ptycfg/auth.go b/pkg/dmsgpty/ptycfg/auth.go deleted file mode 100644 index 817b5c2e5e..0000000000 --- a/pkg/dmsgpty/ptycfg/auth.go +++ /dev/null @@ -1,108 +0,0 @@ -package ptycfg - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - - "github.com/SkycoinProject/dmsg/cipher" -) - -// Whitelist represents a whitelist of public keys. -type Whitelist interface { - Get(pk cipher.PubKey) (bool, error) - All() (map[cipher.PubKey]bool, error) - Add(pks ...cipher.PubKey) error - Remove(pks ...cipher.PubKey) error -} - -// NewJSONFileWhiteList represents a JSON file implementation of a whitelist. -func NewJSONFileWhiteList(fileName string) (Whitelist, error) { - fileName, err := filepath.Abs(fileName) - if err != nil { - return nil, err - } - - if err := os.MkdirAll(filepath.Dir(fileName), 0750); err != nil { - return nil, err - } - - return &jsonFileWhitelist{fileName: fileName}, nil -} - -type jsonFileWhitelist struct { - fileName string -} - -func (w *jsonFileWhitelist) Get(pk cipher.PubKey) (bool, error) { - var ok bool - err := w.open(os.O_RDONLY|os.O_CREATE, func(pkMap map[cipher.PubKey]bool, _ *os.File) error { - ok = pkMap[pk] - return nil - }) - return ok, jsonFileErr(err) -} - -func (w *jsonFileWhitelist) All() (map[cipher.PubKey]bool, error) { - var out map[cipher.PubKey]bool - err := w.open(os.O_RDONLY|os.O_CREATE, func(pkMap map[cipher.PubKey]bool, _ *os.File) error { - out = pkMap - return nil - }) - return out, jsonFileErr(err) -} - -func (w *jsonFileWhitelist) Add(pks ...cipher.PubKey) error { - return jsonFileErr(w.open(os.O_RDWR|os.O_CREATE, func(pkMap map[cipher.PubKey]bool, f *os.File) error { - for _, pk := range pks { - pkMap[pk] = true - } - return json.NewEncoder(f).Encode(pkMap) - })) -} - -func (w *jsonFileWhitelist) Remove(pks ...cipher.PubKey) error { - return jsonFileErr(w.open(os.O_RDWR|os.O_CREATE, func(pkMap map[cipher.PubKey]bool, f *os.File) error { - for _, pk := range pks { - delete(pkMap, pk) - } - return json.NewEncoder(f).Encode(pkMap) - })) -} - -func (w *jsonFileWhitelist) open(perm int, fn func(pkMap map[cipher.PubKey]bool, f *os.File) error) error { - f, err := os.OpenFile(w.fileName, perm, 0600) - if err != nil { - return err - } - defer func() { _ = f.Close() }() //nolint:errcheck - - // get file size - info, err := f.Stat() - if err != nil { - return err - } - - // read public key map from file - pks := make(map[cipher.PubKey]bool) - if info.Size() > 0 { - if err := json.NewDecoder(f).Decode(&pks); err != nil { - return err - } - } - - // seek back to start of file - if _, err := f.Seek(0, 0); err != nil { - return err - } - - return fn(pks, f) -} - -func jsonFileErr(err error) error { - if err != nil { - return fmt.Errorf("json file whitelist: %v", err) - } - return nil -} diff --git a/pkg/dmsgpty/ptycfg/client.go b/pkg/dmsgpty/ptycfg/client.go deleted file mode 100644 index 95a20efc25..0000000000 --- a/pkg/dmsgpty/ptycfg/client.go +++ /dev/null @@ -1,32 +0,0 @@ -package ptycfg - -import ( - "io" - "net/rpc" - - "github.com/SkycoinProject/dmsg/cipher" -) - -// Used for RPC calls -var empty struct{} - -// ViewWhitelist obtains the whitelist entries from host. -func ViewWhitelist(conn io.ReadWriteCloser) ([]cipher.PubKey, error) { - var pks []cipher.PubKey - err := rpc.NewClient(conn).Call(rpcMethod("Whitelist"), &empty, &pks) - return pks, err -} - -// WhitelistAdd adds a whitelist entry to host. -func WhitelistAdd(conn io.ReadWriteCloser, pks ...cipher.PubKey) error { - return rpc.NewClient(conn).Call(rpcMethod("WhitelistAdd"), &pks, &empty) -} - -// WhitelistRemove removes a whitelist entry from host. -func WhitelistRemove(conn io.ReadWriteCloser, pks ...cipher.PubKey) error { - return rpc.NewClient(conn).Call(rpcMethod("WhitelistRemove"), &pks, &empty) -} - -func rpcMethod(m string) string { - return GatewayName + "." + m -} diff --git a/pkg/dmsgpty/ptycfg/gateway.go b/pkg/dmsgpty/ptycfg/gateway.go deleted file mode 100644 index 47ff03ba0b..0000000000 --- a/pkg/dmsgpty/ptycfg/gateway.go +++ /dev/null @@ -1,46 +0,0 @@ -package ptycfg - -import ( - "context" - - "github.com/SkycoinProject/dmsg/cipher" -) - -// GatewayName is the RPC gateway name for 'Cfg' type requests. -const GatewayName = "CfgGateway" - -// Gateway is the configuration gateway. -type Gateway struct { - ctx context.Context - auth Whitelist -} - -// NewGateway creates a new configuration gateway. -func NewGateway(ctx context.Context, auth Whitelist) *Gateway { - return &Gateway{ctx: ctx, auth: auth} -} - -// Whitelist obtains the whitelist entries. -func (g *Gateway) Whitelist(_ *struct{}, out *[]cipher.PubKey) error { - pks, err := g.auth.All() - if err != nil { - return err - } - *out = make([]cipher.PubKey, 0, len(pks)) - for pk, ok := range pks { - if ok { - *out = append(*out, pk) - } - } - return nil -} - -// WhitelistAdd adds a whitelist entry. -func (g *Gateway) WhitelistAdd(in *[]cipher.PubKey, _ *struct{}) error { - return g.auth.Add(*in...) -} - -// WhitelistRemove removes a whitelist entry. -func (g *Gateway) WhitelistRemove(in *[]cipher.PubKey, _ *struct{}) error { - return g.auth.Remove(*in...) -} diff --git a/pkg/dmsgpty/ptyutil/cmdutil.go b/pkg/dmsgpty/ptyutil/cmdutil.go index 511c70f98a..9e9d865568 100644 --- a/pkg/dmsgpty/ptyutil/cmdutil.go +++ b/pkg/dmsgpty/ptyutil/cmdutil.go @@ -75,8 +75,7 @@ const ( ConfDir = ".dmsgpty" ) -// TODO(evanlinjin): Determine if this is still needed. -//func DefaultKeysPath() string { return filepath.Join(pathutil.HomeDir(), ConfDir, "keys.json") } - // DefaultAuthPath returns the default auth path. -func DefaultAuthPath() string { return filepath.Join(pathutil.HomeDir(), ConfDir, "whitelist.json") } +func DefaultAuthPath() string { + return filepath.Join(pathutil.HomeDir(), ConfDir, "whitelist.json") +}