forked from vponomarev/libsmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool-hdr.go
111 lines (91 loc) · 2.5 KB
/
pool-hdr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package libsmpp
import (
"sync"
"time"
)
// PoolQueue SessionID
type PQSessionID uint32
// Session Pool Entry
type SPEntry struct {
SessionID PQSessionID // ID of the session
Session *SMPPSession // Reference to Session
IsClosed bool // FLAG: Is connection closed
}
// Structure for routed packet tracking (reply routing)
type PoolPacketTracking struct {
OrigSessionID PQSessionID // Originator sessionID
DestSessionID PQSessionID // Recipient sessionID
T time.Time // Routing origination time
TransactionID uint32 // UNIQ Transaction ID [KEY] for routing
Packet SMPPPacket // Original SMPP packet
}
// Session Pool
type SessionPool struct {
Pool map[PQSessionID]*SPEntry // Pool for storing sessions
poolMutex sync.RWMutex //
Queue chan PQPacket // Outgoing queue from all SMPP Sessions
QResp chan PQPacket // RESPONSE Queue for packet delivery
maxSessionID PQSessionID
sessionMutex sync.RWMutex
maxTransaction uint32
// transactionMutex sync.RWMutex
Track map[uint32]PoolPacketTracking
trackMutex sync.RWMutex
RoutePolicy []PRoutePolicy
// routeMutex sync.RWMutex
}
// Pool Queue Packet
type PQPacket struct {
OrigSessionID PQSessionID // Originator sessionID
DestSessionID PQSessionID // Recipient sessionID
T time.Time // Packet origination timestamp
IsReply bool // FLAG: This is reply
PacketSeq uint32 // SeqNo of the original/reply packet
Packet SMPPPacket // SMPP Packet
}
// Routing policy entry
type PRoutePolicy struct {
origID string
destID string
}
func (p *SessionPool) GetSystemIdBySessionID(id PQSessionID) (string, bool) {
p.sessionMutex.RLock()
defer p.sessionMutex.RUnlock()
if o, ok := p.Pool[id]; ok {
return o.Session.Bind.SystemID, ok
}
return "", false
}
func (p *SessionPool) GetSessionIdBySystemID(id string) (PQSessionID, bool) {
p.sessionMutex.RLock()
defer p.sessionMutex.RUnlock()
for k, v := range p.Pool {
if !v.IsClosed && (v.Session.Bind.SystemID == id) {
return k, true
}
}
return 0, false
}
type SessionListInfo struct {
Id PQSessionID
Closed bool
Cs connState
Bind SMPPBind
MaxSeq uint32
}
func (p *SessionPool) GetSessionList() (l []SessionListInfo) {
p.sessionMutex.RLock()
defer p.sessionMutex.RUnlock()
for k, v := range p.Pool {
v.Session.seqMTX.RLock()
l = append(l, SessionListInfo{
Id: k,
Closed: v.IsClosed,
Cs: v.Session.Cs,
Bind: v.Session.Bind,
MaxSeq: v.Session.LastTXSeq,
})
v.Session.seqMTX.RUnlock()
}
return
}