]> git.lizzy.rs Git - go-anidb.git/commitdiff
udpapi: Handle encryption correctly
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 17:34:21 +0000 (14:34 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Sun, 14 Jul 2013 17:34:21 +0000 (14:34 -0300)
Previously, the very first packet to be received after the ENCRYPT call
was not properly decrypted; the getPacket function was using the old
encryption state.

udp/comm.go
udp/packet.go

index a966789e866c77f8428118f3011f53e356fe1499..1017c69006aebac83b6da80c0cf6fc0aac76ad5c 100755 (executable)
@@ -219,7 +219,7 @@ func (a *AniDBUDP) recvLoop() {
                                brk <- true
                                return
                        default:
-                               b, err := getPacket(a.conn, a.ecb)
+                               b, err := a.getPacket()
                                pkt <- packet{b: b, err: err}
                        }
                }
@@ -268,7 +268,6 @@ func (a *AniDBUDP) recvLoop() {
 
                                a.routerLock.RLock()
                                if ch, ok := a.tagRouter[r.Tag()]; ok {
-
                                        log.Println("<<<", string(b))
                                        ch <- r
                                } else {
index 279af06fe00aa0de7649640e0a04a5d87f923980..ea247e3875f1716c43069b51e6c0e7c8633faf9c 100755 (executable)
@@ -5,7 +5,6 @@ import (
        "compress/zlib"
        "io"
        "io/ioutil"
-       "net"
 )
 
 type packet struct {
@@ -14,11 +13,11 @@ type packet struct {
        sent chan bool
 }
 
-func getPacket(conn *net.UDPConn, ecb *ecbState) (buf []byte, err error) {
+func (a *AniDBUDP) getPacket() (buf []byte, err error) {
        buf = make([]byte, 1500)
-       n, err := conn.Read(buf)
+       n, err := a.conn.Read(buf)
 
-       buf = ecb.Decrypt(buf[:n])
+       buf = a.ecb.Decrypt(buf[:n])
 
        if buf[0] == 0 && buf[1] == 0 {
                def, _ := zlib.NewReader(bytes.NewReader(buf[2:]))
@@ -29,6 +28,7 @@ func getPacket(conn *net.UDPConn, ecb *ecbState) (buf []byte, err error) {
                        err = e
                }
        }
+
        return buf, err
 }