Ejemplo n.º 1
0
void svThreadStorage::BroadcastHostKeyResult(
	svEventHostKeyResult *result)
{
	map<string, vector<svEventClient *> >::iterator i;
	i = client.find(result->GetDevice());
	if (i == client.end()) {
		svDebug("%s: No hostkey clients awaiting device: %s",
			name.c_str(), result->GetDevice().c_str());
		return;
	}

	vector<svEventClient *>::iterator ci = i->second.begin();
	for ( ; ci != i->second.end(); ci++) {
		svEventServer::GetInstance()->Dispatch(
			new svEventHostKeyResult(GetDefaultDest(), (*ci),
				result->GetDevice(), result->GetOrganization(),
				result->GetKey()));
	}
	svDebug("%s: Hostkey client broadcast: %s: %d",
		name.c_str(), result->GetDevice().c_str(),
		client[result->GetDevice()].size());
	client.erase(i);

	svHostKey key(result->GetKey());
	if (key.GetKey().size() && !key.HasExpired(hostkey_ttl)) {
		map<string, svHostKey *>::iterator ki;
		ki = hostkey_cache.find(result->GetDevice());
		if (ki != hostkey_cache.end()) {
			ki->second->SetAge(key.GetAge());
			ki->second->SetKey(key.GetKey());
			return;
		}
		hostkey_cache[result->GetDevice()] = new svHostKey(key);
	}
}
Ejemplo n.º 2
0
uint32_t svThreadStorage::AddHostKeyClient(const string &dev,
	svEventClient *c)
{
	client[dev].push_back(c);
	svDebug("%s: Hostkey clients awaiting device: %s: %d",
		name.c_str(), dev.c_str(), client[dev].size());
	return client[dev].size();
}
Ejemplo n.º 3
0
void svCrypto::Initialize(void)
{
	if (mutex_crypto) return;
	int num_locks = CRYPTO_num_locks();
	if (num_locks <= 0) return;

	mutex_crypto = new pthread_mutex_t *[num_locks];
	for (int i = 0; i < num_locks; i++) {
		mutex_crypto[i] = new pthread_mutex_t;
		pthread_mutex_init(mutex_crypto[i], NULL);
	}
	CRYPTO_set_locking_callback(sv_crypto_lock);
	svDebug("svCrypto: Initialized %d lock(s)\n", num_locks);
}
Ejemplo n.º 4
0
void svThreadStorage::UpdatePoolClient(	
	svEventPoolClientUpdate *request)
{
	string state("unknown");
	switch (request->GetState()) {
	case svPCS_IDLE:
		state = "idle";
		break;
	case svPCS_INUSE:
		state = "in-use";
		break;
	case svPCS_OFFLINE:
		state = "offline";
		break;
	};
	
	svDebug("%s: Update pool client: %s %s: %s",
		name.c_str(), request->GetPoolName().c_str(),
		request->GetDevice().c_str(), state.c_str());

	for (vector<svStorageEngine *>::iterator i = engine.begin();
		i != engine.end(); i++) {
		if ((*i)->GetType() != svDT_PGSQL &&
			(*i)->GetType() != svDT_MYSQL) continue;
		try {
			(*i)->UpdatePoolClient(node, request->GetPoolName(),
				request->GetDevice(), org, request->GetState());
			continue;
		} catch (svExStorageRecordNotFound &e) {
		} catch (runtime_error &e) {
			svError("%s: %s", name.c_str(), e.what());
			continue;
		}

		try {
			(*i)->InsertPoolClient(node, request->GetPoolName(),
				request->GetDevice(), org, request->GetState());
		} catch (runtime_error &e) {
			svError("%s: %s", name.c_str(), e.what());
			continue;
		}
	}
}
Ejemplo n.º 5
0
void svThreadStorage::GetHostKey(svEventHostKeyRequest *request)
{
	svHostKey key;

	for (vector<svStorageEngine *>::iterator i = engine.begin();
		i != engine.end(); i++) {
		if ((*i)->GetType() != svDT_BDB) continue;
		try {
			(*i)->GetHostKey(request->GetDevice(), org, key);
		} catch (svExStorageRecordNotFound &e) {
			svDebug("%s: %s", org.c_str(), e.what());
			continue;
		} catch (runtime_error &e) {
			svError("%s: %s", org.c_str(), e.what());
			continue;
		}

		if (!key.HasExpired(hostkey_ttl)) {
			svEventServer::GetInstance()->Dispatch(
				new svEventHostKeyResult(this, NULL,
					request->GetDevice(),
					request->GetOrganization(), key));
			svDebug("%s: Using cached hostkey for: %s",
				org.c_str(), request->GetDevice().c_str());
			return;
		}
	}

	for (vector<svStorageEngine *>::iterator i = engine.begin();
		i != engine.end(); i++) {
		if ((*i)->GetType() != svDT_PGSQL &&
			(*i)->GetType() != svDT_MYSQL) continue;
		try {
			(*i)->GetHostKey(request->GetDevice(), org, key);
#if 0
		} catch (svExStorageConnect &e) {
			svError("%s: svExStorageConnect", org.c_str());
			continue;
		} catch (svExStorageDisconnect &e) {
			svError("%s: svExStorageDisconnect", org.c_str());
			continue;
		} catch (svExStorageQuery &e) {
			svError("%s: svExStorageQuery", org.c_str());
			continue;
		} catch (svExStorageEscapeString &e) {
			svError("%s: svExStorageEscapeString", org.c_str());
			continue;
		} catch (svExStorageRecordNotFound &e) {
			svError("%s: svExStorageRecordNotFound", org.c_str());
			continue;
		} catch (svExStorageInvalidConf &e) {
			svError("%s: svExStorageInvalidConf", org.c_str());
			continue;
		} catch (svExStorageUnsupportedMethod &e) {
			svError("%s: svExStorageUsupportedMethod", org.c_str());
			continue;
		} catch (runtime_error &e) {
			//svError("%s: %s", org.c_str(), e.what());
			svError("%s: runtime_error", org.c_str());
			continue;
#endif
		} catch (svExStorageRecordNotFound &e) {
			svDebug("%s: %s", org.c_str(), e.what());
			continue;
		} catch (runtime_error &e) {
			svError("%s: %s", org.c_str(), e.what());
			continue;
		}

		break;
	}

	svEventServer::GetInstance()->Dispatch(
		new svEventHostKeyResult(this, NULL,
			request->GetDevice(), request->GetOrganization(), key));

	if (key.GetKey().size()) {
		if (key.HasExpired(hostkey_ttl)) {
			svDebug("%s: Using expired hostkey for: %s",
				org.c_str(), request->GetDevice().c_str());
			return;
		}

		for (vector<svStorageEngine *>::iterator i = engine.begin();
			i != engine.end(); i++) {
			if ((*i)->GetType() != svDT_BDB) continue;
			try {
				(*i)->CacheHostKey(request->GetDevice(), org, key);
			} catch (runtime_error &e) {
				svError("%s: %s", org.c_str(), e.what());
				continue;
			}
		}

		return;
	}

	svError("%s: Hostkey not found for: %s",
		org.c_str(), request->GetDevice().c_str());
}
Ejemplo n.º 6
0
void svServer::PoolClientSave(svEventPoolClientSave *event)
{
	svPoolClient *client = event->GetClient();
	svConfOrganization *org =
		conf->GetOrganization(client->GetOrganization());
	if (!org) {
		svError("%s: Organization not found: %s",
			name.c_str(), client->GetOrganization().c_str());
		delete client;
		return;
	}

	if (org->GetMaxPoolConnections() == 0) {
		svError("%s: %s: Pool connections disabled",
			name.c_str(), org->GetName().c_str());
		delete client;
		return;
	}

	map<string, map<string, vector<svPoolClient *> > >::iterator io;
	io = pool.find(client->GetOrganization());
	if (io != pool.end()) {
		map<string, vector<svPoolClient *> >::iterator id;
		id = io->second.find(client->GetDevice());
		if (id != io->second.end()) {
			if (id->second.size() >= org->GetMaxPoolConnections()) {
				svError("%s: %s: Maximum pool connections reached, "
					"clients: %d", name.c_str(),
					org->GetName().c_str(), skt_client.size());
				delete client;
				return;
			}
		}
	}

	svSocket *skt = client->GetSocket();
	skt->SetDevice(client->GetDevice());
	skt->SetOrganization(client->GetOrganization());
	skt->SetConnected();
	skt_client.push_back(skt);
	skt_set.SelectForRead(skt);

	pool[org->GetName()][client->GetDevice()].push_back(client);

	svLog("%s: Saved pool client: %s %s [%s] (%d)",
		name.c_str(), client->GetName().c_str(),
		client->GetDevice().c_str(), client->GetOrganization().c_str(),
		pool[org->GetName()][client->GetDevice()].size());

	map<string, svThreadStorage *>::iterator i;
	i = storage.find(client->GetOrganization());
	if (i != storage.end()) {
		svEventServer::GetInstance()->Dispatch(
			new svEventPoolClientUpdate(
				i->second, client->GetName(), client->GetDevice(),
				svPCS_IDLE));
	}

	for (io = pool.begin(); io != pool.end(); io++) {
		map<string, vector<svPoolClient *> >::iterator id;
		for (id = io->second.begin(); id != io->second.end(); id++) {
			vector<svPoolClient *>::iterator pci;
			for (pci = id->second.begin(); pci != id->second.end(); pci++) {
				svDebug("%s: Pool client: %s %s [%s]",
					name.c_str(), (*pci)->GetName().c_str(),
					(*pci)->GetDevice().c_str(), (*pci)->GetOrganization().c_str());
			}
		}
	}
}
Ejemplo n.º 7
0
void svObject::DumpState(void) const
{
	svDebug("%s: no state information", name.c_str());
}
Ejemplo n.º 8
0
void svEventClient::HandleStateRequest(void)
{
    svDebug("%s: No state information", name.c_str());
}