Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cNetAddrTracker Class Reference

#include <cNetAddrTracker.h>

Inheritance diagram for GrayLib::cNetAddrTracker:
Gray::cThreadLockableRef Gray::cRefBase Gray::cThreadLockStub IUnknown Gray::cLockableBase GrayLib::cClientAddrObj

Public Member Functions

 cNetAddrTracker (const cNetAddress &addr)
 
virtual ~cNetAddrTracker ()
 
cString get_Name () const
 
HASHCODE_t get_HashCode () const noexcept
 
cStringA get_DescString () const
 
bool LookupHostName ()
 
HRESULT DisposeThis ()
 
bool IsNeverDecay () const
 When to delete this IP tracking record? More...
 
void BumpDecayTimeSec (TIMESECD_t iSeconds)
 
bool IsBlocked () const
 Is this IP blocked from connecting. More...
 
bool SetBlocked (TIMESECD_t iTimeDecaySeconds, const char *pszReason)
 
bool onTickAddr (int iRefCount)
 
int get_Pings () const
 Transient Activity tracking info. More...
 
bool IncPingBlock (bool bPreAccept=false)
 Some event has occurred. More...
 
bool IncBadPassword (const char *pszAttackedAccountName)
 
void put_Account (cRefBase *pAccount)
 
cRefBasePtr get_Account () const
 
- Public Member Functions inherited from Gray::cThreadLockableRef
 cThreadLockableRef (int iStaticRefCount=0) noexcept
 
virtual ~cThreadLockableRef ()
 
virtual void onThreadLockFail (TIMESYSD_t dwWaitMS)
 
- Public Member Functions inherited from Gray::cRefBase
 cRefBase (int iRefCount=0) noexcept
 
virtual ~cRefBase ()
 
int get_RefCount () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept
 
virtual void onFinalRelease ()
 
bool isValidObj () const noexcept
 
 STDMETHOD_ (ULONG, AddRef)(void) override
 
 STDMETHOD_ (ULONG, Release)(void) override
 
STDMETHOD() QueryInterface (const IID &riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
 
void IncRefCount ()
 
void DecRefCount ()
 
bool isStaticConstruct () const noexcept
 
void StaticConstruct ()
 
void StaticDestruct ()
 
bool isDestructing () noexcept
 
void SetDestructing ()
 
- Public Member Functions inherited from Gray::cThreadLockStub
THREADID_t get_ThreadLockOwner () const
 

Public Attributes

cNetAddress m_addr
 The remote address we are tracking. IP4 OR IP6. More...
 
cStringA m_sIPHost
 Look up this IP host name. reverse DNS lookup. (Maybe async lookup) More...
 
cStringA m_sDescription
 Description of why this IP is blocked. or why we track it. More...
 
bool m_bTrusted
 This is a trusted IP. (don't ever block it. e.g. localhost) More...
 

Static Public Attributes

static const TIMESECD_t k_PING_WINDOW_LEN = (5 * 60)
 
static const int k_PINGS_PER_WINDOW = 5 * 10
 
static const TIMESECD_t k_BLOCK_LEN = (60)
 

Protected Attributes

cTimeInt m_timeCreated
 When was this record created? More...
 
cTimeInt m_timeDecay
 Time this record should be gone. (may be set to NEVER) More...
 
cTimeInt m_timeBlockTil
 Blocked until this time. More...
 
cTimeInt m_timeWindowStart
 My ping check window started at this time. More...
 
cTimeInt m_timeLastEvent
 Last time we last interacted with this IP. More...
 
int m_iPings
 How many pings have we seen since m_timeWindowStart. More...
 
int m_iBadPasswords
 How many bad passwords since m_timeWindowStart. More...
 
cRefBasePtr m_pAccount
 associate this IP address with an account. (allow auto log in based on IP?) More...
 

Friends

class cClientAddrObj
 To Expose this stuff to cXObjDef. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Gray::cLockableBase
 cLockableBase () noexcept
 
 ~cLockableBase ()
 
LONG get_LockCount () const
 
bool isLocked () const
 
void IncLockCount ()
 
LONG DecLockCount ()
 
void Lock ()
 
LONG Unlock ()
 

Detailed Description

a Tracked / Blocked address for a server. Shared information about bad actors to any server type. Keep a log of recent IP's/address's/clients a server has talked to (or tried to). Even if not authenticated. Used to prevent DoS attacks, ping floods, password guessing, fuzz, general hacking, etc.

Note
Try to look up host name or 'tracert' etc ??

Constructor & Destructor Documentation

◆ cNetAddrTracker()

GrayLib::cNetAddrTracker::cNetAddrTracker ( const cNetAddress addr)

◆ ~cNetAddrTracker()

GrayLib::cNetAddrTracker::~cNetAddrTracker ( )
virtual

Member Function Documentation

◆ BumpDecayTimeSec()

void GrayLib::cNetAddrTracker::BumpDecayTimeSec ( TIMESECD_t  iSeconds)

Keep this around longer.

◆ DisposeThis()

HRESULT GrayLib::cNetAddrTracker::DisposeThis ( void  )

◆ get_Account()

cRefBasePtr GrayLib::cNetAddrTracker::get_Account ( ) const
inline

CAccount attached to this address?

◆ get_DescString()

cStringA GrayLib::cNetAddrTracker::get_DescString ( ) const

m_sDescription

◆ get_HashCode()

HASHCODE_t GrayLib::cNetAddrTracker::get_HashCode ( ) const
inlinenoexcept

◆ get_Name()

cString GrayLib::cNetAddrTracker::get_Name ( ) const
inline

◆ get_Pings()

int GrayLib::cNetAddrTracker::get_Pings ( ) const
inline

Transient Activity tracking info.

◆ IncBadPassword()

bool GrayLib::cNetAddrTracker::IncBadPassword ( const char *  pszAttackedAccountName)

If we get too many bad passwords from an IP in 15 minute window Then block this for a bit from this address.

Returns
true = boot this client.

◆ IncPingBlock()

bool GrayLib::cNetAddrTracker::IncPingBlock ( bool  bPreAccept = false)

Some event has occurred.

A ping has occurred from this ip. Have we had too many pings in a short time ?

  • bPreAccept = is this the pre-accept stage? cannot reject this yet.
    Note
    If the addr is blocked and this is the first ping then try to give a response.
    Returns
    true = block this.

◆ IsBlocked()

bool GrayLib::cNetAddrTracker::IsBlocked ( ) const

Is this IP blocked from connecting.

this IP is blocked until some future time ?

◆ IsNeverDecay()

bool GrayLib::cNetAddrTracker::IsNeverDecay ( ) const

When to delete this IP tracking record?

◆ LookupHostName()

bool GrayLib::cNetAddrTracker::LookupHostName ( )

Populate m_sIPHost via reverse DNS lookup.

Note
Blocking call !! Try to do this Async.

◆ onTickAddr()

bool GrayLib::cNetAddrTracker::onTickAddr ( int  iRefCount)

Periodically decay the list.

  • iRefCount = get_RefCount();
    Returns
    true = this record is not needed anymore.

◆ put_Account()

void GrayLib::cNetAddrTracker::put_Account ( cRefBase pAccount)
inline

Attach an Account when success login for this IP. Clears the amount of bad passwords tried.

◆ SetBlocked()

bool GrayLib::cNetAddrTracker::SetBlocked ( TIMESECD_t  iTimeDecaySeconds,
const char *  pszReason 
)

Block this IP.

  • iSecToBlock = seconds, INT_MAX = forever

Friends And Related Function Documentation

◆ cClientAddrObj

friend class cClientAddrObj
friend

To Expose this stuff to cXObjDef.

Member Data Documentation

◆ k_BLOCK_LEN

const TIMESECD_t GrayLib::cNetAddrTracker::k_BLOCK_LEN = (60)
static

◆ k_PING_WINDOW_LEN

const TIMESECD_t GrayLib::cNetAddrTracker::k_PING_WINDOW_LEN = (5 * 60)
static

◆ k_PINGS_PER_WINDOW

const int GrayLib::cNetAddrTracker::k_PINGS_PER_WINDOW = 5 * 10
static

◆ m_addr

cNetAddress GrayLib::cNetAddrTracker::m_addr

The remote address we are tracking. IP4 OR IP6.

◆ m_bTrusted

bool GrayLib::cNetAddrTracker::m_bTrusted

This is a trusted IP. (don't ever block it. e.g. localhost)

◆ m_iBadPasswords

int GrayLib::cNetAddrTracker::m_iBadPasswords
protected

How many bad passwords since m_timeWindowStart.

◆ m_iPings

int GrayLib::cNetAddrTracker::m_iPings
protected

How many pings have we seen since m_timeWindowStart.

◆ m_pAccount

cRefBasePtr GrayLib::cNetAddrTracker::m_pAccount
protected

associate this IP address with an account. (allow auto log in based on IP?)

based on something like cAuthUser or CAccount

◆ m_sDescription

cStringA GrayLib::cNetAddrTracker::m_sDescription

Description of why this IP is blocked. or why we track it.

◆ m_sIPHost

cStringA GrayLib::cNetAddrTracker::m_sIPHost

Look up this IP host name. reverse DNS lookup. (Maybe async lookup)

◆ m_timeBlockTil

cTimeInt GrayLib::cNetAddrTracker::m_timeBlockTil
protected

Blocked until this time.

◆ m_timeCreated

cTimeInt GrayLib::cNetAddrTracker::m_timeCreated
protected

When was this record created?

◆ m_timeDecay

cTimeInt GrayLib::cNetAddrTracker::m_timeDecay
protected

Time this record should be gone. (may be set to NEVER)

◆ m_timeLastEvent

cTimeInt GrayLib::cNetAddrTracker::m_timeLastEvent
protected

Last time we last interacted with this IP.

◆ m_timeWindowStart

cTimeInt GrayLib::cNetAddrTracker::m_timeWindowStart
protected

My ping check window started at this time.


The documentation for this class was generated from the following files: