Esempio n. 1
0
static OpenSSL * _openssl_init(AppTransportPluginHelper * helper,
		AppTransportMode mode, char const * name)
{
	OpenSSL * openssl;
	int res = -1;

	if((openssl = object_new(sizeof(*openssl))) == NULL)
		return NULL;
	openssl->helper = helper;
	openssl->fd = -1;
	openssl->ssl_ctx = NULL;
	openssl->ssl = NULL;
	switch(mode)
	{
		case ATM_CLIENT:
			res = _init_client(openssl, name);
			break;
		case ATM_SERVER:
			res = _init_server(openssl, name);
			break;
	}
	/* check for errors */
	if(res != 0)
	{
		_openssl_destroy(openssl);
		return NULL;
	}
	return openssl;
}
Esempio n. 2
0
static SSLTransport * _ssl_init(AppTransportPluginHelper * helper,
		AppTransportMode mode, char const * name)
{
	SSLTransport * ssl;
	int res;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%u, \"%s\")\n", __func__, mode, name);
#endif
	if((ssl = object_new(sizeof(*ssl))) == NULL)
		return NULL;
	memset(ssl, 0, sizeof(*ssl));
	ssl->helper = helper;
	if((ssl->ssl_ctx = SSL_CTX_new(TLSv1_method())) == NULL
			|| SSL_CTX_set_cipher_list(ssl->ssl_ctx,
				SSL_DEFAULT_CIPHER_LIST) != 1
			|| SSL_CTX_load_verify_locations(ssl->ssl_ctx, NULL,
				"/etc/openssl/certs") != 1)
		/* FIXME report the underlying error */
		res = -error_set_code(1, "Could not initialize SSL");
	else
		switch((ssl->mode = mode))
		{
			case ATM_CLIENT:
				res = _init_client(ssl, name);
				break;
			case ATM_SERVER:
				res = _init_server(ssl, name);
				break;
			default:
				res = -error_set_code(1,
						"Unknown transport mode");
				break;
		}
	/* check for errors */
	if(res != 0)
	{
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() => %d (%s)\n", __func__, res,
				error_get(NULL));
#endif
		_ssl_destroy(ssl);
		return NULL;
	}
#if 0 /* XXX may be useful */
	SSL_CTX_set_mode(ssl->ssl_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
#endif
	return ssl;
}
Esempio n. 3
0
Master::Master()throw(std::runtime_error):
	Server(MASTER_PORT), 
	_registed_IOnodes(IOnode_t()), 
	_file_no(file_no_t()), 
	_buffered_files(File_t()), 
	_IOnode_socket(IOnode_sock_t()), 
	_node_number(0), 
	_file_number(0), 
	_node_id_pool(new bool[MAX_NODE_NUMBER]), 
	_file_no_pool(new bool[MAX_FILE_NUMBER]), 
	_now_node_number(0), 
	_now_file_no(0) 
{
	memset(_node_id_pool, 0, MAX_NODE_NUMBER*sizeof(bool)); 
	memset(_file_no_pool, 0, MAX_FILE_NUMBER*sizeof(bool)); 
	try
	{
		_init_server(); 
	}
	catch(std::runtime_error)
	{
		throw; 
	}
}