Documentation ¶
Overview ¶
this file define the type and functions that serve as the clients data base
This file contains the Pane type and all associated functions ¶
This file holds the struct and code to communicate with remote peers over webrtc data channels.
Index ¶
- Constants
- Variables
- func CompressFP(hex string) string
- func DecodeOffer(dst interface{}, src []byte) error
- func EncodeOffer(dst []byte, obj interface{}) (int, error)
- func ExecCommand(command []string, env map[string]string, ws *pty.Winsize, pID int, fp string) (*exec.Cmd, io.ReadWriteCloser, error)
- func ExtractFP(certificate *webrtc.Certificate) (string, error)
- func GetFingerprint(offer *webrtc.SessionDescription) (string, error)
- func ParseWinsize(s string) (*pty.Winsize, error)
- func SetLastPeer(p *Peer)
- func Shutdown()
- type AckArgs
- type AddPaneArgs
- type Buffer
- type CTRLMessage
- type CandidatePairStats
- type Client
- type ClientsDB
- type Conf
- type NAckArgs
- type Pane
- type PanesDB
- type Peer
- func (peer *Peer) AddCandidate(candidate webrtc.ICECandidateInit) error
- func (peer *Peer) Broadcast(typ string, args interface{}) error
- func (peer *Peer) Close()
- func (peer *Peer) GetCandidatePair(ret *CandidatePairStats) error
- func (peer *Peer) GetOrCreatePane(d *webrtc.DataChannel) (*Pane, error)
- func (peer *Peer) Listen(offer webrtc.SessionDescription) (*webrtc.SessionDescription, error)
- func (peer *Peer) OnChannelReq(d *webrtc.DataChannel)
- func (peer *Peer) Reconnect(d *webrtc.DataChannel, id int) (*Pane, error)
- func (peer *Peer) SendAck(cm CTRLMessage, body string) error
- func (peer *Peer) SendControlMessage(typ string, args interface{}) error
- func (peer *Peer) SendControlMessageAndWait(typ string, args interface{}) (string, error)
- func (peer *Peer) SendMessage(msg []byte) error
- func (peer *Peer) SendNack(cm CTRLMessage, desc string) error
- type PtyMuxInterface
- type PtyMuxType
- type ReconnectPaneArgs
- type ResizeArgs
- type RestoreArgs
- type RunCommandInterface
- type SetClipboardArgs
- type SetPayloadArgs
Constants ¶
const OutBufSize = 4096
Variables ¶
var ( // Peers holds all the peers (connected and disconnected) Peers map[string]*Peer // Payload holds the client's payload Payload []byte // WebRTCAPI is the gateway to webrtc calls WebRTCAPI *webrtc.API CDB = NewClientsDB() )
var Panes = NewPanesDB()
Panes is an array that hol;ds all the panes
Functions ¶
func CompressFP ¶
func DecodeOffer ¶
DecodeOffer decodes the input from base64
func EncodeOffer ¶
EncodeOffer encodes the input in base64
func ExecCommand ¶
func ExecCommand(command []string, env map[string]string, ws *pty.Winsize, pID int, fp string) (*exec.Cmd, io.ReadWriteCloser, error)
ExecCommand in ahelper function for executing a command
func GetFingerprint ¶
GetFingerprint extract the fingerprints from a client's offer and returns a compressed fingerprint
func ParseWinsize ¶
ParseWinsize gets a string in the format of "24x80" and returns a Winsize
Types ¶
type AckArgs ¶
type AckArgs struct { // Ref holds the message id the error refers to or 0 for system errors Ref int `json:"ref"` Body string `json:"body,omitempty"` }
AckArgs is a type to hold the args for an Ack message
type AddPaneArgs ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a used to represet a fixed size buffer with markers
func (*Buffer) GetSinceMarker ¶
GetSinceMarker returns a byte slice with all the accumlated data since a given marker id and deltes the marker. If the marker is too ancient cycle or id is -1 then all the buffer's data is returned.
type CTRLMessage ¶
type CTRLMessage struct { // Time is in msec since EPOCH Time int64 `json:"time"` Ref int `json:"message_id"` Type string `json:"type"` Args interface{} `json:"args"` // TODO: add omitempty }
CTRLMessage type holds control messages passed over the control channel
type CandidatePairStats ¶ added in v1.5.0
type CandidatePairStats struct { FP string `json:"fp"` LocalAddr string `json:"local_addr"` // IP:Port LocalProtocol string `json:"local_proto"` LocalType string `json:"local_type"` RemoteAddr string `json:"remote_addr"` RemoteProtocol string `json:"remote_proto"` RemoteType string `json:"remote_type"` }
CandidatePairStats is a struct that holds the values of a ICE candidate pair
func (*CandidatePairStats) Write ¶ added in v1.5.0
func (p *CandidatePairStats) Write(w *tabwriter.Writer)
CandidatePairStats.Write writes the candidate pair to a tabwriter
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client ties together the dta channel, its peer and the pane
type ClientsDB ¶
type ClientsDB struct {
// contains filtered or unexported fields
}
ClientsDB represents a data channels data base
type Conf ¶
type Conf struct { AckTimeout time.Duration Certificate *webrtc.Certificate DisconnectTimeout time.Duration Env map[string]string FailedTimeout time.Duration GatheringTimeout time.Duration GetICEServers func() ([]webrtc.ICEServer, error) GetWelcome func() string KeepAliveInterval time.Duration Logger *zap.SugaredLogger OnCTRLMsg func(*Peer, *CTRLMessage, json.RawMessage) OnStateChange func(*Peer, webrtc.PeerConnectionState) PortMax uint16 PortMin uint16 RunCommand RunCommandInterface WebrtcSetting *webrtc.SettingEngine }
type NAckArgs ¶
type NAckArgs struct { // Desc hold the textual desciption of the error Desc string `json:"desc"` // Ref holds the message id the error refers to or 0 for system errors Ref int `json:"ref"` }
NAckArgs is a type that holds the args for an error message
type Pane ¶
type Pane struct { sync.Mutex ID int // C holds the exectuted command C *exec.Cmd IsRunning bool TTY io.ReadWriteCloser Buffer *Buffer Ws *pty.Winsize // contains filtered or unexported fields }
Pane type hold a command, a pseudo tty and the connected data channels
func (*Pane) OnMessage ¶
func (pane *Pane) OnMessage(msg webrtc.DataChannelMessage)
OnMessage is called when a new client message is recieved
func (*Pane) ReadLoop ¶
func (pane *Pane) ReadLoop()
ReadLoop reads the tty and send data it finds to the open data channels
func (*Pane) Resize ¶
Resize is used to resize the pane's tty. the function does nothing if it's given a nil size or the current size
type PanesDB ¶
type PanesDB struct {
// contains filtered or unexported fields
}
PanesDB is use to store and access the panes' database
type Peer ¶
type Peer struct { sync.Mutex FP string Token string LastContact *time.Time LastRef int PC *webrtc.PeerConnection Marker int Conf *Conf // contains filtered or unexported fields }
Peer is a type used to remember a client.
func GetActivePeer ¶ added in v1.4.0
func GetActivePeer() *Peer
GetActivePeer returns the last active peer or nil if no peer has been active for a while
func (*Peer) AddCandidate ¶
Peer.AddCandidate adds a new ICE candidate to the peer
func (*Peer) GetCandidatePair ¶ added in v1.5.0
func (peer *Peer) GetCandidatePair(ret *CandidatePairStats) error
func (*Peer) GetOrCreatePane ¶
GetOrCreatePane gets a data channel and creates an associated pane The function parses the label to figure out what it needs to exec:
the command to run and rows & cols of the pseudo tty.
returns a nil when it fails to parse the channel name or when the name is '%' used for command & control channel.
label examples:
simple form with no pty: `echo,Hello world` to start bash: `24x80,bash` to reconnect to pane id 123: `>123`
func (*Peer) OnChannelReq ¶
func (peer *Peer) OnChannelReq(d *webrtc.DataChannel)
OnChannelReq starts the cdc channel. Upon establishing the connection, the client opens this channel with the api version he uses
func (*Peer) Reconnect ¶
Reconnect reconnects to a pane and restore the screen/buffer buffer from that marker if not we use our headless terminal emulator to send over the current screen.
func (*Peer) SendAck ¶
func (peer *Peer) SendAck(cm CTRLMessage, body string) error
SendAck sends an ack for a given control message
func (*Peer) SendControlMessage ¶ added in v1.3.0
SendControlMessage sends a control message to the client
func (*Peer) SendControlMessageAndWait ¶ added in v1.4.0
SendControlMessage sends a control message and wait for ack
func (*Peer) SendMessage ¶ added in v1.3.0
SendMessage marshales a message and sends it over the cdc
type PtyMuxInterface ¶
type PtyMuxInterface interface { Start(c *exec.Cmd) (pty *os.File, err error) StartWithSize(c *exec.Cmd, sz *pty.Winsize) (pty *os.File, err error) }
var PtyMux PtyMuxInterface
type ReconnectPaneArgs ¶
type ReconnectPaneArgs struct {
ID int `json:"id"`
}
type ResizeArgs ¶
ResizeArgs is a type that holds the argumnet to the resize pty command ResizeArgs is a type that holds the argumnet to the resize pty command
type RestoreArgs ¶
type RestoreArgs struct {
Marker int `json:"marker"`
}
RestoreArgs is a type that holds client's authentication arguments.
type RunCommandInterface ¶
type RunCommandInterface func([]string, map[string]string, *pty.Winsize, int, string) (*exec.Cmd, io.ReadWriteCloser, error)
RunCommandInterface is an interface for a function that runs a command
type SetClipboardArgs ¶ added in v1.4.0
type SetPayloadArgs ¶
type SetPayloadArgs struct { // Ref holds the message id the error refers to or 0 for system errors Payload json.RawMessage `json:"payload"` }
SetPayloadArgs is a type to hold the args for a set_payload type of a message