multiplex

package
v1.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathCreateConn = "createConn"
	PathStd        = "std"
	PathStdin      = "stdin"
	PathStdout     = "stdout"
	PathStderr     = "stderr"
	PathSession    = "session"
	PathTerminal   = PathSession + "/terminal"
	PathScp        = PathSession + "/scp"
	PathCancel     = "/cancel"
)
View Source
const Delim = '\n'

Variables

View Source
var (
	SocketPath = path.Join(sshwctl.SshwDir, "sshw.socket")
)

Functions

func Copy

func Copy(dst io.Writer, src io.Reader, errCh chan error)

func Get

func Get(via *net.UnixConn, num int, filenames []string) ([]*os.File, error)

Get receives file descriptors from a Unix domain socket.

Num specifies the expected number of file descriptors in one message. Internal files' names to be assigned are specified via optional filenames argument.

You need to close all files in the returned slice. The slice can be non-empty even if this function returns an error.

Use net.FileConn() if you're receiving a network connection.

func GetNum added in v1.9.3

func GetNum() (int64, error)

get a session number

func IsRunning

func IsRunning() bool

func NewClient added in v1.8.1

func NewClient(node *sshwctl.Node) sshwctl.Client

func Put

func Put(via *net.UnixConn, files ...*os.File) error

Put sends file descriptors to Unix domain socket.

Please note that the number of descriptors in one message is limited and is rather small. Use conn.File() to get a file if you want to put a network connection.

func Setup

func Setup() error

make ~/.config/sshw

func Transport

func Transport(conn1 io.ReadWriter, conn2 io.ReadWriter) error

Types

type ChangeWindowRequest

type ChangeWindowRequest struct {
	Width  int
	Height int
}

type ClientRequest

type ClientRequest struct {
	// used to get a stdconn
	Num int64
	// ssh config
	Node *sshwctl.Node
}

create a ssh session

type Handler

type Handler interface {
	Serve(w ResponseWriter, req *Request)
}

func NewMasterHandler

func NewMasterHandler() Handler

type JsonProtoReader

type JsonProtoReader struct {
	R io.Reader
}

func (*JsonProtoReader) Read

func (j *JsonProtoReader) Read(i interface{}) error

type JsonProtoWriter

type JsonProtoWriter struct {
	W io.Writer
}

func (*JsonProtoWriter) Write

func (j *JsonProtoWriter) Write(i interface{}) error

type MasterHandler

type MasterHandler struct {
	// contains filtered or unexported fields
}

func (*MasterHandler) CloseConn

func (m *MasterHandler) CloseConn(w ResponseWriter)

close serve connIn

func (*MasterHandler) CloseStd

func (m *MasterHandler) CloseStd(stdConn *StdConn)

close sshwctl std connIn

func (*MasterHandler) Fail

func (m *MasterHandler) Fail(w ResponseWriter, err error)

func (*MasterHandler) GetClient

func (m *MasterHandler) GetClient(name string) (sshwctl.Client, bool)

func (*MasterHandler) Metric

func (m *MasterHandler) Metric()

show metric data

func (*MasterHandler) NewClient

func (m *MasterHandler) NewClient(node *sshwctl.Node) (sshwctl.Client, error)

func (*MasterHandler) Process

func (m *MasterHandler) Process(w ResponseWriter, stdConn *StdConn, callables ...func() error)

func (*MasterHandler) PutClient

func (m *MasterHandler) PutClient(name string, client sshwctl.Client)

func (*MasterHandler) Serve

func (m *MasterHandler) Serve(w ResponseWriter, req *Request)

serve a sshwctl request

func (*MasterHandler) Success

func (m *MasterHandler) Success(w ResponseWriter, data interface{})

type PlainResult

type PlainResult struct {
	// if code is -1, return error message
	Message string
	// -1 fail, 0 success
	Code int
	// extension data
	Data json.RawMessage
}

client and server standard response

type ProtoReader

type ProtoReader interface {
	Read(i interface{}) error
}

func NewJsonProtoReader

func NewJsonProtoReader(Reader io.Reader) ProtoReader

type ProtoWriter

type ProtoWriter interface {
	Write(i interface{}) error
}

func NewJsonProtoWriter

func NewJsonProtoWriter(Writer io.Writer) ProtoWriter

type Request

type Request struct {
	Path string
	Body json.RawMessage

	// reader
	R ProtoReader `json:"-"`
}

type Response

type Response struct {
	Body json.RawMessage
}

type ResponseWriter

type ResponseWriter interface {
	Write(resp *Response) error

	Conn() net.Conn
}

type Server

type Server struct {
	// local socket path
	SocketPath string

	Handler Handler
}

func NewServer

func NewServer() *Server

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

type StdConn

type StdConn struct {
	Num    int64
	Stdin  net.Conn
	Stdout net.Conn
	Stderr net.Conn
}

func (*StdConn) Close

func (s *StdConn) Close() error

type TimerEntry

type TimerEntry struct {
	Key         string
	Value       interface{}
	ExpiredTime time.Time
	Callback    func(key string, value interface{})
	ReferNum    int64
}

func (*TimerEntry) Done

func (t *TimerEntry) Done()

func (*TimerEntry) IncrRef

func (t *TimerEntry) IncrRef()

func (*TimerEntry) IsExpired

func (t *TimerEntry) IsExpired() bool

func (*TimerEntry) ZeroRef

func (t *TimerEntry) ZeroRef() bool

type TimerMap

type TimerMap struct {
	Kv       sync.Map
	Interval time.Duration
	Timeout  time.Duration
}

to control recycle of resource open a daemon goroutine, poll map periodically and delete data that is expired and zeroRef

func NewTimerMap

func NewTimerMap() *TimerMap

func (*TimerMap) Daemon

func (t *TimerMap) Daemon()

func (*TimerMap) Delete

func (t *TimerMap) Delete(key string)

func (*TimerMap) Done

func (t *TimerMap) Done(key string)

func (*TimerMap) IncrRef

func (t *TimerMap) IncrRef(key string)

func (*TimerMap) Insert

func (t *TimerMap) Insert(key string, value interface{}, callback func(key string, value interface{}))

func (*TimerMap) Load

func (t *TimerMap) Load(key string) (interface{}, bool)

func (*TimerMap) Size

func (t *TimerMap) Size() int

type WrapperConn added in v1.9.3

type WrapperConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func Forward added in v1.9.3

func Forward(num int64, filters ...func(p []byte)) *WrapperConn

func NewWrapperConn added in v1.10.3

func NewWrapperConn() *WrapperConn

func (*WrapperConn) Close added in v1.9.3

func (w *WrapperConn) Close()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL