transaction

package
v3.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: AGPL-3.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

事务

transaction事务是SIP的基本组成部分。 一个事务是客户发送的一个请求事务(通过通讯层)发送到一个服务器事务,连同服务器事务的所有的该请求的应答发送回客户端事务。 事务层处理应用服务层的重发,匹配请求的应答,以及应用服务层的超时。 任何一个用户代理客户端(user agent client UAC)完成的事情都是由一组事务构成的。 用户代理包含一个事务层,来实现有状态的代理服务器。 事务层包含一个客户元素(可以认为是一个客户事务)和一个服务器元素(可以认为是一个服务器事务),他们都可以用一个有限状态机来处理特定的请求。

在状态机层面,事务分为ict、ist、nict、nist四种。 但底层事务方面,仅根据 method 等信息,分支处理。

关于事务管理

事务在map里面管理,事务ID的选择是要和事务匹配相关。

客户端事件的匹配

当客户端中的传输层收到响应时,它必须确定哪个客户端事务将处理该响应,以便可以进行17.1.1和17.1.2节的处理。头域 Via 字段中的branch参数用于匹配规则。 一个匹配的响应应该满足下面两个条件:
1.如果响应的头域 Via头字段中的branch参数值与创建事务的请求的头域 Via头字段中的branch参数值相同。
2.如果CSeq标头字段中的method参数与创建事务的请求的方法匹配。(由于CANCEL请求会创建新的事务,但共享相同的branch参数值。所以仅用branch参数是不够的)


服务端事务匹配

首先要检查请求中的Via头域的branch参数。如果他以”z9hG4bk”开头,那么这个请求一定是由客户端事务根据本规范产生的。因此,branch参数在该客户端发出的所有的事务中都是唯一的。根据下列规则我们可以判定请求是否和事务匹配:

1、 请求的Via头域的branch参数和创建本事务的请求的Via头域的branch参数一样,并且:
2、 请求的Via头域的send-by参数和创建本事务的请求的Via头域的send-by参数一样(可能存在来自不同客户端的branch参数的意外或恶意重复,所以将 send-by 值用作匹配的一部分),并且:
3、 请求的方法与创建事务的方法匹配,但ACK除外,在ACK中,创建事务的请求的方法为INVITE。

所以,根据匹配规则,事务的ID 使用 branch,然后在匹配逻辑里面,再做条件判断。而因为branch可能会重复,所以如果使用map来简化transaction的管理,key的取值应该:

type key
客户端事务: branch+method
服务端事务: branch + sendby + method,method中ack还要除外。所以只能用branch + sendby

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func GetTXKey added in v3.0.4

func GetTXKey(msg *sip.Message) (key string)

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   //是否开启音频
	LogVerbose        bool
	WaitKeyFrame      bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
	RemoveBanInterval int  //移除禁止设备间隔
	UdpCacheSize      int  //udp缓存大小
}

type Core

type Core struct {
	*Config    //sip server配置信息
	OnRegister func(msg *Request, tx *GBTx)
	OnMessage  func(msg *Request, tx *GBTx)
	// contains filtered or unexported fields
}

Core: transactions manager 管理所有 transactions,以及相关全局参数、运行状态机

func NewCore

func NewCore(config *Config) *Core

初始化一个 Core,需要能响应请求,也要能发起请求 client 发起请求 server 响应请求 TODO:根据角色,增加相关配置信息 TODO:通过context管理子线程 TODO:单元测试

func (*Core) GetTX added in v3.0.4

func (c *Core) GetTX(key string) *GBTx

func (*Core) HandleReceiveMessage

func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error)

接收到的消息处理 收到消息有两种:1、请求消息 2、响应消息 请求消息则直接响应处理。 响应消息则需要匹配到请求,让请求的transaction来处理。 TODO:参考srs和osip的流程,以及文档,做最终处理。需要将逻辑分成两层:TU 层和 transaction 层

func (*Core) MustTX added in v3.0.4

func (c *Core) MustTX(key string) *GBTx

func (*Core) NewTX added in v3.0.4

func (c *Core) NewTX(key string) *GBTx

func (*Core) RegistHandler added in v3.0.4

func (c *Core) RegistHandler(method Method, handler RequestHandler)

RegistHandler RegistHandler

func (*Core) Request added in v3.0.4

func (c *Core) Request(req *Request) (*GBTx, error)

Request Request

func (*Core) ResolveAddress added in v3.0.8

func (c *Core) ResolveAddress(msg *Message) (destAddr net.Addr, err error)

func (*Core) Respond added in v3.0.4

func (c *Core) Respond(resp *Response) (*GBTx, error)

Request Request

func (*Core) SipRequestForResponse added in v3.0.4

func (c *Core) SipRequestForResponse(req *Request) (response *Response, err error)

func (*Core) StartAndWait added in v3.0.4

func (c *Core) StartAndWait()

type GBTx added in v3.0.4

type GBTx struct {
	*Core
	// contains filtered or unexported fields
}

GBTx Gb28181 Transaction

func NewTransaction added in v3.0.4

func NewTransaction(key string, conn Connection) *GBTx

NewTransaction create a new GBtx

func (*GBTx) Close added in v3.0.4

func (tx *GBTx) Close()

Close the Close function closes the GBTx

func (*GBTx) GetResponse added in v3.0.4

func (tx *GBTx) GetResponse() *sip.Response

GetResponse GetResponse

func (*GBTx) Key added in v3.0.4

func (tx *GBTx) Key() string

Key returns the GBTx Key

func (*GBTx) ReceiveResponse added in v3.0.4

func (tx *GBTx) ReceiveResponse(msg *sip.Response)

ReceiveResponse receive a Response

func (*GBTx) Request added in v3.0.4

func (tx *GBTx) Request(req *sip.Request) error

Request Request

func (*GBTx) Respond added in v3.0.4

func (tx *GBTx) Respond(res *sip.Response) error

Respond Respond

func (*GBTx) SipRequestForResponse added in v3.0.4

func (tx *GBTx) SipRequestForResponse(req *sip.Request) (response *sip.Response, err error)

func (*GBTx) SipResponse added in v3.0.4

func (tx *GBTx) SipResponse() (*sip.Response, error)

type GBTxs added in v3.0.4

type GBTxs struct {
	Txs map[string]*GBTx
	RWM *sync.RWMutex
}

GBTxs a GBTxs stands for a Gb28181 Transaction collection

var ActiveTX *GBTxs

func (*GBTxs) GetTX added in v3.0.4

func (txs *GBTxs) GetTX(key string) *GBTx

func (*GBTxs) NewTX added in v3.0.4

func (txs *GBTxs) NewTX(key string, conn Connection) *GBTx

type RequestHandler added in v3.0.4

type RequestHandler func(req *Request, tx *GBTx)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL