Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/ts/apidefs.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,26 @@ extern tsapi const char *const TS_PROTO_TAG_IPV6;
*/
#define TS_NULL_MLOC ((TSMLoc)0)

/* --------------------------------------------------------------------------
HostStatus types */

typedef enum {
TS_HOST_STATUS_INIT,
TS_HOST_STATUS_DOWN,
TS_HOST_STATUS_UP,
} TSHostStatus;

/* MUST match proxy/HostStatus.h Reason.
* If a value is added here, it MUST be added there with the same value.
*/
typedef enum {
TS_HOST_STATUS_ACTIVE = 0x1,
TS_HOST_STATUS_LOCAL = 0x2,
TS_HOST_STATUS_MANUAL = 0x4,
TS_HOST_STATUS_SELF_DETECT = 0x8,
TS_HOST_STATUS_ALL = 0xf,
} TSHostStatusReason;

/* --------------------------------------------------------------------------
Interface for the UUID APIs. https://www.ietf.org/rfc/rfc4122.txt. */
typedef enum {
Expand Down
49 changes: 0 additions & 49 deletions include/ts/nexthop.h

This file was deleted.

60 changes: 60 additions & 0 deletions include/ts/parentselectdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/** @file

Traffic Server SDK API header file

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@section developers Developers

NextHop plugin interface.

*/

#pragma once

#include <string.h>
#include <netinet/in.h>

// Plugins may set this to indicate how to retry.
//
// If handled is false, then no plugin set it, and Core will proceed to do its own thing.
//
// If handled is true, core will not do any parent processing, markdown, or anything else,
// but will use the values in this for whether to use the existing response or make another request,
// and what that request should look like.
//
// See the API functions which take this for ownership requirements of pointers, like hostname.
//
// hostname is the hostname to use for the next request. It must be null-terminated.
// hostname_len is the length of hostname, not including the terminating null.
//
typedef struct {
// TODO this shouldn't be necessary - plugins should manipulate the response as they see fit,
// core shouldn't "know" if it was a "success" or "failure," only the response or retry data/action.
// But for now, core needs to know, for reasons.
const char *hostname;
size_t hostname_len;
in_port_t port;
bool fail;
bool is_retry;
bool nextHopExists;
bool responseIsRetryable;
bool goDirect;
bool parentIsProxy;
} TSResponseAction;
28 changes: 28 additions & 0 deletions include/ts/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#pragma once

#include <ts/apidefs.h>
#include <ts/parentselectdefs.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -2601,6 +2602,12 @@ tsapi TSReturnCode TSRemapFromUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp);
//
tsapi TSReturnCode TSRemapToUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp);

// Override response behavior, and hard-set the state machine for whether to succeed or fail, and how.
tsapi void TSHttpTxnResponseActionSet(TSHttpTxn txnp, TSResponseAction *action);

// Get the overridden response behavior set by previously called plugins.
tsapi void TSHttpTxnResponseActionGet(TSHttpTxn txnp, TSResponseAction *action);

/*
* Get a TSIOBufferReader to read the buffered body. The return value needs to be freed.
*/
Expand Down Expand Up @@ -2641,6 +2648,27 @@ tsapi TSReturnCode TSHttpTxnClientStreamIdGet(TSHttpTxn txnp, uint64_t *stream_i
*/
tsapi TSReturnCode TSHttpTxnClientStreamPriorityGet(TSHttpTxn txnp, TSHttpPriority *priority);

/*
* Returns TS_SUCCESS if hostname is this machine, as used for parent and remap self-detection.
* Returns TS_ERROR if hostname is not this machine.
*/
tsapi TSReturnCode TSHostnameIsSelf(const char *hostname, size_t hostname_len);

/*
* Gets the status of hostname in the outparam status, and the status reason in the outparam reason.
* The reason is a logical-or combination of the reasons in TSHostStatusReason.
* If either outparam is null, it will not be set and no error will be returned.
* Returns TS_SUCCESS if the hostname was a parent and existed in the HostStatus, else TS_ERROR.
*/
tsapi TSReturnCode TSHostStatusGet(const char *hostname, const size_t hostname_len, TSHostStatus *status, unsigned int *reason);

/*
* Sets the status of hostname in status, down_time, and reason.
* The reason is a logical-or combination of the reasons in TSHostStatusReason.
*/
tsapi void TSHostStatusSet(const char *hostname, const size_t hostname_len, TSHostStatus status, const unsigned int down_time,
const unsigned int reason);

#ifdef __cplusplus
}
#endif /* __cplusplus */
2 changes: 1 addition & 1 deletion iocore/cache/test/stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ ts::svtoi(TextView src, TextView *out, int base)
}

void
HostStatus::setHostStatus(const char *name, HostStatus_t status, const unsigned int down_time, const unsigned int reason)
HostStatus::setHostStatus(const char *name, TSHostStatus status, const unsigned int down_time, const unsigned int reason)
{
}

Expand Down
1 change: 1 addition & 0 deletions iocore/utils/I_Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct Machine {
/// @return The global instance of this class.
static self *instance();
bool is_self(const char *name);
bool is_self(const char *name, int name_len);
bool is_self(const IpAddr *ipaddr);
bool is_self(struct sockaddr const *addr);
void insert_id(char *id);
Expand Down
15 changes: 10 additions & 5 deletions iocore/utils/Machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
#endif

static void
make_to_lower_case(const char *name, char *lower_case_name, int buf_len)
make_to_lower_case(const char *name, int name_len, char *lower_case_name, int buf_len)
{
int name_len = strlen(name);
int i;

if (name_len > (buf_len - 1)) {
Expand Down Expand Up @@ -238,14 +237,20 @@ Machine::~Machine()

bool
Machine::is_self(const char *name)
{
return is_self(name, strlen(name));
}

bool
Machine::is_self(const char *name, int name_len)
{
char lower_case_name[TS_MAX_HOST_NAME_LEN + 1] = {0};

if (name == nullptr) {
if (name_len == 0) {
return false;
}

make_to_lower_case(name, lower_case_name, sizeof(lower_case_name));
make_to_lower_case(name, name_len, lower_case_name, sizeof(lower_case_name));

return machine_id_strings.find(lower_case_name) != machine_id_strings.end();
}
Expand Down Expand Up @@ -279,7 +284,7 @@ Machine::insert_id(char *id)
{
char lower_case_name[TS_MAX_HOST_NAME_LEN + 1] = {0};

make_to_lower_case(id, lower_case_name, sizeof(lower_case_name));
make_to_lower_case(id, strlen(id), lower_case_name, sizeof(lower_case_name));
machine_id_strings.emplace(lower_case_name);
}

Expand Down
1 change: 1 addition & 0 deletions plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ include experimental/custom_redirect/Makefile.inc
include experimental/fq_pacing/Makefile.inc
include experimental/geoip_acl/Makefile.inc
include experimental/header_freq/Makefile.inc
include experimental/parent_select/Makefile.inc
include experimental/hook-trace/Makefile.inc
include experimental/icap/Makefile.inc
include experimental/inliner/Makefile.inc
Expand Down
29 changes: 29 additions & 0 deletions plugins/experimental/parent_select/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

pkglib_LTLIBRARIES += experimental/parent_select/parent_select.la

experimental_parent_select_parent_select_la_SOURCES = \
experimental/parent_select/strategy.cc \
experimental/parent_select/healthstatus.cc \
experimental/parent_select/consistenthash.cc \
experimental/parent_select/consistenthash_config.cc \
experimental/parent_select/parent_select.cc

experimental_parent_select_parent_select_la_LDFLAGS = \
$(AM_LDFLAGS)

AM_CPPFLAGS += @YAMLCPP_INCLUDES@ $(TS_INCLUDES)
Loading