commit
f44e781d01
244 changed files with 8111 additions and 1580 deletions
@ -0,0 +1,14 @@ |
||||
option(gRPC_MSVC_STATIC_RUNTIME "Link with static msvc runtime libraries" OFF) |
||||
|
||||
if(gRPC_MSVC_STATIC_RUNTIME) |
||||
# switch from dynamic to static linking of msvcrt |
||||
foreach(flag_var |
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
||||
|
||||
if(${flag_var} MATCHES "/MD") |
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
||||
endif(${flag_var} MATCHES "/MD") |
||||
endforeach(flag_var) |
||||
endif() |
||||
|
@ -0,0 +1,61 @@ |
||||
/*
|
||||
* |
||||
* 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_CENSUS_TRACE_LABEL_H |
||||
#define GRPC_CORE_EXT_CENSUS_TRACE_LABEL_H |
||||
|
||||
#include "src/core/ext/census/trace_string.h" |
||||
|
||||
/* Trace label (key/value pair) stores a label name and the label value. The
|
||||
value can be one of trace_string/int64_t/bool. */ |
||||
typedef struct trace_label { |
||||
trace_string key; |
||||
enum label_type { |
||||
/* Unknown value for debugging/error purposes */ |
||||
LABEL_UNKNOWN = 0, |
||||
/* A string value */ |
||||
LABEL_STRING = 1, |
||||
/* An integer value. */ |
||||
LABEL_INT = 2, |
||||
/* A boolean value. */ |
||||
LABEL_BOOL = 3, |
||||
} value_type; |
||||
|
||||
union value { |
||||
trace_string label_str; |
||||
int64_t label_int; |
||||
bool label_bool; |
||||
} value; |
||||
} trace_label; |
||||
|
||||
#endif |
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* |
||||
* 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_CENSUS_TRACE_PROPAGATION_H |
||||
#define GRPC_CORE_EXT_CENSUS_TRACE_PROPAGATION_H |
||||
|
||||
#include "src/core/ext/census/tracing.h" |
||||
|
||||
/* Encoding and decoding functions for receiving and sending trace contexts
|
||||
over the wire. Only RPC libraries should be calling these |
||||
functions. These functions return the number of bytes encoded/decoded |
||||
(0 if a failure has occurred). buf_size indicates the size of the |
||||
input/output buffer. trace_span_context is a struct that includes the |
||||
trace ID, span ID, and a set of option flags (is_sampled, etc.). */ |
||||
|
||||
/* Converts a span context to a binary byte buffer. */ |
||||
size_t trace_span_context_to_binary(const trace_span_context *ctxt, |
||||
uint8_t *buf, size_t buf_size); |
||||
|
||||
/* Reads a binary byte buffer and populates a span context structure. */ |
||||
size_t binary_to_trace_span_context(const uint8_t *buf, size_t buf_size, |
||||
trace_span_context *ctxt); |
||||
|
||||
/* Converts a span context to an http metadata compatible string. */ |
||||
size_t trace_span_context_to_http_format(const trace_span_context *ctxt, |
||||
char *buf, size_t buf_size); |
||||
|
||||
/* Reads an http metadata compatible string and populates a span context
|
||||
structure. */ |
||||
size_t http_format_to_trace_span_context(const char *buf, size_t buf_size, |
||||
trace_span_context *ctxt); |
||||
|
||||
#endif |
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* |
||||
* 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_CENSUS_TRACE_STATUS_H |
||||
#define GRPC_CORE_EXT_CENSUS_TRACE_STATUS_H |
||||
|
||||
#include "src/core/ext/census/trace_string.h" |
||||
|
||||
/* Stores a status code and status message for a trace. */ |
||||
typedef struct trace_status { |
||||
int64_t errorCode; |
||||
trace_string errorMessage; |
||||
} trace_status; |
||||
|
||||
#endif |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* 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_CENSUS_TRACE_STRING_H |
||||
#define GRPC_CORE_EXT_CENSUS_TRACE_STRING_H |
||||
|
||||
#include <grpc/slice.h> |
||||
|
||||
/* String struct for tracing messages. Since this is a C API, we do not have
|
||||
access to a string class. This is intended for use by higher level |
||||
languages which wrap around the C API, as most of them have a string class. |
||||
This will also be more efficient when copying, as we have an explicitly |
||||
specified length. Also, grpc_slice has reference counting which allows for |
||||
interning. */ |
||||
typedef struct trace_string { |
||||
char *string; |
||||
size_t length; |
||||
} trace_string; |
||||
|
||||
#endif |
@ -0,0 +1,124 @@ |
||||
/*
|
||||
* |
||||
* 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_CENSUS_TRACING_H |
||||
#define GRPC_CORE_EXT_CENSUS_TRACING_H |
||||
|
||||
#include <grpc/support/time.h> |
||||
#include <stdbool.h> |
||||
#include "src/core/ext/census/trace_context.h" |
||||
#include "src/core/ext/census/trace_label.h" |
||||
#include "src/core/ext/census/trace_status.h" |
||||
|
||||
/* This is the low level tracing API that other languages will interface with.
|
||||
This is not intended to be accessed by the end-user, therefore it has been |
||||
designed with performance in mind rather than ease of use. */ |
||||
|
||||
/* The tracing level. */ |
||||
enum TraceLevel { |
||||
/* Annotations on this context will be silently discarded. */ |
||||
NO_TRACING = 0, |
||||
/* Annotations will not be saved to a persistent store. They will be
|
||||
available via local APIs only. This setting is not propagated to child |
||||
spans. */ |
||||
TRANSIENT_TRACING = 1, |
||||
/* Annotations are recorded for the entire distributed trace and they are
|
||||
saved to a persistent store. This setting is propagated to child spans. */ |
||||
PERSISTENT_TRACING = 2, |
||||
}; |
||||
|
||||
typedef struct trace_span_context { |
||||
/* Trace span context stores Span ID, Trace ID, and option flags. */ |
||||
/* Trace ID is 128 bits split into 2 64-bit chunks (hi and lo). */ |
||||
uint64_t trace_id_hi; |
||||
uint64_t trace_id_lo; |
||||
/* Span ID is 64 bits. */ |
||||
uint64_t span_id; |
||||
/* Span-options is 32-bit value which contains flag options. */ |
||||
uint32_t span_options; |
||||
} trace_span_context; |
||||
|
||||
typedef struct start_span_options { |
||||
/* If set, this will override the Span.local_start_time for the Span. */ |
||||
gpr_timespec local_start_timestamp; |
||||
|
||||
/* Linked spans can be used to identify spans that are linked to this span in
|
||||
a different trace. This can be used (for example) in batching operations, |
||||
where a single batch handler processes multiple requests from different |
||||
traces. If set, points to a list of Spans are linked to the created Span.*/ |
||||
trace_span_context *linked_spans; |
||||
/* The number of linked spans. */ |
||||
size_t n_linked_spans; |
||||
} start_span_options; |
||||
|
||||
/* Create a new child Span (or root if parent is NULL), with parent being the
|
||||
designated Span. The child span will have the provided name and starting |
||||
span options (optional). The bool has_remote_parent marks whether the |
||||
context refers to a remote parent span or not. */ |
||||
void trace_start_span(const trace_span_context *span_ctxt, |
||||
const trace_string name, const start_span_options *opts, |
||||
trace_span_context *new_span_ctxt, |
||||
bool has_remote_parent); |
||||
|
||||
/* Add a new Annotation to the Span. Annotations consist of a description
|
||||
(trace_string) and a set of n labels (trace_label). This can be populated |
||||
with arbitrary user data. */ |
||||
void trace_add_span_annotation(const trace_string description, |
||||
const trace_label *labels, const size_t n_labels, |
||||
trace_span_context *span_ctxt); |
||||
|
||||
/* Add a new NetworkEvent annotation to a Span. This function is only intended
|
||||
to be used by RPC systems (either client or server), not by higher level |
||||
applications. The timestamp type will be system-defined, the sent argument |
||||
designates whether this is a network send event (client request, server |
||||
reply)or receive (server request, client reply). The id argument corresponds |
||||
to Span.Annotation.NetworkEvent.id from the data model, and serves to uniquely |
||||
identify each network message. */ |
||||
void trace_add_span_network_event(const trace_string description, |
||||
const trace_label *labels, |
||||
const size_t n_labels, |
||||
const gpr_timespec timestamp, bool sent, |
||||
uint64_t id, trace_span_context *span_ctxt); |
||||
|
||||
/* Add a set of labels to the Span. These will correspond to the field
|
||||
Span.labels in the data model. */ |
||||
void trace_add_span_labels(const trace_label *labels, const size_t n_labels, |
||||
trace_span_context *span_ctxt); |
||||
|
||||
/* Mark the end of Span Execution with the given status. Only the timing of the
|
||||
first EndSpan call for a given Span will be recorded, and implementations are |
||||
free to ignore all further calls using the Span. EndSpanOptions can |
||||
optionally be NULL. */ |
||||
void trace_end_span(const trace_status *status, trace_span_context *span_ctxt); |
||||
|
||||
#endif |
@ -0,0 +1,77 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/ext/client_channel/client_channel.h" |
||||
#include "src/core/ext/lb_policy/grpclb/grpclb_channel.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/iomgr/sockaddr_utils.h" |
||||
#include "src/core/lib/support/string.h" |
||||
|
||||
grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( |
||||
grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, |
||||
grpc_client_channel_factory *client_channel_factory, |
||||
grpc_channel_args *args) { |
||||
grpc_channel *lb_channel = grpc_client_channel_factory_create_channel( |
||||
exec_ctx, client_channel_factory, lb_service_target_addresses, |
||||
GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args); |
||||
return lb_channel; |
||||
} |
||||
|
||||
grpc_channel_args *get_lb_channel_args(grpc_exec_ctx *exec_ctx, |
||||
grpc_slice_hash_table *targets_info, |
||||
const grpc_channel_args *args) { |
||||
/* We strip out the channel arg for the LB policy name, since we want
|
||||
* to use the default (pick_first) in this case. |
||||
* |
||||
* We also strip out the channel arg for the resolved addresses, since |
||||
* that will be generated by the name resolver used in the LB channel. |
||||
* Note that the LB channel will use the sockaddr resolver, so this |
||||
* won't actually generate a query to DNS (or some other name service). |
||||
* However, the addresses returned by the sockaddr resolver will have |
||||
* is_balancer=false, whereas our own addresses have is_balancer=true. |
||||
* We need the LB channel to return addresses with is_balancer=false |
||||
* so that it does not wind up recursively using the grpclb LB policy, |
||||
* as per the special case logic in client_channel.c. |
||||
* |
||||
* Lastly, we also strip out the channel arg for the server URI, |
||||
* since that will be different for the LB channel than for the parent |
||||
* channel (the client channel factory will re-add this arg with |
||||
* the right value). */ |
||||
static const char *keys_to_remove[] = { |
||||
GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES, GRPC_ARG_SERVER_URI}; |
||||
return grpc_channel_args_copy_and_remove(args, keys_to_remove, |
||||
GPR_ARRAY_SIZE(keys_to_remove)); |
||||
} |
@ -0,0 +1,56 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H |
||||
#define GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H |
||||
|
||||
#include "src/core/ext/client_channel/lb_policy_factory.h" |
||||
#include "src/core/lib/slice/slice_hash_table.h" |
||||
|
||||
/** Create the channel used for communicating with an LB service.
|
||||
* Note that an LB *service* may be comprised of several LB *servers*. |
||||
* |
||||
* \a lb_service_target_addresses is the target URI containing the addresses |
||||
* from resolving the LB service's name (eg, ipv4:10.0.0.1:1234,10.2.3.4:9876). |
||||
* \a client_channel_factory will be used for the creation of the LB channel, |
||||
* alongside the channel args passed in \a args. */ |
||||
grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( |
||||
grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, |
||||
grpc_client_channel_factory *client_channel_factory, |
||||
grpc_channel_args *args); |
||||
|
||||
grpc_channel_args *get_lb_channel_args(grpc_exec_ctx *exec_ctx, |
||||
grpc_slice_hash_table *targets_info, |
||||
const grpc_channel_args *args); |
||||
|
||||
#endif /* GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H */ |
@ -0,0 +1,107 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/ext/client_channel/client_channel.h" |
||||
#include "src/core/ext/lb_policy/grpclb/grpclb_channel.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/iomgr/sockaddr_utils.h" |
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
#include "src/core/lib/security/transport/lb_targets_info.h" |
||||
#include "src/core/lib/slice/slice_internal.h" |
||||
#include "src/core/lib/support/string.h" |
||||
|
||||
grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( |
||||
grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, |
||||
grpc_client_channel_factory *client_channel_factory, |
||||
grpc_channel_args *args) { |
||||
grpc_channel_args *new_args = args; |
||||
grpc_channel_credentials *channel_credentials = |
||||
grpc_channel_credentials_find_in_args(args); |
||||
if (channel_credentials != NULL) { |
||||
/* Substitute the channel credentials with a version without call
|
||||
* credentials: the load balancer is not necessarily trusted to handle |
||||
* bearer token credentials */ |
||||
static const char *keys_to_remove[] = {GRPC_ARG_CHANNEL_CREDENTIALS}; |
||||
grpc_channel_credentials *creds_sans_call_creds = |
||||
grpc_channel_credentials_duplicate_without_call_credentials( |
||||
channel_credentials); |
||||
GPR_ASSERT(creds_sans_call_creds != NULL); |
||||
grpc_arg args_to_add[] = { |
||||
grpc_channel_credentials_to_arg(creds_sans_call_creds)}; |
||||
/* Create the new set of channel args */ |
||||
new_args = grpc_channel_args_copy_and_add_and_remove( |
||||
args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add, |
||||
GPR_ARRAY_SIZE(args_to_add)); |
||||
grpc_channel_credentials_unref(exec_ctx, creds_sans_call_creds); |
||||
} |
||||
grpc_channel *lb_channel = grpc_client_channel_factory_create_channel( |
||||
exec_ctx, client_channel_factory, lb_service_target_addresses, |
||||
GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); |
||||
if (channel_credentials != NULL) { |
||||
grpc_channel_args_destroy(exec_ctx, new_args); |
||||
} |
||||
return lb_channel; |
||||
} |
||||
|
||||
grpc_channel_args *get_lb_channel_args(grpc_exec_ctx *exec_ctx, |
||||
grpc_slice_hash_table *targets_info, |
||||
const grpc_channel_args *args) { |
||||
const grpc_arg targets_info_arg = |
||||
grpc_lb_targets_info_create_channel_arg(targets_info); |
||||
/* We strip out the channel arg for the LB policy name, since we want
|
||||
* to use the default (pick_first) in this case. |
||||
* |
||||
* We also strip out the channel arg for the resolved addresses, since |
||||
* that will be generated by the name resolver used in the LB channel. |
||||
* Note that the LB channel will use the sockaddr resolver, so this |
||||
* won't actually generate a query to DNS (or some other name service). |
||||
* However, the addresses returned by the sockaddr resolver will have |
||||
* is_balancer=false, whereas our own addresses have is_balancer=true. |
||||
* We need the LB channel to return addresses with is_balancer=false |
||||
* so that it does not wind up recursively using the grpclb LB policy, |
||||
* as per the special case logic in client_channel.c. |
||||
* |
||||
* Lastly, we also strip out the channel arg for the server URI, |
||||
* since that will be different for the LB channel than for the parent |
||||
* channel (the client channel factory will re-add this arg with |
||||
* the right value). */ |
||||
static const char *keys_to_remove[] = { |
||||
GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES, GRPC_ARG_SERVER_URI}; |
||||
/* Add the targets info table to be used for secure naming */ |
||||
return grpc_channel_args_copy_and_add_and_remove( |
||||
args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &targets_info_arg, |
||||
1); |
||||
} |
@ -0,0 +1,70 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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 "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/security/transport/lb_targets_info.h" |
||||
|
||||
/* Channel arg key for the mapping of LB server addresses to their names for
|
||||
* secure naming purposes. */ |
||||
#define GRPC_ARG_LB_SECURE_NAMING_MAP "grpc.lb_secure_naming_map" |
||||
|
||||
static void *targets_info_copy(void *p) { return grpc_slice_hash_table_ref(p); } |
||||
static void targets_info_destroy(grpc_exec_ctx *exec_ctx, void *p) { |
||||
grpc_slice_hash_table_unref(exec_ctx, p); |
||||
} |
||||
static int targets_info_cmp(void *a, void *b) { return GPR_ICMP(a, b); } |
||||
static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = { |
||||
targets_info_copy, targets_info_destroy, targets_info_cmp}; |
||||
|
||||
grpc_arg grpc_lb_targets_info_create_channel_arg( |
||||
grpc_slice_hash_table *targets_info) { |
||||
grpc_arg arg; |
||||
arg.type = GRPC_ARG_POINTER; |
||||
arg.key = GRPC_ARG_LB_SECURE_NAMING_MAP; |
||||
arg.value.pointer.p = targets_info; |
||||
arg.value.pointer.vtable = &server_to_balancer_names_vtable; |
||||
return arg; |
||||
} |
||||
|
||||
grpc_slice_hash_table *grpc_lb_targets_info_find_in_args( |
||||
const grpc_channel_args *args) { |
||||
const grpc_arg *targets_info_arg = |
||||
grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP); |
||||
if (targets_info_arg != NULL) { |
||||
GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER); |
||||
return targets_info_arg->value.pointer.p; |
||||
} |
||||
return NULL; |
||||
} |
@ -0,0 +1,47 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017, 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_TRANSPORT_LB_TARGETS_INFO_H |
||||
#define GRPC_CORE_LIB_SECURITY_TRANSPORT_LB_TARGETS_INFO_H |
||||
|
||||
#include "src/core/lib/slice/slice_hash_table.h" |
||||
|
||||
/** Return a channel argument containing \a targets_info. */ |
||||
grpc_arg grpc_lb_targets_info_create_channel_arg( |
||||
grpc_slice_hash_table *targets_info); |
||||
|
||||
/** Return the instance of targets info in \a args or NULL */ |
||||
grpc_slice_hash_table *grpc_lb_targets_info_find_in_args( |
||||
const grpc_channel_args *args); |
||||
|
||||
#endif /* GRPC_CORE_LIB_SECURITY_TRANSPORT_LB_TARGETS_INFO_H */ |
@ -0,0 +1,104 @@ |
||||
/*
|
||||
* |
||||
* 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/transport/bdp_estimator.h" |
||||
|
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
int grpc_bdp_estimator_trace = 0; |
||||
|
||||
void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name) { |
||||
estimator->estimate = 65536; |
||||
estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED; |
||||
estimator->name = name; |
||||
} |
||||
|
||||
bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator, |
||||
int64_t *estimate) { |
||||
*estimate = estimator->estimate; |
||||
return true; |
||||
} |
||||
|
||||
bool grpc_bdp_estimator_add_incoming_bytes(grpc_bdp_estimator *estimator, |
||||
int64_t num_bytes) { |
||||
estimator->accumulator += num_bytes; |
||||
switch (estimator->ping_state) { |
||||
case GRPC_BDP_PING_UNSCHEDULED: |
||||
return true; |
||||
case GRPC_BDP_PING_SCHEDULED: |
||||
return false; |
||||
case GRPC_BDP_PING_STARTED: |
||||
return false; |
||||
} |
||||
GPR_UNREACHABLE_CODE(return false); |
||||
} |
||||
|
||||
void grpc_bdp_estimator_schedule_ping(grpc_bdp_estimator *estimator) { |
||||
if (grpc_bdp_estimator_trace) { |
||||
gpr_log(GPR_DEBUG, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64, |
||||
estimator->name, estimator->accumulator, estimator->estimate); |
||||
} |
||||
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_UNSCHEDULED); |
||||
estimator->ping_state = GRPC_BDP_PING_SCHEDULED; |
||||
estimator->accumulator = 0; |
||||
} |
||||
|
||||
void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator) { |
||||
if (grpc_bdp_estimator_trace) { |
||||
gpr_log(GPR_DEBUG, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64, |
||||
estimator->name, estimator->accumulator, estimator->estimate); |
||||
} |
||||
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_SCHEDULED); |
||||
estimator->ping_state = GRPC_BDP_PING_STARTED; |
||||
estimator->accumulator = 0; |
||||
} |
||||
|
||||
void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator) { |
||||
if (grpc_bdp_estimator_trace) { |
||||
gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64, |
||||
estimator->name, estimator->accumulator, estimator->estimate); |
||||
} |
||||
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_STARTED); |
||||
if (estimator->accumulator > 2 * estimator->estimate / 3) { |
||||
estimator->estimate *= 2; |
||||
if (grpc_bdp_estimator_trace) { |
||||
gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64, |
||||
estimator->name, estimator->estimate); |
||||
} |
||||
} |
||||
estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED; |
||||
estimator->accumulator = 0; |
||||
} |
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* |
||||
* 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_TRANSPORT_BDP_ESTIMATOR_H |
||||
#define GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H |
||||
|
||||
#include <stdbool.h> |
||||
#include <stdint.h> |
||||
|
||||
#define GRPC_BDP_SAMPLES 16 |
||||
#define GRPC_BDP_MIN_SAMPLES_FOR_ESTIMATE 3 |
||||
|
||||
extern int grpc_bdp_estimator_trace; |
||||
|
||||
typedef enum { |
||||
GRPC_BDP_PING_UNSCHEDULED, |
||||
GRPC_BDP_PING_SCHEDULED, |
||||
GRPC_BDP_PING_STARTED |
||||
} grpc_bdp_estimator_ping_state; |
||||
|
||||
typedef struct grpc_bdp_estimator { |
||||
grpc_bdp_estimator_ping_state ping_state; |
||||
int64_t accumulator; |
||||
int64_t estimate; |
||||
const char *name; |
||||
} grpc_bdp_estimator; |
||||
|
||||
void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name); |
||||
|
||||
// Returns true if a reasonable estimate could be obtained
|
||||
bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator, |
||||
int64_t *estimate); |
||||
// Returns true if the user should schedule a ping
|
||||
bool grpc_bdp_estimator_add_incoming_bytes(grpc_bdp_estimator *estimator, |
||||
int64_t num_bytes); |
||||
// Schedule a ping: call in response to receiving a true from
|
||||
// grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a
|
||||
// transport (but not necessarily started)
|
||||
void grpc_bdp_estimator_schedule_ping(grpc_bdp_estimator *estimator); |
||||
// Start a ping: call after calling grpc_bdp_estimator_schedule_ping and once
|
||||
// the ping is on the wire
|
||||
void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator); |
||||
// Completes a previously started ping
|
||||
void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator); |
||||
|
||||
#endif |
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
// This file is autogenerated from a template file. Please make
|
||||
// modifications to
|
||||
// `templates/src/objective-c/GRPCClient/private/version.h.template`
|
||||
// instead. This file can be regenerated from the template by running
|
||||
// `tools/buildgen/generate_projects.sh`.
|
||||
|
||||
|
||||
#define GRPC_OBJC_VERSION_STRING @"1.2.0-dev" |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue