28 std::string GNet::ResolverInfo::sockless(
const std::string & s )
34 bool GNet::ResolverInfo::socked(
const std::string & s , std::string & far_host ,
unsigned int & far_port )
37 if( pos != std::string::npos )
43 return pos != std::string::npos ;
46 std::string GNet::ResolverInfo::part(
const std::string & s ,
bool first )
48 std::string host_part ;
49 std::string service_part ;
51 throw InvalidFormat( s ) ;
52 return first ? host_part : service_part ;
56 m_host(part(sockless(host_and_service),true)) ,
57 m_service(part(sockless(host_and_service),false)) ,
58 m_address_valid(false) ,
59 m_address(
Address::invalidAddress()) ,
64 m_socks = socked( host_and_service , m_socks_far_host , m_socks_far_port ) ;
70 m_address_valid(false) ,
71 m_address(
Address::invalidAddress()) ,
90 return m_address_valid ;
100 m_address = address ;
101 m_address_valid = true ;
102 m_canonical_name = name ;
108 return m_canonical_name ;
113 return m_host +
":" + m_service ;
118 std::string s = m_host +
":" + m_service ;
119 if( simple && hasAddress() )
121 s = address().displayString() ;
126 s.append( std::string() +
" [" + address().displayString() +
"]" ) ;
127 if( !name().empty() )
128 s.append( std::string() +
" (" + name() +
")" ) ;
135 return m_update_time ;
145 return m_socks_far_port ;
150 return m_socks_far_host ;
static EpochTime now()
Returns the current epoch time.
void update(const Address &address, const std::string &canonical_name)
Updates the address and canonical name, typically after doing a name lookup on host() and service()...
static unsigned int toUInt(const std::string &s, bool limited=false)
Converts string 's' to an unsigned int.
std::string socksFarHost() const
Returns the port for the socks far server.
The Address class encapsulates an IP transport address.
std::string::size_type size_type
A std::size_t type.
static std::string tail(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
ResolverInfo(const std::string &host, const std::string &service)
Constructor.
unsigned int socksFarPort() const
Returns the port number for the socks far server.
Address address() const
Returns the remote address.
bool hasAddress() const
Returns true after update() has been called.
bool socks() const
Returns true if using socks.
static bool parse(const std::string &in, std::string &host_or_address, std::string &service_or_port)
Parses a string that contains a hostname or ip address plus a server name or port number...
static std::string head(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
std::string str() const
Returns a string representation of the host and service names that can be passed to the Resolver's re...
std::string displayString(bool simple=false) const
Returns a string representation for logging and debug.
std::string service() const
Returns the remote service name, as passed in to the constructor.
G::DateTime::EpochTime updateTime() const
Returns the time of the last update().
std::string name() const
Returns the remote canonical name.
std::string host() const
Returns the remote host name, as passed in to the constructor.