From bf90092ec0761fe8d8f6812688faa2ba9d8c2e81 Mon Sep 17 00:00:00 2001 From: jjLee Date: Fri, 15 Jul 2022 15:44:31 +0900 Subject: [PATCH] =?UTF-8?q?writeSIPto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icsnet/icsnet.go | 1 + icsnet/icstcp.go | 4 ++++ icsnet/icsudp.go | 21 +++++++++++++++++++++ icssessionmanager/agentoperator.go | 9 ++++++--- icssessionmanager/icssession.go | 3 +++ icssessionmanager/icssessionmanager.go | 2 ++ 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/icsnet/icsnet.go b/icsnet/icsnet.go index f34eb64..c4095be 100644 --- a/icsnet/icsnet.go +++ b/icsnet/icsnet.go @@ -17,6 +17,7 @@ type IcsNeter interface { Write(b []byte) (int, *icserror.IcsError) WriteSIP(b []byte) (int, *icserror.IcsError) + WriteSIPTo(b []byte, addr *net.UDPAddr) (int, *icserror.IcsError) WriteRTP(b []byte) (int, *icserror.IcsError) Read(size int) ([]byte, int, *icserror.IcsError) diff --git a/icsnet/icstcp.go b/icsnet/icstcp.go index 1ba1738..eef75b1 100644 --- a/icsnet/icstcp.go +++ b/icsnet/icstcp.go @@ -118,6 +118,10 @@ func (u *IcsTCPNet) WriteSIP(b []byte) (int, *icserror.IcsError) { return 0, nil } +func (u *IcsTCPNet) WriteSIPTo(b []byte, addr *net.UDPAddr) (int, *icserror.IcsError) { + return 0, nil +} + func (u *IcsTCPNet) WriteRTP(b []byte) (int, *icserror.IcsError) { return 0, nil } diff --git a/icsnet/icsudp.go b/icsnet/icsudp.go index 40142b9..e26dd85 100644 --- a/icsnet/icsudp.go +++ b/icsnet/icsudp.go @@ -6,6 +6,7 @@ import ( "time" "gitlab.com/ics_cinnamon/voicegateway/icserror" + "gitlab.com/ics_cinnamon/voicegateway/icslog" ) type IcsUDPNet struct { @@ -164,6 +165,26 @@ func (u *IcsUDPNet) WriteSIP(b []byte) (int, *icserror.IcsError) { return wsize, nil } +func (u *IcsUDPNet) WriteSIPTo(b []byte, addr *net.UDPAddr) (int, *icserror.IcsError) { + l := icslog.GetIcsLog() + if u.conn.ICSUDPConn == nil { + return 0, icserror.ICSERRNETNotConnectError + } + l.Printf(icslog.LOG_LEVEL_DEBUG, -1, "################### addr [%v] ", addr) + + //fmt.Println("Write addr ", raddr) + //wsize, err := u.conn.ICSUDPConn.WriteTo(b, raddr) + wsize, err := u.conn.ICSUDPConn.WriteToUDP(b, addr) + //wsize, err := u.conn.ICSUDPConn.Write(b) + if err != nil { + icserror.ICSERRNETWriteError.SetError(err) + l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Writing RTP error[%v] ", err) + //fmt.Println("UDP WRITE ERROR -", err) + return -1, icserror.ICSERRNETWriteError + } + return wsize, nil +} + func (u *IcsUDPNet) WriteRTP(b []byte) (int, *icserror.IcsError) { if u.conn.ICSUDPConn == nil { return 0, icserror.ICSERRNETNotConnectError diff --git a/icssessionmanager/agentoperator.go b/icssessionmanager/agentoperator.go index e3b8d5e..c18425a 100644 --- a/icssessionmanager/agentoperator.go +++ b/icssessionmanager/agentoperator.go @@ -928,7 +928,8 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, "0") reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR) - wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqAck.String())) + // wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqAck.String())) + wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqAck.String()), s.remoteSIPAddr) if werr != nil { l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage()) s.SetAgentStatus(STATUS_AGENT_READY) @@ -1208,7 +1209,8 @@ func (s *IcsSession) ProcBye(sip *icspacketparser.SIP) *icserror.IcsError { res200.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact) res200.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR) - wlen, werr := (*s.sipNeter).WriteSIP([]byte(res200.String())) + // wlen, werr := (*s.sipNeter).WriteSIP([]byte(res200.String())) + wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(res200.String()), s.remoteSIPAddr) if werr != nil { l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage()) s.SetAgentStatus(STATUS_AGENT_READY) @@ -2033,7 +2035,8 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) { reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, contentLength) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR) - wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqOpt.String())) + // wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqOpt.String())) + wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqOpt.String()), s.remoteSIPAddr) if werr != nil { l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage()) return diff --git a/icssessionmanager/icssession.go b/icssessionmanager/icssession.go index 1ee7989..19518c3 100644 --- a/icssessionmanager/icssession.go +++ b/icssessionmanager/icssession.go @@ -5,6 +5,7 @@ import ( "strings" "sync" "time" + "net" "gitlab.com/ics_cinnamon/joy4/format" "gitlab.com/ics_cinnamon/voicegateway/icscbtimer" @@ -54,6 +55,8 @@ type IcsSession struct { RTPCBStatus int //TTS data tts []byte + + remoteSIPAddr *net.UDPAddr //call info StartTimeStamp int64 diff --git a/icssessionmanager/icssessionmanager.go b/icssessionmanager/icssessionmanager.go index 2b26cb5..7cbab37 100644 --- a/icssessionmanager/icssessionmanager.go +++ b/icssessionmanager/icssessionmanager.go @@ -426,6 +426,8 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) { continue } } + + s.remoteSIPAddr = addr //post the sip event to session h := icsevent.NewEventH()