multiplex

package
v1.8.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathCreateConn = "createConn"
	PathStd        = "std"
	PathStdin      = "stdin"
	PathStdout     = "stdout"
	PathStderr     = "stderr"
	PathSession    = "createSession"
)
View Source
const Delim = '\n'

Variables

View Source
var (
	SocketDir  = path.Dir(SocketPath)
	SocketPath = homeDir + "/.config/sshw/sshw.socket"
)

Functions

func Copy

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

func ExecNode

func ExecNode(node *sshwctl.Node) error

func IsRunning

func IsRunning() bool

func Transport

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

Types

type Agent

type Agent struct {
	Node   *sshwctl.Node
	Client sshwctl.Client
}

func (*Agent) Forward

func (c *Agent) Forward(num int64) chan error

forward stdout, stderr, stdin to master

func (*Agent) GetNum

func (c *Agent) GetNum() (int64, error)

get a session number

func (*Agent) OpenSession

func (c *Agent) OpenSession(num int64) error

open a new session

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 conn

func (*MasterHandler) CloseStd

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

close sshwctl std conn

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, w ResponseWriter, stdConn *StdConn) (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()

close all connection

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

Jump to

Keyboard shortcuts

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