Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #70 from ali-ince/1.7-pass-access-mode
Browse files Browse the repository at this point in the history
Pass AccessMode in BEGIN and RUN messages
  • Loading branch information
ali-ince authored Mar 6, 2019
2 parents 552fc23 + 5e8b327 commit 1c0e8c2
Show file tree
Hide file tree
Showing 23 changed files with 890 additions and 194 deletions.
28 changes: 8 additions & 20 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ BoltAddress

.. doxygenfunction:: BoltAddress_port

.. doxygenfunction:: BoltAddress_resolve

.. doxygenfunction:: BoltAddress_copy_resolved_host


BoltAddressSet
--------------
Expand Down Expand Up @@ -78,9 +74,9 @@ BoltConfig

.. doxygenfunction:: BoltConfig_destroy

.. doxygenfunction:: BoltConfig_get_mode
.. doxygenfunction:: BoltConfig_get_scheme

.. doxygenfunction:: BoltConfig_set_mode
.. doxygenfunction:: BoltConfig_set_scheme

.. doxygenfunction:: BoltConfig_get_transport

Expand Down Expand Up @@ -128,16 +124,6 @@ BoltConnection

.. doxygentypedef:: BoltConnection

.. doxygenfunction:: BoltConnection_create

.. doxygenfunction:: BoltConnection_destroy

.. doxygenfunction:: BoltConnection_open

.. doxygenfunction:: BoltConnection_close

.. doxygenfunction:: BoltConnection_init

.. doxygenfunction:: BoltConnection_send

.. doxygenfunction:: BoltConnection_fetch
Expand Down Expand Up @@ -300,14 +286,16 @@ BoltLog
.. doxygenfunction:: BoltLog_set_debug_func


BoltMode
BoltScheme
--------

.. doxygentypedef:: BoltMode
.. doxygentypedef:: BoltScheme

.. doxygendefine:: BOLT_SCHEME_DIRECT

.. doxygendefine:: BOLT_MODE_DIRECT
.. doxygendefine:: BOLT_SCHEME_ROUTING

.. doxygendefine:: BOLT_MODE_ROUTING
.. doxygendefine:: BOLT_SCHEME_NEO4J


BoltSocketOptions
Expand Down
2 changes: 1 addition & 1 deletion src/seabolt-cli/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct Application* app_create(int argc, char** argv)

BoltLog* log = create_logger(app->command==CMD_DEBUG);
BoltConfig* config = BoltConfig_create();
BoltConfig_set_mode(config, (strcmp(BOLT_CONFIG_ROUTING, "1")==0) ? BOLT_MODE_ROUTING : BOLT_MODE_DIRECT);
BoltConfig_set_scheme(config, (strcmp(BOLT_CONFIG_ROUTING, "1")==0) ? BOLT_SCHEME_NEO4J : BOLT_SCHEME_DIRECT);
BoltConfig_set_transport(config,
(strcmp(BOLT_CONFIG_SECURE, "1")==0) ? BOLT_TRANSPORT_ENCRYPTED : BOLT_TRANSPORT_PLAINTEXT);
BoltConfig_set_user_agent(config, "seabolt/" SEABOLT_VERSION);
Expand Down
5 changes: 3 additions & 2 deletions src/seabolt/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ list(APPEND private_source_files
${CMAKE_CURRENT_LIST_DIR}/bolt/connector.c
${CMAKE_CURRENT_LIST_DIR}/bolt/communication.c
${CMAKE_CURRENT_LIST_DIR}/bolt/communication-plain.c
${CMAKE_CURRENT_LIST_DIR}/bolt/communication-mock.c
${CMAKE_CURRENT_LIST_DIR}/bolt/direct-pool.c
${CMAKE_CURRENT_LIST_DIR}/bolt/error.c
${CMAKE_CURRENT_LIST_DIR}/bolt/lifecycle.c
${CMAKE_CURRENT_LIST_DIR}/bolt/log.c
${CMAKE_CURRENT_LIST_DIR}/bolt/mem.c
${CMAKE_CURRENT_LIST_DIR}/bolt/name.c
${CMAKE_CURRENT_LIST_DIR}/bolt/no-pool.c
${CMAKE_CURRENT_LIST_DIR}/bolt/packstream.c
${CMAKE_CURRENT_LIST_DIR}/bolt/protocol.c
${CMAKE_CURRENT_LIST_DIR}/bolt/routing-pool.c
Expand Down Expand Up @@ -240,8 +242,7 @@ endif ()
include(GenerateExportHeader)
generate_export_header(${SEABOLT_SHARED}
BASE_NAME seabolt
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/bolt/bolt-exports.h"
DEFINE_NO_DEPRECATED)
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/bolt/bolt-exports.h")
target_compile_definitions(${SEABOLT_STATIC}
PUBLIC
SEABOLT_STATIC_DEFINE)
Expand Down
31 changes: 31 additions & 0 deletions src/seabolt/src/bolt/address-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ BoltAddress* BoltAddress_create_with_lock(const char* host, const char* port);

BoltAddress* BoltAddress_create_from_string(const char* endpoint_str, uint64_t endpoint_len);

/**
* Resolves the original host and port into one or more IP addresses and
* a port number.
*
* This can be carried out more than once on the same
* address. Any newly-resolved addresses will replace any previously stored.
*
* The name resolution is a synchronized operation, i.e. concurrent resolution requests on the same
* instance are protected by a mutex.
*
* @param address the instance to be resolved.
* @param n_resolved number of resolved addresses that will be set upon successful resolution.
* @param log an optional \ref BoltLog instance to be used for logging purposes.
* @returns 0 for success, and non-zero error codes returned from getaddrinfo call on error.
*/
int32_t BoltAddress_resolve(BoltAddress* address, int32_t* n_resolved, BoltLog* log);

/**
* Copies the textual representation of the resolved IP address at the specified index into an already
* allocated buffer.
*
* If successful, AF_INET or AF_INET6 is returned depending on the address family. If unsuccessful, -1 is returned.
* Failure may be a result of a system problem or because the supplied buffer is too small for the address.
*
* @param address the instance to be queried.
* @param index index of the resolved IP address
* @param buffer destination buffer to write the IP address's string representation
* @param buffer_size size of the buffer
* @return address family (AF_INET or AF_INET6) or -1 on error
*/
int32_t
BoltAddress_copy_resolved_host(BoltAddress* address, int32_t index, char* buffer, int32_t buffer_size);

#endif //SEABOLT_ADDRESS_PRIVATE_H
33 changes: 0 additions & 33 deletions src/seabolt/src/bolt/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,6 @@ SEABOLT_EXPORT const char* BoltAddress_host(BoltAddress* address);
*/
SEABOLT_EXPORT const char* BoltAddress_port(BoltAddress* address);

/**
* Resolves the original host and port into one or more IP addresses and
* a port number.
*
* This can be carried out more than once on the same
* address. Any newly-resolved addresses will replace any previously stored.
*
* The name resolution is a synchronized operation, i.e. concurrent resolution requests on the same
* instance are protected by a mutex.
*
* @param address the instance to be resolved.
* @param n_resolved number of resolved addresses that will be set upon successful resolution.
* @param log an optional \ref BoltLog instance to be used for logging purposes.
* @returns 0 for success, and non-zero error codes returned from getaddrinfo call on error.
*/
SEABOLT_EXPORT int32_t BoltAddress_resolve(BoltAddress* address, int32_t* n_resolved, BoltLog* log);

/**
* Copies the textual representation of the resolved IP address at the specified index into an already
* allocated buffer.
*
* If successful, AF_INET or AF_INET6 is returned depending on the address family. If unsuccessful, -1 is returned.
* Failure may be a result of a system problem or because the supplied buffer is too small for the address.
*
* @param address the instance to be queried.
* @param index index of the resolved IP address
* @param buffer destination buffer to write the IP address's string representation
* @param buffer_size size of the buffer
* @return address family (AF_INET or AF_INET6) or -1 on error
*/
SEABOLT_EXPORT int32_t
BoltAddress_copy_resolved_host(BoltAddress* address, int32_t index, char* buffer, int32_t buffer_size);

/**
* Destroys the passed \ref BoltAddress instance.
*
Expand Down
188 changes: 188 additions & 0 deletions src/seabolt/src/bolt/communication-mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "communication-mock.h"
#include "bolt-private.h"
#include "config-private.h"
#include "mem.h"
#include "name.h"
#include "status-private.h"
#include "log-private.h"

#define MAX_IPADDR_LEN 64

int mock_last_error(BoltCommunication* comm)
{
UNUSED(comm);
return BOLT_SUCCESS;
}

int mock_transform_error(BoltCommunication* comm, int error_code)
{
UNUSED(comm);
UNUSED(error_code);
return BOLT_SUCCESS;
}

int mock_socket_ignore_sigpipe(BoltCommunication* comm)
{
BoltLog_debug(comm->log, "socket_ignore_sigpipe");
return BOLT_SUCCESS;
}

int mock_socket_restore_sigpipe(BoltCommunication* comm)
{
BoltLog_debug(comm->log, "socket_restore_sigpipe");
return BOLT_SUCCESS;
}

int mock_socket_open(BoltCommunication* comm, const struct sockaddr_storage* address)
{
BoltLog_debug(comm->log, "socket_open");

MockCommunicationContext* context = comm->context;

char resolved_host[MAX_IPADDR_LEN], resolved_port[6];
int status = get_address_components(address, resolved_host, MAX_IPADDR_LEN, resolved_port, 6);
if (status!=0) {
BoltStatus_set_error_with_ctx(comm->status, BOLT_ADDRESS_NAME_INFO_FAILED,
"mock_socket_open(%s:%d), remote get_address_components error code: %d", __FILE__, __LINE__, status);
return BOLT_STATUS_SET;
}
context->remote_endpoint = BoltAddress_create(resolved_host, resolved_port);
context->local_endpoint = BoltAddress_create("localhost", "65000");

BoltLog_debug(comm->log, "socket_open: connected");

return BOLT_SUCCESS;
}

int mock_socket_close(BoltCommunication* comm)
{
BoltLog_debug(comm->log, "socket_close");

MockCommunicationContext* context = comm->context;

if (context->local_endpoint!=NULL) {
BoltAddress_destroy(context->local_endpoint);
context->local_endpoint = NULL;
}

if (context->remote_endpoint!=NULL) {
BoltAddress_destroy(context->remote_endpoint);
context->remote_endpoint = NULL;
}

return BOLT_SUCCESS;
}

int mock_socket_send(BoltCommunication* comm, char* buffer, int length, int* sent)
{
UNUSED(buffer);
BoltLog_debug(comm->log, "socket_send: %d bytes", length);

*sent = length;

return BOLT_SUCCESS;
}

int mock_socket_recv(BoltCommunication* comm, char* buffer, int length, int* received)
{
BoltLog_debug(comm->log, "socket_recv: %d bytes", length);

MockCommunicationContext* context = comm->context;
if (!context->protocol_version_sent) {
memcpy_be(buffer, &context->protocol_version, sizeof(int32_t));
context->protocol_version_sent = 1;
}

*received = length;

return BOLT_SUCCESS;
}

int mock_socket_destroy(BoltCommunication* comm)
{
BoltLog_debug(comm->log, "socket_destroy");

MockCommunicationContext* context = comm->context;

if (context!=NULL) {
if (context->local_endpoint!=NULL) {
BoltAddress_destroy(context->local_endpoint);
context->local_endpoint = NULL;
}
if (context->remote_endpoint!=NULL) {
BoltAddress_destroy(context->remote_endpoint);
context->remote_endpoint = NULL;
}

BoltMem_deallocate(context, sizeof(MockCommunicationContext));
comm->context = NULL;
}

return BOLT_SUCCESS;
}

BoltAddress* mock_socket_local_endpoint(BoltCommunication* comm)
{
MockCommunicationContext* context = comm->context;
return context->local_endpoint;
}

BoltAddress* mock_socket_remote_endpoint(BoltCommunication* comm)
{
MockCommunicationContext* context = comm->context;
return context->remote_endpoint;
}

BoltCommunication*
BoltCommunication_create_mock(int32_t version, BoltSocketOptions* sock_opts, BoltLog* log)
{
BoltCommunication* comm = BoltMem_allocate(sizeof(BoltCommunication));
comm->open = &mock_socket_open;
comm->close = &mock_socket_close;
comm->send = &mock_socket_send;
comm->recv = &mock_socket_recv;
comm->destroy = &mock_socket_destroy;

comm->get_local_endpoint = &mock_socket_local_endpoint;
comm->get_remote_endpoint = &mock_socket_remote_endpoint;

comm->ignore_sigpipe = &mock_socket_ignore_sigpipe;
comm->restore_sigpipe = &mock_socket_restore_sigpipe;

comm->last_error = &mock_last_error;
comm->transform_error = &mock_transform_error;

comm->status_owned = 1;
comm->status = BoltStatus_create_with_ctx(1024);
comm->sock_opts_owned = sock_opts==NULL;
comm->sock_opts = sock_opts==NULL ? BoltSocketOptions_create() : sock_opts;
comm->log = log;

MockCommunicationContext* context = BoltMem_allocate(sizeof(MockCommunicationContext));
context->local_endpoint = NULL;
context->remote_endpoint = NULL;
context->protocol_version = version;
context->protocol_version_sent = 0;

comm->context = context;

return comm;
}
35 changes: 35 additions & 0 deletions src/seabolt/src/bolt/communication-mock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SEABOLT_COMMUNICATION_MOCK_H
#define SEABOLT_COMMUNICATION_MOCK_H

#include "communication.h"
#include "config.h"

typedef struct MockCommunicationContext {
BoltAddress* local_endpoint;
BoltAddress* remote_endpoint;

int32_t protocol_version;
int protocol_version_sent;
} MockCommunicationContext;

BoltCommunication* BoltCommunication_create_mock(int32_t version, BoltSocketOptions* socket_options, BoltLog* log);

#endif //SEABOLT_COMMUNICATION_MOCK_H
Loading

0 comments on commit 1c0e8c2

Please sign in to comment.