Commit 845b9831 authored by Joseph Noir's avatar Joseph Noir

Use datagram handle to lookup remote UDP addresses

parent e0c8ff16
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
#include "caf/message.hpp" #include "caf/message.hpp"
#include "caf/io/datagram_handle.hpp"
#include "caf/io/broker_servant.hpp" #include "caf/io/broker_servant.hpp"
#include "caf/io/system_messages.hpp" #include "caf/io/datagram_handle.hpp"
#include "caf/io/network/ip_endpoint.hpp"
#include "caf/io/network/datagram_manager.hpp" #include "caf/io/network/datagram_manager.hpp"
#include "caf/io/network/ip_endpoint.hpp"
#include "caf/io/network/receive_buffer.hpp" #include "caf/io/network/receive_buffer.hpp"
#include "caf/io/system_messages.hpp"
namespace caf { namespace caf {
namespace io { namespace io {
...@@ -62,13 +62,16 @@ public: ...@@ -62,13 +62,16 @@ public:
/// Returns the local port of associated socket. /// Returns the local port of associated socket.
virtual uint16_t local_port() const = 0; virtual uint16_t local_port() const = 0;
/// Returns the address of the remote endpoint for the handle.
virtual std::string remote_addr(datagram_handle) const = 0;
/// Returns all the handles associated with this servant /// Returns all the handles associated with this servant
virtual std::vector<datagram_handle> hdls() const = 0; virtual std::vector<datagram_handle> hdls() const = 0;
/// Adds a new remote endpoint identified by the `ip_endpoint` to /// Adds a new remote endpoint identified by the `ip_endpoint` to
/// the related manager. /// the related manager.
virtual void add_endpoint(const network::ip_endpoint& ep, virtual void add_endpoint(const network::ip_endpoint& ep, datagram_handle hdl)
datagram_handle hdl) = 0; = 0;
virtual void remove_endpoint(datagram_handle hdl) = 0; virtual void remove_endpoint(datagram_handle hdl) = 0;
...@@ -96,4 +99,3 @@ using datagram_servant_ptr = intrusive_ptr<datagram_servant>; ...@@ -96,4 +99,3 @@ using datagram_servant_ptr = intrusive_ptr<datagram_servant>;
// Allows the `middleman_actor` to create an `datagram_servant` and then send it // Allows the `middleman_actor` to create an `datagram_servant` and then send it
// to the BASP broker. // to the BASP broker.
CAF_ALLOW_UNSAFE_MESSAGE_TYPE(caf::io::datagram_servant_ptr) CAF_ALLOW_UNSAFE_MESSAGE_TYPE(caf::io::datagram_servant_ptr)
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
#pragma once #pragma once
#include "caf/io/fwd.hpp"
#include "caf/io/datagram_servant.hpp" #include "caf/io/datagram_servant.hpp"
#include "caf/io/fwd.hpp"
#include "caf/io/network/native_socket.hpp"
#include "caf/io/network/datagram_handler_impl.hpp" #include "caf/io/network/datagram_handler_impl.hpp"
#include "caf/io/network/native_socket.hpp"
#include "caf/policy/udp.hpp" #include "caf/policy/udp.hpp"
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
void flush() override; void flush() override;
std::string remote_addr(datagram_handle hdl) const override;
std::string addr() const override; std::string addr() const override;
uint16_t port(datagram_handle hdl) const override; uint16_t port(datagram_handle hdl) const override;
......
...@@ -320,7 +320,8 @@ datagram_handle abstract_broker::datagram_hdl_by_port(uint16_t port) { ...@@ -320,7 +320,8 @@ datagram_handle abstract_broker::datagram_hdl_by_port(uint16_t port) {
std::string abstract_broker::remote_addr(datagram_handle hdl) { std::string abstract_broker::remote_addr(datagram_handle hdl) {
auto i = datagram_servants_.find(hdl); auto i = datagram_servants_.find(hdl);
return i != datagram_servants_.end() ? i->second->addr() : std::string{}; return i != datagram_servants_.end() ? i->second->remote_addr(hdl)
: std::string{};
} }
uint16_t abstract_broker::remote_port(datagram_handle hdl) { uint16_t abstract_broker::remote_port(datagram_handle hdl) {
......
...@@ -94,6 +94,14 @@ std::string datagram_servant_impl::addr() const { ...@@ -94,6 +94,14 @@ std::string datagram_servant_impl::addr() const {
return *x; return *x;
} }
std::string datagram_servant_impl::remote_addr(datagram_handle hdl) const {
auto& eps = handler_.endpoints();
auto itr = eps.find(hdl);
if (itr == eps.end())
return 0;
return network::host(itr->second);
}
uint16_t datagram_servant_impl::port(datagram_handle hdl) const { uint16_t datagram_servant_impl::port(datagram_handle hdl) const {
auto& eps = handler_.endpoints(); auto& eps = handler_.endpoints();
auto itr = eps.find(hdl); auto itr = eps.find(hdl);
......
...@@ -373,6 +373,9 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl, ...@@ -373,6 +373,9 @@ datagram_servant_ptr test_multiplexer::new_datagram_servant(datagram_handle hdl,
void flush() override { void flush() override {
// nop // nop
} }
std::string remote_addr(datagram_handle) const override {
return "test";
}
std::string addr() const override { std::string addr() const override {
return "test"; return "test";
} }
......
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