From a887bcd0b938962ae4c92a6ac842624435f15600 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 2 May 2018 22:43:05 +0200 Subject: [PATCH] removed debug --- ws/message/public.go | 50 +++----------------------------------------- ws/server/public.go | 4 ++-- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/ws/message/public.go b/ws/message/public.go index 8d2ac46..fccd011 100644 --- a/ws/message/public.go +++ b/ws/message/public.go @@ -24,9 +24,6 @@ func Read(socket net.Conn) (*T, error){ m.Final = bool( buffer[0] & 0x80 == 0x80 ) m.Type = byte( buffer[0] & 0x0f ) - fmt.Printf(" + read\n") - fmt.Printf(" - final: %t\n", m.Final) - fmt.Printf(" - Type: %x\n", m.Type) /* (3) Byte 2: Mask and Length[0] */ buffer = make([]byte, 1) @@ -38,11 +35,9 @@ func Read(socket net.Conn) (*T, error){ if buffer[0] & 0x80 == 0x80 { mask = make([]byte, 0) } - fmt.Printf(" - has mask ? %t\n", mask != nil) // payload length m.Size = uint( buffer[0] & 0x7f ) - fmt.Printf(" - size/flag: %d\n", m.Size) /* (4) Extended payload */ if m.Size == 127 { @@ -63,8 +58,6 @@ func Read(socket net.Conn) (*T, error){ } - fmt.Printf(" - final size: %d\n", m.Size) - /* (5) Masking key */ if mask != nil { @@ -76,7 +69,6 @@ func Read(socket net.Conn) (*T, error){ copy(mask, buffer) } - fmt.Printf(" - mask: %x\n", mask) /* (6) Read payload */ buffer = make([]byte, int(m.Size)) @@ -84,7 +76,6 @@ func Read(socket net.Conn) (*T, error){ if err != nil { return nil, fmt.Errorf("Cannot read payload (%s)", err) } m.Data = make([]byte, 0, m.Size) - fmt.Printf(" - raw data: '%s'\n", buffer) /* (7) Unmask payload */ if len(mask) == 4 { @@ -99,9 +90,6 @@ func Read(socket net.Conn) (*T, error){ } - - fmt.Printf(" - unmasked data: '%s'\n", m.Data) - return m, nil } @@ -112,25 +100,15 @@ func Read(socket net.Conn) (*T, error){ // Send sends a frame over a socket func (m T) Send(socket net.Conn) error { - var bi uint = 0; - buffer := make([]byte, 0) - fmt.Printf(" + write\n") - fmt.Printf(" - final: %t\n", m.Final) - fmt.Printf(" - type: %x\n", m.Type) /* (1) Byte 0 : FIN + opcode */ buffer = append(buffer, 0x80 | TEXT ) - fmt.Printf(" > byte[%d]: '%x'\n", bi, 0x80 | TEXT); bi++ - fmt.Printf(" ? '%x'\n", buffer[bi-1]); /* (2) Get payload length */ if m.Size < 126 { // simple buffer = append(buffer, byte(m.Size) ) - fmt.Printf(" - size: %d\n", m.Size) - fmt.Printf(" > byte[%d]: '%.2x'\n", bi, m.Size); bi++ - fmt.Printf(" ? '%.2x'\n", buffer[bi-1]); } else if m.Size < 0xffff { // extended: 16 bits @@ -139,12 +117,6 @@ func (m T) Send(socket net.Conn) error { buf := make([]byte, 2) binary.BigEndian.PutUint16(buf, uint16(m.Size)) buffer = append(buffer, buf...) - fmt.Printf(" - size flag: %d\n", 126) - fmt.Printf(" > byte[%d]: '%.2x'\n", bi, 126); bi++ - fmt.Printf(" ? '%x'\n", buffer[bi-1]); - fmt.Printf(" - size: %d\n", m.Size) - fmt.Printf(" > byte[%d.%d]: '%4.x'\n", bi, bi+2-1, m.Size); bi+=2 - fmt.Printf(" ? '%.4x'\n", buffer[bi-2:bi]); } else if m.Size < 0xffffffffffffffff { // extended: 64 bits @@ -153,30 +125,14 @@ func (m T) Send(socket net.Conn) error { buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(m.Size)) buffer = append(buffer, buf...) - fmt.Printf(" - size flag: %d\n", 127) - fmt.Printf(" > byte[%d]: '%.2x'\n", bi, 127); bi++ - fmt.Printf(" ? '%x'\n", buffer[bi-1]); - fmt.Printf(" - size: %d\n", m.Size) - fmt.Printf(" > byte[%d.%d]: '%16.x'\n", bi, bi+8-1, m.Size); bi+=8 - fmt.Printf(" ? '%.16x'\n", buffer[bi-8:bi]); } - /* (3) Write header */ - // fmt.Printf(" - header: %x\n", buffer) - // _, err := socket.Write(buffer) - // if err != nil { return err } - - /* (4) Add payload */ + /* (3) Add payload */ buffer = append(buffer, m.Data...) - fmt.Printf(" - data: '%s'\n", m.Data) - fmt.Printf(" - data: %x\n", m.Data) - fmt.Printf(" > byte[%d.%d]: '%x'\n", bi, bi+m.Size-1, buffer[bi:]); bi+=m.Size - /* (4) Send message */ - nbw, err := socket.Write(buffer) - fmt.Printf(" - buffer: '%x'\n", buffer) - fmt.Printf(" - written: %d / %d\n", nbw, bi) + /* (4) Send over socket */ + _, err := socket.Write(buffer) if err != nil { return err } return nil diff --git a/ws/server/public.go b/ws/server/public.go index 17e3d37..9f2e63e 100644 --- a/ws/server/public.go +++ b/ws/server/public.go @@ -126,13 +126,13 @@ func (s *T) scheduler(){ /* (1) New client */ case client := <- s.ch.register: - fmt.Printf(" + client (sock: %p)\n", client.IO.Sock) + fmt.Printf(" + client\n") s.clients[client.IO.Sock] = client /* (2) New client */ case client := <- s.ch.unregister: - fmt.Printf(" - client (sock: %p)\n", client.IO.Sock) + fmt.Printf(" - client\n") delete(s.clients, client.IO.Sock) client.IO.Sock.Close()