Commit 37516575 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1539] refactoring: move push details to the forwarder holder.

this will simplify the main code, and allow the underlying forwarder
to be hidden as private.  also, expecting we'll eventually use this for
xfrout, it will help reduce duplicate code.
parent 2570f273
......@@ -130,10 +130,39 @@ public:
}
}
BaseSocketSessionForwarder& forwarder_;
// Push a socket session corresponding to given IOMessage.
//
// NOTE: Right now, there's no API to retrieve the local address from
// the IOMessage. Until it's added, we pass the remote address as
// local.
//
// If the underlying forwarder throws on push(), the exception will be
// propagated to the caller.
void push(const IOMessage& io_message) {
const IOEndpoint& remote_ep = io_message.getRemoteEndpoint();
const int protocol = remote_ep.getProtocol();
const int sock_type = getSocketType(protocol);
forwarder_.push(io_message.getSocket().getNative(),
remote_ep.getFamily(), sock_type, protocol,
remote_ep.getSockAddr(), remote_ep.getSockAddr(),
io_message.getData(), io_message.getDataSize());
}
private:
BaseSocketSessionForwarder& forwarder_;
bool connected_;
static int getSocketType(int protocol) {
switch (protocol) {
case IPPROTO_UDP:
return (SOCK_DGRAM);
case IPPROTO_TCP:
return (SOCK_STREAM);
default:
isc_throw(isc::InvalidParameter,
"Unexpected socket address family: " << protocol);
}
}
};
}
......@@ -787,19 +816,8 @@ AuthSrvImpl::processUpdate(const IOMessage& io_message,
OutputBuffer& /*buffer*/,
std::auto_ptr<TSIGContext> /*tsig_context*/)
{
// hardcode for initial test
ddns_forwarder_.connect();
const IOEndpoint& remote_ep = io_message.getRemoteEndpoint();
const int protocol = remote_ep.getProtocol();
const int sock_type = (protocol == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
ddns_forwarder_.forwarder_.push(io_message.getSocket().getNative(),
remote_ep.getFamily(), sock_type, protocol,
// XXX: no I/F to get local
remote_ep.getSockAddr(),
remote_ep.getSockAddr(),
io_message.getData(),
io_message.getDataSize());
ddns_forwarder_.push(io_message);
return (false);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment