Skip to content

Commit

Permalink
fixes for proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov committed Jun 29, 2017
1 parent 3153ecf commit a823255
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 72 deletions.
42 changes: 33 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,23 @@ func (c *ClientConn) Write(buf []byte) (int, error) {
return c.bw.Write(buf)
}

func (c *ClientConn) ColorMap() *ColorMap {
func (c *ClientConn) ColorMap() ColorMap {
return c.colorMap
}

func (c *ClientConn) SetColorMap(cm *ColorMap) {
func (c *ClientConn) SetColorMap(cm ColorMap) {
c.colorMap = cm
}
func (c *ClientConn) DesktopName() []byte {
return c.desktopName
}
func (c *ClientConn) PixelFormat() *PixelFormat {
func (c *ClientConn) PixelFormat() PixelFormat {
return c.pixelFormat
}
func (c *ClientConn) SetDesktopName(name []byte) {
copy(c.desktopName, name)
}
func (c *ClientConn) SetPixelFormat(pf *PixelFormat) error {
func (c *ClientConn) SetPixelFormat(pf PixelFormat) error {
c.pixelFormat = pf
return nil
}
Expand Down Expand Up @@ -151,7 +151,7 @@ type ClientConn struct {
// map that is used. This should not be modified directly, since
// the data comes from the server.
// Definition in §5 - Representation of Pixel Data.
colorMap *ColorMap
colorMap ColorMap

// Name associated with the desktop, sent from the server.
desktopName []byte
Expand All @@ -169,7 +169,7 @@ type ClientConn struct {
// The pixel format associated with the connection. This shouldn't
// be modified. If you wish to set a new pixel format, use the
// SetPixelFormat method.
pixelFormat *PixelFormat
pixelFormat PixelFormat

quitCh chan struct{}
quit chan struct{}
Expand Down Expand Up @@ -215,6 +215,10 @@ type SetPixelFormat struct {
PF PixelFormat // pixel-format
}

func (msg *SetPixelFormat) String() string {
return fmt.Sprintf("%s", msg.PF)
}

func (*SetPixelFormat) Type() ClientMessageType {
return SetPixelFormatMsgType
}
Expand All @@ -231,7 +235,7 @@ func (msg *SetPixelFormat) Write(c Conn) error {
pf := c.PixelFormat()
// Invalidate the color map.
if pf.TrueColor != 1 {
c.SetColorMap(&ColorMap{})
c.SetColorMap(ColorMap{})
}

return c.Flush()
Expand All @@ -252,6 +256,10 @@ type SetEncodings struct {
Encodings []EncodingType
}

func (msg *SetEncodings) String() string {
return fmt.Sprintf("encnum: %d, encodings[]: { %v }", msg.EncNum, msg.Encodings)
}

func (*SetEncodings) Type() ClientMessageType {
return SetEncodingsMsgType
}
Expand Down Expand Up @@ -308,6 +316,10 @@ type FramebufferUpdateRequest struct {
Width, Height uint16 // width, height
}

func (msg *FramebufferUpdateRequest) String() string {
return fmt.Sprintf("incremental: %d, x: %d, y: %d, width: %d, height: %d", msg.Inc, msg.X, msg.Y, msg.Width, msg.Height)
}

func (*FramebufferUpdateRequest) Type() ClientMessageType {
return FramebufferUpdateRequestMsgType
}
Expand Down Expand Up @@ -337,6 +349,10 @@ type KeyEvent struct {
Key Key // key
}

func (msg *KeyEvent) String() string {
return fmt.Sprintf("down: %d, key: %v", msg.Down, msg.Key)
}

func (*KeyEvent) Type() ClientMessageType {
return KeyEventMsgType
}
Expand Down Expand Up @@ -365,6 +381,10 @@ type PointerEvent struct {
X, Y uint16 // x-, y-position
}

func (msg *PointerEvent) String() string {
return fmt.Sprintf("mask %d, x: %d, y: %d", msg.Mask, msg.X, msg.Y)
}

func (*PointerEvent) Type() ClientMessageType {
return PointerEventMsgType
}
Expand Down Expand Up @@ -394,6 +414,10 @@ type ClientCutText struct {
Text []byte
}

func (msg *ClientCutText) String() string {
return fmt.Sprintf("length: %d, text: %s", msg.Length, msg.Text)
}

func (*ClientCutText) Type() ClientMessageType {
return ClientCutTextMsgType
}
Expand Down Expand Up @@ -509,8 +533,8 @@ type ClientConfig struct {
Handlers []ClientHandler
SecurityHandlers []SecurityHandler
Encodings []Encoding
PixelFormat *PixelFormat
ColorMap *ColorMap
PixelFormat PixelFormat
ColorMap ColorMap
ClientMessageCh chan ClientMessage
ServerMessageCh chan ServerMessage
Exclusive bool
Expand Down
8 changes: 4 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type Conn interface {
Conn() net.Conn
Config() interface{}
Protocol() string
PixelFormat() *PixelFormat
SetPixelFormat(*PixelFormat) error
ColorMap() *ColorMap
SetColorMap(*ColorMap)
PixelFormat() PixelFormat
SetPixelFormat(PixelFormat) error
ColorMap() ColorMap
SetColorMap(ColorMap)
Encodings() []Encoding
SetEncodings([]EncodingType) error
Width() uint16
Expand Down
9 changes: 7 additions & 2 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const (
EncJRLE EncodingType = 22
EncTRLE EncodingType = 15
EncZRLE EncodingType = 16
EncAtenAST2100 EncodingType = 0x57
EncAtenASTJPEG EncodingType = 0x58
EncAtenHermon EncodingType = 0x59
EncAtenYarkon EncodingType = 0x60
EncAtenPilot3 EncodingType = 0x61
EncJPEGQualityLevelPseudo10 EncodingType = -23
EncJPEGQualityLevelPseudo9 EncodingType = -24
EncJPEGQualityLevelPseudo8 EncodingType = -25
Expand All @@ -35,7 +40,7 @@ const (
EncJPEGQualityLevelPseudo3 EncodingType = -30
EncJPEGQualityLevelPseudo2 EncodingType = -31
EncJPEGQualityLevelPseudo1 EncodingType = -32
EncColorPseudo EncodingType = -239
EncCursorPseudo EncodingType = -239
EncXCursorPseudo EncodingType = -240
EncDesktopSizePseudo EncodingType = -223
EncLastRectPseudo EncodingType = -224
Expand All @@ -55,9 +60,9 @@ const (
EncDesktopNamePseudo EncodingType = -307
EncExtendedDesktopSizePseudo EncodingType = -308
EncXvpPseudo EncodingType = -309
EncClientRedirect EncodingType = -311
EncFencePseudo EncodingType = -312
EncContinuousUpdatesPseudo EncodingType = -313
EncClientRedirect EncodingType = -311
)

var bPool = sync.Pool{
Expand Down
2 changes: 1 addition & 1 deletion encoding_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (enc *RawEncoding) Read(c Conn, rect *Rectangle) error {
Loop:
for y := uint16(0); y < rect.Height; y++ {
for x := uint16(0); x < rect.Width; x++ {
color := NewColor(pf, cm)
color := NewColor(&pf, &cm)
if err = color.Read(c); err != nil {
break Loop
}
Expand Down
61 changes: 33 additions & 28 deletions encodingtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (

// ClientMessage is the interface
type ClientMessage interface {
String() string
Type() ClientMessageType
Read(Conn) (ClientMessage, error)
Write(Conn) error
}

// ServerMessage is the interface
type ServerMessage interface {
String() string
Type() ServerMessageType
Read(Conn) (ServerMessage, error)
Write(Conn) error
Expand Down Expand Up @@ -253,7 +255,7 @@ func (*DefaultClientServerInitHandler) Handle(c Conn) error {
c.SetDesktopName(srvInit.NameText)
c.SetWidth(srvInit.FBWidth)
c.SetHeight(srvInit.FBHeight)
c.SetPixelFormat(&srvInit.PixelFormat)
c.SetPixelFormat(srvInit.PixelFormat)

if c.Protocol() == "aten" {
ikvm := struct {
Expand Down
24 changes: 11 additions & 13 deletions pixel_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

var (
PixelFormat8bit *PixelFormat = NewPixelFormat(8)
PixelFormat16bit *PixelFormat = NewPixelFormat(16)
PixelFormat32bit *PixelFormat = NewPixelFormat(32)
PixelFormat8bit PixelFormat = NewPixelFormat(8)
PixelFormat16bit PixelFormat = NewPixelFormat(16)
PixelFormat32bit PixelFormat = NewPixelFormat(32)
)

// PixelFormat describes the way a pixel is formatted for a VNC connection.
Expand Down Expand Up @@ -47,7 +47,7 @@ qemu:
const pixelFormatLen = 16

// NewPixelFormat returns a populated PixelFormat structure.
func NewPixelFormat(bpp uint8) *PixelFormat {
func NewPixelFormat(bpp uint8) PixelFormat {
bigEndian := uint8(0)
// rgbMax := uint16(math.Exp2(float64(bpp))) - 1
rMax := uint16(255)
Expand All @@ -71,11 +71,11 @@ func NewPixelFormat(bpp uint8) *PixelFormat {
// rs, gs, bs = 0, 8, 16
rs, gs, bs = 16, 8, 0
}
return &PixelFormat{bpp, depth, bigEndian, tc, rMax, gMax, bMax, rs, gs, bs, [3]byte{}}
return PixelFormat{bpp, depth, bigEndian, tc, rMax, gMax, bMax, rs, gs, bs, [3]byte{}}
}

// Marshal implements the Marshaler interface.
func (pf *PixelFormat) Marshal() ([]byte, error) {
func (pf PixelFormat) Marshal() ([]byte, error) {
// Validation checks.
switch pf.BPP {
case 8, 16, 32:
Expand Down Expand Up @@ -105,7 +105,7 @@ func (pf *PixelFormat) Marshal() ([]byte, error) {
}

// Read reads from an io.Reader, and populates the PixelFormat.
func (pf *PixelFormat) Read(r io.Reader) error {
func (pf PixelFormat) Read(r io.Reader) error {
buf := make([]byte, pixelFormatLen)
if _, err := io.ReadAtLeast(r, buf, pixelFormatLen); err != nil {
return err
Expand All @@ -114,7 +114,7 @@ func (pf *PixelFormat) Read(r io.Reader) error {
}

// Unmarshal implements the Unmarshaler interface.
func (pf *PixelFormat) Unmarshal(data []byte) error {
func (pf PixelFormat) Unmarshal(data []byte) error {
buf := bPool.Get().(*bytes.Buffer)
buf.Reset()
defer bPool.Put(buf)
Expand All @@ -123,22 +123,20 @@ func (pf *PixelFormat) Unmarshal(data []byte) error {
return err
}

var msg PixelFormat
if err := binary.Read(buf, binary.BigEndian, &msg); err != nil {
if err := binary.Read(buf, binary.BigEndian, &pf); err != nil {
return err
}
*pf = msg

return nil
}

// String implements the fmt.Stringer interface.
func (pf *PixelFormat) String() string {
func (pf PixelFormat) String() string {
return fmt.Sprintf("{ bpp: %d depth: %d big-endian: %d true-color: %d red-max: %d green-max: %d blue-max: %d red-shift: %d green-shift: %d blue-shift: %d }",
pf.BPP, pf.Depth, pf.BigEndian, pf.TrueColor, pf.RedMax, pf.GreenMax, pf.BlueMax, pf.RedShift, pf.GreenShift, pf.BlueShift)
}

func (pf *PixelFormat) order() binary.ByteOrder {
func (pf PixelFormat) order() binary.ByteOrder {
if pf.BigEndian == 1 {
return binary.BigEndian
}
Expand Down
Loading

0 comments on commit a823255

Please sign in to comment.