Beispiel #1
0
func init() {
	prefix := []byte{0x01, 0x0a, 0x41, 0x0e}
	suffix := []byte{0x02, 0x15, 0x02, 0x02, 0x15, 0x05, 0x02, 0x15, 0x0e}
	middle := make([]byte, 64)
	xio.NewRandomReader(time.Now().UnixNano()).ReadBytes(middle)
	magic := make([]byte, len(prefix)+len(middle)+len(suffix))
	copy(magic, prefix)
	copy(magic[len(prefix):], middle)
	copy(magic[len(prefix)+len(middle):], suffix)
	certificate = magic
	log.Printf("[certificate]: \n%s\n", utils.Formatted(certificate))
}
Beispiel #2
0
func HandlePacket(lport uint16, raddr *net.UDPAddr, xid uint32, data []byte) {
	s := FindByXid(xid)
	if s == nil {
		counts.Count("session.notfound", 1)
		return
	}
	s.Lock()
	defer s.Unlock()
	if s.closed {
		counts.Count("session.hasclosed", 1)
		return
	}
	defer s.flush()

	var err error
	if data, err = rtmfp.DecodePacket(s, data); err != nil {
		counts.Count("session.decode.error", 1)
		xlog.ErrLog.Printf("[session]: decode error = '%v'\n", err)
		return
	}
	xlog.OutLog.Printf("[session]: recv addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))

	s.lport, s.raddr = lport, raddr

	if len(s.cookie) != 0 {
		cookies.Commit(s.cookie)
		s.cookie = ""
		rpc.Join(s.xid, s.raddr)
	}

	s.manage.cnt, s.manage.lasttime = 0, time.Now().UnixNano()

	if err = s.handle(xio.NewPacketReader(data[6:])); err != nil {
		counts.Count("session.handle.error", 1)
		xlog.ErrLog.Printf("[session]: handle error = '%v'\n", err)
	}
}
Beispiel #3
0
func flush(s *Session, msgs []rtmfp.ResponseMessage) {
	lport, raddr := s.lport, s.raddr
	if data, err := rtmfp.PacketToBytes(&packet{s.yid, s.manage.lasttime, s.stmptime, msgs}); err != nil {
		counts.Count("session.tobytes.error", 1)
		xlog.ErrLog.Printf("[session]: packet to bytes error = '%v'\n", err)
		return
	} else {
		xlog.OutLog.Printf("[session]: send addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))
		if data, err = rtmfp.EncodePacket(s, s.yid, data); err != nil {
			counts.Count("session.encode.error", 1)
			xlog.ErrLog.Printf("[session]: encode packet error = '%v'\n", err)
			return
		}
		udp.Send(lport, raddr, data)
	}
}
Beispiel #4
0
func HandlePacket(lport uint16, raddr *net.UDPAddr, data []byte) {
	h := getHandshake()
	if h == nil {
		return
	}
	defer putHandshake(h)

	var err error
	if data, err = rtmfp.DecodePacket(h, data); err != nil {
		counts.Count("handshake.decode.error", 1)
		xlog.ErrLog.Printf("[handshake]: decode error = '%v'\n", err)
		return
	}
	xlog.OutLog.Printf("[handshake]: recv addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))

	h.lport, h.raddr = lport, raddr

	var pkt *packet
	if pkt, err = h.handle(xio.NewPacketReader(data[6:])); err != nil {
		counts.Count("handshake.handle.error", 1)
		xlog.ErrLog.Printf("[handshake]: handle error = '%v'\n", err)
		return
	} else if pkt == nil {
		xlog.OutLog.Printf("[handshake]: response packet is empty\n")
		return
	}

	if data, err = rtmfp.PacketToBytes(pkt); err != nil {
		counts.Count("handshake.tobytes.error", 1)
		xlog.ErrLog.Printf("[handshake]: packet to bytes error = '%v'\n", err)
		return
	}
	xlog.OutLog.Printf("[handshake]: send addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))

	if data, err = rtmfp.EncodePacket(h, pkt.yid, data); err != nil {
		counts.Count("handshake.encode.error", 1)
		xlog.ErrLog.Printf("[handshake]: encode packet error = '%v'\n", err)
		return
	}
	udp.Send(lport, raddr, data)
}