Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate FFI client code in one common place. #133

Draft
wants to merge 5 commits into
base: ffi/integ_yuryf_glide_ffi
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion glide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ futures = "^0.3"
redis = { path = "../submodules/redis-rs/redis", features = ["aio", "tokio-comp", "tokio-rustls-comp", "connection-manager","cluster", "cluster-async"] }
signal-hook = "^0.3"
signal-hook-tokio = {version = "^0.3", features = ["futures-v0_3"] }
tokio = { version = "1", features = ["macros", "time"] }
tokio = { version = "1", features = ["macros", "time", "rt-multi-thread"] }
logger_core = {path = "../logger_core"}
dispose = "0.5.0"
tokio-util = {version = "^0.7", features = ["rt"]}
Expand Down
90 changes: 90 additions & 0 deletions glide-core/src/ffi/configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0
*/
use std::ffi::c_char;

/// A mirror of `ConnectionRequest` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
#[repr(C)]
pub struct ConnectionConfig {
pub address_count: usize,
/// Pointer to an array.
pub addresses: *const *const NodeAddress,
pub tls_mode: TlsMode,
pub cluster_mode: bool,
pub request_timeout: u32,
pub read_from: ReadFrom,
pub connection_retry_strategy: ConnectionRetryStrategy,
pub authentication_info: AuthenticationInfo,
pub database_id: u32,
pub protocol: ProtocolVersion,
pub client_name: *const c_char,
}

/// A mirror of `NodeAddress` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
/// Represents the address and port of a node in the cluster.
#[repr(C)]
pub struct NodeAddress {
pub host: *const c_char,
pub port: u16,
}

// TODO replace with redis::TlsMode
/// A mirror of `TlsMode` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
#[repr(C)]
pub enum TlsMode {
NoTls = 0,
Secure = 1,
Insecure = 2,
}

/// A mirror of `ReadFrom` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
/// Represents the client's read from strategy.
#[repr(C)]
pub enum ReadFrom {
/// Always get from primary, in order to get the freshest data.
Primary = 0,
/// Spread the requests between all replicas in a round-robin manner. If no replica is available, route the requests to the primary.
PreferReplica = 1,
LowestLatency = 2,
AZAffinity = 3,
}

/// A mirror of `ConnectionRetryStrategy` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
/// Represents the strategy used to determine how and when to reconnect, in case of connection failures.
/// The time between attempts grows exponentially, to the formula
/// ```
/// rand(0 ... factor * (exponentBase ^ N))
/// ```
/// where `N` is the number of failed attempts.
///
/// Once the maximum value is reached, that will remain the time between retry attempts until a
/// reconnect attempt is successful. The client will attempt to reconnect indefinitely.
#[repr(C)]
pub struct ConnectionRetryStrategy {
/// Number of retry attempts that the client should perform when disconnected from the server,
/// where the time between retries increases. Once the retries have reached the maximum value, the
/// time between retries will remain constant until a reconnect attempt is successful.
pub number_of_retries: u32,
/// The multiplier that will be applied to the waiting time between each retry.
pub factor: u32,
/// The exponent base configured for the strategy.
pub exponent_base: u32,
}

/// A mirror of `AuthenticationInfo` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
#[repr(C)]
pub struct AuthenticationInfo {
pub username: *const c_char,
pub password: *const c_char,
}

// TODO replace with redis::ProtocolVersion
/// A mirror of `ProtocolVersion` from [`connection_request.proto`](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/connection_request.proto).
/// Represents the communication protocol with the server.
#[repr(C)]
pub enum ProtocolVersion {
/// Use RESP3 to communicate with the server nodes.
RESP3 = 0,
/// Use RESP2 to communicate with the server nodes.
RESP2 = 1,
}
Loading
Loading