reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
GeoProximityTargetSorter.hxx
Go to the documentation of this file.
1#ifndef GEO_PROXIMITY_TARGET_SORTER_HXX
2#define GEO_PROXIMITY_TARGET_SORTER_HXX 1
3
4#ifndef RESIP_FIXED_POINT
5
6#include <regex>
7
8#include "repro/Processor.hxx"
10#include "repro/ProxyConfig.hxx"
11
12#include "rutil/Data.hxx"
13
14namespace resip
15{
16 class SipMessage;
17}
18
19namespace repro
20{
21
22class RequestContext;
23
24/*
25 If enabled, then this baboon can post-process the target list.
26 This includes targets from the StaticRoute monkey and/or targets
27 from the LocationServer monkey. Requests that meet the filter
28 criteria will have their Target list, flatened (serialized) and
29 ordered based on the proximity of the target to the client sending
30 the request. Proximity is determined by looking for a
31 x-repro-geolocation="<latitude>,<longitude>" parameter on the Contact
32 header of a received request, or the Contact headers of Registration
33 requests. If this parameter is not found, then this processor will
34 attempt to determine the public IP address closest to the client or
35 target and use the MaxMind Geo IP library to lookup the geo location.
36
37 There are several requirements for using this Processor/Baboon:
38 1. RESIP_FIXED_POINT preprocessor define is required to allow floating
39 point operations required for distance calculations.
40 2. USE_MAXMIND_GEOIP preprocessor define is required to allow linking
41 with the MaxMind Geo IP library for looking up lat/long information
42 for an IP address.
43 3. A copy of the GeoIP City database is required for looking up lat/long
44 information for an IP address. A free version of the databases can
45 be downloaded from here:
46 http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
47 and here (v6):
48 http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/
49 For a more accurate database, please see the details here:
50 http://www.maxmind.com/app/city
51 The location of these files are specifed in the following setting2:
52 GeoProximityIPv4CityDatabaseFile and GeoProximityIPv6CityDatabaseFile
53 4. A request URI filter must be defined in the repro configuration. This
54 filter uses a PCRE compliant regular expression to attempt
55 to match against the request URI of inbound requests. Any requests
56 matching this expression, will have its Targets sorted as described
57 above.
58 ie: GeoProximityRequestUriFilter = ^sip:mediaserver.*@mydomain.com$
59
60 Some additional settings are:
61 GeoProximityDefaultDistance - The distance (in Kilometers) to use for
62 proximity sorting, when the Geo Location of a target cannot be
63 determined.
64
65 LoadBalanceEqualDistantTargets - If enabled, then targets that are
66 determined to be of equal distance from the client, will be placed in
67 a random order.
68*/
69
70
72{
73 public:
74
76
79
81
82 // static fn available for other parts of repro to access the geoip library
83 // fills in any non-null field
84 static bool geoIPLookup(const resip::Tuple& address,
85 double* latitude,
86 double* longitude,
89 resip::Data* city=0);
90
91 protected:
93 void getTargetGeoLocation(const Target& target, double& latitude, double& longitude);
94 double getTargetDistance(const Target& target, double clientLatitude, double clientLongitude);
96 double calculateDistance(double latitude1, double longitude1, double latitude2, double longitude2);
97
100
101 unsigned long mDefaultDistance;
103
104 // Use static instance of the GeoIP library
105 // - allows static geoIPLookup method
106 // - reduces memory in cases where multiple instances of GeoProximityTargetSorter are needed
107 // (take care when creating multipleinstances since static initialization is not mutexed)
108 static void* mGeoIPv4;
109 static void* mGeoIPv6;
110};
111
112}
113
114#endif // ndef RESIP_FIXED_POINT
115
116#endif
117
118/* ====================================================================
119 * The Vovida Software License, Version 1.0
120 *
121 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
122 *
123 * Redistribution and use in source and binary forms, with or without
124 * modification, are permitted provided that the following conditions
125 * are met:
126 *
127 * 1. Redistributions of source code must retain the above copyright
128 * notice, this list of conditions and the following disclaimer.
129 *
130 * 2. Redistributions in binary form must reproduce the above copyright
131 * notice, this list of conditions and the following disclaimer in
132 * the documentation and/or other materials provided with the
133 * distribution.
134 *
135 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
136 * and "Vovida Open Communication Application Library (VOCAL)" must
137 * not be used to endorse or promote products derived from this
138 * software without prior written permission. For written
139 * permission, please contact vocal@vovida.org.
140 *
141 * 4. Products derived from this software may not be called "VOCAL", nor
142 * may "VOCAL" appear in their name, without prior written
143 * permission of Vovida Networks, Inc.
144 *
145 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
146 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
147 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
148 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
149 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
150 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
151 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
152 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
153 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
154 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
155 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
156 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
157 * DAMAGE.
158 *
159 * ====================================================================
160 */
static bool geoIPLookup(const resip::Tuple &address, double *latitude, double *longitude, resip::Data *country=0, resip::Data *region=0, resip::Data *city=0)
virtual processor_action_t process(RequestContext &)
void parseGeoLocationParameter(const resip::Data &parameter, double &latitude, double &longitude)
void getClientGeoLocation(const resip::SipMessage &request, double &latitude, double &longitude)
double getTargetDistance(const Target &target, double clientLatitude, double clientLongitude)
double calculateDistance(double latitude1, double longitude1, double latitude2, double longitude2)
void getTargetGeoLocation(const Target &target, double &latitude, double &longitude)
static resip::KeyValueStore::Key mGeoTargetSortingDoneKey
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Represents a SIP message.
Represents a network address.
Definition Tuple.hxx:59
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66