sip: Introduce a SIPIdentityManager to register and manage identities
A list of identities can be added and they will be re-gistered and re-registered. The manager can be asked which of the of the identities are available. This is understood as being registered.
This commit is contained in:
parent
8c4ca4a6d4
commit
547b7e1531
|
@ -7,6 +7,8 @@
|
||||||
<prereq>OsmoSIP</prereq>
|
<prereq>OsmoSIP</prereq>
|
||||||
|
|
||||||
<filein>src/Logging.st</filein>
|
<filein>src/Logging.st</filein>
|
||||||
|
<filein>src/sip/SIPIdentityManager.st</filein>
|
||||||
|
<filein>src/sip/MSCSIPIdentity.st</filein>
|
||||||
<filein>src/VLR.st</filein>
|
<filein>src/VLR.st</filein>
|
||||||
<filein>src/HLR.st</filein>
|
<filein>src/HLR.st</filein>
|
||||||
<filein>src/BSCConfig.st</filein>
|
<filein>src/BSCConfig.st</filein>
|
||||||
|
@ -35,6 +37,7 @@
|
||||||
<sunit>OsmoMSC.BSCIPAConnectionTest</sunit>
|
<sunit>OsmoMSC.BSCIPAConnectionTest</sunit>
|
||||||
<sunit>OsmoMSC.AuthTestNull</sunit>
|
<sunit>OsmoMSC.AuthTestNull</sunit>
|
||||||
<sunit>OsmoMSC.AuthTestIdentity</sunit>
|
<sunit>OsmoMSC.AuthTestIdentity</sunit>
|
||||||
|
<sunit>OsmoMSC.SIPIdentityManagerTest</sunit>
|
||||||
<filein>tests/HLRDummyResolver.st</filein>
|
<filein>tests/HLRDummyResolver.st</filein>
|
||||||
<filein>tests/BSCConfigTest.st</filein>
|
<filein>tests/BSCConfigTest.st</filein>
|
||||||
<filein>tests/BSCIPAConnectionTest.st</filein>
|
<filein>tests/BSCIPAConnectionTest.st</filein>
|
||||||
|
@ -48,5 +51,7 @@
|
||||||
<filein>tests/GSMProcessorMockForAuthCheat.st</filein>
|
<filein>tests/GSMProcessorMockForAuthCheat.st</filein>
|
||||||
<filein>tests/GSMProcessorMockForAuthIMSI.st</filein>
|
<filein>tests/GSMProcessorMockForAuthIMSI.st</filein>
|
||||||
<filein>tests/GSMProcessorMockForAuthTimeout.st</filein>
|
<filein>tests/GSMProcessorMockForAuthTimeout.st</filein>
|
||||||
|
<filein>tests/MockSIPUserAgent.st</filein>
|
||||||
|
<filein>tests/SIPIdentityManagerTest.st</filein>
|
||||||
</test>
|
</test>
|
||||||
</package>
|
</package>
|
||||||
|
|
|
@ -63,3 +63,16 @@ Osmo.LogArea subclass: LogAreaMSC [
|
||||||
enabled: true; minLevel: Osmo.LogLevel debug; yourself.
|
enabled: true; minLevel: Osmo.LogLevel debug; yourself.
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Osmo.LogArea subclass: LogAreaMSCSIP [
|
||||||
|
<category: 'OsmoMSC-Logging'>
|
||||||
|
|
||||||
|
LogAreaMSCSIP class >> areaName [^ #mscSIP]
|
||||||
|
LogAreaMSCSIP class >> areaDescription [^'MSC SIP']
|
||||||
|
LogAreaMSCSIP class >> default [
|
||||||
|
^self new
|
||||||
|
enabled: true;
|
||||||
|
minLevel: Osmo.LogLevel debug;
|
||||||
|
yourself
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
"
|
||||||
|
(C) 2014 by Holger Hans Peter Freyther
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"
|
||||||
|
|
||||||
|
Osmo.SIPIdentity subclass: MSCSIPIdentity [
|
||||||
|
| available manager registerTimer |
|
||||||
|
<category: 'OsmoMSC-SIP'>
|
||||||
|
<comment: 'I add timers and others to the plain identity. This
|
||||||
|
way we can keep track if something is available or not.'>
|
||||||
|
|
||||||
|
MSCSIPIdentity class >> new [
|
||||||
|
^super new
|
||||||
|
initialize;
|
||||||
|
yourself
|
||||||
|
]
|
||||||
|
|
||||||
|
initialize [
|
||||||
|
available := false.
|
||||||
|
]
|
||||||
|
|
||||||
|
manager: aManager [
|
||||||
|
manager := aManager
|
||||||
|
]
|
||||||
|
|
||||||
|
startRegistration [
|
||||||
|
| register dialog |
|
||||||
|
dialog := (Osmo.SIPDialog fromUser: 'sip:', username host: hostname port: 5060)
|
||||||
|
identity: self;
|
||||||
|
yourself.
|
||||||
|
register := (Osmo.SIPRegisterTransaction createWith: dialog on: manager useragent cseq: 1)
|
||||||
|
destination: 'sip:', hostname;
|
||||||
|
onTimeout: [self registrationTimedOut];
|
||||||
|
onFailure: [:response :dialog | self registrationFailed];
|
||||||
|
onSuccess: [:response :dialog | self registrationSuccess];
|
||||||
|
yourself.
|
||||||
|
register start.
|
||||||
|
]
|
||||||
|
|
||||||
|
registrationTimedOut [
|
||||||
|
self logNotice: 'SIPIdentity(%1@%2) registration timed-out' % {username. hostname}
|
||||||
|
area: #mscSIP.
|
||||||
|
available := false.
|
||||||
|
self reRegisterIn: 10.
|
||||||
|
]
|
||||||
|
|
||||||
|
registrationFailed [
|
||||||
|
self logNotice: 'SIPIdentity(%1@%2) registration timed-out' % {username. hostname}
|
||||||
|
area: #mscSIP.
|
||||||
|
available := false.
|
||||||
|
self reRegisterIn: 10.
|
||||||
|
]
|
||||||
|
|
||||||
|
registrationSuccess [
|
||||||
|
self logNotice: 'SIPIdentity(%1@%2) registered' % {username. hostname}
|
||||||
|
area: #mscSIP.
|
||||||
|
available := true.
|
||||||
|
self reRegisterIn: 3590.
|
||||||
|
]
|
||||||
|
|
||||||
|
reRegisterIn: seconds [
|
||||||
|
"Re-register the identity..."
|
||||||
|
registerTimer ifNotNil: [registerTimer cancel].
|
||||||
|
registerTimer := (Osmo.TimerScheduler instance)
|
||||||
|
scheduleInSeconds: seconds block: [self startRegistration].
|
||||||
|
]
|
||||||
|
|
||||||
|
isAvailable [
|
||||||
|
^available
|
||||||
|
]
|
||||||
|
]
|
|
@ -0,0 +1,62 @@
|
||||||
|
"
|
||||||
|
(C) 2014 by Holger Hans Peter Freyther
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"
|
||||||
|
|
||||||
|
Object subclass: SIPIdentityManager [
|
||||||
|
| identities useragent |
|
||||||
|
|
||||||
|
<category: 'OsmoMSC-SIP'>
|
||||||
|
<comment: 'I help in managing and registering different
|
||||||
|
SIPIdentities. This includes running the register transaction,
|
||||||
|
re-running it shortly before the expiration and helping to
|
||||||
|
keep track which one is used and not.'>
|
||||||
|
|
||||||
|
SIPIdentityManager class >> new [
|
||||||
|
^super new
|
||||||
|
initialize;
|
||||||
|
yourself
|
||||||
|
]
|
||||||
|
|
||||||
|
SIPIdentityManager class >> initWith: aUseragent [
|
||||||
|
^self new
|
||||||
|
useragent: aUseragent;
|
||||||
|
yourself
|
||||||
|
]
|
||||||
|
|
||||||
|
initialize [
|
||||||
|
identities := OrderedCollection new.
|
||||||
|
]
|
||||||
|
|
||||||
|
useragent [
|
||||||
|
^useragent
|
||||||
|
]
|
||||||
|
|
||||||
|
useragent: aUseragent [
|
||||||
|
useragent := aUseragent
|
||||||
|
]
|
||||||
|
|
||||||
|
addIdentity: anIdentity [
|
||||||
|
identities add: anIdentity.
|
||||||
|
anIdentity
|
||||||
|
manager: self;
|
||||||
|
startRegistration.
|
||||||
|
]
|
||||||
|
|
||||||
|
available [
|
||||||
|
^identities select: [:each | each isAvailable]
|
||||||
|
]
|
||||||
|
]
|
|
@ -0,0 +1,38 @@
|
||||||
|
"
|
||||||
|
(C) 2014 by Holger Hans Peter Freyther
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"
|
||||||
|
|
||||||
|
Object subclass: MockSIPUserAgent [
|
||||||
|
MockSIPUserAgent class >> generateBranch [
|
||||||
|
^'z9hG4bK776asdhds'
|
||||||
|
]
|
||||||
|
|
||||||
|
generateVia: aBranch [
|
||||||
|
^'SIP/2.0/UDP pc33.atlanta.com;branch=', aBranch
|
||||||
|
]
|
||||||
|
|
||||||
|
addTransaction: aTransaction [
|
||||||
|
]
|
||||||
|
|
||||||
|
injectDefaults: aRequest [
|
||||||
|
aRequest addParameter: 'Max-Forwards' value: '70'.
|
||||||
|
aRequest addParameter: 'User-Agent' value: 'mock'.
|
||||||
|
]
|
||||||
|
|
||||||
|
queueData: aData dialog: aDialog [
|
||||||
|
]
|
||||||
|
]
|
|
@ -0,0 +1,35 @@
|
||||||
|
"
|
||||||
|
(C) 2014 by Holger Hans Peter Freyther
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"
|
||||||
|
|
||||||
|
TestCase subclass: SIPIdentityManagerTest [
|
||||||
|
testEmpty [
|
||||||
|
| manager |
|
||||||
|
manager := SIPIdentityManager new.
|
||||||
|
self assert: manager available isEmpty.
|
||||||
|
]
|
||||||
|
|
||||||
|
testAvailable [
|
||||||
|
| manager |
|
||||||
|
manager := SIPIdentityManager initWith: MockSIPUserAgent new.
|
||||||
|
manager addIdentity: (MSCSIPIdentity new
|
||||||
|
username: 'user';
|
||||||
|
hostname: 'localhost';
|
||||||
|
yourself).
|
||||||
|
self assert: manager available isEmpty.
|
||||||
|
]
|
||||||
|
]
|
Reference in New Issue