RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
core/agent_configuration/blacklist.h
00001 /* blacklist.h                                                     -*- C++ -*-
00002    Jeremy Barnes, 1 March 2012
00003    Copyright (c) 2012 Datacratic.  All rights reserved.
00004 
00005    Blacklist functionality.
00006 */
00007 
00008 #ifndef __rtb_router__blacklist_h__
00009 #define __rtb_router__blacklist_h__
00010 
00011 #include <string>
00012 #include <vector>
00013 #include "rtbkit/common/bid_request.h"
00014 #include "rtbkit/core/router/router_types.h"
00015 #include "soa/service/timeout_map.h"
00016 
00017 
00018 namespace RTBKIT {
00019 
00020 struct AgentConfig;
00021 
00022 
00023 /*****************************************************************************/
00024 /* BLACKLIST INFO                                                            */
00025 /*****************************************************************************/
00026 
00030 struct BlacklistInfo {
00031     struct Entry {
00032         std::string agent;
00033         AccountKey account;
00034         std::string site;
00035         Date expiry;
00036     };
00037     std::vector<Entry> entries;
00038     Date earliestExpiry;
00039 
00040     /* Does the given agent and bid request match the blacklist? */
00041     bool matches(const BidRequest & request,
00042                  const std::string & agent,
00043                  const AgentConfig & agentConfig) const;
00044         
00049     Date add(const BidRequest & bidRequest,
00050              const std::string & agent,
00051              const AgentConfig & agentConfig);
00052         
00053     /* Expire any that need to be expired, and return the next lowest
00054        expiry date or an empty date if none.
00055     */
00056     Date expire(Date now);
00057 };
00058 
00059 
00060 /*****************************************************************************/
00061 /* BLACKLIST                                                                 */
00062 /*****************************************************************************/
00063 
00065 struct Blacklist {
00066     void doExpiries();
00067 
00068     size_t size() const { return entries.size(); }
00069     
00070     bool matches(const BidRequest & request,
00071                  const std::string & agentName,
00072                  const AgentConfig & config) const;
00073 
00074     void add(const BidRequest & bidRequest,
00075              const std::string & agent,
00076              const AgentConfig & agentConfig);
00077     
00078     typedef TimeoutMap<Id, BlacklistInfo> Entries;
00079     Entries entries;
00080 };
00081 
00082 } // namespace RTBKIT
00083 
00084 #endif /* __rtb_router__blacklist_h__ */
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator