Ejemplo n.º 1
0
    /*
     * Update repository information and return thre repoId, otherwise empty 
     * string.
     */
    void updateRepo(const string &path) {
        RepoControl repo = RepoControl(path);
        RepoInfo info;

        try {
            repo.open();
        } catch (SystemException &e) {
            WARNING("Failed to open repository %s: %s", path.c_str(), e.what());
            return;
        }

        RWKey::sp key = infoLock.writeLock();
        if (myInfo.hasRepo(repo.getUUID())) {
            info = myInfo.getRepo(repo.getUUID());
        } else {
            info = RepoInfo(repo.getUUID(), repo.getPath());
        }
        info.updateHead(repo.getHead());
        myInfo.updateRepo(repo.getUUID(), info);

        LOG("Checked %s: %s %s", path.c_str(), repo.getHead().c_str(), repo.getUUID().c_str());
        
        repo.close();

        return;
    }
Ejemplo n.º 2
0
QString HostInfoManager::nameForHost(unsigned int id) const
{
    HostInfo* hostInfo = find(id);
    if (hostInfo)
        return hostInfo->name();

    return tr("<unknown>");
}
Ejemplo n.º 3
0
//host information mode
int getHostInfo(int argc, const char* arg, HostInfo& h)
{
	hostent* remoteHost;
	unsigned int addr;

	#ifdef WIN32
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2,2), &wsaData);

	char* hostname = (char*) malloc(40);
	strcpy(hostname, arg);
	if(isalpha(hostname[0]) != 0)
	{
		//name -> ipaddr
		hostname[strlen(hostname)] = '\0';
		remoteHost = gethostbyname(hostname);
		if(!remoteHost)
		{
			cout << "Cannot resolve host information: " << WSAGetLastError() << endl;
		}
		else
		{
			h.setName(string(remoteHost->h_name));
			struct in_addr rawaddr;
			if(remoteHost -> h_addrtype == AF_INET)
			{
				for(int i=0; remoteHost->h_addr_list[i] != 0; i++)
				{
					rawaddr.s_addr = *(u_long*) remoteHost->h_addr_list[i];
					h.addAddr(string(inet_ntoa(rawaddr)));
				}
			}
		}
	}
	else
	{
		//num
		addr = inet_addr(hostname);
		remoteHost = gethostbyaddr((char*) &addr, 4, AF_INET);
		if(!remoteHost)
		{
			cout << "Cannot resolve host information: " << WSAGetLastError() << endl;
		}
		else
		{
			cout << remoteHost->h_name << endl;
			h.setName(string(remoteHost->h_name));
			h.addAddr(hostname);
		}
	}
	WSACleanup();
	#else
		cout << "Windows only function" << endl;
	#endif
	return 0;
}
Ejemplo n.º 4
0
unsigned int HostInfoManager::maxJobs(unsigned int id) const
{
    if (id) {
        HostInfo* hostInfo = find(id);
        if (hostInfo)
            return hostInfo->maxJobs();
    }

    return 0;
}
Ejemplo n.º 5
0
void MatrixMasterThriftRpc::to_thrift(const HostInfo& info,
                                      const std::string& host_ip,
                                      const std::string& host_name,
                                      ThriftHostInfo& t_info)
{
    t_info.hostIp = host_ip;
    t_info.hostName = host_name;
    t_info.hostState = static_cast<ThriftHostState::type>(info.get_host_state());
    to_thrift(info.get_total_resource(), t_info.totalResource);
}
Ejemplo n.º 6
0
void SensorBrowserModel::addHost(KSGRD::SensorAgent *sensorAgent, const QString &hostName)
{
    beginInsertRows( QModelIndex() , mHostInfoMap.size(), mHostInfoMap.size() );
    HostInfo* hostInfo = new HostInfo( mIdCount, sensorAgent, hostName);
    mHostInfoMap.insert(mIdCount, hostInfo);
    mTreeMap.insert(mIdCount, QList<int>());
    mHostSensorsMap.insert(mIdCount, QHash<QString, bool>());
    mIdCount++;
    endInsertRows();
    hostInfo->sensorAgent()->sendRequest( "monitors", this, mIdCount-1 );
}
Ejemplo n.º 7
0
QVariant SensorBrowserModel::data( const QModelIndex & index, int role) const { //virtual
    if(!index.isValid()) return QVariant();
    switch(role) {
        case Qt::DisplayRole: {
            if(index.column()==0) {
                uint id = index.internalId();
                if(mSensorInfoMap.contains(id)) {
                    Q_ASSERT(mSensorInfoMap.value(id));
                    SensorInfo *sensorInfo = mSensorInfoMap.value(id);
                    return QString(sensorInfo->description() + " (" + KSGRD::SensorMgr->translateSensorType(sensorInfo->type()) + ')' );
                }
                if(mTreeNodeNames.contains(id)) return mTreeNodeNames.value(id);
                if(mHostInfoMap.contains(id)) {
                    Q_ASSERT(mHostInfoMap.value(id));
                    return mHostInfoMap.value(id)->hostName();
                }
            }
            return QString();
        }
        case Qt::DecorationRole: {
            if(index.column() == 0) {
                HostInfo *host = getHostInfo(index.internalId());
                KSGRD::SensorAgent *agent;
                if(host != NULL && (agent = host->sensorAgent())) {
                    if(agent->daemonOnLine())
                        return KIcon("computer");
                    else
                        return KIcon("dialog-warning");
                } else
                    return QIcon();
            } else
                return QIcon();
            break;
        }
        case Qt::ToolTipRole: {
            if(index.column() == 0) {
                HostInfo *host = getHostInfo(index.internalId());
                KSGRD::SensorAgent *agent;
                if(host != NULL && (agent = host->sensorAgent())) {
                    if(agent->daemonOnLine())
                        return agent->hostName();
                    else
                        return agent->reasonForOffline();
                }
            }
            break;
        }

    } //switch
    return QVariant();
}
Ejemplo n.º 8
0
HostInfo* HostInfoManager::checkNode(unsigned int hostid, const HostInfo::StatsMap& stats)
{
    HostMap::ConstIterator it = m_hostMap.constFind(hostid);
    HostInfo* hostInfo;
    if (it == m_hostMap.constEnd()) {
        hostInfo = new HostInfo(hostid);
        m_hostMap.insert(hostid, hostInfo);
    } else {
        hostInfo = *it;
    }

    hostInfo->updateFromStatsMap(stats);

    return hostInfo;
}
Ejemplo n.º 9
0
void SensorBrowserModel::hostRemoved(const QString &hostName)  {
    HostInfo* toRemove = findHostInfoByHostName(hostName);
    if (toRemove != NULL)  {
        beginResetModel();
        int hostId = toRemove->id();
        removeAllSensorUnderBranch(toRemove,hostId);
        removeEmptyParentTreeBranches(hostId,hostId,hostId);

        delete mHostInfoMap.take(hostId);
        mTreeMap.take(hostId);
        mHostSensorsMap.take(hostId);
        endResetModel();
    }
    update();
}
Ejemplo n.º 10
0
bool StarView::event (QEvent* e)
{
    if (e->type() != QEvent::ToolTip)
        return QWidget::event(e);

    QPoint p (static_cast<QHelpEvent*>(e)->pos());

    HostItem *item = 0;
    QGraphicsItem* graphicsItem = m_canvasView->itemAt(p);
    if (graphicsItem)
        item = dynamic_cast<HostItem*>(graphicsItem->parentItem());
    if (item) {
        HostInfo *hostInfo = item->hostInfo();
        const QPoint gp(static_cast<QHelpEvent*>(e)->globalPos());
        const QRect itemRect = m_canvasView->mapFromScene(graphicsItem->sceneBoundingRect()).boundingRect();
        if (hostInfo) {
            QToolTip::showText(gp+QPoint(10,10),
                           "<p><table><tr><td>"
                           "<img align=\"right\" source=\":/computer.png\"><br><b>" + item->hostName() +
                           "</b><br>" +

                           "<table>" +
                           "<tr><td>" + tr("IP:") + "</td><td>" + hostInfo->ip()
                           + "</td></tr>" +
                           "<tr><td>" + tr("Platform:") + "</td><td>" +
                           hostInfo->platform() + "</td></tr>" +
                           "<tr><td>" + tr("Id:") + "</td><td>" +
                           QString::number(hostInfo->id()) + "</td></tr>" +
                           "<tr><td>" + tr("Speed:") + "</td><td>" +
                           QString::number(hostInfo->serverSpeed()) + "</td></tr>" +
                           "</table>"

                           "</td></tr></table></p>", this, itemRect);
        } else {
            QToolTip::showText(gp+QPoint(10,10),
                           "<p><table><tr><td>"
                           "<img align=\"right\" source=\":/computer.png\"><br><b>" + tr("Scheduler") + "</b><br/>"
                           "<table>" +
                           "<tr><td>" + tr("Host: %1").arg(hostInfoManager()->schedulerName()) + "</td></tr>" +
                           "<tr><td>" + tr("Network name: %1").arg(hostInfoManager()->networkName()) + "</td></tr>" +
                           "</table>"
                           "</td></tr></table></p>", this, itemRect);
        }
    } else {
         QToolTip::hideText();
    }
    return QWidget::event(e);
}
Ejemplo n.º 11
0
void Tracker::hostResolved(HostInfo info) {
	if (info.error()) {
		logError(
			boost::format("[%s] Host lookup failed: %s")
			% info.getName() % info.errorMsg()
		);
		Utils::timedCallback(this, &Tracker::hostLookup, 60000);
	} else {
		m_addrs = info.getAddresses();
		for (uint32_t i = 0; i < m_addrs.size(); ++i) {
			m_addrs[i].setPort(m_port);
		}
		m_curAddr = m_addrs.begin();
		connect(*m_curAddr);
	}
}
Ejemplo n.º 12
0
QColor HostInfoManager::hostColor(unsigned int id) const
{
    if (id) {
        HostInfo* hostInfo = find(id);
        if (hostInfo) {
            QColor tmp = hostInfo->color();
            assert(tmp.isValid() && (tmp.red() + tmp.green() + tmp.blue()));
            return tmp;
        }
    }

    qWarning() << "id " << id << " got no color\n";
    assert(false);

    return QColor(0, 0, 0);
}
Ejemplo n.º 13
0
int
start_server()
{
    MSG("Starting OriSync");
    rc = OriSyncConf();
    announcer = new Announcer();
    listener = new Listener();
    repoMonitor = new RepoMonitor();
    syncer = new Syncer();

    myInfo = HostInfo(rc.getUUID(), rc.getCluster());
    // XXX: Update addresses periodically
    myInfo.setHost(OriStr_Join(OriNet_GetAddrs(), ','));

    announcer->start();
    listener->start();
    repoMonitor->start();
    syncer->start();

    struct event_base *base = event_base_new();
    struct evhttp *httpd = evhttp_new(base);
    evhttp_bind_socket(httpd, "0.0.0.0", 8051);

    evhttp_set_cb(httpd, "/", Httpd_getRoot, NULL);

    // Event loop
    event_base_dispatch(base);

    evhttp_free(httpd);
    event_base_free(base);

    // XXX: Wait for worker threads

    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char* argv[]) {

    vector<HostInfo> hostinfo_vector;
    HostInfo hostinfo;

    ifstream input(argv[1]);
    string ip;
    while (std::getline(input, ip)) {
        int port_start = ip.find(':');
        hostinfo.hostname = ip.substr(0, port_start);
        hostinfo.port = std::stoi(ip.substr(port_start + 1));
        hostinfo_vector.push_back(hostinfo);
    }

    auto num_hosts = hostinfo.size();
    auto num_direct_hosts = num_hosts;
    int vp_index = -1;
    uint16_t vp_hosts_bits = 0;
    vector<int> others_indices;
    for (int i = 0; i < num_direct_hosts; ++i) {
        others_hosts.push_back(i);
    }

    if (argc == 3 && argv[2][0] == 'v' && argv[2][1]) {
        num_direct_hosts = num_hosts / 2;
        vp_index = 1;

        for (int i = num_direct_hosts; i < num_hosts; ++i) {
            uint16_t mask = 1 << i;
            vp_hosts_bits |= mask;
        }
    }

    int data = 0;

    AppendEntriesPacket packet(1, 0, 1, 0, 0, vp_index, uint16_t vp_hosts_bits) : header(term, previous_log_index,
        previous_log_term, commit_index, president_index, vp_index, vp_hosts_bits)

    while (true) {
        sleep_for(milliseconds(300));
        Network::SendPackets(packet.ToNetworkOrder().ToBytes(), LARGE_PACKET_SIZE, others_hosts);
    }

    return 0;
}
Ejemplo n.º 15
0
HostItem *StarView::createHostItem(unsigned int hostid)
{
    HostInfo *i = hostInfoManager()->find(hostid);

    if (!i || i->isOffline() || i->name().isEmpty())
        return 0;

    HostItem *hostItem = new HostItem(i, m_canvas, hostInfoManager());
    hostItem->setHostColor(hostColor(hostid));
    m_hostItems.insert(hostid, hostItem);
    hostItem->show();

    arrangeHostItems();

    if (m_hostItems.count() > 25)
        m_configDialog->setMaxNodes(m_hostItems.count());

    return hostItem;
}
Ejemplo n.º 16
0
    void pullRepo(HostInfo &localHost,
                  HostInfo &remoteHost,
                  const std::string &uuid)
    {
        RepoInfo local = localHost.getRepo(uuid);
        RepoInfo remote = remoteHost.getRepo(uuid);
        RepoControl repo = RepoControl(local.getPath());

        DLOG("Local and Remote heads mismatch on repo %s", uuid.c_str());

        repo.open();
        if (!repo.hasCommit(remote.getHead())) {
            LOG("Pulling from %s:%s",
                remoteHost.getPreferredIp().c_str(),
                remote.getPath().c_str());
            repo.pull(remoteHost.getPreferredIp(), remote.getPath());
        }
        repo.close();
    }
Ejemplo n.º 17
0
    void run() {
        while (!interruptionRequested()) {
            HostInfo infoSnapshot;
            list<string> repos;
            list<string>::iterator it;

            infoSnapshot = myInfo;
            repos = infoSnapshot.listRepos();

            for (it = repos.begin(); it != repos.end(); it++) {
                LOG("Syncer checking %s", (*it).c_str());
                checkRepo(infoSnapshot, *it);
            }

            sleep(ORISYNC_SYNCINTERVAL);
        }

        DLOG("Syncer exited!");
    }
Ejemplo n.º 18
0
bool TcpSocket::ConnectToHost(const string& hostName,
                              const string& port,
                              IBamIODevice::OpenMode mode)
{
    // create new address object with requested host name
    HostAddress hostAddress;
    hostAddress.SetAddress(hostName);

    HostInfo info;
    // if host name was IP address ("x.x.x.x" or IPv6 format)
    // otherwise host name was 'plain-text' ("www.foo.bar")
    // we need to look up IP address(es)
    if ( hostAddress.HasIPAddress() )
        info.SetAddresses( vector<HostAddress>(1, hostAddress) );
    else
        info = HostInfo::Lookup(hostName, port);

    // attempt connection on requested port
    return ConnectImpl(info, port, mode);
}
Ejemplo n.º 19
0
    string generate() {
        RWKey::sp key = infoLock.readLock();
        char buf[32];
        string msg;

        // First 31 bytes of cluster with null
        memset(buf, 0, 32);
        strncpy(buf, rc.getCluster().c_str(), 31);
        msg.assign(buf, 32);
        msg.append(OriCrypt_Encrypt(myInfo.getBlob(), rc.getKey()));

        return msg;
    }
Ejemplo n.º 20
0
void Monitor::handleStats(Msg* _m)
{
    MonStatsMsg *m = dynamic_cast<MonStatsMsg*>(_m);
    if (!m)
        return;

    QStringList statmsg = QString(m->statmsg.c_str()).split('\n');
    HostInfo::StatsMap stats;
    QStringList::ConstIterator it;
    for (it = statmsg.constBegin(); it != statmsg.constEnd(); ++it) {
        QString key = *it;
        key = key.left(key.indexOf(':'));
        QString value = *it;
        value = value.mid(value.indexOf(':') + 1);
        stats[key] = value;
    }

    HostInfo *hostInfo = m_hostInfoManager->checkNode(m->hostid, stats);
    if (hostInfo->isOffline())
        m_view->removeNode(m->hostid);
    else
        m_view->checkNode(m->hostid);
}
Ejemplo n.º 21
0
void
WebviewThread::ssl_create(const char *ssl_key_file, const char *ssl_cert_file)
{
  logger->log_info(name(), "Creating SSL key and certificate. "
		   "This may take a while...");
  HostInfo h;

  char *cmd;
  if (asprintf(&cmd, "openssl req -new -x509 -batch -nodes -days 365 "
	       "-subj \"/C=XX/L=World/O=Fawkes/CN=%s.local\" "
	       "-out \"%s\" -keyout \"%s\" >/dev/null 2>&1",
	       h.short_name(), ssl_cert_file, ssl_key_file) == -1)
  {
    throw OutOfMemoryException("Webview/SSL: Could not generate OpenSSL string");
  }

  int status = system(cmd);
  free(cmd);

  if (WEXITSTATUS(status) != 0) {
    throw Exception("Failed to auto-generate key/certificate pair");
  }
}
Ejemplo n.º 22
0
void printHostInfo(HostInfo& h)//string name, queue<string> ipaddr)
{
	#ifdef WIN32
	//cout << "host information mode" << endl;
	if(h.ipaddr.empty())
		return;
	cout << "Official Name: " << h.getName() << endl;
	while (!h.ipaddr.empty())
	{
		cout << "IP Address: " << h.ipaddr.front() << endl;
		h.ipaddr.pop();
	}
	#else
		cout << "Windows only function" << endl;
	#endif
	return;
}
Ejemplo n.º 23
0
    void checkRepo(HostInfo &infoSnapshot, const std::string &uuid)
    {
        map<string, HostInfo *> hostSnapshot;
        map<string, HostInfo *>::iterator it;
        RepoInfo localInfo = infoSnapshot.getRepo(uuid);

        hostSnapshot = hosts;

        for (it = hostSnapshot.begin(); it != hostSnapshot.end(); it++) {
            list<string> repos = it->second->listRepos();
            list<string>::iterator rIt;

            for (rIt = repos.begin(); rIt != repos.end(); rIt++) {
                RepoInfo info = it->second->getRepo(uuid);

                if (info.getHead() != localInfo.getHead()) {
                    pullRepo(infoSnapshot, *(it->second), uuid);
                }
            }
        }
    }
Ejemplo n.º 24
0
HostInfo HostInfo::Lookup(const string& hostname, const string& port) {

    HostInfo result;
    result.SetHostName(hostname);
    set<HostAddress> uniqueAddresses;

#ifdef _WIN32
    WindowsSockInit init;
#endif

    HostAddress address;
    address.SetAddress(hostname);

    // if hostname is an IP string ('0.0.0.0' or IPv6 format)
    // do reverse lookup for host domain name
    //
    // TODO: might just remove this... not sure if proper 'hostname' from IP string is needed
    //
    //       so far, haven't been able to successfully fetch a domain name with reverse DNS
    //       getnameinfo() on test sites just returns original IP string. BUT this is likely a rare
    //       case that client code tries to use an IP string and the connection should work fine
    //       anyway. GetHostName() just won't quite show what I was hoping for. :(
    if ( address.HasIPAddress() ) {

        const uint16_t portNum = static_cast<uint16_t>( atoi(port.c_str()) );

        sockaddr_in  sa4;
        sockaddr_in6 sa6;
        sockaddr* sa = 0;
        BT_SOCKLEN_T saSize = 0;

        // IPv4
        if ( address.GetProtocol() == HostAddress::IPv4Protocol ) {
            sa = (sockaddr*)&sa4;
            saSize = sizeof(sa4);
            memset(&sa4, 0, sizeof(sa4));
            sa4.sin_family = AF_INET;
            sa4.sin_addr.s_addr = htonl(address.GetIPv4Address());
            sa4.sin_port = htons(portNum);
        }

        // IPv6
        else if ( address.GetProtocol() == HostAddress::IPv4Protocol ){
            sa = (sockaddr*)&sa6;
            saSize = sizeof(sa6);
            memset(&sa6, 0, sizeof(sa6));
            sa6.sin6_family = AF_INET6;
            memcpy(sa6.sin6_addr.s6_addr, address.GetIPv6Address().data, sizeof(sa6.sin6_addr.s6_addr));
            sa6.sin6_port = htons(portNum);
        }

        // unknown (should be unreachable)
        else BT_ASSERT_X(false, "HostInfo::Lookup: unknown network protocol");

        // lookup name for IP
        char hbuf[NI_MAXHOST];
        char serv[NI_MAXSERV];
        if ( sa && (getnameinfo(sa, saSize, hbuf, sizeof(hbuf), serv, sizeof(serv), 0) == 0) )
            result.SetHostName(string(hbuf));

        // if no domain name found, just use the original address's IP string
        if ( result.HostName().empty() )
            result.SetHostName(address.GetIPString());

        // store address in HostInfo
        uniqueAddresses.insert(address);
    }

    // otherwise, hostname is a domain name ('www.foo.bar')
    // do 'normal' lookup
    else {

        // setup address lookup 'hints'
        addrinfo hints;
        memset(&hints, 0, sizeof(hints));
        hints.ai_family   = AF_UNSPEC;   // allow either IPv4 or IPv6
        hints.ai_socktype = SOCK_STREAM; // for TCP
        hints.ai_protocol = IPPROTO_TCP;

        // fetch addresses for requested hostname/port
        addrinfo* res;
        int status = getaddrinfo(hostname.c_str(), port.c_str(), &hints, &res );

        // if everything OK
        if ( status == 0 ) {

            // iterate over all IP addresses found
            addrinfo* p = res;
            for ( ; p != NULL; p = p->ai_next ) {

                // IPv4
                if ( p->ai_family == AF_INET ) {
                    sockaddr_in* ipv4 = (sockaddr_in*)p->ai_addr;
                    HostAddress a( ntohl(ipv4->sin_addr.s_addr) );
                    uniqueAddresses.insert(a);
                }

                // IPv6
                else if ( p->ai_family == AF_INET6 ) {
                    sockaddr_in6* ipv6 = (sockaddr_in6*)p->ai_addr;
                    HostAddress a(ipv6->sin6_addr.s6_addr);
                    uniqueAddresses.insert(a);
                }
            }

            // if we iterated, but no addresses were stored
            if ( uniqueAddresses.empty() && (p == NULL) ) {
                result.SetError(HostInfo::UnknownError);
                result.SetErrorString("HostInfo: unknown address types found");
            }
        }

        // handle error cases
        else if (
#ifndef _WIN32
                     status == EAI_NONAME
                  || status == EAI_FAIL
#  ifdef EAI_NODATA
                  || status == EAI_NODATA  // officially deprecated, but just in case we happen to hit it
#  endif // EAI_NODATA

#else  // _WIN32
                     WSAGetLastError() == WSAHOST_NOT_FOUND
                  || WSAGetLastError() == WSANO_DATA
                  || WSAGetLastError() == WSANO_RECOVERY
#endif // _WIN32
                )
        {
            result.SetError(HostInfo::HostNotFound);
            result.SetErrorString("HostInfo: host not found");
        }
        else {
            result.SetError(HostInfo::UnknownError);
            result.SetErrorString("HostInfo: unknown error encountered");
        }

        // cleanup
        freeaddrinfo(res);
    }

    // store fetched addresses (converting set -> vector) in result & return
    result.SetAddresses( vector<HostAddress>(uniqueAddresses.begin(), uniqueAddresses.end()) );
    return result;
}
Ejemplo n.º 25
0
bool TcpSocket::ConnectImpl(const HostInfo& hostInfo,
                            const std::string& port,
                            IBamIODevice::OpenMode mode)
{
    // skip if we're already connected
    if ( m_state == TcpSocket::ConnectedState ) {
        m_error = TcpSocket::SocketResourceError;
        m_errorString = "socket already connected";
        return false;
    }

    // reset socket state
    m_hostName   = hostInfo.HostName();
    m_mode       = mode;
    m_state      = TcpSocket::UnconnectedState;
    m_error      = TcpSocket::UnknownSocketError;
//    m_localPort  = 0;
    m_remotePort = 0;
//    m_localAddress.Clear();
    m_remoteAddress.Clear();
    m_readBuffer.Clear();

    // fetch candidate addresses for requested host
    vector<HostAddress> addresses = hostInfo.Addresses();
    if ( addresses.empty() ) {
        m_error = TcpSocket::HostNotFoundError;
        m_errorString = "no IP addresses found for host";
        return false;
    }

    // convert port string to integer
    stringstream ss(port);
    uint16_t portNumber(0);
    ss >> portNumber;

    // iterate through adddresses
    vector<HostAddress>::const_iterator addrIter = addresses.begin();
    vector<HostAddress>::const_iterator addrEnd  = addresses.end();
    for ( ; addrIter != addrEnd; ++addrIter) {
        const HostAddress& addr = (*addrIter);

        // try to initialize socket engine with this address
        if ( !InitializeSocketEngine(addr.GetProtocol()) ) {
            // failure to initialize is OK here
            // we'll just try the next available address
            continue;
        }

        // attempt actual connection
        if ( m_engine->Connect(addr, portNumber) ) {

            // if connection successful, update our state & return true
            m_mode = mode;
//            m_localAddress  = m_engine->GetLocalAddress();
//            m_localPort     = m_engine->GetLocalPort();
            m_remoteAddress = m_engine->GetRemoteAddress();
            m_remotePort    = m_engine->GetRemotePort();
            m_cachedSocketDescriptor = m_engine->GetSocketDescriptor();
            m_state = TcpSocket::ConnectedState;
            return true;
        }
    }

    // if we get here, no connection could be made
    m_error = TcpSocket::HostNotFoundError;
    m_errorString = "could not connect to any host addresses";
    return false;
}