Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Core
- func (c *Core) AddTransaction(ta *Transaction)
- func (c *Core) DelTransaction(tid string)
- func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error)
- func (c *Core) Handler()
- func (c *Core) Send(msg *sip.Message) error
- func (c *Core) SendMessage(msg *sip.Message) *Response
- func (c *Core) Start()
- type Event
- func (e Event) IsIncomingMessage() bool
- func (e Event) IsIncomingRequest() bool
- func (e Event) IsIncomingResponse() bool
- func (e Event) IsOutgoingMessage() bool
- func (e Event) IsOutgoingRequest() bool
- func (e Event) IsOutgoingResponse() bool
- func (e Event) IsSipMessage() bool
- func (e Event) String() string
- type EventObj
- type FSMType
- type Handler
- type Header
- type Request
- type Response
- type SipTimer
- type State
- type Transaction
Constants ¶
const ( T1 = 100 * time.Millisecond T2 = 4 * time.Second T4 = 5 * time.Second TimeA = T1 TimeB = 64 * T1 TimeD = 32 * time.Second TimeE = T1 TimeF = 64 * T1 TimeG = T1 TimeH = 64 * T1 TimeI = T4 TimeJ = 64 * T1 TimeK = T4 Time1xx = 100 * time.Millisecond )
timer相关基础常量、方法等定义
Variables ¶
var ( ErrorSyntax = errors.New("message syntax error") ErrorCheck = errors.New("message check failed") ErrorParse = errors.New("message parse failed") ErrorUnknown = errors.New("message unknown") )
transaction 的错误定义
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { //sip服务器的配置 SipNetwork string //传输协议,默认UDP,可选TCP SipIP string //sip 服务器公网IP SipPort uint16 //sip 服务器端口,默认 5060 Serial string //sip 服务器 id, 默认 34020000002000000001 Realm string //sip 服务器域,默认 3402000000 Username string //sip 服务器账号 Password string //sip 服务器密码 AckTimeout uint16 //sip 服务应答超时,单位秒 RegisterValidity int //注册有效期,单位秒,默认 3600 RegisterInterval int //注册间隔,单位秒,默认 60 HeartbeatInterval int //心跳间隔,单位秒,默认 60 HeartbeatRetry int //心跳超时次数,默认 3 //媒体服务器配置 MediaIP string //媒体服务器地址 MediaPort uint16 //媒体服务器端口 MediaPortMin uint16 MediaPortMax uint16 MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连 AudioEnable bool //是否开启音频 WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流 RemoveBanInterval int //移除禁止设备间隔 UdpCacheSize int //udp缓存大小 }
type Core ¶
type Core struct { *Config //sip server配置信息 OnRegister func(*sip.Message) OnMessage func(*sip.Message) bool // contains filtered or unexported fields }
Core: transactions manager 管理所有 transactions,以及相关全局参数、运行状态机
func NewCore ¶
初始化一个 Core,需要能响应请求,也要能发起请求 client 发起请求 server 响应请求 TODO:根据角色,增加相关配置信息 TODO:通过context管理子线程 TODO:单元测试
func (*Core) AddTransaction ¶
func (c *Core) AddTransaction(ta *Transaction)
add transaction to core
func (*Core) HandleReceiveMessage ¶
接收到的消息处理 收到消息有两种:1、请求消息 2、响应消息 请求消息则直接响应处理。 响应消息则需要匹配到请求,让请求的transaction来处理。 TODO:参考srs和osip的流程,以及文档,做最终处理。需要将逻辑分成两层:TU 层和 transaction 层
func (*Core) SendMessage ¶
发送消息:发送请求或者响应 发送消息仅负责发送。报错有两种:1、发送错误。2、发送了但是超时没有收到响应 如果发送成功,如何判断是否收到响应?没有收到响应要重传 所以一个transaction 有read和wriet的chan。 发送的时候写 write chan 接收的时候读取 read chan 发送之后,就开启timer,超时重传,还要记录和修改每次超时时间。不超时的话,记得删掉timer 发送 register 消息
type Event ¶
type Event int
状态机之事件
const ( /* TIMEOUT EVENTS for ICT */ TIMEOUT_A Event = iota /**< Timer A */ TIMEOUT_B /**< Timer B */ TIMEOUT_D /**< Timer D */ /* TIMEOUT EVENTS for NICT */ TIMEOUT_E /**< Timer E */ TIMEOUT_F /**< Timer F */ TIMEOUT_K /**< Timer K */ /* TIMEOUT EVENTS for IST */ TIMEOUT_G /**< Timer G */ TIMEOUT_H /**< Timer H */ TIMEOUT_I /**< Timer I */ /* TIMEOUT EVENTS for NIST */ TIMEOUT_J /**< Timer J */ /* FOR INCOMING MESSAGE */ RCV_REQINVITE /**< Event is an incoming INVITE request */ RCV_REQACK /**< Event is an incoming ACK request */ RCV_REQUEST /**< Event is an incoming NON-INVITE and NON-ACK request */ RCV_STATUS_1XX /**< Event is an incoming informational response */ RCV_STATUS_2XX /**< Event is an incoming 2XX response */ RCV_STATUS_3456XX /**< Event is an incoming final response (not 2XX) */ /* FOR OUTGOING MESSAGE */ SND_REQINVITE /**< Event is an outgoing INVITE request */ SND_REQACK /**< Event is an outgoing ACK request */ SND_REQUEST /**< Event is an outgoing NON-INVITE and NON-ACK request */ SND_STATUS_1XX /**< Event is an outgoing informational response */ SND_STATUS_2XX /**< Event is an outgoing 2XX response */ SND_STATUS_3456XX /**< Event is an outgoing final response (not 2XX) */ KILL_TRANSACTION /**< Event to 'kill' the transaction before termination */ UNKNOWN_EVT /**< Max event */ )
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
对外将sip通讯封装成请求和响应 TODO:可参考http的request和response,屏蔽sip协议细节
type SipTimer ¶
type SipTimer struct {
// contains filtered or unexported fields
}
func NewSipTimer ¶
type State ¶
type State int
状态机之状态
const ( /* STATES for invite client transaction */ ICT_PRE_CALLING State = iota ICT_CALLING ICT_PROCEEDING ICT_COMPLETED ICT_TERMINATED /* STATES for invite server transaction */ IST_PRE_PROCEEDING IST_PROCEEDING IST_COMPLETED IST_CONFIRMED IST_TERMINATED /* STATES for NON-invite client transaction */ NICT_PRE_TRYING NICT_TRYING NICT_PROCEEDING NICT_COMPLETED NICT_TERMINATED /* STATES for NON-invite server transaction */ NIST_PRE_TRYING NIST_TRYING NIST_PROCEEDING NIST_COMPLETED NIST_TERMINATED /* STATES for dialog */ DIALOG_EARLY DIALOG_CONFIRMED DIALOG_CLOSE )
type Transaction ¶
type Transaction struct { context.Context //线程管理、其他参数 sync.Mutex // contains filtered or unexported fields }
是否需要tp layer?
func (*Transaction) GetTid ¶
func (ta *Transaction) GetTid() string
func (*Transaction) Run ¶
func (ta *Transaction) Run(evt Event, m *sip.Message)
每一个transaction至少有一个状态机线程运行 TODO:如果是一个uac的transaction,则把最后响应的消息返回(通过response chan) transaction有很多消息需要传递到TU,也接收来自TU的消息。
func (*Transaction) SetState ¶
func (ta *Transaction) SetState(s State)