minor fixes and proper auth

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-06-20 00:55:32 +03:00
parent ff60108c41
commit 4ceeeebeb2
4 changed files with 23 additions and 30 deletions

View File

@ -66,13 +66,7 @@ func (c *ClientConn) SetEncodings(encs []EncodingType) error {
return msg.Write(c) return msg.Write(c)
} }
func (c *ClientConn) UnreadByte() error {
return c.br.UnreadByte()
}
func (c *ClientConn) Flush() error { func (c *ClientConn) Flush() error {
// c.m.Lock()
// defer c.m.Unlock()
return c.bw.Flush() return c.bw.Flush()
} }
@ -85,8 +79,6 @@ func (c *ClientConn) Read(buf []byte) (int, error) {
} }
func (c *ClientConn) Write(buf []byte) (int, error) { func (c *ClientConn) Write(buf []byte) (int, error) {
// c.m.Lock()
// defer c.m.Unlock()
return c.bw.Write(buf) return c.bw.Write(buf)
} }

View File

@ -211,6 +211,7 @@ func (enc *TightPngEncoding) Write(c Conn, rect *Rectangle) error {
buf.Reset() buf.Reset()
defer bPool.Put(buf) defer bPool.Put(buf)
pngEnc := &png.Encoder{CompressionLevel: png.BestSpeed} pngEnc := &png.Encoder{CompressionLevel: png.BestSpeed}
//pngEnc := &png.Encoder{CompressionLevel: png.NoCompression}
if err := pngEnc.Encode(buf, enc.Image); err != nil { if err := pngEnc.Encode(buf, enc.Image); err != nil {
return err return err
} }

View File

@ -68,8 +68,7 @@ func ClientVersionHandler(cfg *ClientConfig, c Conn) error {
if pv == ProtoVersionUnknown { if pv == ProtoVersionUnknown {
return fmt.Errorf("ProtocolVersion handshake failed; unsupported version '%v'", string(version[:])) return fmt.Errorf("ProtocolVersion handshake failed; unsupported version '%v'", string(version[:]))
} }
c.SetProtoVersion(string(version[:]))
c.SetProtoVersion(pv)
if err := binary.Write(c, binary.BigEndian, []byte(pv)); err != nil { if err := binary.Write(c, binary.BigEndian, []byte(pv)); err != nil {
return err return err
@ -120,6 +119,15 @@ func ClientSecurityHandler(cfg *ClientConfig, c Conn) error {
return err return err
} }
var secType SecurityHandler
for _, st := range cfg.SecurityHandlers {
for _, sc := range secTypes {
if st.Type() == sc {
secType = st
}
}
}
if err := binary.Write(c, binary.BigEndian, cfg.SecurityHandlers[0].Type()); err != nil { if err := binary.Write(c, binary.BigEndian, cfg.SecurityHandlers[0].Type()); err != nil {
return err return err
} }
@ -128,6 +136,11 @@ func ClientSecurityHandler(cfg *ClientConfig, c Conn) error {
return err return err
} }
err := secType.Auth(c)
if err != nil {
return err
}
var authCode uint32 var authCode uint32
if err := binary.Read(c, binary.BigEndian, &authCode); err != nil { if err := binary.Read(c, binary.BigEndian, &authCode); err != nil {
return err return err

View File

@ -27,10 +27,6 @@ type ServerInit struct {
var _ Conn = (*ServerConn)(nil) var _ Conn = (*ServerConn)(nil)
func (c *ServerConn) UnreadByte() error {
return c.br.UnreadByte()
}
func (c *ServerConn) Conn() net.Conn { func (c *ServerConn) Conn() net.Conn {
return c.c return c.c
} }
@ -53,8 +49,6 @@ func (c *ServerConn) SetProtoVersion(pv string) {
} }
func (c *ServerConn) Flush() error { func (c *ServerConn) Flush() error {
// c.m.Lock()
// defer c.m.Unlock()
return c.bw.Flush() return c.bw.Flush()
} }
@ -62,22 +56,11 @@ func (c *ServerConn) Close() error {
return c.c.Close() return c.c.Close()
} }
/*
func (c *ServerConn) Input() chan *ServerMessage {
return c.cfg.ServerMessageCh
}
func (c *ServerConn) Output() chan *ClientMessage {
return c.cfg.ClientMessageCh
}
*/
func (c *ServerConn) Read(buf []byte) (int, error) { func (c *ServerConn) Read(buf []byte) (int, error) {
return c.br.Read(buf) return c.br.Read(buf)
} }
func (c *ServerConn) Write(buf []byte) (int, error) { func (c *ServerConn) Write(buf []byte) (int, error) {
// c.m.Lock()
// defer c.m.Unlock()
return c.bw.Write(buf) return c.bw.Write(buf)
} }
@ -232,6 +215,7 @@ type ServerConfig struct {
ColorMap *ColorMap ColorMap *ColorMap
ClientMessageCh chan ClientMessage ClientMessageCh chan ClientMessage
ServerMessageCh chan ServerMessage ServerMessageCh chan ServerMessage
ErrorCh chan error
ClientMessages []ClientMessage ClientMessages []ClientMessage
DesktopName []byte DesktopName []byte
Height uint16 Height uint16
@ -402,7 +386,7 @@ func (msg *ServerCutText) Write(c Conn) error {
if err := binary.Write(c, binary.BigEndian, msg.Text); err != nil { if err := binary.Write(c, binary.BigEndian, msg.Text); err != nil {
return err return err
} }
return nil return c.Flush()
} }
type Bell struct{} type Bell struct{}
@ -416,7 +400,10 @@ func (*Bell) Read(c Conn) (ServerMessage, error) {
} }
func (msg *Bell) Write(c Conn) error { func (msg *Bell) Write(c Conn) error {
return binary.Write(c, binary.BigEndian, msg.Type()) if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
}
return c.Flush()
} }
type SetColorMapEntries struct { type SetColorMapEntries struct {
@ -486,5 +473,5 @@ func (msg *SetColorMapEntries) Write(c Conn) error {
} }
} }
return nil return c.Flush()
} }