Example #1
0
func newHandshake() *Handshake {
	h := &Handshake{}
	h.AESEngine = rtmfp.NewAESEngine()
	if err := h.SetKey(cryptkey, cryptkey); err != nil {
		utils.Panic(fmt.Sprintf("handshake init error = '%v'", err))
	}
	h.DHEngine = rtmfp.NewDHEngine()
	counts.Count("handshake.new", 1)
	return h
}
Example #2
0
func Create(yid uint32, pid string, cookie string, encrypt, decrypt []byte, lport uint16, raddr *net.UDPAddr) (uint32, error) {
	s := &Session{}
	s.xid = 0
	s.yid = yid
	s.pid = pid
	s.lport, s.raddr = lport, raddr
	s.addrs = nil
	s.cookie = cookie
	s.closed = false
	s.manage.cnt, s.manage.lasttime = 0, time.Now().UnixNano()
	s.stmptime = 0
	s.AESEngine = rtmfp.NewAESEngine()
	if err := s.SetKey(encrypt, decrypt); err != nil {
		return 0, err
	}
	s.lastfid = 0
	s.lastsid = 0
	s.mainfw = nil
	s.readers = make(map[uint64]*flowReader)
	s.writers = make(map[uint64]*flowWriter)
	s.rsplist.Init()

	sessions.Lock()
	defer sessions.Unlock()

	xid := sessions.lastxid
	for {
		xid++
		if xid == 0 {
			continue
		}
		if xid == sessions.lastxid {
			return 0, errors.New("too many sessions")
		}
		if getSessionByXid(xid) == nil {
			break
		}
	}
	s.xid = xid
	sessions.lastxid = xid
	addSessionByXid(xid, s)
	addSessionByPid(pid, s)

	m := &sessions.manages[int(xid%uint32(len(sessions.manages)))]
	m.Lock()
	m.freshlist.PushBack(s)
	m.Unlock()

	counts.Count("session.new", 1)
	return xid, nil
}