mirror of https://github.com/grpc/grpc.git
pull/6675/head
commit
df204d090c
373 changed files with 16023 additions and 6234 deletions
@ -0,0 +1,6 @@ |
||||
Files generated for use by Census stats and trace recording subsystem. |
||||
|
||||
#Files |
||||
* census.pb.{h,c} - Generated from src/core/ext/census/census.proto, using the |
||||
script `tools/codegen/core/gen_nano_proto.sh src/proto/census/census.proto |
||||
$PWD/src/core/ext/census/gen src/core/ext/census/gen` |
@ -0,0 +1,179 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
/* Automatically generated nanopb constant definitions */ |
||||
/* Generated by nanopb-0.3.5-dev */ |
||||
|
||||
#include "src/core/ext/census/gen/census.pb.h" |
||||
|
||||
#if PB_PROTO_HEADER_VERSION != 30 |
||||
#error Regenerate this file with the current version of nanopb generator. |
||||
#endif |
||||
|
||||
|
||||
|
||||
const pb_field_t google_census_Duration_fields[3] = { |
||||
PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, google_census_Duration, seconds, seconds, 0), |
||||
PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, google_census_Duration, nanos, seconds, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Timestamp_fields[3] = { |
||||
PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, google_census_Timestamp, seconds, seconds, 0), |
||||
PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, google_census_Timestamp, nanos, seconds, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Metric_fields[5] = { |
||||
PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, google_census_Metric, name, name, 0), |
||||
PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, google_census_Metric, description, name, 0), |
||||
PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, google_census_Metric, unit, description, &google_census_Metric_MeasurementUnit_fields), |
||||
PB_FIELD( 4, INT32 , OPTIONAL, STATIC , OTHER, google_census_Metric, id, unit, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Metric_BasicUnit_fields[2] = { |
||||
PB_FIELD( 1, UENUM , OPTIONAL, STATIC , FIRST, google_census_Metric_BasicUnit, type, type, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Metric_MeasurementUnit_fields[4] = { |
||||
PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, google_census_Metric_MeasurementUnit, prefix, prefix, 0), |
||||
PB_FIELD( 2, MESSAGE , REPEATED, CALLBACK, OTHER, google_census_Metric_MeasurementUnit, numerator, prefix, &google_census_Metric_BasicUnit_fields), |
||||
PB_FIELD( 3, MESSAGE , REPEATED, CALLBACK, OTHER, google_census_Metric_MeasurementUnit, denominator, numerator, &google_census_Metric_BasicUnit_fields), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_AggregationDescriptor_fields[3] = { |
||||
PB_ONEOF_FIELD(options, 1, MESSAGE , ONEOF, STATIC , FIRST, google_census_AggregationDescriptor, bucket_boundaries, bucket_boundaries, &google_census_AggregationDescriptor_BucketBoundaries_fields), |
||||
PB_ONEOF_FIELD(options, 2, MESSAGE , ONEOF, STATIC , FIRST, google_census_AggregationDescriptor, interval_boundaries, interval_boundaries, &google_census_AggregationDescriptor_IntervalBoundaries_fields), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_AggregationDescriptor_BucketBoundaries_fields[2] = { |
||||
PB_FIELD( 1, DOUBLE , REPEATED, CALLBACK, FIRST, google_census_AggregationDescriptor_BucketBoundaries, bounds, bounds, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_AggregationDescriptor_IntervalBoundaries_fields[2] = { |
||||
PB_FIELD( 1, DOUBLE , REPEATED, CALLBACK, FIRST, google_census_AggregationDescriptor_IntervalBoundaries, window_size, window_size, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Distribution_fields[5] = { |
||||
PB_FIELD( 1, INT64 , OPTIONAL, STATIC , FIRST, google_census_Distribution, count, count, 0), |
||||
PB_FIELD( 2, DOUBLE , OPTIONAL, STATIC , OTHER, google_census_Distribution, mean, count, 0), |
||||
PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, google_census_Distribution, range, mean, &google_census_Distribution_Range_fields), |
||||
PB_FIELD( 4, INT64 , REPEATED, CALLBACK, OTHER, google_census_Distribution, bucket_count, range, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Distribution_Range_fields[3] = { |
||||
PB_FIELD( 1, DOUBLE , OPTIONAL, STATIC , FIRST, google_census_Distribution_Range, min, min, 0), |
||||
PB_FIELD( 2, DOUBLE , OPTIONAL, STATIC , OTHER, google_census_Distribution_Range, max, min, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_IntervalStats_fields[2] = { |
||||
PB_FIELD( 1, MESSAGE , REPEATED, CALLBACK, FIRST, google_census_IntervalStats, window, window, &google_census_IntervalStats_Window_fields), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_IntervalStats_Window_fields[4] = { |
||||
PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, google_census_IntervalStats_Window, window_size, window_size, &google_census_Duration_fields), |
||||
PB_FIELD( 2, INT64 , OPTIONAL, STATIC , OTHER, google_census_IntervalStats_Window, count, window_size, 0), |
||||
PB_FIELD( 3, DOUBLE , OPTIONAL, STATIC , OTHER, google_census_IntervalStats_Window, mean, count, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Tag_fields[3] = { |
||||
PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, google_census_Tag, key, key, 0), |
||||
PB_FIELD( 2, STRING , OPTIONAL, STATIC , OTHER, google_census_Tag, value, key, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_View_fields[6] = { |
||||
PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, google_census_View, name, name, 0), |
||||
PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, google_census_View, description, name, 0), |
||||
PB_FIELD( 3, INT32 , OPTIONAL, STATIC , OTHER, google_census_View, metric_id, description, 0), |
||||
PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, google_census_View, aggregation, metric_id, &google_census_AggregationDescriptor_fields), |
||||
PB_FIELD( 5, STRING , REPEATED, CALLBACK, OTHER, google_census_View, tag_key, aggregation, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_Aggregation_fields[6] = { |
||||
PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, google_census_Aggregation, name, name, 0), |
||||
PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, google_census_Aggregation, description, name, 0), |
||||
PB_ONEOF_FIELD(data, 3, MESSAGE , ONEOF, STATIC , OTHER, google_census_Aggregation, distribution, description, &google_census_Distribution_fields), |
||||
PB_ONEOF_FIELD(data, 4, MESSAGE , ONEOF, STATIC , OTHER, google_census_Aggregation, interval_stats, description, &google_census_IntervalStats_fields), |
||||
PB_FIELD( 5, MESSAGE , REPEATED, CALLBACK, OTHER, google_census_Aggregation, tag, data.interval_stats, &google_census_Tag_fields), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_census_ViewAggregations_fields[4] = { |
||||
PB_FIELD( 1, MESSAGE , REPEATED, CALLBACK, FIRST, google_census_ViewAggregations, aggregation, aggregation, &google_census_Aggregation_fields), |
||||
PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, google_census_ViewAggregations, start, aggregation, &google_census_Timestamp_fields), |
||||
PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, google_census_ViewAggregations, end, start, &google_census_Timestamp_fields), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
|
||||
/* Check that field information fits in pb_field_t */ |
||||
#if !defined(PB_FIELD_32BIT) |
||||
/* If you get an error here, it means that you need to define PB_FIELD_32BIT
|
||||
* compile-time option. You can do that in pb.h or on compiler command line. |
||||
*
|
||||
* The reason you need to do this is that some of your messages contain tag |
||||
* numbers or field sizes that are larger than what can fit in 8 or 16 bit |
||||
* field descriptors. |
||||
*/ |
||||
PB_STATIC_ASSERT((pb_membersize(google_census_Metric, unit) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 65536 && pb_membersize(google_census_Metric, unit) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 65536 && pb_membersize(google_census_Distribution, range) < 65536 && pb_membersize(google_census_IntervalStats, window) < 65536 && pb_membersize(google_census_IntervalStats_Window, window_size) < 65536 && pb_membersize(google_census_View, aggregation) < 65536 && pb_membersize(google_census_Aggregation, data.distribution) < 65536 && pb_membersize(google_census_Aggregation, data.interval_stats) < 65536 && pb_membersize(google_census_Metric, unit) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 65536 && pb_membersize(google_census_Metric, unit) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 65536 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 65536 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 65536 && pb_membersize(google_census_Distribution, range) < 65536 && pb_membersize(google_census_IntervalStats, window) < 65536 && pb_membersize(google_census_IntervalStats_Window, window_size) < 65536 && pb_membersize(google_census_View, aggregation) < 65536 && pb_membersize(google_census_Aggregation, data.distribution) < 65536 && pb_membersize(google_census_Aggregation, data.interval_stats) < 65536 && pb_membersize(google_census_Aggregation, tag) < 65536 && pb_membersize(google_census_ViewAggregations, aggregation) < 65536 && pb_membersize(google_census_ViewAggregations, start) < 65536 && pb_membersize(google_census_ViewAggregations, end) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_google_census_Duration_google_census_Timestamp_google_census_Metric_google_census_Metric_BasicUnit_google_census_Metric_MeasurementUnit_google_census_AggregationDescriptor_google_census_AggregationDescriptor_BucketBoundaries_google_census_AggregationDescriptor_IntervalBoundaries_google_census_Distribution_google_census_Distribution_Range_google_census_IntervalStats_google_census_IntervalStats_Window_google_census_Tag_google_census_View_google_census_Aggregation_google_census_ViewAggregations) |
||||
#endif |
||||
|
||||
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) |
||||
/* If you get an error here, it means that you need to define PB_FIELD_16BIT
|
||||
* compile-time option. You can do that in pb.h or on compiler command line. |
||||
*
|
||||
* The reason you need to do this is that some of your messages contain tag |
||||
* numbers or field sizes that are larger than what can fit in the default |
||||
* 8 bit descriptors. |
||||
*/ |
||||
PB_STATIC_ASSERT((pb_membersize(google_census_Metric, unit) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 256 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 256 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 256 && pb_membersize(google_census_Metric, unit) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 256 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 256 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 256 && pb_membersize(google_census_Distribution, range) < 256 && pb_membersize(google_census_IntervalStats, window) < 256 && pb_membersize(google_census_IntervalStats_Window, window_size) < 256 && pb_membersize(google_census_View, aggregation) < 256 && pb_membersize(google_census_Aggregation, data.distribution) < 256 && pb_membersize(google_census_Aggregation, data.interval_stats) < 256 && pb_membersize(google_census_Metric, unit) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 256 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 256 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 256 && pb_membersize(google_census_Metric, unit) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, numerator) < 256 && pb_membersize(google_census_Metric_MeasurementUnit, denominator) < 256 && pb_membersize(google_census_AggregationDescriptor, options.bucket_boundaries) < 256 && pb_membersize(google_census_AggregationDescriptor, options.interval_boundaries) < 256 && pb_membersize(google_census_Distribution, range) < 256 && pb_membersize(google_census_IntervalStats, window) < 256 && pb_membersize(google_census_IntervalStats_Window, window_size) < 256 && pb_membersize(google_census_View, aggregation) < 256 && pb_membersize(google_census_Aggregation, data.distribution) < 256 && pb_membersize(google_census_Aggregation, data.interval_stats) < 256 && pb_membersize(google_census_Aggregation, tag) < 256 && pb_membersize(google_census_ViewAggregations, aggregation) < 256 && pb_membersize(google_census_ViewAggregations, start) < 256 && pb_membersize(google_census_ViewAggregations, end) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_google_census_Duration_google_census_Timestamp_google_census_Metric_google_census_Metric_BasicUnit_google_census_Metric_MeasurementUnit_google_census_AggregationDescriptor_google_census_AggregationDescriptor_BucketBoundaries_google_census_AggregationDescriptor_IntervalBoundaries_google_census_Distribution_google_census_Distribution_Range_google_census_IntervalStats_google_census_IntervalStats_Window_google_census_Tag_google_census_View_google_census_Aggregation_google_census_ViewAggregations) |
||||
#endif |
||||
|
||||
|
||||
/* On some platforms (such as AVR), double is really float.
|
||||
* These are not directly supported by nanopb, but see example_avr_double. |
||||
* To get rid of this error, remove any double fields from your .proto. |
||||
*/ |
||||
PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES) |
||||
|
@ -0,0 +1,294 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
/* Automatically generated nanopb header */ |
||||
/* Generated by nanopb-0.3.5-dev */ |
||||
|
||||
#ifndef GRPC_CORE_EXT_CENSUS_GEN_CENSUS_PB_H |
||||
#define GRPC_CORE_EXT_CENSUS_GEN_CENSUS_PB_H |
||||
#include "third_party/nanopb/pb.h" |
||||
#if PB_PROTO_HEADER_VERSION != 30 |
||||
#error Regenerate this file with the current version of nanopb generator. |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Enum definitions */ |
||||
typedef enum _google_census_Metric_BasicUnit_Measure { |
||||
google_census_Metric_BasicUnit_Measure_UNKNOWN = 0, |
||||
google_census_Metric_BasicUnit_Measure_BITS = 1, |
||||
google_census_Metric_BasicUnit_Measure_BYTES = 2, |
||||
google_census_Metric_BasicUnit_Measure_SECS = 3, |
||||
google_census_Metric_BasicUnit_Measure_CORES = 4, |
||||
google_census_Metric_BasicUnit_Measure_MAX_UNITS = 5 |
||||
} google_census_Metric_BasicUnit_Measure; |
||||
|
||||
/* Struct definitions */ |
||||
typedef struct _google_census_AggregationDescriptor_BucketBoundaries { |
||||
pb_callback_t bounds; |
||||
} google_census_AggregationDescriptor_BucketBoundaries; |
||||
|
||||
typedef struct _google_census_AggregationDescriptor_IntervalBoundaries { |
||||
pb_callback_t window_size; |
||||
} google_census_AggregationDescriptor_IntervalBoundaries; |
||||
|
||||
typedef struct _google_census_IntervalStats { |
||||
pb_callback_t window; |
||||
} google_census_IntervalStats; |
||||
|
||||
typedef struct _google_census_AggregationDescriptor { |
||||
pb_size_t which_options; |
||||
union { |
||||
google_census_AggregationDescriptor_BucketBoundaries bucket_boundaries; |
||||
google_census_AggregationDescriptor_IntervalBoundaries interval_boundaries; |
||||
} options; |
||||
} google_census_AggregationDescriptor; |
||||
|
||||
typedef struct _google_census_Distribution_Range { |
||||
bool has_min; |
||||
double min; |
||||
bool has_max; |
||||
double max; |
||||
} google_census_Distribution_Range; |
||||
|
||||
typedef struct _google_census_Duration { |
||||
bool has_seconds; |
||||
int64_t seconds; |
||||
bool has_nanos; |
||||
int32_t nanos; |
||||
} google_census_Duration; |
||||
|
||||
typedef struct _google_census_Metric_BasicUnit { |
||||
bool has_type; |
||||
google_census_Metric_BasicUnit_Measure type; |
||||
} google_census_Metric_BasicUnit; |
||||
|
||||
typedef struct _google_census_Metric_MeasurementUnit { |
||||
bool has_prefix; |
||||
int32_t prefix; |
||||
pb_callback_t numerator; |
||||
pb_callback_t denominator; |
||||
} google_census_Metric_MeasurementUnit; |
||||
|
||||
typedef struct _google_census_Tag { |
||||
bool has_key; |
||||
char key[255]; |
||||
bool has_value; |
||||
char value[255]; |
||||
} google_census_Tag; |
||||
|
||||
typedef struct _google_census_Timestamp { |
||||
bool has_seconds; |
||||
int64_t seconds; |
||||
bool has_nanos; |
||||
int32_t nanos; |
||||
} google_census_Timestamp; |
||||
|
||||
typedef struct _google_census_Distribution { |
||||
bool has_count; |
||||
int64_t count; |
||||
bool has_mean; |
||||
double mean; |
||||
bool has_range; |
||||
google_census_Distribution_Range range; |
||||
pb_callback_t bucket_count; |
||||
} google_census_Distribution; |
||||
|
||||
typedef struct _google_census_IntervalStats_Window { |
||||
bool has_window_size; |
||||
google_census_Duration window_size; |
||||
bool has_count; |
||||
int64_t count; |
||||
bool has_mean; |
||||
double mean; |
||||
} google_census_IntervalStats_Window; |
||||
|
||||
typedef struct _google_census_Metric { |
||||
pb_callback_t name; |
||||
pb_callback_t description; |
||||
bool has_unit; |
||||
google_census_Metric_MeasurementUnit unit; |
||||
bool has_id; |
||||
int32_t id; |
||||
} google_census_Metric; |
||||
|
||||
typedef struct _google_census_View { |
||||
pb_callback_t name; |
||||
pb_callback_t description; |
||||
bool has_metric_id; |
||||
int32_t metric_id; |
||||
bool has_aggregation; |
||||
google_census_AggregationDescriptor aggregation; |
||||
pb_callback_t tag_key; |
||||
} google_census_View; |
||||
|
||||
typedef struct _google_census_ViewAggregations { |
||||
pb_callback_t aggregation; |
||||
bool has_start; |
||||
google_census_Timestamp start; |
||||
bool has_end; |
||||
google_census_Timestamp end; |
||||
} google_census_ViewAggregations; |
||||
|
||||
typedef struct _google_census_Aggregation { |
||||
pb_callback_t name; |
||||
pb_callback_t description; |
||||
pb_size_t which_data; |
||||
union { |
||||
google_census_Distribution distribution; |
||||
google_census_IntervalStats interval_stats; |
||||
} data; |
||||
pb_callback_t tag; |
||||
} google_census_Aggregation; |
||||
|
||||
/* Default values for struct fields */ |
||||
|
||||
/* Initializer values for message structs */ |
||||
#define google_census_Duration_init_default {false, 0, false, 0} |
||||
#define google_census_Timestamp_init_default {false, 0, false, 0} |
||||
#define google_census_Metric_init_default {{{NULL}, NULL}, {{NULL}, NULL}, false, google_census_Metric_MeasurementUnit_init_default, false, 0} |
||||
#define google_census_Metric_BasicUnit_init_default {false, (google_census_Metric_BasicUnit_Measure)0} |
||||
#define google_census_Metric_MeasurementUnit_init_default {false, 0, {{NULL}, NULL}, {{NULL}, NULL}} |
||||
#define google_census_AggregationDescriptor_init_default {0, {google_census_AggregationDescriptor_BucketBoundaries_init_default}} |
||||
#define google_census_AggregationDescriptor_BucketBoundaries_init_default {{{NULL}, NULL}} |
||||
#define google_census_AggregationDescriptor_IntervalBoundaries_init_default {{{NULL}, NULL}} |
||||
#define google_census_Distribution_init_default {false, 0, false, 0, false, google_census_Distribution_Range_init_default, {{NULL}, NULL}} |
||||
#define google_census_Distribution_Range_init_default {false, 0, false, 0} |
||||
#define google_census_IntervalStats_init_default {{{NULL}, NULL}} |
||||
#define google_census_IntervalStats_Window_init_default {false, google_census_Duration_init_default, false, 0, false, 0} |
||||
#define google_census_Tag_init_default {false, "", false, ""} |
||||
#define google_census_View_init_default {{{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, google_census_AggregationDescriptor_init_default, {{NULL}, NULL}} |
||||
#define google_census_Aggregation_init_default {{{NULL}, NULL}, {{NULL}, NULL}, 0, {google_census_Distribution_init_default}, {{NULL}, NULL}} |
||||
#define google_census_ViewAggregations_init_default {{{NULL}, NULL}, false, google_census_Timestamp_init_default, false, google_census_Timestamp_init_default} |
||||
#define google_census_Duration_init_zero {false, 0, false, 0} |
||||
#define google_census_Timestamp_init_zero {false, 0, false, 0} |
||||
#define google_census_Metric_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, false, google_census_Metric_MeasurementUnit_init_zero, false, 0} |
||||
#define google_census_Metric_BasicUnit_init_zero {false, (google_census_Metric_BasicUnit_Measure)0} |
||||
#define google_census_Metric_MeasurementUnit_init_zero {false, 0, {{NULL}, NULL}, {{NULL}, NULL}} |
||||
#define google_census_AggregationDescriptor_init_zero {0, {google_census_AggregationDescriptor_BucketBoundaries_init_zero}} |
||||
#define google_census_AggregationDescriptor_BucketBoundaries_init_zero {{{NULL}, NULL}} |
||||
#define google_census_AggregationDescriptor_IntervalBoundaries_init_zero {{{NULL}, NULL}} |
||||
#define google_census_Distribution_init_zero {false, 0, false, 0, false, google_census_Distribution_Range_init_zero, {{NULL}, NULL}} |
||||
#define google_census_Distribution_Range_init_zero {false, 0, false, 0} |
||||
#define google_census_IntervalStats_init_zero {{{NULL}, NULL}} |
||||
#define google_census_IntervalStats_Window_init_zero {false, google_census_Duration_init_zero, false, 0, false, 0} |
||||
#define google_census_Tag_init_zero {false, "", false, ""} |
||||
#define google_census_View_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, google_census_AggregationDescriptor_init_zero, {{NULL}, NULL}} |
||||
#define google_census_Aggregation_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, 0, {google_census_Distribution_init_zero}, {{NULL}, NULL}} |
||||
#define google_census_ViewAggregations_init_zero {{{NULL}, NULL}, false, google_census_Timestamp_init_zero, false, google_census_Timestamp_init_zero} |
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */ |
||||
#define google_census_AggregationDescriptor_BucketBoundaries_bounds_tag 1 |
||||
#define google_census_AggregationDescriptor_IntervalBoundaries_window_size_tag 1 |
||||
#define google_census_IntervalStats_window_tag 1 |
||||
#define google_census_AggregationDescriptor_bucket_boundaries_tag 1 |
||||
|
||||
#define google_census_AggregationDescriptor_interval_boundaries_tag 2 |
||||
#define google_census_Distribution_Range_min_tag 1 |
||||
#define google_census_Distribution_Range_max_tag 2 |
||||
#define google_census_Duration_seconds_tag 1 |
||||
#define google_census_Duration_nanos_tag 2 |
||||
#define google_census_Metric_BasicUnit_type_tag 1 |
||||
#define google_census_Metric_MeasurementUnit_prefix_tag 1 |
||||
#define google_census_Metric_MeasurementUnit_numerator_tag 2 |
||||
#define google_census_Metric_MeasurementUnit_denominator_tag 3 |
||||
#define google_census_Tag_key_tag 1 |
||||
#define google_census_Tag_value_tag 2 |
||||
#define google_census_Timestamp_seconds_tag 1 |
||||
#define google_census_Timestamp_nanos_tag 2 |
||||
#define google_census_Distribution_count_tag 1 |
||||
#define google_census_Distribution_mean_tag 2 |
||||
#define google_census_Distribution_range_tag 3 |
||||
#define google_census_Distribution_bucket_count_tag 4 |
||||
#define google_census_IntervalStats_Window_window_size_tag 1 |
||||
#define google_census_IntervalStats_Window_count_tag 2 |
||||
#define google_census_IntervalStats_Window_mean_tag 3 |
||||
#define google_census_Metric_name_tag 1 |
||||
#define google_census_Metric_description_tag 2 |
||||
#define google_census_Metric_unit_tag 3 |
||||
#define google_census_Metric_id_tag 4 |
||||
#define google_census_View_name_tag 1 |
||||
#define google_census_View_description_tag 2 |
||||
#define google_census_View_metric_id_tag 3 |
||||
#define google_census_View_aggregation_tag 4 |
||||
#define google_census_View_tag_key_tag 5 |
||||
#define google_census_ViewAggregations_aggregation_tag 1 |
||||
#define google_census_ViewAggregations_start_tag 2 |
||||
#define google_census_ViewAggregations_end_tag 3 |
||||
#define google_census_Aggregation_distribution_tag 3 |
||||
|
||||
#define google_census_Aggregation_interval_stats_tag 4 |
||||
#define google_census_Aggregation_name_tag 1 |
||||
#define google_census_Aggregation_description_tag 2 |
||||
#define google_census_Aggregation_tag_tag 5 |
||||
|
||||
/* Struct field encoding specification for nanopb */ |
||||
extern const pb_field_t google_census_Duration_fields[3]; |
||||
extern const pb_field_t google_census_Timestamp_fields[3]; |
||||
extern const pb_field_t google_census_Metric_fields[5]; |
||||
extern const pb_field_t google_census_Metric_BasicUnit_fields[2]; |
||||
extern const pb_field_t google_census_Metric_MeasurementUnit_fields[4]; |
||||
extern const pb_field_t google_census_AggregationDescriptor_fields[3]; |
||||
extern const pb_field_t google_census_AggregationDescriptor_BucketBoundaries_fields[2]; |
||||
extern const pb_field_t google_census_AggregationDescriptor_IntervalBoundaries_fields[2]; |
||||
extern const pb_field_t google_census_Distribution_fields[5]; |
||||
extern const pb_field_t google_census_Distribution_Range_fields[3]; |
||||
extern const pb_field_t google_census_IntervalStats_fields[2]; |
||||
extern const pb_field_t google_census_IntervalStats_Window_fields[4]; |
||||
extern const pb_field_t google_census_Tag_fields[3]; |
||||
extern const pb_field_t google_census_View_fields[6]; |
||||
extern const pb_field_t google_census_Aggregation_fields[6]; |
||||
extern const pb_field_t google_census_ViewAggregations_fields[4]; |
||||
|
||||
/* Maximum encoded size of messages (where known) */ |
||||
#define google_census_Duration_size 22 |
||||
#define google_census_Timestamp_size 22 |
||||
#define google_census_Metric_BasicUnit_size 2 |
||||
#define google_census_Distribution_Range_size 18 |
||||
#define google_census_IntervalStats_Window_size 44 |
||||
#define google_census_Tag_size 516 |
||||
|
||||
/* Message IDs (where set with "msgid" option) */ |
||||
#ifdef PB_MSGID |
||||
|
||||
#define CENSUS_MESSAGES \ |
||||
|
||||
|
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} /* extern "C" */ |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,132 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <limits.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/sync.h> |
||||
|
||||
#include "src/core/ext/load_reporting/load_reporting.h" |
||||
#include "src/core/ext/load_reporting/load_reporting_filter.h" |
||||
#include "src/core/lib/channel/channel_stack_builder.h" |
||||
#include "src/core/lib/surface/channel_init.h" |
||||
|
||||
struct grpc_load_reporting_config { |
||||
grpc_load_reporting_fn fn; |
||||
void *user_data; |
||||
}; |
||||
|
||||
grpc_load_reporting_config *grpc_load_reporting_config_create( |
||||
grpc_load_reporting_fn fn, void *user_data) { |
||||
GPR_ASSERT(fn != NULL); |
||||
grpc_load_reporting_config *lrc = |
||||
gpr_malloc(sizeof(grpc_load_reporting_config)); |
||||
lrc->fn = fn; |
||||
lrc->user_data = user_data; |
||||
return lrc; |
||||
} |
||||
|
||||
grpc_load_reporting_config *grpc_load_reporting_config_copy( |
||||
grpc_load_reporting_config *src) { |
||||
return grpc_load_reporting_config_create(src->fn, src->user_data); |
||||
} |
||||
|
||||
void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lrc) { |
||||
gpr_free(lrc); |
||||
} |
||||
|
||||
void grpc_load_reporting_config_call( |
||||
grpc_load_reporting_config *lrc, |
||||
const grpc_load_reporting_call_data *call_data) { |
||||
lrc->fn(call_data, lrc->user_data); |
||||
} |
||||
|
||||
static bool is_load_reporting_enabled(const grpc_channel_args *a) { |
||||
if (a == NULL) return false; |
||||
for (size_t i = 0; i < a->num_args; i++) { |
||||
if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_LOAD_REPORTING)) { |
||||
return a->args[i].value.pointer.p != NULL; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
static bool maybe_add_load_reporting_filter(grpc_channel_stack_builder *builder, |
||||
void *arg) { |
||||
const grpc_channel_args *args = |
||||
grpc_channel_stack_builder_get_channel_arguments(builder); |
||||
if (is_load_reporting_enabled(args)) { |
||||
return grpc_channel_stack_builder_prepend_filter( |
||||
builder, (const grpc_channel_filter *)arg, NULL, NULL); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
static void lrd_arg_destroy(void *p) { grpc_load_reporting_config_destroy(p); } |
||||
|
||||
static void *lrd_arg_copy(void *p) { |
||||
return grpc_load_reporting_config_copy(p); |
||||
} |
||||
|
||||
static int lrd_arg_cmp(void *a, void *b) { |
||||
grpc_load_reporting_config *lhs = a; |
||||
grpc_load_reporting_config *rhs = b; |
||||
return !(lhs->fn == rhs->fn && lhs->user_data == rhs->user_data); |
||||
} |
||||
|
||||
static const grpc_arg_pointer_vtable lrd_ptr_vtable = { |
||||
lrd_arg_copy, lrd_arg_destroy, lrd_arg_cmp}; |
||||
|
||||
grpc_arg grpc_load_reporting_config_create_arg( |
||||
grpc_load_reporting_config *lrc) { |
||||
grpc_arg arg; |
||||
arg.type = GRPC_ARG_POINTER; |
||||
arg.key = GRPC_ARG_ENABLE_LOAD_REPORTING; |
||||
arg.value.pointer.p = lrc; |
||||
arg.value.pointer.vtable = &lrd_ptr_vtable; |
||||
return arg; |
||||
} |
||||
|
||||
/* Plugin registration */ |
||||
|
||||
void grpc_load_reporting_plugin_init(void) { |
||||
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, |
||||
maybe_add_load_reporting_filter, |
||||
(void *)&grpc_load_reporting_filter); |
||||
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, |
||||
maybe_add_load_reporting_filter, |
||||
(void *)&grpc_load_reporting_filter); |
||||
} |
||||
|
||||
void grpc_load_reporting_plugin_shutdown() {} |
@ -0,0 +1,75 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_H |
||||
#define GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_H |
||||
|
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/surface/call.h" |
||||
|
||||
typedef struct grpc_load_reporting_config grpc_load_reporting_config; |
||||
|
||||
/** Call information to be passed to the provided load reporting function upon
|
||||
* completion of the call */ |
||||
typedef struct grpc_load_reporting_call_data { |
||||
const grpc_call_stats *stats; /**< Stats for the call */ |
||||
const char *trailing_md_string; /**< LR trailing metadata info */ |
||||
} grpc_load_reporting_call_data; |
||||
|
||||
/** Custom function to be called by the load reporting filter. */ |
||||
typedef void (*grpc_load_reporting_fn)( |
||||
const grpc_load_reporting_call_data *call_data, void *user_data); |
||||
|
||||
/** Register \a fn as the function to be invoked by the load reporting filter.
|
||||
* \a fn will be invoked at the beginning and at the end of the call. |
||||
* |
||||
* For the first invocation, \a fn's first argument |
||||
* (grpc_load_reporting_call_data*) will be NULL. \a user_data is always passed |
||||
* as-is. */ |
||||
grpc_load_reporting_config *grpc_load_reporting_config_create( |
||||
grpc_load_reporting_fn fn, void *user_data); |
||||
|
||||
grpc_load_reporting_config *grpc_load_reporting_config_copy( |
||||
grpc_load_reporting_config *src); |
||||
|
||||
void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lrc); |
||||
|
||||
/** Invoke the function registered by \a grpc_load_reporting_init. */ |
||||
void grpc_load_reporting_config_call( |
||||
grpc_load_reporting_config *lrc, |
||||
const grpc_load_reporting_call_data *call_data); |
||||
|
||||
/** Return a \a grpc_arg enabling load reporting */ |
||||
grpc_arg grpc_load_reporting_config_create_arg(grpc_load_reporting_config *lrc); |
||||
|
||||
#endif /* GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_H */ |
@ -0,0 +1,151 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <string.h> |
||||
|
||||
#include "src/core/ext/load_reporting/load_reporting.h" |
||||
#include "src/core/ext/load_reporting/load_reporting_filter.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/profiling/timers.h" |
||||
#include "src/core/lib/transport/static_metadata.h" |
||||
|
||||
typedef struct call_data { const char *trailing_md_string; } call_data; |
||||
typedef struct channel_data { |
||||
gpr_mu mu; |
||||
grpc_load_reporting_config *lrc; |
||||
} channel_data; |
||||
|
||||
static void invoke_lr_fn_locked(grpc_load_reporting_config *lrc, |
||||
grpc_load_reporting_call_data *lr_call_data) { |
||||
GPR_TIMER_BEGIN("load_reporting_config_fn", 0); |
||||
grpc_load_reporting_config_call(lrc, lr_call_data); |
||||
GPR_TIMER_END("load_reporting_config_fn", 0); |
||||
} |
||||
|
||||
/* Constructor for call_data */ |
||||
static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
||||
grpc_call_element_args *args) { |
||||
call_data *calld = elem->call_data; |
||||
memset(calld, 0, sizeof(call_data)); |
||||
} |
||||
|
||||
/* Destructor for call_data */ |
||||
static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
||||
const grpc_call_stats *stats, void *ignored) { |
||||
channel_data *chand = elem->channel_data; |
||||
call_data *calld = elem->call_data; |
||||
|
||||
grpc_load_reporting_call_data lr_call_data = {stats, |
||||
calld->trailing_md_string}; |
||||
|
||||
gpr_mu_lock(&chand->mu); |
||||
invoke_lr_fn_locked(chand->lrc, &lr_call_data); |
||||
gpr_mu_unlock(&chand->mu); |
||||
} |
||||
|
||||
/* Constructor for channel_data */ |
||||
static void init_channel_elem(grpc_exec_ctx *exec_ctx, |
||||
grpc_channel_element *elem, |
||||
grpc_channel_element_args *args) { |
||||
GPR_ASSERT(!args->is_last); |
||||
|
||||
channel_data *chand = elem->channel_data; |
||||
memset(chand, 0, sizeof(channel_data)); |
||||
|
||||
gpr_mu_init(&chand->mu); |
||||
for (size_t i = 0; i < args->channel_args->num_args; i++) { |
||||
if (0 == strcmp(args->channel_args->args[i].key, |
||||
GRPC_ARG_ENABLE_LOAD_REPORTING)) { |
||||
grpc_load_reporting_config *arg_lrc = |
||||
args->channel_args->args[i].value.pointer.p; |
||||
chand->lrc = grpc_load_reporting_config_copy(arg_lrc); |
||||
GPR_ASSERT(chand->lrc != NULL); |
||||
break; |
||||
} |
||||
} |
||||
GPR_ASSERT(chand->lrc != NULL); /* arg actually found */ |
||||
|
||||
gpr_mu_lock(&chand->mu); |
||||
invoke_lr_fn_locked(chand->lrc, NULL); |
||||
gpr_mu_unlock(&chand->mu); |
||||
} |
||||
|
||||
/* Destructor for channel data */ |
||||
static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, |
||||
grpc_channel_element *elem) { |
||||
channel_data *chand = elem->channel_data; |
||||
gpr_mu_destroy(&chand->mu); |
||||
grpc_load_reporting_config_destroy(chand->lrc); |
||||
} |
||||
|
||||
static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) { |
||||
grpc_call_element *elem = user_data; |
||||
call_data *calld = elem->call_data; |
||||
|
||||
if (md->key == GRPC_MDSTR_LOAD_REPORTING) { |
||||
calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); |
||||
return NULL; |
||||
} |
||||
|
||||
return md; |
||||
} |
||||
|
||||
static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, |
||||
grpc_call_element *elem, |
||||
grpc_transport_stream_op *op) { |
||||
GPR_TIMER_BEGIN("lr_start_transport_stream_op", 0); |
||||
|
||||
if (op->send_trailing_metadata) { |
||||
grpc_metadata_batch_filter(op->send_trailing_metadata, |
||||
lr_trailing_md_filter, elem); |
||||
} |
||||
grpc_call_next_op(exec_ctx, elem, op); |
||||
|
||||
GPR_TIMER_END("lr_start_transport_stream_op", 0); |
||||
} |
||||
|
||||
const grpc_channel_filter grpc_load_reporting_filter = { |
||||
lr_start_transport_stream_op, |
||||
grpc_channel_next_op, |
||||
sizeof(call_data), |
||||
init_call_elem, |
||||
grpc_call_stack_ignore_set_pollset, |
||||
destroy_call_elem, |
||||
sizeof(channel_data), |
||||
init_channel_elem, |
||||
destroy_channel_elem, |
||||
grpc_call_next_get_peer, |
||||
"load_reporting"}; |
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_FILTER_H |
||||
#define GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_FILTER_H |
||||
|
||||
#include "src/core/lib/channel/channel_stack.h" |
||||
|
||||
extern const grpc_channel_filter grpc_load_reporting_filter; |
||||
|
||||
#endif /* GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_FILTER_H */ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,262 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/security/credentials/composite/composite_credentials.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include "src/core/lib/surface/api_trace.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
/* -- Composite call credentials. -- */ |
||||
|
||||
typedef struct { |
||||
grpc_composite_call_credentials *composite_creds; |
||||
size_t creds_index; |
||||
grpc_credentials_md_store *md_elems; |
||||
grpc_auth_metadata_context auth_md_context; |
||||
void *user_data; |
||||
grpc_pollset *pollset; |
||||
grpc_credentials_metadata_cb cb; |
||||
} grpc_composite_call_credentials_metadata_context; |
||||
|
||||
static void composite_call_destruct(grpc_call_credentials *creds) { |
||||
grpc_composite_call_credentials *c = (grpc_composite_call_credentials *)creds; |
||||
size_t i; |
||||
for (i = 0; i < c->inner.num_creds; i++) { |
||||
grpc_call_credentials_unref(c->inner.creds_array[i]); |
||||
} |
||||
gpr_free(c->inner.creds_array); |
||||
} |
||||
|
||||
static void composite_call_md_context_destroy( |
||||
grpc_composite_call_credentials_metadata_context *ctx) { |
||||
grpc_credentials_md_store_unref(ctx->md_elems); |
||||
gpr_free(ctx); |
||||
} |
||||
|
||||
static void composite_call_metadata_cb(grpc_exec_ctx *exec_ctx, void *user_data, |
||||
grpc_credentials_md *md_elems, |
||||
size_t num_md, |
||||
grpc_credentials_status status) { |
||||
grpc_composite_call_credentials_metadata_context *ctx = |
||||
(grpc_composite_call_credentials_metadata_context *)user_data; |
||||
if (status != GRPC_CREDENTIALS_OK) { |
||||
ctx->cb(exec_ctx, ctx->user_data, NULL, 0, status); |
||||
return; |
||||
} |
||||
|
||||
/* Copy the metadata in the context. */ |
||||
if (num_md > 0) { |
||||
size_t i; |
||||
for (i = 0; i < num_md; i++) { |
||||
grpc_credentials_md_store_add(ctx->md_elems, md_elems[i].key, |
||||
md_elems[i].value); |
||||
} |
||||
} |
||||
|
||||
/* See if we need to get some more metadata. */ |
||||
if (ctx->creds_index < ctx->composite_creds->inner.num_creds) { |
||||
grpc_call_credentials *inner_creds = |
||||
ctx->composite_creds->inner.creds_array[ctx->creds_index++]; |
||||
grpc_call_credentials_get_request_metadata( |
||||
exec_ctx, inner_creds, ctx->pollset, ctx->auth_md_context, |
||||
composite_call_metadata_cb, ctx); |
||||
return; |
||||
} |
||||
|
||||
/* We're done!. */ |
||||
ctx->cb(exec_ctx, ctx->user_data, ctx->md_elems->entries, |
||||
ctx->md_elems->num_entries, GRPC_CREDENTIALS_OK); |
||||
composite_call_md_context_destroy(ctx); |
||||
} |
||||
|
||||
static void composite_call_get_request_metadata( |
||||
grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds, |
||||
grpc_pollset *pollset, grpc_auth_metadata_context auth_md_context, |
||||
grpc_credentials_metadata_cb cb, void *user_data) { |
||||
grpc_composite_call_credentials *c = (grpc_composite_call_credentials *)creds; |
||||
grpc_composite_call_credentials_metadata_context *ctx; |
||||
|
||||
ctx = gpr_malloc(sizeof(grpc_composite_call_credentials_metadata_context)); |
||||
memset(ctx, 0, sizeof(grpc_composite_call_credentials_metadata_context)); |
||||
ctx->auth_md_context = auth_md_context; |
||||
ctx->user_data = user_data; |
||||
ctx->cb = cb; |
||||
ctx->composite_creds = c; |
||||
ctx->pollset = pollset; |
||||
ctx->md_elems = grpc_credentials_md_store_create(c->inner.num_creds); |
||||
grpc_call_credentials_get_request_metadata( |
||||
exec_ctx, c->inner.creds_array[ctx->creds_index++], pollset, |
||||
auth_md_context, composite_call_metadata_cb, ctx); |
||||
} |
||||
|
||||
static grpc_call_credentials_vtable composite_call_credentials_vtable = { |
||||
composite_call_destruct, composite_call_get_request_metadata}; |
||||
|
||||
static grpc_call_credentials_array get_creds_array( |
||||
grpc_call_credentials **creds_addr) { |
||||
grpc_call_credentials_array result; |
||||
grpc_call_credentials *creds = *creds_addr; |
||||
result.creds_array = creds_addr; |
||||
result.num_creds = 1; |
||||
if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) { |
||||
result = *grpc_composite_call_credentials_get_credentials(creds); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
grpc_call_credentials *grpc_composite_call_credentials_create( |
||||
grpc_call_credentials *creds1, grpc_call_credentials *creds2, |
||||
void *reserved) { |
||||
size_t i; |
||||
size_t creds_array_byte_size; |
||||
grpc_call_credentials_array creds1_array; |
||||
grpc_call_credentials_array creds2_array; |
||||
grpc_composite_call_credentials *c; |
||||
GRPC_API_TRACE( |
||||
"grpc_composite_call_credentials_create(creds1=%p, creds2=%p, " |
||||
"reserved=%p)", |
||||
3, (creds1, creds2, reserved)); |
||||
GPR_ASSERT(reserved == NULL); |
||||
GPR_ASSERT(creds1 != NULL); |
||||
GPR_ASSERT(creds2 != NULL); |
||||
c = gpr_malloc(sizeof(grpc_composite_call_credentials)); |
||||
memset(c, 0, sizeof(grpc_composite_call_credentials)); |
||||
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE; |
||||
c->base.vtable = &composite_call_credentials_vtable; |
||||
gpr_ref_init(&c->base.refcount, 1); |
||||
creds1_array = get_creds_array(&creds1); |
||||
creds2_array = get_creds_array(&creds2); |
||||
c->inner.num_creds = creds1_array.num_creds + creds2_array.num_creds; |
||||
creds_array_byte_size = c->inner.num_creds * sizeof(grpc_call_credentials *); |
||||
c->inner.creds_array = gpr_malloc(creds_array_byte_size); |
||||
memset(c->inner.creds_array, 0, creds_array_byte_size); |
||||
for (i = 0; i < creds1_array.num_creds; i++) { |
||||
grpc_call_credentials *cur_creds = creds1_array.creds_array[i]; |
||||
c->inner.creds_array[i] = grpc_call_credentials_ref(cur_creds); |
||||
} |
||||
for (i = 0; i < creds2_array.num_creds; i++) { |
||||
grpc_call_credentials *cur_creds = creds2_array.creds_array[i]; |
||||
c->inner.creds_array[i + creds1_array.num_creds] = |
||||
grpc_call_credentials_ref(cur_creds); |
||||
} |
||||
return &c->base; |
||||
} |
||||
|
||||
const grpc_call_credentials_array * |
||||
grpc_composite_call_credentials_get_credentials(grpc_call_credentials *creds) { |
||||
const grpc_composite_call_credentials *c = |
||||
(const grpc_composite_call_credentials *)creds; |
||||
GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); |
||||
return &c->inner; |
||||
} |
||||
|
||||
grpc_call_credentials *grpc_credentials_contains_type( |
||||
grpc_call_credentials *creds, const char *type, |
||||
grpc_call_credentials **composite_creds) { |
||||
size_t i; |
||||
if (strcmp(creds->type, type) == 0) { |
||||
if (composite_creds != NULL) *composite_creds = NULL; |
||||
return creds; |
||||
} else if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) { |
||||
const grpc_call_credentials_array *inner_creds_array = |
||||
grpc_composite_call_credentials_get_credentials(creds); |
||||
for (i = 0; i < inner_creds_array->num_creds; i++) { |
||||
if (strcmp(type, inner_creds_array->creds_array[i]->type) == 0) { |
||||
if (composite_creds != NULL) *composite_creds = creds; |
||||
return inner_creds_array->creds_array[i]; |
||||
} |
||||
} |
||||
} |
||||
return NULL; |
||||
} |
||||
|
||||
/* -- Composite channel credentials. -- */ |
||||
|
||||
static void composite_channel_destruct(grpc_channel_credentials *creds) { |
||||
grpc_composite_channel_credentials *c = |
||||
(grpc_composite_channel_credentials *)creds; |
||||
grpc_channel_credentials_unref(c->inner_creds); |
||||
grpc_call_credentials_unref(c->call_creds); |
||||
} |
||||
|
||||
static grpc_security_status composite_channel_create_security_connector( |
||||
grpc_channel_credentials *creds, grpc_call_credentials *call_creds, |
||||
const char *target, const grpc_channel_args *args, |
||||
grpc_channel_security_connector **sc, grpc_channel_args **new_args) { |
||||
grpc_composite_channel_credentials *c = |
||||
(grpc_composite_channel_credentials *)creds; |
||||
grpc_security_status status = GRPC_SECURITY_ERROR; |
||||
|
||||
GPR_ASSERT(c->inner_creds != NULL && c->call_creds != NULL && |
||||
c->inner_creds->vtable != NULL && |
||||
c->inner_creds->vtable->create_security_connector != NULL); |
||||
/* If we are passed a call_creds, create a call composite to pass it
|
||||
downstream. */ |
||||
if (call_creds != NULL) { |
||||
grpc_call_credentials *composite_call_creds = |
||||
grpc_composite_call_credentials_create(c->call_creds, call_creds, NULL); |
||||
status = c->inner_creds->vtable->create_security_connector( |
||||
c->inner_creds, composite_call_creds, target, args, sc, new_args); |
||||
grpc_call_credentials_unref(composite_call_creds); |
||||
} else { |
||||
status = c->inner_creds->vtable->create_security_connector( |
||||
c->inner_creds, c->call_creds, target, args, sc, new_args); |
||||
} |
||||
return status; |
||||
} |
||||
|
||||
static grpc_channel_credentials_vtable composite_channel_credentials_vtable = { |
||||
composite_channel_destruct, composite_channel_create_security_connector}; |
||||
|
||||
grpc_channel_credentials *grpc_composite_channel_credentials_create( |
||||
grpc_channel_credentials *channel_creds, grpc_call_credentials *call_creds, |
||||
void *reserved) { |
||||
grpc_composite_channel_credentials *c = gpr_malloc(sizeof(*c)); |
||||
memset(c, 0, sizeof(*c)); |
||||
GPR_ASSERT(channel_creds != NULL && call_creds != NULL && reserved == NULL); |
||||
GRPC_API_TRACE( |
||||
"grpc_composite_channel_credentials_create(channel_creds=%p, " |
||||
"call_creds=%p, reserved=%p)", |
||||
3, (channel_creds, call_creds, reserved)); |
||||
c->base.type = channel_creds->type; |
||||
c->base.vtable = &composite_channel_credentials_vtable; |
||||
gpr_ref_init(&c->base.refcount, 1); |
||||
c->inner_creds = grpc_channel_credentials_ref(channel_creds); |
||||
c->call_creds = grpc_call_credentials_ref(call_creds); |
||||
return &c->base; |
||||
} |
@ -0,0 +1,231 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/channel/http_client_filter.h" |
||||
#include "src/core/lib/http/httpcli.h" |
||||
#include "src/core/lib/http/parser.h" |
||||
#include "src/core/lib/iomgr/executor.h" |
||||
#include "src/core/lib/json/json.h" |
||||
#include "src/core/lib/support/string.h" |
||||
#include "src/core/lib/surface/api_trace.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
/* -- Common. -- */ |
||||
|
||||
grpc_credentials_metadata_request *grpc_credentials_metadata_request_create( |
||||
grpc_call_credentials *creds, grpc_credentials_metadata_cb cb, |
||||
void *user_data) { |
||||
grpc_credentials_metadata_request *r = |
||||
gpr_malloc(sizeof(grpc_credentials_metadata_request)); |
||||
r->creds = grpc_call_credentials_ref(creds); |
||||
r->cb = cb; |
||||
r->user_data = user_data; |
||||
return r; |
||||
} |
||||
|
||||
void grpc_credentials_metadata_request_destroy( |
||||
grpc_credentials_metadata_request *r) { |
||||
grpc_call_credentials_unref(r->creds); |
||||
gpr_free(r); |
||||
} |
||||
|
||||
grpc_channel_credentials *grpc_channel_credentials_ref( |
||||
grpc_channel_credentials *creds) { |
||||
if (creds == NULL) return NULL; |
||||
gpr_ref(&creds->refcount); |
||||
return creds; |
||||
} |
||||
|
||||
void grpc_channel_credentials_unref(grpc_channel_credentials *creds) { |
||||
if (creds == NULL) return; |
||||
if (gpr_unref(&creds->refcount)) { |
||||
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); |
||||
gpr_free(creds); |
||||
} |
||||
} |
||||
|
||||
void grpc_channel_credentials_release(grpc_channel_credentials *creds) { |
||||
GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); |
||||
grpc_channel_credentials_unref(creds); |
||||
} |
||||
|
||||
grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds) { |
||||
if (creds == NULL) return NULL; |
||||
gpr_ref(&creds->refcount); |
||||
return creds; |
||||
} |
||||
|
||||
void grpc_call_credentials_unref(grpc_call_credentials *creds) { |
||||
if (creds == NULL) return; |
||||
if (gpr_unref(&creds->refcount)) { |
||||
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); |
||||
gpr_free(creds); |
||||
} |
||||
} |
||||
|
||||
void grpc_call_credentials_release(grpc_call_credentials *creds) { |
||||
GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); |
||||
grpc_call_credentials_unref(creds); |
||||
} |
||||
|
||||
void grpc_call_credentials_get_request_metadata( |
||||
grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds, |
||||
grpc_pollset *pollset, grpc_auth_metadata_context context, |
||||
grpc_credentials_metadata_cb cb, void *user_data) { |
||||
if (creds == NULL || creds->vtable->get_request_metadata == NULL) { |
||||
if (cb != NULL) { |
||||
cb(exec_ctx, user_data, NULL, 0, GRPC_CREDENTIALS_OK); |
||||
} |
||||
return; |
||||
} |
||||
creds->vtable->get_request_metadata(exec_ctx, creds, pollset, context, cb, |
||||
user_data); |
||||
} |
||||
|
||||
grpc_security_status grpc_channel_credentials_create_security_connector( |
||||
grpc_channel_credentials *channel_creds, const char *target, |
||||
const grpc_channel_args *args, grpc_channel_security_connector **sc, |
||||
grpc_channel_args **new_args) { |
||||
*new_args = NULL; |
||||
if (channel_creds == NULL) { |
||||
return GRPC_SECURITY_ERROR; |
||||
} |
||||
GPR_ASSERT(channel_creds->vtable->create_security_connector != NULL); |
||||
return channel_creds->vtable->create_security_connector( |
||||
channel_creds, NULL, target, args, sc, new_args); |
||||
} |
||||
|
||||
grpc_server_credentials *grpc_server_credentials_ref( |
||||
grpc_server_credentials *creds) { |
||||
if (creds == NULL) return NULL; |
||||
gpr_ref(&creds->refcount); |
||||
return creds; |
||||
} |
||||
|
||||
void grpc_server_credentials_unref(grpc_server_credentials *creds) { |
||||
if (creds == NULL) return; |
||||
if (gpr_unref(&creds->refcount)) { |
||||
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); |
||||
if (creds->processor.destroy != NULL && creds->processor.state != NULL) { |
||||
creds->processor.destroy(creds->processor.state); |
||||
} |
||||
gpr_free(creds); |
||||
} |
||||
} |
||||
|
||||
void grpc_server_credentials_release(grpc_server_credentials *creds) { |
||||
GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); |
||||
grpc_server_credentials_unref(creds); |
||||
} |
||||
|
||||
grpc_security_status grpc_server_credentials_create_security_connector( |
||||
grpc_server_credentials *creds, grpc_server_security_connector **sc) { |
||||
if (creds == NULL || creds->vtable->create_security_connector == NULL) { |
||||
gpr_log(GPR_ERROR, "Server credentials cannot create security context."); |
||||
return GRPC_SECURITY_ERROR; |
||||
} |
||||
return creds->vtable->create_security_connector(creds, sc); |
||||
} |
||||
|
||||
void grpc_server_credentials_set_auth_metadata_processor( |
||||
grpc_server_credentials *creds, grpc_auth_metadata_processor processor) { |
||||
GRPC_API_TRACE( |
||||
"grpc_server_credentials_set_auth_metadata_processor(" |
||||
"creds=%p, " |
||||
"processor=grpc_auth_metadata_processor { process: %p, state: %p })", |
||||
3, (creds, (void *)(intptr_t)processor.process, processor.state)); |
||||
if (creds == NULL) return; |
||||
if (creds->processor.destroy != NULL && creds->processor.state != NULL) { |
||||
creds->processor.destroy(creds->processor.state); |
||||
} |
||||
creds->processor = processor; |
||||
} |
||||
|
||||
static void server_credentials_pointer_arg_destroy(void *p) { |
||||
grpc_server_credentials_unref(p); |
||||
} |
||||
|
||||
static void *server_credentials_pointer_arg_copy(void *p) { |
||||
return grpc_server_credentials_ref(p); |
||||
} |
||||
|
||||
static int server_credentials_pointer_cmp(void *a, void *b) { |
||||
return GPR_ICMP(a, b); |
||||
} |
||||
|
||||
static const grpc_arg_pointer_vtable cred_ptr_vtable = { |
||||
server_credentials_pointer_arg_copy, server_credentials_pointer_arg_destroy, |
||||
server_credentials_pointer_cmp}; |
||||
|
||||
grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials *p) { |
||||
grpc_arg arg; |
||||
memset(&arg, 0, sizeof(grpc_arg)); |
||||
arg.type = GRPC_ARG_POINTER; |
||||
arg.key = GRPC_SERVER_CREDENTIALS_ARG; |
||||
arg.value.pointer.p = p; |
||||
arg.value.pointer.vtable = &cred_ptr_vtable; |
||||
return arg; |
||||
} |
||||
|
||||
grpc_server_credentials *grpc_server_credentials_from_arg(const grpc_arg *arg) { |
||||
if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return NULL; |
||||
if (arg->type != GRPC_ARG_POINTER) { |
||||
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, |
||||
GRPC_SERVER_CREDENTIALS_ARG); |
||||
return NULL; |
||||
} |
||||
return arg->value.pointer.p; |
||||
} |
||||
|
||||
grpc_server_credentials *grpc_find_server_credentials_in_args( |
||||
const grpc_channel_args *args) { |
||||
size_t i; |
||||
if (args == NULL) return NULL; |
||||
for (i = 0; i < args->num_args; i++) { |
||||
grpc_server_credentials *p = |
||||
grpc_server_credentials_from_arg(&args->args[i]); |
||||
if (p != NULL) return p; |
||||
} |
||||
return NULL; |
||||
} |
@ -0,0 +1,138 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/security/credentials/fake/fake_credentials.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/iomgr/executor.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
/* -- Fake transport security credentials. -- */ |
||||
|
||||
static grpc_security_status fake_transport_security_create_security_connector( |
||||
grpc_channel_credentials *c, grpc_call_credentials *call_creds, |
||||
const char *target, const grpc_channel_args *args, |
||||
grpc_channel_security_connector **sc, grpc_channel_args **new_args) { |
||||
*sc = grpc_fake_channel_security_connector_create(call_creds); |
||||
return GRPC_SECURITY_OK; |
||||
} |
||||
|
||||
static grpc_security_status |
||||
fake_transport_security_server_create_security_connector( |
||||
grpc_server_credentials *c, grpc_server_security_connector **sc) { |
||||
*sc = grpc_fake_server_security_connector_create(); |
||||
return GRPC_SECURITY_OK; |
||||
} |
||||
|
||||
static grpc_channel_credentials_vtable |
||||
fake_transport_security_credentials_vtable = { |
||||
NULL, fake_transport_security_create_security_connector}; |
||||
|
||||
static grpc_server_credentials_vtable |
||||
fake_transport_security_server_credentials_vtable = { |
||||
NULL, fake_transport_security_server_create_security_connector}; |
||||
|
||||
grpc_channel_credentials *grpc_fake_transport_security_credentials_create( |
||||
void) { |
||||
grpc_channel_credentials *c = gpr_malloc(sizeof(grpc_channel_credentials)); |
||||
memset(c, 0, sizeof(grpc_channel_credentials)); |
||||
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; |
||||
c->vtable = &fake_transport_security_credentials_vtable; |
||||
gpr_ref_init(&c->refcount, 1); |
||||
return c; |
||||
} |
||||
|
||||
grpc_server_credentials *grpc_fake_transport_security_server_credentials_create( |
||||
void) { |
||||
grpc_server_credentials *c = gpr_malloc(sizeof(grpc_server_credentials)); |
||||
memset(c, 0, sizeof(grpc_server_credentials)); |
||||
c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY; |
||||
gpr_ref_init(&c->refcount, 1); |
||||
c->vtable = &fake_transport_security_server_credentials_vtable; |
||||
return c; |
||||
} |
||||
|
||||
/* -- Metadata-only test credentials. -- */ |
||||
|
||||
static void md_only_test_destruct(grpc_call_credentials *creds) { |
||||
grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds; |
||||
grpc_credentials_md_store_unref(c->md_store); |
||||
} |
||||
|
||||
static void on_simulated_token_fetch_done(grpc_exec_ctx *exec_ctx, |
||||
void *user_data, bool success) { |
||||
grpc_credentials_metadata_request *r = |
||||
(grpc_credentials_metadata_request *)user_data; |
||||
grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)r->creds; |
||||
r->cb(exec_ctx, r->user_data, c->md_store->entries, c->md_store->num_entries, |
||||
GRPC_CREDENTIALS_OK); |
||||
grpc_credentials_metadata_request_destroy(r); |
||||
} |
||||
|
||||
static void md_only_test_get_request_metadata( |
||||
grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds, |
||||
grpc_pollset *pollset, grpc_auth_metadata_context context, |
||||
grpc_credentials_metadata_cb cb, void *user_data) { |
||||
grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds; |
||||
|
||||
if (c->is_async) { |
||||
grpc_credentials_metadata_request *cb_arg = |
||||
grpc_credentials_metadata_request_create(creds, cb, user_data); |
||||
grpc_executor_enqueue( |
||||
grpc_closure_create(on_simulated_token_fetch_done, cb_arg), true); |
||||
} else { |
||||
cb(exec_ctx, user_data, c->md_store->entries, 1, GRPC_CREDENTIALS_OK); |
||||
} |
||||
} |
||||
|
||||
static grpc_call_credentials_vtable md_only_test_vtable = { |
||||
md_only_test_destruct, md_only_test_get_request_metadata}; |
||||
|
||||
grpc_call_credentials *grpc_md_only_test_credentials_create( |
||||
const char *md_key, const char *md_value, int is_async) { |
||||
grpc_md_only_test_credentials *c = |
||||
gpr_malloc(sizeof(grpc_md_only_test_credentials)); |
||||
memset(c, 0, sizeof(grpc_md_only_test_credentials)); |
||||
c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; |
||||
c->base.vtable = &md_only_test_vtable; |
||||
gpr_ref_init(&c->base.refcount, 1); |
||||
c->md_store = grpc_credentials_md_store_create(1); |
||||
grpc_credentials_md_store_add_cstrings(c->md_store, md_key, md_value); |
||||
c->is_async = is_async; |
||||
return &c->base; |
||||
} |
@ -0,0 +1,56 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H |
||||
#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H |
||||
|
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
|
||||
/* -- Fake transport security credentials. -- */ |
||||
|
||||
/* Creates a fake transport security credentials object for testing. */ |
||||
grpc_channel_credentials *grpc_fake_transport_security_credentials_create(void); |
||||
|
||||
/* Creates a fake server transport security credentials object for testing. */ |
||||
grpc_server_credentials *grpc_fake_transport_security_server_credentials_create( |
||||
void); |
||||
|
||||
/* -- Metadata-only Test credentials. -- */ |
||||
|
||||
typedef struct { |
||||
grpc_call_credentials base; |
||||
grpc_credentials_md_store *md_store; |
||||
int is_async; |
||||
} grpc_md_only_test_credentials; |
||||
|
||||
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue