更改dtlssession的存储方式

This commit is contained in:
bjdgyc
2021-05-26 21:24:53 +08:00
parent f342b12372
commit 061f625448
3 changed files with 13 additions and 28 deletions

View File

@@ -9,6 +9,7 @@ import (
)
func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
base.Debug("LinkDtls connect", cSess.IpAddr, conn.RemoteAddr())
dSess := cSess.NewDtlsConn()
if dSess == nil {
// 创建失败,直接关闭链接
@@ -28,14 +29,7 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
go dtlsWrite(conn, dSess, cSess)
now := time.Now()
for {
if time.Now().Sub(now) > time.Second*30 {
// return
}
err := conn.SetReadDeadline(time.Now().Add(dead))
if err != nil {
base.Error("SetDeadline: ", err)
@@ -63,15 +57,7 @@ func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) {
return
case 0x03: // DPD-REQ
// base.Debug("recv DPD-REQ", cSess.IpAddr)
payload := &sessdata.Payload{
LType: sessdata.LTypeIPData,
PType: 0x04,
Data: nil,
}
select {
case cSess.PayloadOutDtls <- payload:
case <-dSess.CloseChan:
if payloadOutDtls(cSess, dSess, sessdata.LTypeIPData, 0x04, nil) {
return
}
case 0x04:

View File

@@ -39,7 +39,7 @@ func payloadOut(cSess *sessdata.ConnSession, lType sessdata.LType, pType byte, d
if dSess == nil {
return payloadOutCstp(cSess, lType, pType, data)
} else {
return payloadOutDtls(dSess, lType, pType, data)
return payloadOutDtls(cSess, dSess, lType, pType, data)
}
}
@@ -61,7 +61,7 @@ func payloadOutCstp(cSess *sessdata.ConnSession, lType sessdata.LType, pType byt
return closed
}
func payloadOutDtls(dSess *sessdata.DtlsSession, lType sessdata.LType, pType byte, data []byte) bool {
func payloadOutDtls(cSess *sessdata.ConnSession, dSess *sessdata.DtlsSession, lType sessdata.LType, pType byte, data []byte) bool {
payload := &sessdata.Payload{
LType: lType,
PType: pType,
@@ -69,7 +69,7 @@ func payloadOutDtls(dSess *sessdata.DtlsSession, lType sessdata.LType, pType byt
}
select {
case dSess.CSess.PayloadOutDtls <- payload:
case cSess.PayloadOutDtls <- payload:
case <-dSess.CloseChan:
}