EV-Etcd
view release on metacpan or search on metacpan
etcd_common.h view on Meta::CPAN
/*
* etcd_common.h - Common types and declarations for EV::Etcd
*/
#ifndef ETCD_COMMON_H
#define ETCD_COMMON_H
/* Need EV types for ev_async in struct definitions */
#include <EV/EVAPI.h>
/* Threading support for hybrid gRPC/EV approach */
#include <pthread.h>
/* Reconnect backoff: 0.5s * attempt (capped at 5s) */
#define RECONNECT_BACKOFF_SECONDS(attempt) \
((attempt) * 0.5 > 5.0 ? 5.0 : (attempt) * 0.5)
#include <grpc/grpc.h>
#ifdef HAVE_GRPC_CREDENTIALS_H
#include <grpc/credentials.h>
#else
#include <grpc/grpc_security.h>
#endif
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
/*
* gRPC channel creation compatibility.
* - New API (>= ~1.42): grpc_insecure_credentials_create + grpc_channel_create
* - Old API (< ~1.42): grpc_insecure_channel_create
*/
static inline grpc_channel *
etcd_create_insecure_channel(const char *target, const grpc_channel_args *args) {
#ifdef HAVE_GRPC_NEW_CHANNEL_API
grpc_channel_credentials *creds = grpc_insecure_credentials_create();
grpc_channel *channel = grpc_channel_create(target, creds, args);
grpc_channel_credentials_release(creds);
return channel;
#else
return grpc_insecure_channel_create(target, args, NULL);
#endif
}
#include "kv.pb-c.h"
#include "rpc.pb-c.h"
#include "lock.pb-c.h"
#include "election.pb-c.h"
/*
* Size limits for keys and values.
* etcd defaults: MaxRequestBytes = 1.5 MiB
* We use slightly lower limits to leave room for protobuf overhead.
*/
#define ETCD_MAX_KEY_SIZE (1024 * 1024) /* 1 MiB max key size */
#define ETCD_MAX_VALUE_SIZE (1024 * 1024) /* 1 MiB max value size */
/* Validation macros for input sizes */
#define VALIDATE_KEY_SIZE(key_len) \
do { \
if ((key_len) > ETCD_MAX_KEY_SIZE) { \
croak("key too large: %zu bytes (max %d)", (size_t)(key_len), ETCD_MAX_KEY_SIZE); \
} \
} while (0)
#define VALIDATE_VALUE_SIZE(value_len) \
do { \
if ((value_len) > ETCD_MAX_VALUE_SIZE) { \
croak("value too large: %zu bytes (max %d)", (size_t)(value_len), ETCD_MAX_VALUE_SIZE); \
} \
} while (0)
/* Auth input limits - prevent DoS via oversized credentials */
#define ETCD_MAX_USERNAME_SIZE 256 /* Reasonable username limit */
#define ETCD_MAX_PASSWORD_SIZE 4096 /* Reasonable password limit */
#define VALIDATE_USERNAME_SIZE(len) \
do { \
if ((len) > ETCD_MAX_USERNAME_SIZE) { \
croak("username too large: %zu bytes (max %d)", (size_t)(len), ETCD_MAX_USERNAME_SIZE); \
} \
} while (0)
#define VALIDATE_PASSWORD_SIZE(len) \
do { \
if ((len) > ETCD_MAX_PASSWORD_SIZE) { \
croak("password too large: %zu bytes (max %d)", (size_t)(len), ETCD_MAX_PASSWORD_SIZE); \
} \
} while (0)
/* URL limit for cluster member peer URLs */
#define ETCD_MAX_URL_SIZE 2048 /* Standard URL length limit */
#define VALIDATE_URL_SIZE(len) \
do { \
if ((len) > ETCD_MAX_URL_SIZE) { \
croak("peer URL too large: %zu bytes (max %d)", (size_t)(len), ETCD_MAX_URL_SIZE); \
} \
} while (0)
/* Call types for tag identification */
typedef enum {
CALL_TYPE_NONE = 0, /* Sentinel for fire-and-forget batches (e.g. watch cancel send) */
CALL_TYPE_RANGE = 1,
CALL_TYPE_PUT,
CALL_TYPE_DELETE,
CALL_TYPE_WATCH,
CALL_TYPE_WATCH_RECV,
CALL_TYPE_LEASE_GRANT,
CALL_TYPE_LEASE_REVOKE,
CALL_TYPE_LEASE_KEEPALIVE,
CALL_TYPE_LEASE_KEEPALIVE_RECV,
CALL_TYPE_LEASE_TIME_TO_LIVE,
CALL_TYPE_LEASE_LEASES,
CALL_TYPE_COMPACT,
CALL_TYPE_STATUS,
CALL_TYPE_TXN,
CALL_TYPE_AUTH,
CALL_TYPE_USER_ADD,
CALL_TYPE_USER_DELETE,
CALL_TYPE_USER_CHANGE_PASSWORD,
CALL_TYPE_AUTH_ENABLE,
CALL_TYPE_AUTH_DISABLE,
CALL_TYPE_ROLE_ADD,
CALL_TYPE_ROLE_DELETE,
CALL_TYPE_ROLE_GET,
CALL_TYPE_ROLE_LIST,
CALL_TYPE_ROLE_GRANT_PERMISSION,
CALL_TYPE_ROLE_REVOKE_PERMISSION,
CALL_TYPE_USER_GRANT_ROLE,
CALL_TYPE_USER_REVOKE_ROLE,
CALL_TYPE_USER_GET,
CALL_TYPE_USER_LIST,
( run in 0.859 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )