1
#ifndef GEO_PROXIMITY_TARGET_SORTER_HXX
2
#define GEO_PROXIMITY_TARGET_SORTER_HXX 1
4
#ifndef RESIP_FIXED_POINT
12
#include "repro/Processor.hxx"
13
#include "repro/ResponseContext.hxx"
14
#include "repro/ProxyConfig.hxx"
16
#include "rutil/Data.hxx"
29
If enabled, then this baboon can post-process the target list.
30
This includes targets from the StaticRoute monkey and/or targets
31
from the LocationServer monkey. Requests that meet the filter
32
criteria will have their Target list, flatened (serialized) and
33
ordered based on the proximity of the target to the client sending
34
the request. Proximity is determined by looking for a
35
x-repro-geolocation="<latitude>,<longitude>" parameter on the Contact
36
header of a received request, or the Contact headers of Registration
37
requests. If this parameter is not found, then this processor will
38
attempt to determine the public IP address closest to the client or
39
target and use the MaxMind Geo IP library to lookup the geo location.
41
There are several requirements for using this Processor/Baboon:
42
1. RESIP_FIXED_POINT preprocessor define is required to allow floating
43
point operations required for distance calculations.
44
2. USE_MAXMIND_GEOIP preprocessor define is required to allow linking
45
with the MaxMind Geo IP library for looking up lat/long information
47
3. A copy of the GeoIP City database is required for looking up lat/long
48
information for an IP address. A free version of the databases can
49
be downloaded from here:
50
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
52
http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/
53
For a more accurate database, please see the details here:
54
http://www.maxmind.com/app/city
55
The location of these files are specifed in the following setting2:
56
GeoProximityIPv4CityDatabaseFile and GeoProximityIPv6CityDatabaseFile
57
4. A request URI filter must be defined in the repro configuration. This
58
filter uses a PCRE compliant regular expression to attempt
59
to match against the request URI of inbound requests. Any requests
60
matching this expression, will have its Targets sorted as described
62
ie: GeoProximityRequestUriFilter = ^sip:mediaserver.*@mydomain.com$
64
Some additional settings are:
65
GeoProximityDefaultDistance - The distance (in Kilometers) to use for
66
proximity sorting, when the Geo Location of a target cannot be
69
LoadBalanceEqualDistantTargets - If enabled, then targets that are
70
determined to be of equal distance from the client, will be placed in
75
class GeoProximityTargetSorter : public Processor
79
static resip::KeyValueStore::Key mGeoTargetSortingDoneKey;
81
GeoProximityTargetSorter(ProxyConfig& config);
82
virtual ~GeoProximityTargetSorter();
84
virtual processor_action_t process(RequestContext &);
87
void getClientGeoLocation(const resip::SipMessage& request, double& latitude, double& longitude);
88
void getTargetGeoLocation(const Target& target, double& latitude, double& longitude);
89
double getTargetDistance(const Target& target, double clientLatitude, double clientLongitude);
90
void parseGeoLocationParameter(const resip::Data& parameter, double& latitude, double& longitude);
91
double calculateDistance(double latitude1, double longitude1, double latitude2, double longitude2);
92
bool geoIPLookup(const resip::Tuple& address, double& latitude, double& longitude);
94
resip::Data mRUriRegularExpressionData;
95
regex_t* mRUriRegularExpression;
97
unsigned long mDefaultDistance;
98
bool mLoadBalanceEqualDistantTargets;
105
#endif // ndef RESIP_FIXED_POINT
109
/* ====================================================================
110
* The Vovida Software License, Version 1.0
112
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
114
* Redistribution and use in source and binary forms, with or without
115
* modification, are permitted provided that the following conditions
118
* 1. Redistributions of source code must retain the above copyright
119
* notice, this list of conditions and the following disclaimer.
121
* 2. Redistributions in binary form must reproduce the above copyright
122
* notice, this list of conditions and the following disclaimer in
123
* the documentation and/or other materials provided with the
126
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
127
* and "Vovida Open Communication Application Library (VOCAL)" must
128
* not be used to endorse or promote products derived from this
129
* software without prior written permission. For written
130
* permission, please contact vocal@vovida.org.
132
* 4. Products derived from this software may not be called "VOCAL", nor
133
* may "VOCAL" appear in their name, without prior written
134
* permission of Vovida Networks, Inc.
136
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
137
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
138
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
139
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
140
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
141
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
142
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
143
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
144
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
145
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
146
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
147
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
150
* ====================================================================