cmpp

package module
v0.0.0-...-e611134 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 15 Imported by: 3

README

Build Status Coverage Status Go Report Card GoDoc

gocmpp

An implementation of China Mobile Peer to Peer(cmpp) protocol in golang for both client and server sides.

The protocol versions below are covered:

Overview

gocmpp is a library that implements China Mobile Peer to Peer(cmpp) protocol. You can use the lib to implement any app, tool or system that use cmpp protocol for both client and server side.

gocmpp is portable well. It can be used on linux, darwin or even windows.

gocmpp has covered cmpp2.x and cmpp3.x versions. It has supported the connect, submit, deliver, fwd, active test, and terminate packets of cmpp protocol. But other less use packets like cmpp query, cancel and route have not been supported. And they are not in the roadmap at all.

QuickStart

1. Download gocmpp
$go get github.com/bigwhite/gocmpp
2. Build gocmpp

gocmpp's build use the vendor mechanism introduced in go 1.5, so we need go 1.5 or later version to build it.

$export GO15VENDOREXPERIMENT="1"
$cd $GOPATH/src/github.com/bigwhite/gocmpp
$make
$make
go build -o examples/server/server examples/server/server.go
go build -o examples/client/client examples/client/client.go
go build
go build ./utils
go test
PASS
ok  	github.com/bigwhite/gocmpp	0.009s
go test ./utils
ok  	github.com/bigwhite/gocmpp/utils	0.008s
3. Run the examples

run the two programs below in order:

  • ./examples/server/server
  • ./examples/client/client

you would get the output like below:

server:

cmppserver: 2015/11/19 16:28:50 accept a connection from 127.0.0.1:49847
cmppserver: 2015/11/19 16:28:50 receive a cmpp30 connect request from 127.0.0.1:49847[0]
cmppserver: 2015/11/19 16:28:50 handleLogin: 900001 login ok
cmppserver: 2015/11/19 16:28:55 receive a cmpp active response from 127.0.0.1:49847[0]
cmppserver: 2015/11/19 16:29:00 receive a cmpp active response from 127.0.0.1:49847[1]
cmppserver: 2015/11/19 16:29:00 receive a cmpp30 submit request from 127.0.0.1:49847[1]
cmppserver: 2015/11/19 16:29:00 handleSubmit: handle submit from 900001 ok! msgid[12878564852733378560], srcId[900001], destTerminalId[13500002696]
cmppserver: 2015/11/19 16:29:05 receive a cmpp active response from 127.0.0.1:49847[2]
cmppserver: 2015/11/19 16:29:05 receive a cmpp30 submit request from 127.0.0.1:49847[2]
cmppserver: 2015/11/19 16:29:05 handleSubmit: handle submit from 900001 ok! msgid[12878564852733378560], srcId[900001], destTerminalId[13500002696]
cmppserver: 2015/11/19 16:29:10 receive a cmpp active response from 127.0.0.1:49847[3]
cmppserver: 2015/11/19 16:29:10 receive a cmpp30 submit request from 127.0.0.1:49847[3]
cmppserver: 2015/11/19 16:29:10 handleSubmit: handle submit from 900001 ok! msgid[12878564852733378560], srcId[900001], destTerminalId[13500002696]
cmppserver: 2015/11/19 16:29:13 close connection with 127.0.0.1:49847!

client:

2015/11/19 16:28:50 client connect and auth ok
2015/11/19 16:28:55 receive a cmpp active request: &{0}
2015/11/19 16:29:00 receive a cmpp active request: &{1}
2015/11/19 16:29:00 send a cmpp3 submit request
2015/11/19 16:29:00 receive a cmpp3 submit response: &{12878564852733378560 0 1}
2015/11/19 16:29:05 receive a cmpp active request: &{2}
2015/11/19 16:29:05 send a cmpp3 submit request
2015/11/19 16:29:05 receive a cmpp3 submit response: &{12878564852733378560 0 2}
2015/11/19 16:29:10 receive a cmpp active request: &{3}
2015/11/19 16:29:10 send a cmpp3 submit request
2015/11/19 16:29:10 receive a cmpp3 submit response: &{12878564852733378560 0 3}
4.How to use the library

The best start entry is the code in folder 'examples'.

  • client.go tells you how to use gocmpp in client side.
  • server.go presents you how to construct a cmpp server in gocmpp.

Who use gocmpp

Documentation

Index

Constants

View Source
const (
	CmppActiveTestReqPktLen uint32 = 12     //12d, 0xc
	CmppActiveTestRspPktLen uint32 = 12 + 1 //13d, 0xd
)

Packet length const for cmpp active test request and response packets.

View Source
const (
	CmppConnReqPktLen  uint32 = 4 + 4 + 4 + 6 + 16 + 1 + 4 //39d, 0x27
	Cmpp2ConnRspPktLen uint32 = 4 + 4 + 4 + 1 + 16 + 1     //30d, 0x1e
	Cmpp3ConnRspPktLen uint32 = 4 + 4 + 4 + 4 + 16 + 1     //33d, 0x21
)

Packet length const for cmpp connect request and response packets.

View Source
const (
	Cmpp2DeliverReqPktMaxLen uint32 = 12 + 233   //245d, 0xf5
	Cmpp2DeliverRspPktLen    uint32 = 12 + 8 + 1 //21d, 0x15

	Cmpp3DeliverReqPktMaxLen uint32 = 12 + 257   //269d, 0x10d
	Cmpp3DeliverRspPktLen    uint32 = 12 + 8 + 4 //24d, 0x18
)

Packet length const for cmpp deliver request and response packets.

View Source
const (
	Cmpp2FwdReqPktMaxLen uint32 = 12 + 2379          //2277d, 0x957
	Cmpp2FwdRspPktLen    uint32 = 12 + 8 + 1 + 1 + 1 //23d, 0x17

	Cmpp3FwdReqPktMaxLen uint32 = 12 + 2491          //2503d, 0x9c7
	Cmpp3FwdRspPktLen    uint32 = 12 + 8 + 1 + 1 + 4 //26d, 0x1a
)

Packet length const for cmpp fwd request and response packets.

View Source
const (
	CMPP_HEADER_LEN  uint32 = 12
	CMPP2_PACKET_MAX uint32 = 2477
	CMPP2_PACKET_MIN uint32 = 12
	CMPP3_PACKET_MAX uint32 = 3335
	CMPP3_PACKET_MIN uint32 = 12
)
View Source
const (
	Cmpp2SubmitReqPktMaxLen uint32 = 12 + 2265  //2277d, 0x8e5
	Cmpp2SubmitRspPktLen    uint32 = 12 + 8 + 1 //21d, 0x15

	Cmpp3SubmitReqPktMaxLen uint32 = 12 + 3479  //3491d, 0xda3
	Cmpp3SubmitRspPktLen    uint32 = 12 + 8 + 4 //24d, 0x18
)

Packet length const for cmpp submit request and response packets.

View Source
const (
	CmppTerminateReqPktLen uint32 = 12 //12d, 0xc
	CmppTerminateRspPktLen uint32 = 12 //12d, 0xc
)

Packet length const for cmpp terminate request and response packets.

View Source
const (
	CmppReceiptPktLen uint32 = 60 //60d, 0x3c
)

Packet length const for cmpp receipt packet.

Variables

View Source
var (
	ErrConnIsClosed       = errors.New("connection is closed")
	ErrReadCmdIDTimeout   = errors.New("read commandId timeout")
	ErrReadPktBodyTimeout = errors.New("read packet body timeout")
)

Errors for conn operations

View Source
var (
	ErrnoConnInvalidStruct  uint8 = 1
	ErrnoConnInvalidSrcAddr uint8 = 2
	ErrnoConnAuthFailed     uint8 = 3
	ErrnoConnVerTooHigh     uint8 = 4
	ErrnoConnOthers         uint8 = 5

	ConnRspStatusErrMap = map[uint8]error{
		ErrnoConnInvalidStruct:  errConnInvalidStruct,
		ErrnoConnInvalidSrcAddr: errConnInvalidSrcAddr,
		ErrnoConnAuthFailed:     errConnAuthFailed,
		ErrnoConnVerTooHigh:     errConnVerTooHigh,
		ErrnoConnOthers:         errConnOthers,
	}
)

Errors for connect resp status.

View Source
var (
	ErrnoDeliverInvalidStruct      uint8 = 1
	ErrnoDeliverInvalidCommandId   uint8 = 2
	ErrnoDeliverInvalidSequence    uint8 = 3
	ErrnoDeliverInvalidMsgLength   uint8 = 4
	ErrnoDeliverInvalidFeeCode     uint8 = 5
	ErrnoDeliverExceedMaxMsgLength uint8 = 6
	ErrnoDeliverInvalidServiceId   uint8 = 7
	ErrnoDeliverNotPassFlowControl uint8 = 8
	ErrnoDeliverOtherError         uint8 = 9

	DeliverRspResultErrMap = map[uint8]error{
		ErrnoDeliverInvalidStruct:      errDeliverInvalidStruct,
		ErrnoDeliverInvalidCommandId:   errDeliverInvalidCommandId,
		ErrnoDeliverInvalidSequence:    errDeliverInvalidSequence,
		ErrnoDeliverInvalidMsgLength:   errDeliverInvalidMsgLength,
		ErrnoDeliverInvalidFeeCode:     errDeliverInvalidFeeCode,
		ErrnoDeliverExceedMaxMsgLength: errDeliverExceedMaxMsgLength,
		ErrnoDeliverInvalidServiceId:   errDeliverInvalidServiceId,
		ErrnoDeliverNotPassFlowControl: errDeliverNotPassFlowControl,
		ErrnoDeliverOtherError:         errDeliverOtherError,
	}
)
View Source
var (
	ErrnoFwdInvalidStruct      uint8 = 1
	ErrnoFwdInvalidCommandId   uint8 = 2
	ErrnoFwdInvalidSequence    uint8 = 3
	ErrnoFwdInvalidMsgLength   uint8 = 4
	ErrnoFwdInvalidFeeCode     uint8 = 5
	ErrnoFwdExceedMaxMsgLength uint8 = 6
	ErrnoFwdInvalidServiceId   uint8 = 7
	ErrnoFwdNotPassFlowControl uint8 = 8
	ErrnoFwdNoPrivilege        uint8 = 9

	FwdRspResultErrMap = map[uint8]error{
		ErrnoFwdInvalidStruct:      errFwdInvalidStruct,
		ErrnoFwdInvalidCommandId:   errFwdInvalidCommandId,
		ErrnoFwdInvalidSequence:    errFwdInvalidSequence,
		ErrnoFwdInvalidMsgLength:   errFwdInvalidMsgLength,
		ErrnoFwdInvalidFeeCode:     errFwdInvalidFeeCode,
		ErrnoFwdExceedMaxMsgLength: errFwdExceedMaxMsgLength,
		ErrnoFwdInvalidServiceId:   errFwdInvalidServiceId,
		ErrnoFwdNotPassFlowControl: errFwdNotPassFlowControl,
		ErrnoFwdNoPrivilege:        errFwdNoPrivilege,
	}
)

Errors for result in fwd resp.

View Source
var (
	ErrEmptyServerAddr = errors.New("cmpp server listen: empty server addr")
	ErrNoHandlers      = errors.New("cmpp server: no connection handler")
	ErrUnsupportedPkt  = errors.New("cmpp server read packet: receive a unsupported pkt")
)

errors for cmpp server

View Source
var (
	ErrnoSubmitInvalidStruct         uint8 = 1
	ErrnoSubmitInvalidCommandId      uint8 = 2
	ErrnoSubmitInvalidSequence       uint8 = 3
	ErrnoSubmitInvalidMsgLength      uint8 = 4
	ErrnoSubmitInvalidFeeCode        uint8 = 5
	ErrnoSubmitExceedMaxMsgLength    uint8 = 6
	ErrnoSubmitInvalidServiceId      uint8 = 7
	ErrnoSubmitNotPassFlowControl    uint8 = 8
	ErrnoSubmitNotServeFeeTerminalId uint8 = 9
	ErrnoSubmitInvalidSrcId          uint8 = 10
	ErrnoSubmitInvalidMsgSrc         uint8 = 11
	ErrnoSubmitInvalidFeeTerminalId  uint8 = 12
	ErrnoSubmitInvalidDestTerminalId uint8 = 13

	SubmitRspResultErrMap = map[uint8]error{
		ErrnoSubmitInvalidStruct:         errSubmitInvalidStruct,
		ErrnoSubmitInvalidCommandId:      errSubmitInvalidCommandId,
		ErrnoSubmitInvalidSequence:       errSubmitInvalidSequence,
		ErrnoSubmitInvalidMsgLength:      errSubmitInvalidMsgLength,
		ErrnoSubmitInvalidFeeCode:        errSubmitInvalidFeeCode,
		ErrnoSubmitExceedMaxMsgLength:    errSubmitExceedMaxMsgLength,
		ErrnoSubmitInvalidServiceId:      errSubmitInvalidServiceId,
		ErrnoSubmitNotPassFlowControl:    errSubmitNotPassFlowControl,
		ErrnoSubmitNotServeFeeTerminalId: errSubmitNotServeFeeTerminalId,
		ErrnoSubmitInvalidSrcId:          errSubmitInvalidSrcId,
		ErrnoSubmitInvalidMsgSrc:         errSubmitInvalidMsgSrc,
		ErrnoSubmitInvalidFeeTerminalId:  errSubmitInvalidFeeTerminalId,
		ErrnoSubmitInvalidDestTerminalId: errSubmitInvalidDestTerminalId,
	}
)

Errors for result in submit resp.

View Source
var ErrCommandIdInvalid = errors.New("command_Id in Packet data is invalid")
View Source
var ErrCommandIdNotSupported = errors.New("command_Id in Packet data is not supported")
View Source
var ErrMethodParamsInvalid = errors.New("params passed to method is invalid")

Common errors.

View Source
var ErrNotCompleted = errors.New("data not being handled completed")
View Source
var ErrRespNotMatch = errors.New("the response is not matched with the request")
View Source
var ErrTotalLengthInvalid = errors.New("total_length in Packet data is invalid")

Protocol errors.

Functions

func ListenAndServe

func ListenAndServe(addr string, typ Type, t time.Duration, n int32, logWriter io.Writer, handlers ...Handler) error

ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client stands for one client-side instance, just like a session. It may connect to the server, send & recv cmpp packets and terminate the connection.

func NewClient

func NewClient(typ Type) *Client

New establishes a new cmpp client.

func (*Client) Connect

func (cli *Client) Connect(servAddr, user, password string, timeout time.Duration) error

Connect connect to the cmpp server in block mode. It sends login packet, receive and parse connect response packet.

func (*Client) Disconnect

func (cli *Client) Disconnect()

func (*Client) RecvAndUnpackPkt

func (cli *Client) RecvAndUnpackPkt(timeout time.Duration) (interface{}, error)

RecvAndUnpackPkt receives cmpp byte stream, and unpack it to some cmpp packet structure.

func (*Client) SendReqPkt

func (cli *Client) SendReqPkt(packet Packer) (uint32, error)

SendReqPkt pack the cmpp request packet structure and send it to the other peer.

func (*Client) SendRspPkt

func (cli *Client) SendRspPkt(packet Packer, seqId uint32) error

SendRspPkt pack the cmpp response packet structure and send it to the other peer.

type Cmpp2ConnRspPkt

type Cmpp2ConnRspPkt struct {
	Status   uint8
	AuthIsmg string
	Version  Type
	Secret   string
	AuthSrc  string
	SeqId    uint32
}

Cmpp2ConnRspPkt represents a Cmpp2 connect response packet.

when used in server side(pack), you should initialize it with correct Status, AuthSrc, Secret and Version.

when used in client side(unpack), nothing needed to be initialized. unpack will fill the Status, AuthImsg, Version and SeqId

func (*Cmpp2ConnRspPkt) Pack

func (p *Cmpp2ConnRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2ConnRspPkt to bytes stream for server side. Before calling Pack, you should initialize a Cmpp2ConnRspPkt variable with correct Status,AuthenticatorSource, Secret and Version.

func (*Cmpp2ConnRspPkt) Unpack

func (p *Cmpp2ConnRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2ConnRspPkt variable. Usually it is used in client side. After unpack, you will get SeqId, Status, AuthenticatorIsmg, and Version. Parameter data contains seqId in header and the whole packet body.

type Cmpp2DeliverReqPkt

type Cmpp2DeliverReqPkt struct {
	MsgId            uint64
	DestId           string
	ServiceId        string
	TpPid            uint8
	TpUdhi           uint8
	MsgFmt           uint8
	SrcTerminalId    string
	RegisterDelivery uint8
	MsgLength        uint8
	MsgContent       string
	Reserve          string

	//session info
	SeqId uint32
}

func (*Cmpp2DeliverReqPkt) Pack

func (p *Cmpp2DeliverReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2DeliverReqPkt to bytes stream for client side.

func (*Cmpp2DeliverReqPkt) Unpack

func (p *Cmpp2DeliverReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2DeliverReqPkt variable. After unpack, you will get all value of fields in Cmpp2DeliverReqPkt struct.

type Cmpp2DeliverRspPkt

type Cmpp2DeliverRspPkt struct {
	MsgId  uint64
	Result uint8

	//session info
	SeqId uint32
}

func (*Cmpp2DeliverRspPkt) Pack

func (p *Cmpp2DeliverRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2DeliverRspPkt to bytes stream for client side.

func (*Cmpp2DeliverRspPkt) Unpack

func (p *Cmpp2DeliverRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2DeliverRspPkt variable. After unpack, you will get all value of fields in Cmpp2DeliverRspPkt struct.

type Cmpp2FwdReqPkt

type Cmpp2FwdReqPkt struct {
	SourceId           string
	DestinationId      string
	NodesCount         uint8
	MsgFwdType         uint8
	MsgId              uint64
	PkTotal            uint8
	PkNumber           uint8
	RegisteredDelivery uint8
	MsgLevel           uint8
	ServiceId          string
	FeeUserType        uint8
	FeeTerminalId      string
	TpPid              uint8
	TpUdhi             uint8
	MsgFmt             uint8
	MsgSrc             string
	FeeType            string
	FeeCode            string
	ValidTime          string
	AtTime             string
	SrcId              string
	DestUsrTl          uint8
	DestId             []string
	MsgLength          uint8
	MsgContent         string
	Reserve            string

	// session info
	SeqId uint32
}

func (*Cmpp2FwdReqPkt) Pack

func (p *Cmpp2FwdReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2FwdReqPkt to bytes stream for client side. Before calling Pack, you should initialize a Cmpp2FwdReqPkt variable with correct field value.

func (*Cmpp2FwdReqPkt) Unpack

func (p *Cmpp2FwdReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2FwdReqPkt variable. After unpack, you will get all value of fields in Cmpp2FwdReqPkt struct.

type Cmpp2FwdRspPkt

type Cmpp2FwdRspPkt struct {
	MsgId    uint64
	PkTotal  uint8
	PkNumber uint8
	Result   uint8

	// session info
	SeqId uint32
}

func (*Cmpp2FwdRspPkt) Pack

func (p *Cmpp2FwdRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2FwdRspPkt to bytes stream for server side. Before calling Pack, you should initialize a Cmpp2FwdRspPkt variable with correct field value.

func (*Cmpp2FwdRspPkt) Unpack

func (p *Cmpp2FwdRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2FwdRspPkt variable. After unpack, you will get all value of fields in Cmpp2FwdRspPkt struct.

type Cmpp2SubmitReqPkt

type Cmpp2SubmitReqPkt struct {
	MsgId              uint64
	PkTotal            uint8
	PkNumber           uint8
	RegisteredDelivery uint8
	MsgLevel           uint8
	ServiceId          string
	FeeUserType        uint8
	FeeTerminalId      string
	TpPid              uint8
	TpUdhi             uint8
	MsgFmt             uint8
	MsgSrc             string
	FeeType            string
	FeeCode            string
	ValidTime          string
	AtTime             string
	SrcId              string
	DestUsrTl          uint8
	DestTerminalId     []string
	MsgLength          uint8
	MsgContent         string
	Reserve            string

	// session info
	SeqId uint32
}

func (*Cmpp2SubmitReqPkt) Pack

func (p *Cmpp2SubmitReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2SubmitReqPkt to bytes stream for client side. Before calling Pack, you should initialize a Cmpp2SubmitReqPkt variable with correct field value.

func (*Cmpp2SubmitReqPkt) Unpack

func (p *Cmpp2SubmitReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2SubmitReqPkt variable. Usually it is used in server side. After unpack, you will get all value of fields in Cmpp2SubmitReqPkt struct.

type Cmpp2SubmitRspPkt

type Cmpp2SubmitRspPkt struct {
	MsgId  uint64
	Result uint8

	// session info
	SeqId uint32
}

func (*Cmpp2SubmitRspPkt) Pack

func (p *Cmpp2SubmitRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp2SubmitRspPkt to bytes stream for Server side. Before calling Pack, you should initialize a Cmpp2SubmitRspPkt variable with correct field value.

func (*Cmpp2SubmitRspPkt) Unpack

func (p *Cmpp2SubmitRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp2SubmitRspPkt variable. Usually it is used in client side. After unpack, you will get all value of fields in Cmpp2SubmitRspPkt struct.

type Cmpp3ConnRspPkt

type Cmpp3ConnRspPkt struct {
	Status   uint32
	AuthIsmg string
	Version  Type
	Secret   string
	AuthSrc  string
	SeqId    uint32
}

Cmpp3ConnRspPkt represents a Cmpp3 connect response packet.

when used in server side(pack), you should initialize it with correct Status, AuthSrc, Secret and Version.

when used in client side(unpack), nothing needed to be initialized. unpack will fill the Status, AuthImsg, Version and SeqId

func (*Cmpp3ConnRspPkt) Pack

func (p *Cmpp3ConnRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3ConnRspPkt to bytes stream for server side. Before calling Pack, you should initialize a Cmpp3ConnRspPkt variable with correct Status,AuthenticatorSource, Secret and Version.

func (*Cmpp3ConnRspPkt) Unpack

func (p *Cmpp3ConnRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3ConnRspPkt variable. Usually it is used in client side. After unpack, you will get SeqId, Status, AuthenticatorIsmg, and Version. Parameter data contains seqId in header and the whole packet body.

type Cmpp3DeliverReqPkt

type Cmpp3DeliverReqPkt struct {
	MsgId            uint64
	DestId           string
	ServiceId        string
	TpPid            uint8
	TpUdhi           uint8
	MsgFmt           uint8
	SrcTerminalId    string
	SrcTerminalType  uint8
	RegisterDelivery uint8
	MsgLength        uint8
	MsgContent       string
	LinkId           string

	//session info
	SeqId uint32
}

func (*Cmpp3DeliverReqPkt) Pack

func (p *Cmpp3DeliverReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3DeliverReqPkt to bytes stream for client side.

func (*Cmpp3DeliverReqPkt) Unpack

func (p *Cmpp3DeliverReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3DeliverReqPkt variable. After unpack, you will get all value of fields in Cmpp3DeliverReqPkt struct.

type Cmpp3DeliverRspPkt

type Cmpp3DeliverRspPkt struct {
	MsgId  uint64
	Result uint32

	//session info
	SeqId uint32
}

func (*Cmpp3DeliverRspPkt) Pack

func (p *Cmpp3DeliverRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3DeliverRspPkt to bytes stream for client side.

func (*Cmpp3DeliverRspPkt) Unpack

func (p *Cmpp3DeliverRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3DeliverRspPkt variable. After unpack, you will get all value of fields in Cmpp3DeliverRspPkt struct.

type Cmpp3FwdReqPkt

type Cmpp3FwdReqPkt struct {
	SourceId            string
	DestinationId       string
	NodesCount          uint8
	MsgFwdType          uint8
	MsgId               uint64
	PkTotal             uint8
	PkNumber            uint8
	RegisteredDelivery  uint8
	MsgLevel            uint8
	ServiceId           string
	FeeUserType         uint8
	FeeTerminalId       string
	FeeTerminalPseudo   string
	FeeTerminalUserType uint8
	TpPid               uint8
	TpUdhi              uint8
	MsgFmt              uint8
	MsgSrc              string
	FeeType             string
	FeeCode             string
	ValidTime           string
	AtTime              string
	SrcId               string
	SrcPseudo           string
	SrcUserType         uint8
	SrcType             uint8
	DestUsrTl           uint8
	DestId              []string
	DestPseudo          string
	DestUserType        uint8
	MsgLength           uint8
	MsgContent          string
	LinkId              string

	// session info
	SeqId uint32
}

func (*Cmpp3FwdReqPkt) Pack

func (p *Cmpp3FwdReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3FwdReqPkt to bytes stream for client side. Before calling Pack, you should initialize a Cmpp3FwdReqPkt variable with correct field value.

func (*Cmpp3FwdReqPkt) Unpack

func (p *Cmpp3FwdReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3FwdReqPkt variable. After unpack, you will get all value of fields in Cmpp3FwdReqPkt struct.

type Cmpp3FwdRspPkt

type Cmpp3FwdRspPkt struct {
	MsgId    uint64
	PkTotal  uint8
	PkNumber uint8
	Result   uint32

	// session info
	SeqId uint32
}

func (*Cmpp3FwdRspPkt) Pack

func (p *Cmpp3FwdRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3FwdRspPkt to bytes stream for server side. Before calling Pack, you should initialize a Cmpp3FwdRspPkt variable with correct field value.

func (*Cmpp3FwdRspPkt) Unpack

func (p *Cmpp3FwdRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3FwdRspPkt variable. After unpack, you will get all value of fields in Cmpp3FwdRspPkt struct.

type Cmpp3SubmitReqPkt

type Cmpp3SubmitReqPkt struct {
	MsgId              uint64
	PkTotal            uint8
	PkNumber           uint8
	RegisteredDelivery uint8
	MsgLevel           uint8
	ServiceId          string
	FeeUserType        uint8
	FeeTerminalId      string
	FeeTerminalType    uint8
	TpPid              uint8
	TpUdhi             uint8
	MsgFmt             uint8
	MsgSrc             string
	FeeType            string
	FeeCode            string
	ValidTime          string
	AtTime             string
	SrcId              string
	DestUsrTl          uint8
	DestTerminalId     []string
	DestTerminalType   uint8
	MsgLength          uint8
	MsgContent         string
	LinkId             string

	// session info
	SeqId uint32
}

func (*Cmpp3SubmitReqPkt) Pack

func (p *Cmpp3SubmitReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3SubmitReqPkt to bytes stream for client side. Before calling Pack, you should initialize a Cmpp3SubmitReqPkt variable with correct field value.

func (*Cmpp3SubmitReqPkt) Unpack

func (p *Cmpp3SubmitReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3SubmitReqPkt variable. Usually it is used in server side. After unpack, you will get all value of fields in Cmpp3SubmitReqPkt struct.

type Cmpp3SubmitRspPkt

type Cmpp3SubmitRspPkt struct {
	MsgId  uint64
	Result uint32

	// session info
	SeqId uint32
}

func (*Cmpp3SubmitRspPkt) Pack

func (p *Cmpp3SubmitRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the Cmpp3SubmitRspPkt to bytes stream for Server side. Before calling Pack, you should initialize a Cmpp3SubmitRspPkt variable with correct field value.

func (*Cmpp3SubmitRspPkt) Unpack

func (p *Cmpp3SubmitRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a Cmpp3SubmitRspPkt variable. Usually it is used in client side. After unpack, you will get all value of fields in Cmpp3SubmitRspPkt struct.

type CmppActiveTestReqPkt

type CmppActiveTestReqPkt struct {
	// session info
	SeqId uint32
}

func (*CmppActiveTestReqPkt) Pack

func (p *CmppActiveTestReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the CmppActiveTestReqPkt to bytes stream for client side.

func (*CmppActiveTestReqPkt) Unpack

func (p *CmppActiveTestReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppActiveTestReqPkt variable. After unpack, you will get all value of fields in CmppActiveTestReqPkt struct.

type CmppActiveTestRspPkt

type CmppActiveTestRspPkt struct {
	Reserved uint8
	// session info
	SeqId uint32
}

func (*CmppActiveTestRspPkt) Pack

func (p *CmppActiveTestRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the CmppActiveTestRspPkt to bytes stream for client side.

func (*CmppActiveTestRspPkt) Unpack

func (p *CmppActiveTestRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppActiveTestRspPkt variable. After unpack, you will get all value of fields in CmppActiveTestRspPkt struct.

type CmppConnReqPkt

type CmppConnReqPkt struct {
	SrcAddr   string
	AuthSrc   string
	Version   Type
	Timestamp uint32
	Secret    string
	SeqId     uint32
}

CmppConnReqPkt represents a Cmpp2 or Cmpp3 connect request packet.

when used in client side(pack), you should initialize it with correct SourceAddr(SrcAddr), Secret and Version.

when used in server side(unpack), nothing needed to be initialized. unpack will fill the SourceAddr(SrcAddr), AuthSrc, Version, Timestamp and SeqId

func (*CmppConnReqPkt) Pack

func (p *CmppConnReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the CmppConnReqPkt to bytes stream for client side. Before calling Pack, you should initialize a CmppConnReqPkt variable with correct SourceAddr(SrcAddr), Secret and Version.

func (*CmppConnReqPkt) Unpack

func (p *CmppConnReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppConnReqPkt variable. Usually it is used in server side. After unpack, you will get SeqId, SourceAddr, AuthenticatorSource, Version and Timestamp.

type CmppReceiptPkt

type CmppReceiptPkt struct {
	MsgId          uint64
	Stat           string
	SubmitTime     string // YYMMDDHHMM
	DoneTime       string // YYMMDDHHMM
	DestTerminalId string
	SmscSequence   uint32
}

func (*CmppReceiptPkt) Pack

func (p *CmppReceiptPkt) Pack() ([]byte, error)

Pack packs the CmppReceiptPkt to bytes stream for client side.

func (*CmppReceiptPkt) Unpack

func (p *CmppReceiptPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppReceiptPkt variable. After unpack, you will get all value of fields in CmppReceiptPkt struct.

type CmppTerminateReqPkt

type CmppTerminateReqPkt struct {
	// session info
	SeqId uint32
}

func (*CmppTerminateReqPkt) Pack

func (p *CmppTerminateReqPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the CmppTerminateReqPkt to bytes stream for client side.

func (*CmppTerminateReqPkt) Unpack

func (p *CmppTerminateReqPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppTerminateReqPkt variable. After unpack, you will get all value of fields in CmppTerminateReqPkt struct.

type CmppTerminateRspPkt

type CmppTerminateRspPkt struct {
	// session info
	SeqId uint32
}

func (*CmppTerminateRspPkt) Pack

func (p *CmppTerminateRspPkt) Pack(seqId uint32) ([]byte, error)

Pack packs the CmppTerminateRspPkt to bytes stream for client side.

func (*CmppTerminateRspPkt) Unpack

func (p *CmppTerminateRspPkt) Unpack(data []byte) error

Unpack unpack the binary byte stream to a CmppTerminateRspPkt variable. After unpack, you will get all value of fields in CmppTerminateRspPkt struct.

type CommandId

type CommandId uint32
const (
	CMPP_REQUEST_MIN, CMPP_RESPONSE_MIN CommandId = iota, 0x80000000 + iota
	CMPP_CONNECT, CMPP_CONNECT_RESP
	CMPP_TERMINATE, CMPP_TERMINATE_RESP

	CMPP_SUBMIT, CMPP_SUBMIT_RESP
	CMPP_DELIVER, CMPP_DELIVER_RESP
	CMPP_QUERY, CMPP_QUERY_RESP
	CMPP_CANCEL, CMPP_CANCEL_RESP
	CMPP_ACTIVE_TEST, CMPP_ACTIVE_TEST_RESP
	CMPP_FWD, CMPP_FWD_RESP
	CMPP_MT_ROUTE, CMPP_MT_ROUTE_RESP CommandId = 0x00000010 - 10 + iota, 0x80000010 - 10 + iota
	CMPP_MO_ROUTE, CMPP_MO_ROUTE_RESP
	CMPP_GET_MT_ROUTE, CMPP_GET_MT_ROUTE_RESP
	CMPP_MT_ROUTE_UPDATE, CMPP_MT_ROUTE_UPDATE_RESP
	CMPP_MO_ROUTE_UPDATE, CMPP_MO_ROUTE_UPDATE_RESP
	CMPP_PUSH_MT_ROUTE_UPDATE, CMPP_PUSH_MT_ROUTE_UPDATE_RESP
	CMPP_PUSH_MO_ROUTE_UPDATE, CMPP_PUSH_MO_ROUTE_UPDATE_RESP
	CMPP_GET_MO_ROUTE, CMPP_GET_MO_ROUTE_RESP
	CMPP_REQUEST_MAX, CMPP_RESPONSE_MAX
)

func (CommandId) String

func (id CommandId) String() string

type Conn

type Conn struct {
	net.Conn
	State State
	Typ   Type

	// for SeqId generator goroutine
	SeqId <-chan uint32
	// contains filtered or unexported fields
}

func NewConn

func NewConn(conn net.Conn, typ Type) *Conn

New returns an abstract structure for successfully established underlying net.Conn.

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) RecvAndUnpackPkt

func (c *Conn) RecvAndUnpackPkt(timeout time.Duration) (interface{}, error)

RecvAndUnpackPkt receives cmpp byte stream, and unpack it to some cmpp packet structure.

func (*Conn) SendPkt

func (c *Conn) SendPkt(packet Packer, seqId uint32) error

SendPkt pack the cmpp packet structure and send it to the other peer.

func (*Conn) SetState

func (c *Conn) SetState(state State)

type Handler

type Handler interface {
	ServeCmpp(*Response, *Packet, *log.Logger) (bool, error)
}

type HandlerFunc

type HandlerFunc func(*Response, *Packet, *log.Logger) (bool, error)

The HandlerFunc type is an adapter to allow the use of ordinary functions as Cmpp handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

The first return value indicates whether to invoke next handler in the chain of handlers.

The second return value shows the error returned from the handler. And if it is non-nil, server will close the client connection after sending back the corresponding response.

func (HandlerFunc) ServeCmpp

func (f HandlerFunc) ServeCmpp(r *Response, p *Packet, l *log.Logger) (bool, error)

ServeCmpp calls f(r, p).

type OpError

type OpError struct {
	// contains filtered or unexported fields
}

OpError is the error type usually returned by functions in the cmpppacket package. It describes the operation and the error which the operation caused.

func NewOpError

func NewOpError(e error, op string) *OpError

func (*OpError) Cause

func (e *OpError) Cause() error

func (*OpError) Error

func (e *OpError) Error() string

func (*OpError) Op

func (e *OpError) Op() string

type Packer

type Packer interface {
	Pack(seqId uint32) ([]byte, error)
	Unpack(data []byte) error
}

type Packet

type Packet struct {
	Packer
	*Conn
}

type Response

type Response struct {
	*Packet
	Packer
	SeqId uint32
}

type Server

type Server struct {
	Addr    string
	Handler Handler

	// protocol info
	Typ Type
	T   time.Duration // interval betwwen two active tests
	N   int32         // continuous send times when no response back

	// ErrorLog specifies an optional logger for errors accepting
	// connections and unexpected behavior from handlers.
	// If nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger
}

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.

type State

type State uint8
const (
	CONN_CLOSED State = iota
	CONN_CONNECTED
	CONN_AUTHOK
)

Conn States

type Type

type Type int8
const (
	V30 Type = 0x30
	V21 Type = 0x21
	V20 Type = 0x20
)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis
examples
fuzztest

Jump to

Keyboard shortcuts

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