Skip to content

Commit

Permalink
[ch2901] Converted qpdu liid and network to shared_ptr strings, elimi…
Browse files Browse the repository at this point in the history
…nates two

string copies.
  • Loading branch information
cybermaggedon committed Mar 1, 2018
1 parent 48de435 commit 8af770a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
28 changes: 20 additions & 8 deletions src/delivery.C
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ bool delivery::ipv4_match(const_iterator& start,
// Cache manipulation
// FIXME: but this doesn't deal with templating.
if (md->mangled.find(saddr) == md->mangled.end()) {
md->mangled[saddr].liid =
boost::shared_ptr<std::string>(new std::string);
md->mangled[saddr].network =
boost::shared_ptr<std::string>(new std::string);
expand_template(md->liid, md->mangled[saddr].liid, saddr, link);
expand_template(md->network, md->mangled[saddr].network, saddr,
link);
Expand Down Expand Up @@ -175,6 +179,10 @@ bool delivery::ipv4_match(const_iterator& start,
// Cache manipulation
// FIXME: but this doesn't deal with templating.
if (md->mangled.find(daddr) == md->mangled.end()) {
md->mangled[saddr].liid =
boost::shared_ptr<std::string>(new std::string);
md->mangled[saddr].network =
boost::shared_ptr<std::string>(new std::string);
expand_template(md->liid, md->mangled[daddr].liid, daddr, link);
expand_template(md->network, md->mangled[daddr].network, daddr,
link);
Expand Down Expand Up @@ -236,6 +244,8 @@ bool delivery::ipv6_match(const_iterator& start,
// Cache manipulation
// FIXME: but this doesn't deal with templating.
if (md->mangled6.find(saddr) == md->mangled6.end()) {
md->mangled6[saddr].liid = boost::shared_ptr<std::string>();
md->mangled6[saddr].network = boost::shared_ptr<std::string>();
expand_template(md->liid, md->mangled6[saddr].liid, saddr,
link);
expand_template(md->network, md->mangled6[saddr].network, saddr,
Expand Down Expand Up @@ -267,6 +277,8 @@ bool delivery::ipv6_match(const_iterator& start,
// Cache manipulation
// FIXME: but this doesn't deal with templating.
if (md->mangled6.find(daddr) == md->mangled6.end()) {
md->mangled6[saddr].liid = boost::shared_ptr<std::string>();
md->mangled6[saddr].network = boost::shared_ptr<std::string>();
expand_template(md->liid, md->mangled6[daddr].liid, daddr,
link);
expand_template(md->network, md->mangled6[daddr].network, daddr,
Expand Down Expand Up @@ -683,12 +695,12 @@ void delivery::get_endpoints(std::list<sender_info>& info)
}

void delivery::expand_template(const std::string& in,
std::string& out,
boost::shared_ptr<std::string> out,
const tcpip::address& addr,
const link_info& link)
{

out.erase();
out->erase();

for(std::string::const_iterator it = in.begin(); it != in.end(); it++) {

Expand All @@ -697,14 +709,14 @@ void delivery::expand_template(const std::string& in,
it++;

if (it == in.end()) {
out.push_back('%');
out->push_back('%');
continue;
}

if (*it == 'i') {
std::string a;
addr.to_string(a);
out.append(a);
out->append(a);
continue;
}

Expand All @@ -721,23 +733,23 @@ void delivery::expand_template(const std::string& in,
buf << std::hex << std::setw(2) << std::setfill('0')
<< (unsigned int)*it;
}
out.append(buf.str());
out->append(buf.str());
continue;
}

if (*it == 'v') {
std::ostringstream buf;
buf << std::dec << std::setw(1) << link.vlan;
out.append(buf.str());
out->append(buf.str());
continue;
}

out.push_back(*it);
out->push_back(*it);
continue;

} else

out.push_back(*it);
out->push_back(*it);

}

Expand Down
7 changes: 4 additions & 3 deletions src/delivery.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <map>
#include <list>
#include <algorithm>
#include <boost/shared_ptr.hpp>

// Defines an endpoint.
class ep {
Expand Down Expand Up @@ -57,8 +58,8 @@ class ep {
// Results of a match, returned by ipv4_match and ipv6_match.
class match {
public:
std::string liid;
std::string network;
boost::shared_ptr<std::string> liid;
boost::shared_ptr<std::string> network;
};

// Internal ipv4_match and ipv6_match state.
Expand Down Expand Up @@ -173,7 +174,7 @@ class delivery : public parameters, public management, public packet_consumer {

// Expand liid/network template
static void expand_template(const std::string& in,
std::string& out,
boost::shared_ptr<std::string> out,
const tcpip::address& addr,
const link_info& link);

Expand Down
20 changes: 10 additions & 10 deletions src/sender.C
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

// Called to add packets to the queue.
void sender::deliver(timeval tv,
const std::string& liid, // LIID
const std::string& network, // Network
boost::shared_ptr<std::string> liid, // LIID
boost::shared_ptr<std::string> network, // Network
const_iterator& start, // Start of packet
const_iterator& end) // End of packet
{
Expand Down Expand Up @@ -47,9 +47,9 @@ void sender::deliver(timeval tv,
}

// Called to add packets to the queue.
void sender::target_up(const std::string& liid, // LIID
const std::string& network, // Network
const tcpip::address& addr) // Address
void sender::target_up(boost::shared_ptr<std::string> liid, // LIID
boost::shared_ptr<std::string> network, // Network
const tcpip::address& addr) // Address
{

// Get lock.
Expand Down Expand Up @@ -101,8 +101,8 @@ void sender::target_up(const std::string& liid, // LIID
}

// Called to add packets to the queue.
void sender::target_down(const std::string& liid, // LIID
const std::string& network) // Network
void sender::target_down(boost::shared_ptr<std::string> liid, // LIID
boost::shared_ptr<std::string> network) // Network
{

// Get lock.
Expand Down Expand Up @@ -201,7 +201,7 @@ void nhis11_sender::handle(qpdu_ptr next)
{

// Short-hand.
const std::string& liid = next->liid;
const std::string& liid = *(next->liid);

// Network is ignored, not used for NHIS.

Expand Down Expand Up @@ -266,8 +266,8 @@ void etsi_li_sender::handle(qpdu_ptr next)
{

// Short-hand.
const std::string& liid = next->liid;
const std::string& network = next->network;
const std::string& liid = *(next->liid);
const std::string& network = *(next->network);
const std::vector<unsigned char>& pdu = next->pdu;
const address_ptr addr = next->addr;

Expand Down
15 changes: 8 additions & 7 deletions src/sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class qpdu {
public:
enum { PDU, TARGET_UP, TARGET_DOWN } msg_type;
timeval tv; // Valid for: PDU
std::string liid; // Valid for: PDU, TARGET_UP/DOWN
std::string network; // Valid for: PDU, TARGET_UP/DOWN
boost::shared_ptr<std::string> liid; // Valid for: PDU, TARGET_UP/DOWN
boost::shared_ptr<std::string> network; // Valid for: PDU, TARGET_UP/DOWN
std::vector<unsigned char> pdu; // Valid for: PDU
address_ptr addr; // Valid for: TARGET_UP
};
Expand Down Expand Up @@ -68,15 +68,16 @@ class sender : public threads::thread {
typedef std::vector<unsigned char>::const_iterator const_iterator;

// Hints about targets coming on/off-stream
virtual void target_up(const std::string& l, const std::string& n,
virtual void target_up(boost::shared_ptr<std::string> l,
boost::shared_ptr<std::string> n,
const tcpip::address& a);
virtual void target_down(const std::string& liid,
const std::string& n);
virtual void target_down(boost::shared_ptr<std::string> liid,
boost::shared_ptr<std::string> n);

// Called to push a packet down the sender transport.
void deliver(timeval tv,
const std::string& liid,
const std::string& n,
boost::shared_ptr<std::string> liid,
boost::shared_ptr<std::string> n,
const_iterator& start,
const_iterator& end);

Expand Down

0 comments on commit 8af770a

Please sign in to comment.