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
10 changes: 5 additions & 5 deletions include/wccp/Wccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
#include <memory.h>
#include <string_view>

#include "tscore/TsBuffer.h"
#include "tscore/Errata.h"
// INADDR_ANY
#include <netinet/in.h>

#include "tscore/ink_defs.h"
#include "tscore/ink_memory.h"
#include "tscore/IntrusivePtr.h"
#include "tscore/Errata.h"

// Nasty, defining this with no prefix. The value is still available
// in TS_VERSION_STRING.
#undef VERSION

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

/// WCCP Support.
namespace wccp
{
Expand Down
2 changes: 1 addition & 1 deletion src/wccp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AM_CPPFLAGS += \
-I$(abs_top_srcdir)/lib \
-I$(abs_top_srcdir)/proxy \
$(TS_INCLUDES) \
@YAMLCPP_INCLUDES@
@SWOC_INCLUDES@ @YAMLCPP_INCLUDES@

noinst_LIBRARIES = libwccp.a

Expand Down
22 changes: 11 additions & 11 deletions src/wccp/WccpEndPoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ Impl::handleMessage()

// Check to see if there is a valid header.
MsgHeaderComp header;
MsgBuffer msg_buffer(buffer, n);
MsgBuffer msg_buffer(buffer_type(buffer, n));
if (PARSE_SUCCESS == header.parse(msg_buffer)) {
message_type_t msg_type = header.getType();
ts::Buffer chunk(buffer, n);
buffer_type chunk(buffer, n);

switch (msg_type) {
case HERE_I_AM:
Expand All @@ -257,22 +257,22 @@ Impl::handleMessage()
}

ts::Errata
Impl::handleHereIAm(IpHeader const &, ts::Buffer const &)
Impl::handleHereIAm(IpHeader const &, buffer_type const &)
{
return log(LVL_INFO, "Unanticipated WCCP2_HERE_I_AM message ignored");
}
ts::Errata
Impl::handleISeeYou(IpHeader const &, ts::Buffer const & /* data ATS_UNUSED */)
Impl::handleISeeYou(IpHeader const &, buffer_type const & /* data ATS_UNUSED */)
{
return log(LVL_INFO, "Unanticipated WCCP2_I_SEE_YOU message ignored.");
}
ts::Errata
Impl::handleRedirectAssign(IpHeader const &, ts::Buffer const & /* data ATS_UNUSED */)
Impl::handleRedirectAssign(IpHeader const &, buffer_type const & /* data ATS_UNUSED */)
{
return log(LVL_INFO, "Unanticipated WCCP2_REDIRECT_ASSIGN message ignored.");
}
ts::Errata
Impl::handleRemovalQuery(IpHeader const &, ts::Buffer const & /* data ATS_UNUSED */)
Impl::handleRemovalQuery(IpHeader const &, buffer_type const & /* data ATS_UNUSED */)
{
return log(LVL_INFO, "Unanticipated WCCP2_REMOVAL_QUERY message ignored.");
}
Expand Down Expand Up @@ -604,7 +604,7 @@ CacheImpl::housekeeping()
static size_t const BUFFER_SIZE = 4096;
MsgBuffer msg_buffer;
char msg_data[BUFFER_SIZE];
msg_buffer.set(msg_data, BUFFER_SIZE);
msg_buffer.assign({msg_data, BUFFER_SIZE});

// Set up everything except the IP address.
memset(&dst_addr, 0, sizeof(dst_addr));
Expand Down Expand Up @@ -690,7 +690,7 @@ CacheImpl::housekeeping()
}

ts::Errata
CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr ATS_UNUSED */, ts::Buffer const &chunk)
CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr ATS_UNUSED */, buffer_type const &chunk)
{
ts::Errata zret;
ISeeYouMsg msg;
Expand Down Expand Up @@ -849,7 +849,7 @@ CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr ATS_UNUSED */, ts::Buffer co
}

ts::Errata
CacheImpl::handleRemovalQuery(IpHeader const & /* ip_hdr ATS_UNUSED */, ts::Buffer const &chunk)
CacheImpl::handleRemovalQuery(IpHeader const & /* ip_hdr ATS_UNUSED */, buffer_type const &chunk)
{
ts::Errata zret;
RemovalQueryMsg msg;
Expand Down Expand Up @@ -937,7 +937,7 @@ RouterImpl::GroupData::resizeRouterSources()
}

ts::Errata
RouterImpl::handleHereIAm(IpHeader const &ip_hdr, ts::Buffer const &chunk)
RouterImpl::handleHereIAm(IpHeader const &ip_hdr, buffer_type const &chunk)
{
ts::Errata zret;
HereIAmMsg msg;
Expand Down Expand Up @@ -1058,7 +1058,7 @@ RouterImpl::xmitISeeYou()
memset(&dst_addr, 0, sizeof(dst_addr));
dst_addr.sin_family = AF_INET;
dst_addr.sin_port = htons(DEFAULT_PORT);
buffer.set(data, BUFFER_SIZE);
buffer.assign({data, BUFFER_SIZE});

// Send out messages for each service group.
for (GroupMap::iterator svc_spot = m_groups.begin(), svc_limit = m_groups.end(); svc_spot != svc_limit; ++svc_spot) {
Expand Down
90 changes: 42 additions & 48 deletions src/wccp/WccpLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@

#pragma once

#include "wccp/Wccp.h"
#include "WccpUtil.h"
#include "ts/apidefs.h"
#include "tscore/Errata.h"
// Needed for template use of byte ordering functions.
#include <netinet/in.h>
#include <memory.h>
#include <map>
#include <string_view>

#include "swoc/MemSpan.h"

#include "wccp/Wccp.h"
#include "WccpUtil.h"
#include "ts/apidefs.h"

namespace YAML
{
class Node;
};

namespace wccp
{

using buffer_type = swoc::MemSpan<char>;

// Forward declares
namespace detail
{
Expand Down Expand Up @@ -97,24 +102,16 @@ static int const PARSE_DATA_OVERRUN = 10;
Takes the basic ATS buffer and adds a count field to track
the amount of buffer in use.
*/
class MsgBuffer : protected ts::Buffer
class MsgBuffer
{
public:
using self_type = MsgBuffer; ///< Self reference type.
using super_type = ts::Buffer; ///< Parent type.
using self_type = MsgBuffer; ///< Self reference type.

MsgBuffer(); ///< Default construct empty buffer.
/// Construct from ATS buffer.
MsgBuffer(super_type const &that ///< Instance to copy.
);
/// Construct from pointer and size.
MsgBuffer(void *ptr, ///< Pointer to buffer.
size_t n ///< Size of buffer.
);
/// Construct from span.
MsgBuffer(buffer_type const &span);
/// Assign a buffer.
MsgBuffer &set(void *ptr, ///< Pointer to buffer.
size_t n ///< Size of buffer.
);
MsgBuffer &assign(buffer_type const &span);

/// Get the buffer size.
size_t getSize() const;
Expand All @@ -137,7 +134,8 @@ class MsgBuffer : protected ts::Buffer
/// Reset and zero the buffer.
self_type &zero();

size_t _count; ///< Number of bytes in use.
buffer_type _base; ///< Original pointer.
buffer_type _active; ///< Unprocessed data, always a suffix of @a _base.
};

/// Sect 4.4: Cache assignment method.
Expand Down Expand Up @@ -2063,8 +2061,7 @@ class HereIAmMsg : public BaseMsg
void fill_caps(detail::cache::RouterData const &router ///< Target router.
);
/// Parse message data, presumed to be of this type.
int parse(ts::Buffer const &buffer ///< Raw message data.
);
int parse(swoc::MemSpan<char> const &buffer);

CacheIdComp m_cache_id; ///< Web cache identity info.
CacheViewComp m_cache_view; ///< Web cache view.
Expand All @@ -2090,7 +2087,7 @@ class ISeeYouMsg : public BaseMsg
);

/// Parse message data, presumed to be of this type.
int parse(ts::Buffer const &buffer ///< Raw message data.
int parse(buffer_type const &buffer ///< Raw message data.
);

RouterIdComp m_router_id; ///< Router ID.
Expand Down Expand Up @@ -2123,7 +2120,7 @@ class RedirectAssignMsg : public BaseMsg
);

/// Parse message data, presumed to be of this type.
int parse(ts::Buffer const &buffer ///< Raw message data.
int parse(buffer_type const &buffer ///< Raw message data.
);

// Only one of these should be present in an instance.
Expand Down Expand Up @@ -2153,7 +2150,7 @@ class RemovalQueryMsg : public BaseMsg
);

/// Parse message data, presumed to be of this type.
int parse(ts::Buffer const &buffer ///< Raw message data.
int parse(buffer_type const &buffer ///< Raw message data.
);

QueryComp m_query; ///< Router Removal Query component.
Expand Down Expand Up @@ -2235,19 +2232,19 @@ class Impl : public ts::IntrusivePtrCounter
*/
/// Process HERE_I_AM message.
virtual ts::Errata handleHereIAm(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
);
/// Process I_SEE_YOU message.
virtual ts::Errata handleISeeYou(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
);
/// Process REDIRECT_ASSIGN message.
virtual ts::Errata handleRedirectAssign(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
);
/// Process REMOVAL_QUERY message.
virtual ts::Errata handleRemovalQuery(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
);

protected:
Expand Down Expand Up @@ -2520,11 +2517,11 @@ class CacheImpl : public Impl
);
/// Process HERE_I_AM message.
ts::Errata handleISeeYou(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
) override;
/// Process REMOVAL_QUERY message.
ts::Errata handleRemovalQuery(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Message data.
buffer_type const &data ///< Message data.
) override;

/// Map Service Group ID to Service Group Data.
Expand Down Expand Up @@ -2632,7 +2629,7 @@ class RouterImpl : public Impl

/// Process HERE_I_AM message.
ts::Errata handleHereIAm(IpHeader const &header, ///< IP packet data.
ts::Buffer const &data ///< Buffer with message data.
buffer_type const &data ///< Buffer with message data.
) override;
/// Perform all scheduled housekeeping functions.
int housekeeping() override;
Expand Down Expand Up @@ -3208,68 +3205,65 @@ detail::Assignment::getMask() const
return *m_mask_assign;
}

inline MsgBuffer::MsgBuffer() : super_type(), _count(0) {}
inline MsgBuffer::MsgBuffer(super_type const &that) : super_type(that), _count(0) {}
inline MsgBuffer::MsgBuffer(void *p, size_t n) : super_type(static_cast<char *>(p), n), _count(0) {}
inline MsgBuffer::MsgBuffer() {}
inline MsgBuffer::MsgBuffer(buffer_type const &span) : _base(span), _active(span) {}

inline size_t
MsgBuffer::getSize() const
{
return _size;
return _base.size();
}
inline size_t
MsgBuffer::getCount() const
{
return _count;
return _active.size();
}
inline char *
MsgBuffer::getBase()
{
return _ptr;
return _base.data();
}
inline const char *
MsgBuffer::getBase() const
{
return _ptr;
return _base.data();
}
inline char *
MsgBuffer::getTail()
{
return _ptr + _count;
return _active.data();
}
inline size_t
MsgBuffer::getSpace() const
{
return _size - _count;
return _active.size();
}
inline MsgBuffer &
MsgBuffer::reset()
{
_count = 0;
_active = _base;
return *this;
}

inline MsgBuffer &
MsgBuffer::set(void *ptr, size_t n)
MsgBuffer::assign(buffer_type const &span)
{
_ptr = static_cast<char *>(ptr);
_size = n;
_count = 0;
_base = _active = span;
return *this;
}

inline MsgBuffer &
MsgBuffer::use(size_t n)
{
_count += std::min(n, this->getSpace());
_active.remove_prefix(n);
return *this;
}

inline MsgBuffer &
MsgBuffer::zero()
{
memset(_ptr, 0, _size);
_count = 0;
memset(_base, 0);
_active = _base;
return *this;
}

Expand Down Expand Up @@ -3619,7 +3613,7 @@ inline detail::cache::SeedRouter::SeedRouter() {}

inline detail::cache::SeedRouter::SeedRouter(uint32_t addr) : m_addr(addr), m_count(0), m_xmit(0) {}

inline BaseMsg::BaseMsg() : m_buffer(0, 0) {}
inline BaseMsg::BaseMsg() {}
inline MsgBuffer const &
BaseMsg::buffer() const
{
Expand Down
Loading